Browse Source

Created StaticMesh class

Thomas Buck 10 years ago
parent
commit
8fbca37731
13 changed files with 400 additions and 565 deletions
  1. 3
    0
      ChangeLog.md
  2. 0
    4
      include/Game.h
  3. 0
    14
      include/Render.h
  4. 57
    0
      include/StaticMesh.h
  5. 5
    14
      include/World.h
  6. 0
    45
      include/WorldData.h
  7. 1
    0
      src/CMakeLists.txt
  8. 8
    259
      src/Game.cpp
  9. 0
    164
      src/Render.cpp
  10. 3
    7
      src/RoomData.cpp
  11. 4
    4
      src/SkeletalModel.cpp
  12. 300
    0
      src/StaticMesh.cpp
  13. 19
    54
      src/World.cpp

+ 3
- 0
ChangeLog.md View File

@@ -2,6 +2,9 @@
2 2
 
3 3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
4 4
 
5
+    [ 20140621 ]
6
+    * Created StaticMesh class replacing model_mesh_t stuff
7
+
5 8
     [ 20140617 ]
6 9
     * Finally fixed SkeletalModel bugs introduced a month ago
7 10
       (animations and rotations are *mostly* correct now)

+ 0
- 4
include/Game.h View File

@@ -53,10 +53,6 @@ private:
53 53
     void processModels();
54 54
     void processRooms();
55 55
 
56
-#ifdef EXPERIMENTAL
57
-    void setupTextureColor(texture_tri_t *r_tri, float *colorf);
58
-#endif
59
-
60 56
     char *mName;
61 57
     bool mLoaded;
62 58
 

+ 0
- 14
include/Render.h View File

@@ -15,8 +15,6 @@
15 15
 #include "Texture.h"
16 16
 #include "ViewVolume.h"
17 17
 
18
-#include "WorldData.h"
19
-
20 18
 /*!
21 19
  * \brief OpenRaider Renderer class
22 20
  */
@@ -140,16 +138,7 @@ public:
140 138
 
141 139
     bool isVisible(BoundingBox &box);
142 140
 
143
-    /*!
144
-     * \brief Renders a mesh.
145
-     *
146
-     * Texture must be initialized.
147
-     * \param r_mesh Mesh to render.
148
-     */
149
-    void drawModelMesh(model_mesh_t *r_mesh);
150
-
151 141
     //! \fixme should be private
152
-
153 142
     ViewVolume mViewVolume; //!< View Volume for frustum culling
154 143
     Texture mTexture; //!< Texture subsystem
155 144
 
@@ -183,9 +172,6 @@ private:
183 172
      */
184 173
     void updateViewVolume();
185 174
 
186
-    //! \fixme Let them eat cake...? O.o
187
-    void tmpRenderModelMesh(model_mesh_t *r_mesh, texture_tri_t *ttri);
188
-
189 175
     std::vector<Room *> mRoomRenderList;
190 176
 
191 177
     unsigned int mFlags;                  //!< Rendering flags

+ 57
- 0
include/StaticMesh.h View File

@@ -0,0 +1,57 @@
1
+/*!
2
+ * \file include/StaticMesh.h
3
+ * \brief Static Model Meshes
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#ifndef _STATIC_MODEL_H_
9
+#define _STATIC_MODEL_H_
10
+
11
+#include <vector>
12
+#include "math/math.h"
13
+#include "TombRaider.h"
14
+
15
+class TexturedTriangle {
16
+public:
17
+    TexturedTriangle(int i[3], vec_t s[6], int tex, unsigned short trans);
18
+    bool operator< (TexturedTriangle &t);
19
+
20
+    void display(vec_t *vertices, vec_t *colors, vec_t *normals);
21
+
22
+private:
23
+    int index[3];
24
+    vec_t st[6];
25
+    int texture;
26
+    unsigned short transparency;
27
+};
28
+
29
+class StaticMesh {
30
+public:
31
+    StaticMesh(TombRaider &tr, unsigned int index);
32
+    ~StaticMesh();
33
+
34
+    void display();
35
+    vec_t getRadius();
36
+
37
+private:
38
+    bool dontshow;
39
+    vec3_t center;
40
+    vec_t radius;
41
+
42
+    unsigned int vertexCount;
43
+    unsigned int colorCount;
44
+    unsigned int normalCount;
45
+
46
+    vec_t *vertices;
47
+    vec_t *colors;
48
+    vec_t *normals;
49
+
50
+    std::vector<TexturedTriangle *> texturedTriangles;
51
+    std::vector<TexturedTriangle *> coloredTriangles;
52
+    std::vector<TexturedTriangle *> texturedRectangles;
53
+    std::vector<TexturedTriangle *> coloredRectangles;
54
+};
55
+
56
+#endif
57
+

+ 5
- 14
include/World.h View File

@@ -16,8 +16,7 @@
16 16
 #include "Room.h"
17 17
 #include "SkeletalModel.h"
18 18
 #include "Sprite.h"
19
-
20
-#include "WorldData.h"
19
+#include "StaticMesh.h"
21 20
 
22 21
 /*!
23 22
  * \brief The game world (model)
@@ -51,13 +50,9 @@ public:
51 50
     unsigned int sizeSkeletalModel();
52 51
     SkeletalModel &getSkeletalModel(unsigned int index);
53 52
 
54
-    /*!
55
-     * \brief Adds mesh to world
56
-     * \param model mesh to add
57
-     */
58
-    void addMesh(model_mesh_t *model);
59
-
60
-    model_mesh_t *getMesh(int index);
53
+    void addStaticMesh(StaticMesh &model);
54
+    unsigned int sizeStaticMesh();
55
+    StaticMesh &getStaticMesh(unsigned int index);
61 56
 
