Thomas Buck před 10 roky
rodič
revize
6984585d1b
5 změnil soubory, kde provedl 203 přidání a 383 odebrání
  1. 2
    0
      include/Entity.h
  2. 10
    3
      include/SkeletalModel.h
  3. 10
    3
      src/Entity.cpp
  4. 59
    366
      src/Render.cpp
  5. 122
    11
      src/SkeletalModel.cpp

+ 2
- 0
include/Entity.h Zobrazit soubor

31
 
31
 
32
     SkeletalModel &getModel();
32
     SkeletalModel &getModel();
33
     void setSkeletalModel(unsigned int model);
33
     void setSkeletalModel(unsigned int model);
34
+    MoveType getMoveType();
34
     void setMoveType(MoveType m);
35
     void setMoveType(MoveType m);
35
     int getObjectId();
36
     int getObjectId();
36
     void setAngles(vec_t yaw, vec_t pitch);
37
     void setAngles(vec_t yaw, vec_t pitch);
37
     vec_t getPos(unsigned int i);
38
     vec_t getPos(unsigned int i);
38
     vec_t getAngle(unsigned int i);
39
     vec_t getAngle(unsigned int i);
40
+    int getRoom();
39
 
41
 
40
     // Animation State
42
     // Animation State
41
     unsigned int getAnimation();
43
     unsigned int getAnimation();

+ 10
- 3
include/SkeletalModel.h Zobrazit soubor

16
 
16
 
17
 class BoneTag {
17
 class BoneTag {
18
 public:
18
 public:
19
-    BoneTag();
19
+    BoneTag(TombRaider &tr, unsigned int index, int j, unsigned int *l);
20
+    void display();
21
+
22
+    void getOffset(vec3_t o);
23
+    void getRotation(vec3_t r);
24
+    char getFlag();
20
 
25
 
21
 private:
26
 private:
22
     int mesh;
27
     int mesh;
27
 
32
 
28
 class BoneFrame {
33
 class BoneFrame {
29
 public:
34
 public:
30
-    BoneFrame();
35
+    BoneFrame(TombRaider &tr, unsigned int index, unsigned int i, unsigned int frame_offset);
31
     ~BoneFrame();
36
     ~BoneFrame();
32
 
37
 
33
     unsigned int size();
38
     unsigned int size();
42
 
47
 
43
 class AnimationFrame {
48
 class AnimationFrame {
44
 public:
49
 public:
45
-    AnimationFrame();
50
+    AnimationFrame(TombRaider &tr, unsigned int index, unsigned int i, int a);
46
     ~AnimationFrame();
51
     ~AnimationFrame();
47
 
52
 
48
     unsigned int size();
53
     unsigned int size();
58
 public:
63
 public:
59
     SkeletalModel(TombRaider &tr, unsigned int index, unsigned int i, int objectId);
64
     SkeletalModel(TombRaider &tr, unsigned int index, unsigned int i, int objectId);
60
     ~SkeletalModel();
65
     ~SkeletalModel();
66
+    void display(unsigned int aframe, unsigned int bframe);
67
+
61
     int getId();
68
     int getId();
62
     void setPigTail(bool b);
69
     void setPigTail(bool b);
63
     void setPonyPos(vec_t x, vec_t y, vec_t z, vec_t angle);
70
     void setPonyPos(vec_t x, vec_t y, vec_t z, vec_t angle);

+ 10
- 3
src/Entity.cpp Zobrazit soubor

18
 
18
 
19
 #include "Entity.h"
19
 #include "Entity.h"
20
 #include "main.h"
20
 #include "main.h"
21
+#include "Render.h"
21
 
22
 
22
 #include "games/TombRaider1.h"
23
 #include "games/TombRaider1.h"
23
 
24
 
66
 }
67
 }
67
 
68
 
68
 void Entity::display() {
69
 void Entity::display() {
69
-    /*
70
     glPushMatrix();
70
     glPushMatrix();
71
     glTranslatef(pos[0], pos[1], pos[2]);
71
     glTranslatef(pos[0], pos[1], pos[2]);
72
     glRotatef(angles[1], 0, 1, 0);
72
     glRotatef(angles[1], 0, 1, 0);
73
-    getWorld().getSkeletalModel(skeletalModel).display();
73
+    getWorld().getSkeletalModel(skeletalModel).display(animationFrame, boneFrame);
74
     glPopMatrix();
74
     glPopMatrix();
75
-    */
75
+
76
+    // Cycle frames
77
+    if (getRender().getFlags() & Render::fAnimateAllModels) {
78
+        if (boneFrame < (getModel().get(animationFrame).size() - 1))
79
+            boneFrame++;
80
+        else
81
+            boneFrame = 0;
82
+    }
76
 }
83
 }
77
 
84
 
78
 void Entity::move(char movement) {
85
 void Entity::move(char movement) {

+ 59
- 366
src/Render.cpp Zobrazit soubor

28
 #include "Render.h"
28
 #include "Render.h"
29
 #include "utils/strings.h"
29
 #include "utils/strings.h"
30
 
30
 
31
-bool compareEntites(const void *voidA, const void *voidB)
32
-{
33
-    entity_t *a = (entity_t *)voidA, *b = (entity_t *)voidB;
34
-    vec_t distA, distB;
35
-
36
-    if (!a || !b)
37
-        return false; // error really
38
-
39
-    distA = getRender().mViewVolume.getDistToSphereFromNear(a->pos[0],
40
-            a->pos[1],
41
-            a->pos[2],
42
-            1.0f);
43
-    distB = getRender().mViewVolume.getDistToSphereFromNear(b->pos[0],
44
-            b->pos[1],
45
-            b->pos[2],
46
-            1.0f);
47
-
48
-    return (distA < distB);
49
-}
50
-
51
-////////////////////////////////////////////////////////////
52
-// Constructors
53
-////////////////////////////////////////////////////////////
54
-
55
-Render::Render()
56
-{
31
+Render::Render() {
57
     mSkyMesh = -1;
32
     mSkyMesh = -1;
58
     mSkyMeshRotation = false;
33
     mSkyMeshRotation = false;
59
     mMode = Render::modeDisabled;
34
     mMode = Render::modeDisabled;
64
 }
39
 }
65
 
40
 
66
 
41
 
67
-Render::~Render()
68
-{
42
+Render::~Render() {
69
     ClearWorld();
43
     ClearWorld();
70
 }
44
 }
71
 
45
 
72
 
46
 
73
-////////////////////////////////////////////////////////////
74
-// Public Accessors
75
-////////////////////////////////////////////////////////////
76
-
77
 void Render::screenShot(char *filenameBase)
47
 void Render::screenShot(char *filenameBase)
78
 {
48
 {
79
     mTexture.glScreenShot(filenameBase, getWindow().mWidth, getWindow().mHeight);
49
     mTexture.glScreenShot(filenameBase, getWindow().mWidth, getWindow().mHeight);
83
     return mFlags;
53
     return mFlags;
84
 }
54
 }
85
 
55
 
86
-////////////////////////////////////////////////////////////
87
-// Public Mutators
88
-////////////////////////////////////////////////////////////
89
-
90
 
56
 
91
 void Render::loadTexture(unsigned char *image,
57
 void Render::loadTexture(unsigned char *image,
92
         unsigned int width, unsigned int height,
58
         unsigned int width, unsigned int height,
128
 
94
 
129
 void Render::ClearWorld() {
95
 void Render::ClearWorld() {
130
     mRoomRenderList.clear();
96
     mRoomRenderList.clear();
131
-
132
-    for (unsigned int i = 0; i < mModels.size(); i++) {
133
-        if (mModels[i])
134
-            delete mModels[i];
135
-    }
136
-    mModels.clear();
137
 }
97
 }
138
 
98
 
139
 
99
 
235
 
195
 
236
 void Render::clearFlags(unsigned int flags)
196
 void Render::clearFlags(unsigned int flags)
237
 {
197
 {
238
-    // _defaults |= flags; // Force removal if it wasn't set
239
-    mFlags ^= flags;
198
+    mFlags &= ~flags;
240
 
199
 
241
     if (flags & Render::fFog)
200
     if (flags & Render::fFog)
242
     {
201
     {
354
 
313
 
355
 void Render::display()
314
 void Render::display()
356
 {
315
 {
357
-    vec3_t curPos;
358
-    vec3_t camPos;
359
-    vec3_t atPos;
360
-    int index;
361
-
362
     switch (mMode)
316
     switch (mMode)
363
     {
317
     {
364
         case Render::modeDisabled:
318
         case Render::modeDisabled:
368
             drawLoadScreen();
322
             drawLoadScreen();
369
             return;
323
             return;
370
         default:
324
         default:
371
-            ;
325
+            break;
372
     }
326
     }
373
 
327
 
374
     if (mMode == Render::modeWireframe)
328
     if (mMode == Render::modeWireframe)
376
     else
330
     else
377
         glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
331
         glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
378
 
332
 
379
-    index = -1;
333
+    float camOffsetH = 0.0f;
380
 
334
 
381
-    if (getGame().mLara)
335
+    switch (getGame().getLara().getMoveType())
382
     {
336
     {
383
-        float yaw;
384
-        int sector;
385
-        float camOffsetH = 0.0f;
386
-
387
-
388
-        switch (getGame().mLara->moveType)
389
-        {
390
-            case worldMoveType_fly:
391
-            case worldMoveType_noClipping:
392
-            case worldMoveType_swim:
393
-                camOffsetH = 64.0f;
394
-                break;
395
-            case worldMoveType_walk:
396
-            case worldMoveType_walkNoSwim:
397
-                camOffsetH = 512.0f;
398
-                break;
399
-        }
400
-
401
-        curPos[0] = getGame().mLara->pos[0];
402
-        curPos[1] = getGame().mLara->pos[1];
403
-        curPos[2] = getGame().mLara->pos[2];
404
-        yaw = getGame().mLara->angles[1];
405
-
406
-        index = getGame().mLara->room;
337
+        case Entity::MoveTypeFly:
338
+        case Entity::MoveTypeNoClipping:
339
+        case Entity::MoveTypeSwim:
340
+            camOffsetH = 64.0f;
341
+            break;
342
+        case Entity::MoveTypeWalk:
343
+        case Entity::MoveTypeWalkNoSwim:
344
+            camOffsetH = 512.0f;
345
+            break;
346
+    }
407
 
347
 
408
-        // Mongoose 2002.08.24, New 3rd person camera hack
409
-        camPos[0] = curPos[0];
410
-        camPos[1] = curPos[1] - camOffsetH; // UP is lower val
411
-        camPos[2] = curPos[2];
348
+    vec3_t curPos;
349
+    vec3_t camPos;
350
+    vec3_t atPos;
412
 
351
 
413
-        camPos[0] -= (1024.0f * sinf(yaw));
414
-        camPos[2] -= (1024.0f * cosf(yaw));
352
+    curPos[0] = getGame().getLara().getPos(0);
353
+    curPos[1] = getGame().getLara().getPos(1);
354
+    curPos[2] = getGame().getLara().getPos(2);
355
+    vec_t yaw = getGame().getLara().getAngle(1);
415
 
356
 
416
-        sector = getWorld().getSector(index, camPos[0], camPos[2]);
357
+    // Mongoose 2002.08.24, New 3rd person camera hack
358
+    camPos[0] = curPos[0] - (1024.0f * sinf(yaw));
359
+    camPos[1] = curPos[1] - camOffsetH; // UP is lower val
360
+    camPos[2] = curPos[2] - (1024.0f * cosf(yaw));
417
 
361
 
418
-        // Handle camera out of world
419
-        if (sector < 0 || getWorld().isWall(index, sector))
420
-        {
421
-            camPos[0] = curPos[0] + (64.0f * sinf(yaw));
422
-            camPos[1] -= 64.0f;
423
-            camPos[2] = curPos[2] + (64.0f * cosf(yaw));
424
-        }
362
+    int index = getGame().getLara().getRoom();
363
+    int sector = getWorld().getSector(index, camPos[0], camPos[2]);
425
 
364
 
426
-        getCamera().setPosition(camPos);
365
+    // Handle camera out of world
366
+    if (sector < 0 || getWorld().isWall(index, sector)) {
367
+        camPos[0] = curPos[0] + (64.0f * sinf(yaw));
368
+        camPos[1] -= 64.0f;
369
+        camPos[2] = curPos[2] + (64.0f * cosf(yaw));
427
     }
370
     }
428
 
371
 
429
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
372
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
430
     glLoadIdentity();
373
     glLoadIdentity();
431
 
374
 
432
     // Setup view in OpenGL with camera
375
     // Setup view in OpenGL with camera
376
+    getCamera().setPosition(camPos);
433
     getCamera().update();
377
     getCamera().update();
434
-    getCamera().getPosition(camPos);
435
     getCamera().getTarget(atPos);
378
     getCamera().getTarget(atPos);
436
     // Mongoose 2002.08.13, Quick fix to render OpenRaider upside down
379
     // Mongoose 2002.08.13, Quick fix to render OpenRaider upside down
437
-
438
     gluLookAt(camPos[0], camPos[1], camPos[2], atPos[0], atPos[1], atPos[2], 0.0f, -1.0f, 0.0f);
380
     gluLookAt(camPos[0], camPos[1], camPos[2], atPos[0], atPos[1], atPos[2], 0.0f, -1.0f, 0.0f);
439
 
381
 
440
     // Update view volume for vising
382
     // Update view volume for vising
441
     updateViewVolume();
383
     updateViewVolume();
442
 
384
 
443
-    // Let's see the LoS -- should be event controled
444
-    if (getGame().mLara)
445
-    {
446
-        // SkeletalModel *mdl = getGame().mLara->tmpHook;
447
-
448
-        // Draw in solid colors
449
-        glDisable(GL_TEXTURE_2D);
450
-        glDisable(GL_CULL_FACE);
451
-
452
-        if (getGame().mLara->state == 64) // eWeaponFire
453
-        {
454
-            vec3_t u, v; //, s, t;
455
-
456
-            // Center of getGame().mLara
457
-            u[0] = curPos[0];
458
-            u[1] = curPos[1] - 512.0f;
459
-            u[2] = curPos[2];
460
-
461
-            // Location getGame().mLara is aiming at?  ( Not finished yet )
462
-            v[0] = u[0] + (9000.0f * sinf(getGame().mLara->angles[1]));
463
-            v[1] = u[1] + (9000.0f * sinf(getGame().mLara->angles[2]));
464
-            v[2] = u[2] + (9000.0f * cosf(getGame().mLara->angles[1]));
465
-
466
-            // Test tracing of aim
467
-            renderTrace(0, u, v); // v = target
468
-        }
469
-
470
-        glEnable(GL_CULL_FACE);
471
-        glEnable(GL_TEXTURE_2D);
472
-    }
473
-
474
     // Render world
385
     // Render world
475
     glColor3fv(DIM_WHITE); // was WHITE
386
     glColor3fv(DIM_WHITE); // was WHITE
476
     drawSkyMesh(96.0);
387
     drawSkyMesh(96.0);
479
     newRoomRenderList(index);
390
     newRoomRenderList(index);
480
 
391
 
481
     // Room solid pass, need to do depth sorting to avoid 2 pass render
392
     // Room solid pass, need to do depth sorting to avoid 2 pass render
482
-    for (unsigned int i = 0; i < mRoomRenderList.size(); i++)
483
-    {
393
+    for (unsigned int i = 0; i < mRoomRenderList.size(); i++) {
484
         Room &room = *mRoomRenderList[i];
394
         Room &room = *mRoomRenderList[i];
485
 
395
 
486
         if (mFlags & Render::fGL_Lights)
396
         if (mFlags & Render::fGL_Lights)
487
-        {
488
             lightRoom(room);
397
             lightRoom(room);
489
-        }
490
 
398
 
491
         room.display(false);
399
         room.display(false);
492
     }
400
     }
493
 
401
 
494
     // Draw all visible enities
402
     // Draw all visible enities
495
-    if (mFlags & Render::fEntityModels)
496
-    {
497
-        entity_t *e;
498
-        std::vector<entity_t *> entityRenderList;
499
-        std::vector<entity_t *> *entities = getWorld().getEntities();
403
+    if (mFlags & Render::fEntityModels) {
404
+        std::vector<Entity *> entityRenderList;
500
 
405
 
501
-        for (unsigned int i = 0; i < entities->size(); i++)
502
-        {
503
-            e = entities->at(i);
406
+        for (unsigned int i = 0; i < getWorld().sizeEntity(); i++) {
407
+            Entity &e = getWorld().getEntity(i);
504
 
408
 
505
-            // Mongoose 2002.03.26, Don't show lara to it's own player
506
-            if (!e || e == getGame().mLara)
507
-            {
409
+            // Don't show Lara to the player
410
+            if (&e == &getGame().getLara())
508
                 continue;
411
                 continue;
509
-            }
510
 
412
 
511
             // Mongoose 2002.08.15, Nothing to draw, skip
413
             // Mongoose 2002.08.15, Nothing to draw, skip
512
-            // Mongoose 2002.12.24, Some entities have no animation  =p
513
-            if (e->tmpHook)
514
-                if (e->tmpHook->model->animation.empty())
414
+            // Mongoose 2002.12.24, Some entities have no animation =p
415
+            if (e.getModel().size() == 0)
515
                     continue;
416
                     continue;
516
 
417
 
517
             // Is it in view volume? ( Hack to use sphere )
418
             // Is it in view volume? ( Hack to use sphere )
518
-            if (!isVisible(e->pos[0], e->pos[1], e->pos[2], 512.0f))
419
+            if (!isVisible(e.getPos(0), e.getPos(1), e.getPos(2), 512.0f))
519
                 continue;
420
                 continue;
520
 
421
 
521
             //! \fixme Is it in a room we're rendering?
422
             //! \fixme Is it in a room we're rendering?
524
             //  continue;
425
             //  continue;
525
             //}
426
             //}
526
 
427
 
527
-            entityRenderList.push_back(e);
428
+            entityRenderList.push_back(&e);
528
         }
429
         }
529
 
430
 
530
         // Draw objects not tied to rooms
431
         // Draw objects not tied to rooms
533
         glPopMatrix();
434
         glPopMatrix();
534
 
435
 
535
         // Depth sort entityRenderList with qsort
436
         // Depth sort entityRenderList with qsort
536
-        std::sort(entityRenderList.begin(), entityRenderList.end(), compareEntites);
537
-
538
-        for (unsigned int i = 0; i < entityRenderList.size(); i++)
539
-        {
540
-            e = entityRenderList[i];
437
+        std::sort(entityRenderList.begin(), entityRenderList.end());
541
 
438
 
542
-            glPushMatrix();
543
-            glTranslatef(e->pos[0], e->pos[1], e->pos[2]);
544
-            glRotatef(e->angles[1], 0, 1, 0);
545
-            drawModel(e->tmpHook);
546
-            glPopMatrix();
439
+        for (unsigned int i = 0; i < entityRenderList.size(); i++) {
440
+            entityRenderList[i]->display();
547
         }
441
         }
548
     }
442
     }
549
 
443
 
550
     // Room alpha pass
444
     // Room alpha pass
551
     // Skip room alpha pass for modes w/o texture
445
     // Skip room alpha pass for modes w/o texture
552
-    if (!(mMode == Render::modeSolid || mMode == Render::modeWireframe))
553
-    {
446
+    if (!(mMode == Render::modeSolid || mMode == Render::modeWireframe)) {
554
         for (unsigned int i = 0; i < mRoomRenderList.size(); i++)
447
         for (unsigned int i = 0; i < mRoomRenderList.size(); i++)
555
-        {
556
             mRoomRenderList[i]->display(true);
448
             mRoomRenderList[i]->display(true);
557
-        }
558
     }
449
     }
559
 
450
 
560
     if (mMode == Render::modeWireframe)
451
     if (mMode == Render::modeWireframe)
711
 
602
 
712
 void Render::drawSkyMesh(float scale)
603
 void Render::drawSkyMesh(float scale)
713
 {
604
 {
714
-    skeletal_model_t *model = getWorld().getModel(mSkyMesh);
715
-
716
-
717
-    if (!model)
718
-        return;
605
+    //skeletal_model_t *model = getWorld().getModel(mSkyMesh);
606
+    //if (!model)
607
+    //    return;
719
 
608
 
720
     glDisable(GL_DEPTH_TEST);
609
     glDisable(GL_DEPTH_TEST);
721
     glPushMatrix();
610
     glPushMatrix();
734
 }
623
 }
735
 
624
 
736
 
625
 
737
-void Render::drawObjects()
738
-{
626
+void Render::drawObjects() {
739
     // Draw lara or other player model ( move to entity rendering method )
627
     // Draw lara or other player model ( move to entity rendering method )
740
-    if (mFlags & Render::fViewModel && getGame().mLara && getGame().mLara->tmpHook)
741
-    {
742
-        glPushMatrix();
743
-
744
-        glTranslated(getGame().mLara->pos[0], getGame().mLara->pos[1], getGame().mLara->pos[2]);
745
-        glRotated(OR_RAD_TO_DEG(getCamera().getRadianYaw()), 0, 1, 0);
628
+    if (mFlags & Render::fViewModel)
629
+        getGame().getLara().display();
746
 
630
 
747
-        drawModel(getGame().mLara->tmpHook);
748
-        glPopMatrix();
749
-    }
750
-
751
-    // Mongoose 2002.03.22, Draw sprites after player to handle alpha
631
+    // Draw sprites after player to handle alpha
752
     for (unsigned int i = 0; i < getWorld().sizeSprite(); i++) {
632
     for (unsigned int i = 0; i < getWorld().sizeSprite(); i++) {
753
         SpriteSequence &sprite = getWorld().getSprite(i);
633
         SpriteSequence &sprite = getWorld().getSprite(i);
754
         for (unsigned int j = 0; j < sprite.size(); j++)
634
         for (unsigned int j = 0; j < sprite.size(); j++)
757
 }
637
 }
758
 
638
 
759
 
639
 
760
-void Render::drawModel(SkeletalModel *model)
761
-{
762
-    animation_frame_t *animation;
763
-    bone_frame_t *boneframe;
764
-    bone_frame_t *boneframe2 = 0x0;
765
-    bone_tag_t *tag;
766
-    bone_tag_t *tag2;
767
-    int bframe, aframe;
768
-    skeletal_model_t *mdl;
769
-
770
-
771
-    if (!model || !model->model)
772
-        return;
773
-
774
-    mdl = model->model;
775
-    aframe = model->getAnimation();
776
-    bframe = model->getFrame();
777
-    animation = mdl->animation[aframe];
778
-
779
-    if (!animation)
780
-    {
781
-#ifdef DEBUG
782
-        printf("ERROR: No animation for model[%i].aframe[%i] %lu\n",
783
-                mdl->id, aframe, mdl->animation.size());
784
-#endif
785
-        return;
786
-    }
787
-
788
-    if (animation->frame.empty())
789
-    {
790
-#ifdef DEBUG
791
-        printf("ERROR: No boneframes?!?!  *** %i:%i ***\n",
792
-                mdl->id, bframe);
793
-#endif
794
-        return;
795
-    }
796
-
797
-    boneframe = animation->frame[bframe];
798
-
799
-    if (!boneframe)
800
-        return;
801
-
802
-    if (boneframe->tag.empty())
803
-    {
804
-        printf("Empty bone frame?!?!\n");
805
-        return;
806
-    }
807
-
808
-    glTranslatef(boneframe->pos[0], boneframe->pos[1], boneframe->pos[2]);
809
-
810
-    for (unsigned int a = 0; a < boneframe->tag.size(); a++)
811
-    {
812
-        tag = boneframe->tag[a];
813
-
814
-        if (!tag)
815
-            continue;
816
-
817
-        if (a == 0)
818
-        {
819
-            if (!equalEpsilon(tag->rot[1], 0.0f)) // was just if (tag->rot[1])
820
-                glRotatef(tag->rot[1], 0, 1, 0);
821
-
822
-            if (!equalEpsilon(tag->rot[0], 0.0f))
823
-                glRotatef(tag->rot[0], 1, 0, 0);
824
-
825
-            if (!equalEpsilon(tag->rot[2], 0.0f))
826
-                glRotatef(tag->rot[2], 0, 0, 1);
827
-        }
828
-        else
829
-        {
830
-            if (tag->flag & 0x01)
831
-                glPopMatrix();
832
-
833
-            if (tag->flag & 0x02)
834
-                glPushMatrix();
835
-
836
-            glTranslatef(tag->off[0], tag->off[1], tag->off[2]);
837
-
838
-            if (!equalEpsilon(tag->rot[1], 0.0f))
839
-                glRotatef(tag->rot[1], 0, 1, 0);
840
-
841
-            if (!equalEpsilon(tag->rot[0], 0.0f))
842
-                glRotatef(tag->rot[0], 1, 0, 0);
843
-
844
-            if (!equalEpsilon(tag->rot[2], 0.0f))
845
-                glRotatef(tag->rot[2], 0, 0, 1);
846
-        }
847
-
848
-        // Draw layered lara in TR4 ( 2 meshes per tag )
849
-        if (mdl->tr4Overlay == 1)
850
-        {
851
-            boneframe2 = (mdl->animation[0])->frame[0];
852
-
853
-            if (boneframe2)
854
-            {
855
-                tag2 = boneframe2->tag[a];
856
-
857
-                if (tag2)
858
-                {
859
-                    drawModelMesh(getWorld().getMesh(tag2->mesh));
860
-                }
861
-            }
862
-        }
863
-
864
-        if (mFlags & Render::fRenderPonytail)
865
-        {
866
-            if (mdl->ponytailId > 0 &&
867
-                    a == 14)
868
-            {
869
-                glPushMatrix();
870
-
871
-                // Mongoose 2002.08.30, TEST to align offset
872
-                glTranslatef(mdl->ponytail[0], mdl->ponytail[1], mdl->ponytail[2]);
873
-                glRotatef(mdl->ponytailAngle, 1, 0, 0);
874
-
875
-                // HACK: To fill TR4 void between ponytail/head
876
-                //   since no vertex welds are implemented yet
877
-                if (mdl->tr4Overlay == 1)
878
-                {
879
-                    glScalef(1.20f, 1.20f, 1.20f);
880
-                }
881
-
882
-#ifdef EXPERIMENTAL_NON_ITEM_RENDER
883
-                drawModel(mModels[mdl->ponytail], 0, 0);
884
-#else
885
-                for (unsigned int i = 0; i < mdl->ponytailNumMeshes; ++i)
886
-                {
887
-                    glPushMatrix();
888
-
889
-                    if (i > 0)
890
-                    {
891
-                        glRotatef(randomNum(-8.0f, -10.0f), 1, 0, 0);
892
-                        glRotatef(randomNum(-5.0f, 5.0f), 0, 1, 0);
893
-                        glRotatef(randomNum(-5.0f, 5.0f), 0, 0, 1);
894
-
895
-                        glTranslatef(0.0, 0.0, mdl->ponyOff);
896
-                    }
897
-
898
-                    if (mdl->pigtails)
899
-                    {
900
-                        glPushMatrix();
901
-                        glTranslatef(mdl->ponyOff2, 0.0, 0.0);
902
-                        drawModelMesh(getWorld().getMesh(mdl->ponytailMeshId + i));
903
-                        glPopMatrix();
904
-
905
-                        glPushMatrix();
906
-                        glTranslatef(-mdl->ponyOff2, 0.0, 0.0);
907
-                        drawModelMesh(getWorld().getMesh(mdl->ponytailMeshId + i));
908
-                        glPopMatrix();
909
-                    }
910
-                    else
911
-                    {
912
-                        drawModelMesh(getWorld().getMesh(mdl->ponytailMeshId + i));
913
-                    }
914
-                }
915
-
916
-                for (unsigned int i = 0; i < mdl->ponytailNumMeshes; ++i)
917
-                {
918
-                    glPopMatrix();
919
-                }
920
-#endif
921
-                glPopMatrix();
922
-            }
923
-        }
924
-
925
-        drawModelMesh(getWorld().getMesh(tag->mesh));
926
-    }
927
-
928
-    // Cycle frames ( cheap hack from old ent state based system )
929
-    if (mFlags & fAnimateAllModels)
930
-    {
931
-        if (model->getFrame() + 1 > (int)animation->frame.size()-1)
932
-        {
933
-            model->setFrame(0);
934
-        }
935
-        else
936
-        {
937
-            model->setFrame(model->getFrame()+1);
938
-        }
939
-    }
940
-}
941
-
942
-
943
 void Render::tmpRenderModelMesh(model_mesh_t *r_mesh, texture_tri_t *ttri)
640
 void Render::tmpRenderModelMesh(model_mesh_t *r_mesh, texture_tri_t *ttri)
944
 {
641
 {
945
     glBegin(GL_TRIANGLES);
642
     glBegin(GL_TRIANGLES);
1111
 }
808
 }
1112
 
809
 
1113
 
810
 
1114
-void Render::addSkeletalModel(SkeletalModel *mdl)
1115
-{
1116
-    mModels.push_back(mdl);
1117
-}
1118
-
1119
-
1120
 void Render::updateViewVolume()
811
 void Render::updateViewVolume()
1121
 {
812
 {
1122
     matrix_t proj;
813
     matrix_t proj;
1131
 bool Render::isVisible(BoundingBox &box) {
822
 bool Render::isVisible(BoundingBox &box) {
1132
     vec3_t bbox[2];
823
     vec3_t bbox[2];
1133
     box.getBoundingBox(bbox);
824
     box.getBoundingBox(bbox);
825
+
1134
     // For debugging purposes
826
     // For debugging purposes
1135
     if (mMode == Render::modeWireframe)
827
     if (mMode == Render::modeWireframe)
1136
         box.display(true, PINK, RED);
828
         box.display(true, PINK, RED);
829
+
1137
     return mViewVolume.isBboxInFrustum(bbox[0], bbox[1]);
830
     return mViewVolume.isBboxInFrustum(bbox[0], bbox[1]);
1138
 }
831
 }
1139
 
832
 

+ 122
- 11
src/SkeletalModel.cpp Zobrazit soubor

12
 #include "SkeletalModel.h"
12
 #include "SkeletalModel.h"
13
 
13
 
14
 BoneTag::BoneTag(TombRaider &tr, unsigned int index, int j, unsigned int *l) {
14
 BoneTag::BoneTag(TombRaider &tr, unsigned int index, int j, unsigned int *l) {
15
-    tr2_moveable_t *moveable = mTombRaider.Moveable();
16
-    tr2_meshtree_t *meshtree = mTombRaider.MeshTree();
15
+    tr2_moveable_t *moveable = tr.Moveable();
16
+    tr2_meshtree_t *meshtree = tr.MeshTree();
17
 
17
 
18
     off[0] = 0.0;
18
     off[0] = 0.0;
19
     off[1] = 0.0;
19
     off[1] = 0.0;
27
     // Setup offsets to produce skeleton
27
     // Setup offsets to produce skeleton
28
     if (j == 0) {
28
     if (j == 0) {
29
         // Always push tag[0], this isn't really used either
29
         // Always push tag[0], this isn't really used either
30
-        tag->flag = 0x02;
30
+        flag = 0x02;
31
     } else { // Nonprimary tag - position relative to first tag
31
     } else { // Nonprimary tag - position relative to first tag
32
 
32
 
33
         // Hack: moveable[index].mesh_tree is a byte offset
33
         // Hack: moveable[index].mesh_tree is a byte offset
46
     tr.computeRotationAngles(&frame, &frame_offset, l, rot, rot+1, rot+2);
46
     tr.computeRotationAngles(&frame, &frame_offset, l, rot, rot+1, rot+2);
47
 }
47
 }
48
 
48
 
49
+BoneTag::display() {
50
+    getRender().drawModelMesh(getWorld().getMesh(mesh));
51
+}
52
+
49
 BoneFrame::BoneFrame(TombRaider &tr, unsigned int index, unsigned int i, unsigned int frame_offset) {
53
 BoneFrame::BoneFrame(TombRaider &tr, unsigned int index, unsigned int i, unsigned int frame_offset) {
50
-    tr2_moveable_t *moveable = mTombRaider.Moveable();
51
-    unsigned short *frame = mTombRaider.Frame();
54
+    tr2_moveable_t *moveable = tr.Moveable();
55
+    unsigned short *frame = tr.Frame();
52
 
56
 
53
     pos[0] = (short)frame[frame_offset + 6];
57
     pos[0] = (short)frame[frame_offset + 6];
54
     pos[1] = (short)frame[frame_offset + 7];
58
     pos[1] = (short)frame[frame_offset + 7];
83
 }
87
 }
84
 
88
 
85
 AnimationFrame::AnimationFrame(TombRaider &tr, unsigned int index, unsigned int i, int a) {
89
 AnimationFrame::AnimationFrame(TombRaider &tr, unsigned int index, unsigned int i, int a) {
86
-    tr2_moveable_t *moveable = mTombRaider.Moveable();
87
-    tr2_animation_t *animation = mTombRaider.Animation();
90
+    tr2_moveable_t *moveable = tr.Moveable();
91
+    tr2_animation_t *animation = tr.Animation();
88
 
92
 
89
     unsigned int frame_offset = animation[a].frame_offset / 2;
93
     unsigned int frame_offset = animation[a].frame_offset / 2;
90
     int frame_step = animation[a].frame_size;
94
     int frame_step = animation[a].frame_size;
147
 }
151
 }
148
 
152
 
149
 SkeletalModel::SkeletalModel(TombRaider &tr, unsigned int index, unsigned int i, int objectId) {
153
 SkeletalModel::SkeletalModel(TombRaider &tr, unsigned int index, unsigned int i, int objectId) {
150
-    tr2_moveable_t *moveable = mTombRaider.Moveable();
151
-    tr2_animation_t *anim = mTombRaider.Animation();
154
+    tr2_moveable_t *moveable = tr.Moveable();
155
+    tr2_animation_t *anim = tr.Animation();
152
 
156
 
153
     id = objectId;
157
     id = objectId;
154
 
158
 
155
     // Gather more info if this is lara
159
     // Gather more info if this is lara
156
     if (id == 0) {
160
     if (id == 0) {
157
         // Only TR4 lara has 2 layer bone tags/meshes per bone frame
161
         // Only TR4 lara has 2 layer bone tags/meshes per bone frame
158
-        tr4Overlay = (mTombRaider.Engine() == TR_VERSION_4);
162
+        tr4Overlay = (tr.Engine() == TR_VERSION_4);
159
         ponytailId = 0;
163
         ponytailId = 0;
160
     } else {
164
     } else {
161
         tr4Overlay = false;
165
         tr4Overlay = false;
162
         ponytailId = -1;
166
         ponytailId = -1;
163
     }
167
     }
164
 
168
 
165
-    switch (mTombRaider.Engine()) {
169
+    switch (tr.Engine()) {
166
         case TR_VERSION_4:
170
         case TR_VERSION_4:
167
             if (moveable[index].object_id == 30) {
171
             if (moveable[index].object_id == 30) {
168
                 ponytailId = getWorld().sizeSkeletalModel(); //! \fixme Why is this even needed?
172
                 ponytailId = getWorld().sizeSkeletalModel(); //! \fixme Why is this even needed?
240
         delete animation[i];
244
         delete animation[i];
241
 }
245
 }
242
 
246
 
247
+void SkeletalModel::display(unsigned int aframe, unsigned int bframe) {
248
+    assert(aframe < size());
249
+    assert(bframe < get(aframe).size());
250
+
251
+    AnimationFrame &animation = get(aframe);
252
+    BoneFrame &boneframe = animation.get(bframe);
253
+
254
+    if (boneframe.size() == 0) {
255
+        printf("Empty bone frame?!?!\n");
256
+        return;
257
+    }
258
+
259
+    glTranslatef(boneframe->pos[0], boneframe->pos[1], boneframe->pos[2]);
260
+
261
+    for (unsigned int a = 0; a < boneframe.size(); a++) {
262
+        BoneTag &tag = boneframe.get(a);
263
+        vec3_t rot, off;
264
+        tag.getRotation(rot);
265
+        tag.getOffset(off);
266
+
267
+        if (a == 0) {
268
+            if (!equalEpsilon(rot[1], 0.0f))
269
+                glRotatef(rot[1], 0, 1, 0);
270
+
271
+            if (!equalEpsilon(rot[0], 0.0f))
272
+                glRotatef(rot[0], 1, 0, 0);
273
+
274
+            if (!equalEpsilon(rot[2], 0.0f))
275
+                glRotatef(rot[2], 0, 0, 1);
276
+        } else {
277
+            if (tag.getFlag() & 0x01)
278
+                glPopMatrix();
279
+
280
+            if (tag.getFlag() & 0x02)
281
+                glPushMatrix();
282
+
283
+            glTranslatef(off[0], off[1], off[2]);
284
+
285
+            if (!equalEpsilon(rot[1], 0.0f))
286
+                glRotatef(rot[1], 0, 1, 0);
287
+
288
+            if (!equalEpsilon(rot[0], 0.0f))
289
+                glRotatef(rot[0], 1, 0, 0);
290
+
291
+            if (!equalEpsilon(rot[2], 0.0f))
292
+                glRotatef(rot[2], 0, 0, 1);
293
+        }
294
+
295
+        // Draw layered lara in TR4 (2 meshes per tag)
296
+        if (tr4Overlay) {
297
+            BoneFrame &boneframe2 = get(0).get(0); //! \fixme Woot?
298
+            if (a < boneframe2.size())
299
+                boneframe2.get(a).display();
300
+        }
301
+
302
+        if (getRender().getFlags() & Render::fRenderPonytail) {
303
+            if ((mdl->ponytailId > 0) && (a == 14)) {
304
+                glPushMatrix();
305
+
306
+                // Mongoose 2002.08.30, TEST to align offset
307
+                glTranslatef(ponytail[0], ponytail[1], ponytail[2]);
308
+                glRotatef(ponytailAngle, 1, 0, 0);
309
+
310
+                // HACK: To fill TR4 void between ponytail/head
311
+                //   since no vertex welds are implemented yet
312
+                if (tr4Overlay)
313
+                    glScalef(1.20f, 1.20f, 1.20f);
314
+
315
+#ifdef EXPERIMENTAL_NON_ITEM_RENDER
316
+                getWorld().getSkeletalModel(mdl->ponytail).display(0, 0);
317
+#else
318
+                for (unsigned int i = 0; i < ponytailNumMeshes; i++) {
319
+                    glPushMatrix();
320
+
321
+                    if (i > 0) {
322
+                        glRotatef(randomNum(-8.0f, -10.0f), 1, 0, 0);
323
+                        glRotatef(randomNum(-5.0f, 5.0f), 0, 1, 0);
324
+                        glRotatef(randomNum(-5.0f, 5.0f), 0, 0, 1);
325
+                        glTranslatef(0.0, 0.0, ponyOff);
326
+                    }
327
+
328
+                    if (pigtails) {
329
+                        glPushMatrix();
330
+                        glTranslatef(mdl->ponyOff2, 0.0, 0.0);
331
+                        getRender().drawModelMesh(getWorld().getMesh(mdl->ponytailMeshId + i));
332
+                        glPopMatrix();
333
+
334
+                        glPushMatrix();
335
+                        glTranslatef(-mdl->ponyOff2, 0.0, 0.0);
336
+                        getRender().drawModelMesh(getWorld().getMesh(mdl->ponytailMeshId + i));
337
+                        glPopMatrix();
338
+                    } else {
339
+                        getRender().drawModelMesh(getWorld().getMesh(mdl->ponytailMeshId + i));
340
+                    }
341
+                }
342
+
343
+                for (unsigned int i = 0; i < ponytailNumMeshes; i++)
344
+                    glPopMatrix();
345
+#endif
346
+                glPopMatrix();
347
+            }
348
+        }
349
+
350
+        tag.display();
351
+    }
352
+}
353
+
243
 int SkeletalModel::getId() {
354
 int SkeletalModel::getId() {
244
     return id;
355
     return id;
245
 }
356
 }

Loading…
Zrušit
Uložit