62 57
     /*!
63 58
      * \brief Find room a location is in.
@@ -83,15 +78,11 @@ public:
83 78
     int getRoomByLocation(float x, float y, float z);
84 79
 
85 80
 private:
86
-
87
-    // Old World
88
-    std::vector<model_mesh_t *> mMeshes;     //!< Unanimated meshes
89
-
90
-    // New World
91 81
     std::vector<Room *> mRooms;
92 82
     std::vector<SpriteSequence *> mSprites;
93 83
     std::vector<Entity *> mEntities;
94 84
     std::vector<SkeletalModel *> mModels;
85
+    std::vector<StaticMesh *> mMeshes;
95 86
 };
96 87
 
97 88
 World &getWorld();

+ 0
- 45
include/WorldData.h View File

@@ -1,45 +0,0 @@
1
-/*!
2
- * \file include/WorldData.h
3
- * \brief Structs and enums for the game world (model)
4
- *
5
- * \author Mongoose
6
- * \author xythobuz
7
- */
8
-
9
-#ifndef _WORLDDATA_H_
10
-#define _WORLDDATA_H_
11
-
12
-#include "math/math.h"
13
-
14
-/*! \fixme For now shaders are textures on tex objects
15
- * and materials on color objects. If -1
16
- * then it doesn't have that information yet.
17
- */
18
-typedef struct {
19
-    int index[3];
20
-    vec_t st[6];
21
-    int texture;
22
-    unsigned short transparency;
23
-} texture_tri_t;
24
-
25
-typedef struct {
26
-    std::vector<texture_tri_t *> texturedTriangles;
27
-    std::vector<texture_tri_t *> coloredTriangles;
28
-    std::vector<texture_tri_t *> texturedRectangles;
29
-    std::vector<texture_tri_t *> coloredRectangles;
30
-
31
-    vec3_t center;
32
-    float radius;
33
-
34
-    unsigned int vertexCount;
35
-    vec_t *vertices;
36
-
37
-    unsigned int colorCount;
38
-    vec_t *colors;
39
-
40
-    unsigned int normalCount;
41
-    vec_t *normals;
42
-} model_mesh_t;
43
-
44
-#endif
45
-

+ 1
- 0
src/CMakeLists.txt View File

@@ -57,6 +57,7 @@ set (SRCS ${SRCS} "RoomData.cpp")
57 57
 set (SRCS ${SRCS} "SkeletalModel.cpp")
58 58
 set (SRCS ${SRCS} "Sound.cpp")
59 59
 set (SRCS ${SRCS} "Sprite.cpp")
60
+set (SRCS ${SRCS} "StaticMesh.cpp")
60 61
 set (SRCS ${SRCS} "Texture.cpp")
61 62
 set (SRCS ${SRCS} "TombRaider.cpp")
62 63
 set (SRCS ${SRCS} "ViewVolume.cpp")

+ 8
- 259
src/Game.cpp View File

@@ -14,14 +14,11 @@
14 14
 #include "Game.h"
15 15
 #include "OpenRaider.h"
16 16
 #include "Sound.h"
17
+#include "StaticMesh.h"
17 18
 #include "utils/strings.h"
18 19
 
19 20
 #include "games/TombRaider1.h"
20 21
 
21
-#ifdef EXPERIMENTAL
22
-std::vector<unsigned int> gColorTextureHACK;
23
-#endif
24
-
25 22
 #ifdef MULTITEXTURE
26 23
 std::map<int, int> gMapTex2Bump;
27 24
 #endif
@@ -196,6 +193,13 @@ void Game::processRooms() {
196 193
     getConsole().print("Found %d rooms.", mTombRaider.NumRooms());
197 194
 }
198 195
 
196
+void Game::processModels() {
197
+    for (int index = 0; index < mTombRaider.getMeshCount(); index++)
198
+        getWorld().addStaticMesh(*new StaticMesh(mTombRaider, index));
199
+
200
+    getConsole().print("Found %d meshes.", mTombRaider.getMeshCount());
201
+}
202
+
199 203
 void Game::processPakSounds()
200 204
 {
201 205
     unsigned char *riff;
@@ -396,258 +400,3 @@ void Game::processMoveable(int index, int i, int object_id) {
396 400
                 (mTombRaider.Engine() == TR_VERSION_2));
397 401
 }
398 402
 
399
-bool compareFaceTextureId(const void *voidA, const void *voidB)
400
-{
401
-    texture_tri_t *a = (texture_tri_t *)voidA, *b = (texture_tri_t *)voidB;
402
-
403
-    if (!a || !b)
404
-        return false; // error really
405
-
406
-    return (a->texture < b->texture);
407
-}
408
-
409
-#ifdef EXPERIMENTAL
410
-void Game::setupTextureColor(texture_tri_t *r_tri, float *colorf)
411
-{
412
-    unsigned char color[4];
413
-    unsigned int colorI;
414
-
415
-    color[0] = (unsigned char)(colorf[0]*255.0f);
416
-    color[1] = (unsigned char)(colorf[1]*255.0f);
417
-    color[2] = (unsigned char)(colorf[2]*255.0f);
418
-    color[3] = (unsigned char)(colorf[3]*255.0f);
419
-
420
-    ((unsigned char *)(&colorI))[3] = color[0];
421
-    ((unsigned char *)(&colorI))[2] = color[1];
422
-    ((unsigned char *)(&colorI))[1] = color[2];
423
-    ((unsigned char *)(&colorI))[0] = color[3];
424
-
425
-    bool found = false;
426
-    unsigned int foundIndex = 0;
427
-    for (foundIndex = 0; foundIndex < gColorTextureHACK.size(); foundIndex++) {
428
-        if (gColorTextureHACK[foundIndex] == colorI) {
429
-            found = true;
430
-            break;
431
-        }
432
-    }
433
-    if (!found)
434
-    {
435
-        gColorTextureHACK.push_back(colorI);
436
-        r_tri->texture = mTextureOffset + gColorTextureHACK.size();
437
-
438
-        getRender().loadTexture(Texture::generateColorTexture(color, 32, 32),
439
-                32, 32, r_tri->texture);
440
-    }
441
-    else
442
-    {
443
-        //getConsole().print("Color already loaded %i -> 0x%08x",
444
-        //       gColorTextureHACK.getCurrentIndex(),
445
-        //       gColorTextureHACK.current());
446
-
447
-        r_tri->texture = mTextureOffset + foundIndex;
448
-    }
449
-
450
-    //r_tri->texture = white; // White texture
451
-}
452
-#endif
453
-
454
-void Game::processModels()
455
-{
456
-    for (int index = 0; index < mTombRaider.getMeshCount(); index++) {
457
-        int i, j, count, texture;
458
-        int vertexIndices[6];
459
-        float st[12];
460
-        float color[4];
461
-        unsigned short transparency;
462
-        texture_tri_t *r_tri;
463
-
464
-        // Assert common sense
465
-        if (index < 0 || !mTombRaider.isMeshValid(index))
466
-        {
467
-            //! \fixme allow sparse lists with matching ids instead?
468
-            getWorld().addMesh(NULL); // Filler, to make meshes array ids align
469
-            return;
470
-        }
471
-
472
-#ifndef EXPERIMENTAL
473
-        // WHITE texture id
474
-        int white = 0;
475
-#endif
476
-
477
-        model_mesh_t *mesh = new model_mesh_t;
478
-
479
-        // Mongoose 2002.08.30, Testing support for 'shootable' models ( traceable )
480
-        mTombRaider.getMeshCollisionInfo(index, mesh->center, &mesh->radius);
481
-
482
-        //! \fixme Arrays don't work either  =)
483
-        // Mesh geometery, colors, etc
484
-        mTombRaider.getMeshVertexArrays(index,
485
-                &mesh->vertexCount, &mesh->vertices,
486
-                &mesh->normalCount, &mesh->normals,
487
-                &mesh->colorCount,  &mesh->colors);
488
-
489
-        // Textured Triangles
490
-        count = mTombRaider.getMeshTexturedTriangleCount(index);
491
-        mesh->texturedTriangles.reserve(count); // little faster
492
-
493
-        for (i = 0; i < count; ++i)
494
-        {
495
-            r_tri = new texture_tri_t;
496
-
497
-            mTombRaider.getMeshTexturedTriangle(index, i,
498
-                    r_tri->index,
499
-                    r_tri->st,
500
-                    &r_tri->texture,
501
-                    &r_tri->transparency);
502
-
503
-            r_tri->texture += mTextureStart;
504
-
505
-            // Add to face vector
506
-            mesh->texturedTriangles.push_back(r_tri);
507
-        }
508
-
509
-        // Coloured Triangles
510
-        count = mTombRaider.getMeshColoredTriangleCount(index);
511
-        mesh->coloredTriangles.reserve(count); // little faster
512
-
513
-        for (i = 0; i < count; i++)
514
-        {
515
-            r_tri = new texture_tri_t;
516
-
517
-            mTombRaider.getMeshColoredTriangle(index, i,
518
-                    r_tri->index,
519
-                    color);
520
-            r_tri->st[0] = color[0];
521
-            r_tri->st[1] = color[1];
522
-            r_tri->st[2] = color[2];
523
-            r_tri->st[3] = color[3];
524
-            r_tri->st[4] = 1.0;
525
-            r_tri->st[5] = 1.0;
526
-
527
-#ifdef EXPERIMENTAL
528
-            setupTextureColor(r_tri, color);
529
-#else
530
-            r_tri->texture = white; // White texture
531
-#endif
532
-            r_tri->transparency = 0;
533
-
534
-            // Add to face vector
535
-            mesh->coloredTriangles.push_back(r_tri);
536
-        }
537
-
538
-        // Textured Rectangles
539
-        count = mTombRaider.getMeshTexturedRectangleCount(index);
540
-        mesh->texturedRectangles.reserve(count*2); // little faster
541
-
542
-        for (i = 0; i < count; ++i)
543
-        {
544
-            mTombRaider.getMeshTexturedRectangle(index, i,
545
-                    vertexIndices,
546
-                    st,
547
-                    &texture,
548
-                    &transparency);
549
-
550
-            r_tri = new texture_tri_t;
551
-
552
-            for (j = 0; j < 3; ++j)
553
-                r_tri->index[j] = vertexIndices[j];
554
-
555
-            for (j = 0; j < 6; ++j)
556
-                r_tri->st[j] = st[j];
557
-
558
-            r_tri->texture = texture + mTextureStart;
559
-            r_tri->transparency = transparency;
560
-
561
-            // Add to face vector
562
-            mesh->texturedRectangles.push_back(r_tri);
563
-
564
-            r_tri = new texture_tri_t;
565
-
566
-            for (j = 3; j < 6; ++j)
567
-                r_tri->index[j-3] = vertexIndices[j];
568
-
569
-            for (j = 6; j < 12; ++j)
570
-                r_tri->st[j-6] = st[j];
571
-
572
-            r_tri->texture = texture + mTextureStart;
573
-            r_tri->transparency = transparency;
574
-
575
-            // Add to face vector
576
-            mesh->texturedRectangles.push_back(r_tri);
577
-        }
578
-
579
-        // Coloured Rectangles
580
-        count = mTombRaider.getMeshColoredRectangleCount(index);
581
-        mesh->coloredRectangles.reserve(count*2); // little faster
582
-
583
-        for (i = 0; i < count; ++i)
584
-        {
585
-            mTombRaider.getMeshColoredRectangle(index, i,
586
-                    vertexIndices,
587
-                    color);
588
-
589
-            r_tri = new texture_tri_t;
590
-
591
-            for (j = 0; j < 3; ++j)
592
-                r_tri->index[j] = vertexIndices[j];
593
-
594
-            //for (j = 0; j < 6; ++j)
595
-            //  r_tri->st[j] = st[j];
596
-
597
-            r_tri->st[0] = color[0];
598
-            r_tri->st[1] = color[1];
599
-            r_tri->st[2] = color[2];
600
-            r_tri->st[3] = color[3];
601
-            r_tri->st[4] = 1.0;
602
-            r_tri->st[5] = 1.0;
603
-
604
-#ifdef EXPERIMENTAL
605
-            //for (j = 6; j < 12; ++j)
606
-            //  r_tri->st[j-6] = st[j];
607
-            setupTextureColor(r_tri, color);
608
-#else
609
-            r_tri->texture = white; // White texture
610
-#endif
611
-            r_tri->transparency = 0;
612
-
613
-            // Add to face vector
614
-            mesh->coloredRectangles.push_back(r_tri);
615
-
616
-            r_tri = new texture_tri_t;
617
-
618
-            for (j = 3; j < 6; ++j)
619
-                r_tri->index[j-3] = vertexIndices[j];
620
-
621
-            //for (j = 6; j < 12; ++j)
622
-            //  r_tri->st[j-6] = st[j];
623
-
624
-            r_tri->st[0] = color[0];
625
-            r_tri->st[1] = color[1];
626
-            r_tri->st[2] = color[2];
627
-            r_tri->st[3] = color[3];
628
-            r_tri->st[4] = 1.0;
629
-            r_tri->st[5] = 1.0;
630
-
631
-#ifdef EXPERIMENTAL
632
-            setupTextureColor(r_tri, color);
633
-#else
634
-            r_tri->texture = white; // White texture
635
-#endif
636
-            r_tri->transparency = 0;
637
-
638
-            // Add to face vector
639
-            mesh->coloredRectangles.push_back(r_tri);
640
-        }
641
-
642
-        // Sort faces by texture
643
-        std::sort(mesh->texturedTriangles.begin(), mesh->texturedTriangles.end(), compareFaceTextureId);
644
-        std::sort(mesh->coloredTriangles.begin(), mesh->coloredTriangles.end(), compareFaceTextureId);
645
-        std::sort(mesh->texturedRectangles.begin(), mesh->texturedRectangles.end(), compareFaceTextureId);
646
-        std::sort(mesh->coloredRectangles.begin(), mesh->coloredRectangles.end(), compareFaceTextureId);
647
-
648
-        getWorld().addMesh(mesh);
649
-    }
650
-
651
-    getConsole().print("Found %d meshes.", mTombRaider.getMeshCount());
652
-}
653
-

+ 0
- 164
src/Render.cpp View File

@@ -655,170 +655,6 @@ void Render::drawSkyMesh(float scale)
655 655
 }
656 656
 
657 657
 
658
-void Render::tmpRenderModelMesh(model_mesh_t *r_mesh, texture_tri_t *ttri)
659
-{
660
-    glBegin(GL_TRIANGLES);
661
-
662
-    switch (mMode)
663
-    {
664
-        case modeSolid:
665
-        case modeVertexLight:
666
-            if (r_mesh->colors)
667
-            {
668
-                glColor3fv(r_mesh->colors+ttri->index[0]);
669
-                glTexCoord2fv(ttri->st);
670
-                glVertex3fv(r_mesh->vertices+ttri->index[0]*3);
671
-
672
-                glColor3fv(r_mesh->colors+ttri->index[1]);
673
-                glTexCoord2fv(ttri->st+2);
674
-                glVertex3fv(r_mesh->vertices+ttri->index[1]*3);
675
-
676
-                glColor3fv(r_mesh->colors+ttri->index[2]);
677
-                glTexCoord2fv(ttri->st+4);
678
-                glVertex3fv(r_mesh->vertices+ttri->index[2]*3);
679
-            }
680
-            else if (r_mesh->normals)
681
-            {
682
-                glNormal3fv(r_mesh->normals+ttri->index[0]*3);
683
-                glTexCoord2fv(ttri->st);
684
-                glVertex3fv(r_mesh->vertices+ttri->index[0]*3);
685
-
686
-                glNormal3fv(r_mesh->normals+ttri->index[1]*3);
687
-                glTexCoord2fv(ttri->st+2);
688
-                glVertex3fv(r_mesh->vertices+ttri->index[1]*3);
689
-
690
-                glNormal3fv(r_mesh->normals+ttri->index[2]*3);
691
-                glTexCoord2fv(ttri->st+4);
692
-                glVertex3fv(r_mesh->vertices+ttri->index[2]*3);
693
-            }
694
-            else
695
-            {
696
-                glTexCoord2fv(ttri->st);
697
-                glVertex3fv(r_mesh->vertices+ttri->index[0]*3);
698
-                glTexCoord2fv(ttri->st+2);
699
-                glVertex3fv(r_mesh->vertices+ttri->index[1]*3);
700
-                glTexCoord2fv(ttri->st+4);
701
-                glVertex3fv(r_mesh->vertices+ttri->index[2]*3);
702
-            }
703
-            break;
704
-        case modeWireframe:
705
-            glVertex3fv(r_mesh->vertices+ttri->index[0]*3);
706
-            glVertex3fv(r_mesh->vertices+ttri->index[1]*3);
707
-            glVertex3fv(r_mesh->vertices+ttri->index[2]*3);
708
-            break;
709
-        default:
710
-            glTexCoord2fv(ttri->st);
711
-            glVertex3fv(r_mesh->vertices+ttri->index[0]*3);
712
-            glTexCoord2fv(ttri->st+2);
713
-            glVertex3fv(r_mesh->vertices+ttri->index[1]*3);
714
-            glTexCoord2fv(ttri->st+4);
715
-            glVertex3fv(r_mesh->vertices+ttri->index[2]*3);
716
-    }
717
-
718
-    glEnd();
719
-}
720
-
721
-
722
-void Render::drawModelMesh(model_mesh_t *r_mesh)
723
-{
724
-    texture_tri_t *ttri;
725
-    int lastTexture = -1;
726
-
727
-    // If they pass NULL structs let it hang up - this is tmp
728
-
729
-    //! \fixme Duh, vis tests need to be put back
730
-    //if (!isVisible(r_mesh->center,    r_mesh->radius, r_mesh->bbox))
731
-    //{
732
-    //   return;
733
-    //}
734
-
735
-    //! \fixme 'AMBIENT' -- Mongoose 2002.01.08
736
-    glColor3fv(WHITE);
737
-
738
-    if (mMode == modeWireframe)
739
-        glColor3fv(WHITE);
740
-
741
-    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
742
-    glBindTexture(GL_TEXTURE_2D, 1);  // White texture for colors
743
-
744
-    // Colored Triagles
745
-    for (unsigned int i = 0; i < r_mesh->coloredTriangles.size(); i++)
746
-    {
747
-        ttri = r_mesh->coloredTriangles[i];
748
-
749
-        if (!ttri)
750
-            continue;
751
-
752
-        if (mMode != modeWireframe && mMode != modeSolid &&
753
-                ttri->texture != lastTexture)
754
-        {
755
-            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
756
-            glBindTexture(GL_TEXTURE_2D, ttri->texture+1);
757
-            lastTexture = ttri->texture;
758
-        }
759
-
760
-        tmpRenderModelMesh(r_mesh, ttri);
761
-    }
762
-
763
-    // Colored Rectagles
764
-    for (unsigned int i = 0; i < r_mesh->coloredRectangles.size(); i++)
765
-    {
766
-        ttri = r_mesh->coloredRectangles[i];
767
-
768
-        if (!ttri)
769
-            continue;
770
-
771
-        if (mMode != modeWireframe && mMode != modeSolid &&
772
-                ttri->texture != lastTexture)
773
-        {
774
-            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
775
-            glBindTexture(GL_TEXTURE_2D, ttri->texture+1);
776
-            lastTexture = ttri->texture;
777
-        }
778
-
779
-        tmpRenderModelMesh(r_mesh, ttri);
780
-    }
781
-
782
-    // Textured Tris
783
-    for (unsigned int i = 0; i < r_mesh->texturedTriangles.size(); i++)
784
-    {
785
-        ttri = r_mesh->texturedTriangles[i];
786
-
787
-        if (!ttri)
788
-            continue;
789
-
790
-        if (mMode != modeWireframe && mMode != modeSolid &&
791
-                ttri->texture != lastTexture)
792
-        {
793
-            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
794
-            glBindTexture(GL_TEXTURE_2D, ttri->texture+1);
795
-            lastTexture = ttri->texture;
796
-        }
797
-
798
-        tmpRenderModelMesh(r_mesh, ttri);
799
-    }
800
-
801
-    // Textured Quads
802
-    for (unsigned int i = 0; i < r_mesh->texturedRectangles.size(); i++)
803
-    {
804
-        ttri = r_mesh->texturedRectangles[i];
805
-
806
-        if (!ttri)
807
-            continue;
808
-
809
-        if (mMode != modeWireframe && mMode != modeSolid &&
810
-                ttri->texture != lastTexture)
811
-        {
812
-            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
813
-            glBindTexture(GL_TEXTURE_2D, ttri->texture+1);
814
-            lastTexture = ttri->texture;
815
-        }
816
-
817
-        tmpRenderModelMesh(r_mesh, ttri);
818
-    }
819
-}
820
-
821
-
822 658
 void Render::setSkyMesh(int index, bool rot)
823 659
 {
824 660
     mSkyMesh = index;

+ 3
- 7
src/RoomData.cpp View File

@@ -179,19 +179,15 @@ StaticModel::StaticModel(TombRaider &tr, unsigned int room, unsigned int i) {
179 179
 }
180 180
 
181 181
 void StaticModel::display() {
182
-    model_mesh_t *mesh = getWorld().getMesh(index);
182
+    StaticMesh &mesh = getWorld().getStaticMesh(index);
183 183
 
184
-    if (!mesh)
185
-        return;
186
-
187
-    if (!getRender().isVisible(pos[0], pos[1], pos[2], mesh->radius))
184
+    if (!getRender().isVisible(pos[0], pos[1], pos[2], mesh.getRadius()))
188 185
         return;
189 186
 
190 187
     glPushMatrix();
191 188
     glTranslated(pos[0], pos[1], pos[2]);
192 189
     glRotated(yaw, 0, 1, 0);
193
-
194
-    getRender().drawModelMesh(mesh);
190
+    mesh.display();
195 191
     glPopMatrix();
196 192
 }
197 193
 

+ 4
- 4
src/SkeletalModel.cpp View File

@@ -49,7 +49,7 @@ BoneTag::BoneTag(TombRaider &tr, unsigned int index, unsigned int i, unsigned in
49 49
 }
50 50
 
51 51
 void BoneTag::display() {
52
-    getRender().drawModelMesh(getWorld().getMesh(mesh));
52
+    getWorld().getStaticMesh(mesh).display();
53 53
 }
54 54
 
55 55
 void BoneTag::getOffset(vec3_t o) {
@@ -332,15 +332,15 @@ void SkeletalModel::display(unsigned int aframe, unsigned int bframe) {
332 332
                     if (pigtails) {
333 333
                         glPushMatrix();
334 334
                         glTranslatef(ponyOff2, 0.0, 0.0);
335
-                        getRender().drawModelMesh(getWorld().getMesh(ponytailMeshId + i));
335
+                        getWorld().getStaticMesh(ponytailMeshId + i).display();
336 336
                         glPopMatrix();
337 337
 
338 338
                         glPushMatrix();
339 339
                         glTranslatef(-ponyOff2, 0.0, 0.0);
340
-                        getRender().drawModelMesh(getWorld().getMesh(ponytailMeshId + i));
340
+                        getWorld().getStaticMesh(ponytailMeshId + i).display();
341 341
                         glPopMatrix();
342 342
                     } else {
343
-                        getRender().drawModelMesh(getWorld().getMesh(ponytailMeshId + i));
343
+                        getWorld().getStaticMesh(ponytailMeshId + i).display();
344 344
                     }
345 345
                 }
346 346
 

+ 300
- 0
src/StaticMesh.cpp View File

@@ -0,0 +1,300 @@
1
+/*!
2
+ * \file src/StaticMesh.cpp
3
+ * \brief Static Model Meshes
4
+ *
5
+ * \author xythobuz
6
+ */
7
+
8
+#include "global.h"
9
+#include "Game.h"
10
+#include "Render.h"
11
+#include "StaticMesh.h"
12
+
13
+#ifdef EXPERIMENTAL
14
+std::vector<unsigned int> gColorTextureHACK;
15
+#endif
16
+
17
+TexturedTriangle::TexturedTriangle(int i[3], vec_t s[6], int tex, unsigned short trans) {
18
+    index[0] = i[0];
19
+    index[1] = i[1];
20
+    index[2] = i[2];
21
+    st[0] = s[0];
22
+    st[1] = s[1];
23
+    st[2] = s[2];
24
+    st[3] = s[3];
25
+    st[4] = s[4];
26
+    st[5] = s[5];
27
+    texture = tex;
28
+    transparency = trans;
29
+}
30
+
31
+bool TexturedTriangle::operator< (TexturedTriangle &t) {
32
+    return texture < t.texture;
33
+}
34
+
35
+void TexturedTriangle::display(vec_t *vertices, vec_t *colors, vec_t *normals) {
36
+    assert(vertices != NULL);
37
+
38
+    if ((getRender().getMode() != Render::modeWireframe)
39
+            && (getRender().getMode() != Render::modeSolid)) {
40
+        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
41
+        glBindTexture(GL_TEXTURE_2D, texture + 1);
42
+    }
43
+
44
+    glBegin(GL_TRIANGLES);
45
+
46
+    switch (getRender().getMode()) {
47
+        case Render::modeSolid:
48
+        case Render::modeVertexLight:
49
+            if (colors != NULL) {
50
+                glColor3fv(colors + index[0]);
51
+                glTexCoord2fv(st);
52
+                glVertex3fv(vertices + (index[0] * 3));
53
+
54
+                glColor3fv(colors + index[1]);
55
+                glTexCoord2fv(st + 2);
56
+                glVertex3fv(vertices + (index[1] * 3));
57
+
58
+                glColor3fv(colors + index[2]);
59
+                glTexCoord2fv(st + 4);
60
+                glVertex3fv(vertices + (index[2] * 3));
61
+            } else if (normals != NULL) {
62
+                glNormal3fv(normals + (index[0] * 3));
63
+                glTexCoord2fv(st);
64
+                glVertex3fv(vertices + (index[0] * 3));
65
+
66
+                glNormal3fv(normals + (index[1] * 3));
67
+                glTexCoord2fv(st + 2);
68
+                glVertex3fv(vertices + (index[1] * 3));
69
+
70
+                glNormal3fv(normals + (index[2] * 3));
71
+                glTexCoord2fv(st + 4);
72
+                glVertex3fv(vertices + (index[2] * 3));
73
+            } else {
74
+                glTexCoord2fv(st);
75
+                glVertex3fv(vertices + (index[0] * 3));
76
+                glTexCoord2fv(st + 2);
77
+                glVertex3fv(vertices + (index[1] * 3));
78
+                glTexCoord2fv(st + 4);
79
+                glVertex3fv(vertices + (index[2] * 3));
80
+            }
81
+            break;
82
+
83
+        case Render::modeWireframe:
84
+            glVertex3fv(vertices + (index[0] * 3));
85
+            glVertex3fv(vertices + (index[1] * 3));
86
+            glVertex3fv(vertices + (index[2] * 3));
87
+            break;
88
+
89
+        default:
90
+            glTexCoord2fv(st);
91
+            glVertex3fv(vertices + (index[0] * 3));
92
+            glTexCoord2fv(st + 2);
93
+            glVertex3fv(vertices + (index[1] * 3));
94
+            glTexCoord2fv(st + 4);
95
+            glVertex3fv(vertices + (index[2] * 3));
96
+    }
97
+
98
+    glEnd();
99
+}
100
+
101
+#ifdef EXPERIMENTAL
102
+int setupTextureColor(float *colorf) {
103
+    unsigned char color[4];
104
+    unsigned int colorI;
105
+    int texture;
106
+
107
+    color[0] = (unsigned char)(colorf[0]*255.0f);
108
+    color[1] = (unsigned char)(colorf[1]*255.0f);
109
+    color[2] = (unsigned char)(colorf[2]*255.0f);
110
+    color[3] = (unsigned char)(colorf[3]*255.0f);
111
+
112
+    ((unsigned char *)(&colorI))[3] = color[0];
113
+    ((unsigned char *)(&colorI))[2] = color[1];
114
+    ((unsigned char *)(&colorI))[1] = color[2];
115
+    ((unsigned char *)(&colorI))[0] = color[3];
116
+
117
+    bool found = false;
118
+    unsigned int foundIndex = 0;
119
+    for (foundIndex = 0; foundIndex < gColorTextureHACK.size(); foundIndex++) {
120
+        if (gColorTextureHACK[foundIndex] == colorI) {
121
+            found = true;
122
+            break;
123
+        }
124
+    }
125
+
126
+    if (!found) {
127
+        gColorTextureHACK.push_back(colorI);
128
+        texture = getGame().getTextureOffset() + gColorTextureHACK.size();
129
+
130
+        getRender().loadTexture(Texture::generateColorTexture(color, 32, 32),
131
+                32, 32, texture);
132
+    } else {
133
+        texture = getGame().getTextureOffset() + foundIndex;
134
+    }
135
+
136
+    return texture;
137
+}
138
+#endif
139
+
140
+StaticMesh::StaticMesh(TombRaider &tr, unsigned int index) {
141
+    int count, texture;
142
+    int vertexIndices[6];
143
+    float st[12];
144
+    float color[4];
145
+    unsigned short transparency;
146
+
147
+    if (!tr.isMeshValid(index)) {
148
+        dontshow = true;
149
+        return;
150
+    } else {
151
+        dontshow = false;
152
+    }
153
+
154
+    // Mongoose 2002.08.30, Testing support for 'shootable' models ( traceable )
155
+    tr.getMeshCollisionInfo(index, center, &radius);
156
+
157
+    //! \fixme Arrays don't work either  =)
158
+    // Mesh geometery, colors, etc
159
+    tr.getMeshVertexArrays(index,
160
+            &vertexCount, &vertices,
161
+            &normalCount, &normals,
162
+            &colorCount,  &colors);
163
+
164
+    // Textured Triangles
165
+    count = tr.getMeshTexturedTriangleCount(index);
166
+    for (int i = 0; i < count; i++) {
167
+        tr.getMeshTexturedTriangle(index, i,
168
+                vertexIndices, st,
169
+                &texture, &transparency);
170
+        texturedTriangles.push_back(
171
+                new TexturedTriangle(vertexIndices, st, texture + getGame().getTextureStart(), transparency));
172
+    }
173
+
174
+    // Coloured Triangles
175
+    count = tr.getMeshColoredTriangleCount(index);
176
+    for (int i = 0; i < count; i++) {
177
+        tr.getMeshColoredTriangle(index, i,
178
+                vertexIndices, color);
179
+        st[0] = color[0];
180
+        st[1] = color[1];
181
+        st[2] = color[2];
182
+        st[3] = color[3];
183
+        st[4] = 1.0;
184
+        st[5] = 1.0;
185
+
186
+#ifdef EXPERIMENTAL
187
+        texture = setupTextureColor(color);
188
+#else
189
+        texture = 0; // White texture
190
+#endif
191
+        transparency = 0;
192
+
193
+        coloredTriangles.push_back(
194
+                new TexturedTriangle(vertexIndices, st, texture + getGame().getTextureStart(), transparency));
195
+    }
196
+
197
+    // Textured Rectangles
198
+    count = tr.getMeshTexturedRectangleCount(index);
199
+    for (int i = 0; i < count; i++) {
200
+        tr.getMeshTexturedRectangle(index, i,
201
+                vertexIndices, st,
202
+                &texture, &transparency);
203
+        texturedRectangles.push_back(
204
+                new TexturedTriangle(vertexIndices, st, texture + getGame().getTextureStart(), transparency));
205
+        texturedRectangles.push_back(
206
+                new TexturedTriangle(vertexIndices + 3, st + 6, texture + getGame().getTextureStart(), transparency));
207
+    }
208
+
209
+    // Coloured Rectangles
210
+    count = tr.getMeshColoredRectangleCount(index);
211
+    for (int i = 0; i < count; i++) {
212
+        tr.getMeshColoredRectangle(index, i,
213
+                vertexIndices, color);
214
+
215
+        st[0] = color[0];
216
+        st[1] = color[1];
217
+        st[2] = color[2];
218
+        st[3] = color[3];
219
+        st[4] = 1.0;
220
+        st[5] = 1.0;
221
+
222
+#ifdef EXPERIMENTAL
223
+        texture = setupTextureColor(color);
224
+#else
225
+        texture = 0; // White texture
226
+#endif
227
+        transparency = 0;
228
+
229
+        coloredRectangles.push_back(
230
+                new TexturedTriangle(vertexIndices, st, texture + getGame().getTextureStart(), transparency));
231
+        coloredRectangles.push_back(
232
+                new TexturedTriangle(vertexIndices + 3, st, texture + getGame().getTextureStart(), transparency));
233
+    }
234
+
235
+    // Sort faces by texture
236
+    std::sort(texturedTriangles.begin(), texturedTriangles.end());
237
+    std::sort(coloredTriangles.begin(), coloredTriangles.end());
238
+    std::sort(texturedRectangles.begin(), texturedRectangles.end());
239
+    std::sort(coloredRectangles.begin(), coloredRectangles.end());
240
+}
241
+
242
+StaticMesh::~StaticMesh() {
243
+    while (!texturedTriangles.empty()) {
244
+        delete texturedTriangles.back();
245
+        texturedTriangles.pop_back();
246
+    }
247
+
248
+    while (!coloredTriangles.empty()) {
249
+        delete coloredTriangles.back();
250
+        coloredTriangles.pop_back();
251
+    }
252
+
253
+    while (!texturedRectangles.empty()) {
254
+        delete texturedRectangles.back();
255
+        texturedRectangles.pop_back();
256
+    }
257
+
258
+    while (!coloredRectangles.empty()) {
259
+        delete coloredRectangles.back();
260
+        coloredRectangles.pop_back();
261
+    }
262
+
263
+    delete [] vertices;
264
+    delete [] normals;
265
+    delete [] colors;
266
+}
267
+
268
+void StaticMesh::display() {
269
+    if (!dontshow) {
270
+        //! \fixme Duh, vis tests need to be put back
271
+        //if (!isVisible(center, radius, bbox))
272
+        //   return;
273
+
274
+        //! \fixme 'AMBIENT' -- Mongoose 2002.01.08
275
+        glColor3fv(WHITE);
276
+
277
+        if (getRender().getMode() == Render::modeWireframe)
278
+            glColor3fv(WHITE);
279
+
280
+        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
281
+        glBindTexture(GL_TEXTURE_2D, 1);  // White texture for colors
282
+
283
+        for (unsigned int i = 0; i < coloredTriangles.size(); i++)
284
+            coloredTriangles.at(i)->display(vertices, colors, normals);
285
+
286
+        for (unsigned int i = 0; i < coloredRectangles.size(); i++)
287
+            coloredRectangles.at(i)->display(vertices, colors, normals);
288
+
289
+        for (unsigned int i = 0; i < texturedTriangles.size(); i++)
290
+            texturedTriangles.at(i)->display(vertices, colors, normals);
291
+
292
+        for (unsigned int i = 0; i < texturedRectangles.size(); i++)
293
+            texturedRectangles.at(i)->display(vertices, colors, normals);
294
+    }
295
+}
296
+
297
+vec_t StaticMesh::getRadius() {
298
+    return radius;
299
+}
300
+

+ 19
- 54
src/World.cpp View File

@@ -15,19 +15,6 @@ World::~World() {
15 15
     destroy();
16 16
 }
17 17
 
18
-// Temp methods for rendering use until more refactoring is done
19
-model_mesh_t *World::getMesh(int index)
20
-{
21
-    return mMeshes[index];
22
-}
23
-
24
-void World::addMesh(model_mesh_t *mesh)
25
-{
26
-    if (mesh)
27
-        mMeshes.push_back(mesh);
28
-}
29
-
30
-
31 18
 void World::addRoom(Room &room) {
32 19
     mRooms.push_back(&room);
33 20
 }
@@ -80,6 +67,19 @@ SkeletalModel &World::getSkeletalModel(unsigned int index) {
80 67
     return *mModels.at(index);
81 68
 }
82 69
 
70
+void World::addStaticMesh(StaticMesh &model) {
71
+    mMeshes.push_back(&model);
72
+}
73
+
74
+unsigned int World::sizeStaticMesh() {
75
+    return mMeshes.size();
76
+}
77
+
78
+StaticMesh &World::getStaticMesh(unsigned int index) {
79
+    assert(index < mMeshes.size());
80
+    return *mMeshes.at(index);
81
+}
82
+
83 83
 
84 84
 int World::getRoomByLocation(int index, float x, float y, float z)
85 85
 {
@@ -111,59 +111,24 @@ int World::getRoomByLocation(float x, float y, float z) {
111 111
 
112 112
 
113 113
 void World::destroy() {
114
-    for (unsigned int i = 0; i != mRooms.size(); i++)
114
+    for (unsigned int i = 0; i < mRooms.size(); i++)
115 115
         delete mRooms[i];
116 116
     mRooms.clear();
117 117
 
118
-    for (unsigned int i = 0; i != mSprites.size(); i++)
118
+    for (unsigned int i = 0; i < mSprites.size(); i++)
119 119
         delete mSprites[i];
120 120
     mSprites.clear();
121 121
 
122
-    for (unsigned int i = 0; i != mEntities.size(); i++)
122
+    for (unsigned int i = 0; i < mEntities.size(); i++)
123 123
         delete mEntities[i];
124 124
     mEntities.clear();
125 125
 
126
-    for (unsigned int i = 0; i != mModels.size(); i++)
126
+    for (unsigned int i = 0; i < mModels.size(); i++)
127 127
         delete mModels[i];
128 128
     mModels.clear();
129 129
 
130
-    for (std::vector<int>::size_type i = 0; i != mMeshes.size(); i++) {
131
-        model_mesh_t *mesh = mMeshes[i];
132
-
133
-        if (!mesh)
134
-            continue;
135
-
136
-        for (std::vector<int>::size_type j = 0; j != mesh->texturedTriangles.size(); j++) {
137
-            if (mesh->texturedTriangles[j])
138
-                delete mesh->texturedTriangles[j];
139
-        }
140
-
141
-        for (std::vector<int>::size_type j = 0; j != mesh->coloredTriangles.size(); j++) {
142
-            if (mesh->coloredTriangles[j])
143
-                delete mesh->coloredTriangles[j];
144
-        }
145
-
146
-        for (std::vector<int>::size_type j = 0; j != mesh->texturedRectangles.size(); j++) {
147
-            if (mesh->texturedRectangles[j])
148
-                delete mesh->texturedRectangles[j];
149
-        }
150
-
151
-        for (std::vector<int>::size_type j = 0; j != mesh->coloredRectangles.size(); j++) {
152
-            if (mesh->coloredRectangles[j])
153
-                delete mesh->coloredRectangles[j];
154
-        }
155
-
156
-        if (mesh->vertices)
157
-            delete [] mesh->vertices;
158
-
159
-        if (mesh->colors)
160
-            delete [] mesh->colors;
161
-
162
-        if (mesh->normals)
163
-            delete [] mesh->normals;
164
-
165
-        delete mesh;
166
-    }
130
+    for (unsigned int i = 0; i < mMeshes.size(); i++)
131
+        delete mMeshes[i];
167 132
     mMeshes.clear();
168 133
 }
169 134
 

Loading…
Cancel
Save