Преглед изворни кода

Render using new interface

Thomas Buck пре 10 година
родитељ
комит
01d39b4972
5 измењених фајлова са 151 додато и 359 уклоњено
  1. 11
    27
      include/Render.h
  2. 19
    3
      include/Room.h
  3. 77
    318
      src/Render.cpp
  4. 31
    0
      src/Room.cpp
  5. 13
    11
      src/World.cpp

+ 11
- 27
include/Render.h Прегледај датотеку

161
      */
161
      */
162
     bool isVisible(float x, float y, float z, float radius);
162
     bool isVisible(float x, float y, float z, float radius);
163
 
163
 
164
+    /*!
165
+     * \brief Renders a mesh.
166
+     *
167
+     * Texture must be initialized.
168
+     * \param r_mesh Mesh to render.
169
+     * \param type Must be object containing mesh
170
+     */
171
+    void drawModelMesh(model_mesh_t *r_mesh, RenderMeshType type);
172
+
164
     //! \fixme should be private
173
     //! \fixme should be private
165
 
174
 
166
     ViewVolume mViewVolume; //!< View Volume for frustum culling
175
     ViewVolume mViewVolume; //!< View Volume for frustum culling
181
      * only considers its linked rooms and their linked rooms.
190
      * only considers its linked rooms and their linked rooms.
182
      * \param room First room in list
191
      * \param room First room in list
183
      */
192
      */
184
-    void buildRoomRenderList(Room *room);
193
+    void buildRoomRenderList(Room &room);
185
 
194
 
186
     /*!
195
     /*!
187
      * \brief Renders visible world object.
196
      * \brief Renders visible world object.
215
      * \param rRoom room to render
224
      * \param rRoom room to render
216
      * \param draw_alpha once false, once true
225
      * \param draw_alpha once false, once true
217
      */
226
      */
218
-    void drawRoom(Room *rRoom, bool draw_alpha);
219
-
220
-    /*!
221
-     * \brief Renders static room model.
222
-     *
223
-     * Texture must be initialized.
224
-     * \param mesh Static model to render
225
-     */
226
-    void drawRoomModel(StaticModel &mesh);
227
-
228
-    /*!
229
-     * \brief Renders a mesh.
230
-     *
231
-     * Texture must be initialized.
232
-     * \param r_mesh Mesh to render.
233
-     * \param type Must be object containing mesh
234
-     */
235
-    void drawModelMesh(model_mesh_t *r_mesh, RenderMeshType type);
236
-
237
-    /*!
238
-     * \brief Renders a sprite.
239
-     *
240
-     * Texture must be initialized.
241
-     * \param sprite sprite to render
242
-     */
243
-    void drawSprite(Sprite &sprite);
227
+    void drawRoom(Room &rRoom, bool draw_alpha);
244
 
228
 
245
     /*!
229
     /*!
246
      * \brief Updates View Volume. Call once per render frame.
230
      * \brief Updates View Volume. Call once per render frame.

+ 19
- 3
include/Room.h Прегледај датотеку

39
 class StaticModel {
39
 class StaticModel {
40
 public:
40
 public:
41
     StaticModel(int _index, vec_t _yaw, vec3_t _pos);
41
     StaticModel(int _index, vec_t _yaw, vec3_t _pos);
42
+    void display();
42
 
43
 
43
     // Compares distance to ViewVolume for depth sorting
44
     // Compares distance to ViewVolume for depth sorting
44
     bool operator<(const StaticModel &other);
45
     bool operator<(const StaticModel &other);
56
 public:
57
 public:
57
     Portal(vec3_t _vertices[4], vec3_t _normal, int _adjoiningRoom);
58
     Portal(vec3_t _vertices[4], vec3_t _normal, int _adjoiningRoom);
58
 
59
 
59
-    vec3_t *getVertices();
60
+    void getVertices(vec3_t vert[4]);
60
     int getAdjoiningRoom();
61
     int getAdjoiningRoom();
61
 
62
 
62
 private:
63
 private:
110
     void setPos(vec3_t p);
111
     void setPos(vec3_t p);
111
     void getPos(vec3_t p);
112
     void getPos(vec3_t p);
112
 
113
 
114
+    void getBoundingBox(vec3_t box[2]);
113
     void setBoundingBox(vec3_t box[2]);
115
     void setBoundingBox(vec3_t box[2]);
114
     bool inBox(vec_t x, vec_t y, vec_t z);
116
     bool inBox(vec_t x, vec_t y, vec_t z);
115
     bool inBoxPlane(vec_t x, vec_t z);
117
     bool inBoxPlane(vec_t x, vec_t z);
116
 
118
 
119
+    unsigned int sizeAdjacentRooms();
120
+    int getAdjacentRoom(unsigned int index);
117
     void addAdjacentRoom(int r);
121
     void addAdjacentRoom(int r);
118
 
122
 
119
     unsigned int sizePortals();
123
     unsigned int sizePortals();
124
     Sector &getSector(unsigned int index);
128
     Sector &getSector(unsigned int index);
125
     void addSector(Sector &s);
129
     void addSector(Sector &s);
126
 
130
 
131
+    unsigned int sizeBox();
132
+    Box &getBox(unsigned int index);
127
     void addBox(Box &b);
133
     void addBox(Box &b);
134
+
135
+    unsigned int sizeModels();
136
+    StaticModel &getModel(unsigned int index);
128
     void addModel(StaticModel &m);
137
     void addModel(StaticModel &m);
129
-    void addSprite(Sprite &s);
138
+    void sortModels();
139
+
140
+    unsigned int sizeLights();
141
+    Light &getLight(unsigned int index);
130
     void addLight(Light &l);
142
     void addLight(Light &l);
131
 
143
 
144
+    unsigned int sizeSprites();
145
+    Sprite &getSprite(unsigned int index);
146
+    void addSprite(Sprite &s);
147
+
132
     Mesh &getMesh();
148
     Mesh &getMesh();
133
 
149
 
134
 private:
150
 private:
147
     std::vector<Sector *> sectors;
163
     std::vector<Sector *> sectors;
148
 
164
 
149
     // Was previously stored in RenderRoom
165
     // Was previously stored in RenderRoom
150
-    vec_t dist;                  //!< Distance to near plane, move to room?
166
+    //vec_t dist;                  //!< Distance to near plane, move to room?
151
     std::vector<Light *> lights; //!< List of lights in this room
167
     std::vector<Light *> lights; //!< List of lights in this room
152
     Mesh mesh;                   //!< OpenGL mesh that represents this room
168
     Mesh mesh;                   //!< OpenGL mesh that represents this room
153
 };
169
 };

+ 77
- 318
src/Render.cpp Прегледај датотеку

44
     return (distA < distB);
44
     return (distA < distB);
45
 }
45
 }
46
 
46
 
47
-bool compareRoomDist(const void *voidA, const void *voidB)
48
-{
49
-    const RenderRoom *a = static_cast<const RenderRoom *>(voidA);
50
-    const RenderRoom *b = static_cast<const RenderRoom *>(voidB);
51
-
52
-
53
-    if (!a || !b || !a->room || !b->room)
54
-        return false; // error really
55
-
56
-    return (a->dist < b->dist);
57
-}
58
-
59
-
60
 ////////////////////////////////////////////////////////////
47
 ////////////////////////////////////////////////////////////
61
 // Constructors
48
 // Constructors
62
 ////////////////////////////////////////////////////////////
49
 ////////////////////////////////////////////////////////////
97
 ////////////////////////////////////////////////////////////
84
 ////////////////////////////////////////////////////////////
98
 
85
 
99
 
86
 
100
-void Render::addRoom(RenderRoom *room)
101
-{
102
-    mRooms.push_back(room);
103
-}
104
-
105
-
106
 void Render::loadTexture(unsigned char *image,
87
 void Render::loadTexture(unsigned char *image,
107
         unsigned int width, unsigned int height,
88
         unsigned int width, unsigned int height,
108
         unsigned int id)
89
         unsigned int id)
141
 }
122
 }
142
 
123
 
143
 
124
 
144
-void Render::ClearWorld()
145
-{
125
+void Render::ClearWorld() {
146
     mRoomRenderList.clear();
126
     mRoomRenderList.clear();
147
 
127
 
148
-    for (unsigned int i = 0; i < mRooms.size(); i++) {
149
-        if (mRooms[i])
150
-            delete mRooms[i];
151
-    }
152
-    mRooms.clear();
153
-
154
     for (unsigned int i = 0; i < mModels.size(); i++) {
128
     for (unsigned int i = 0; i < mModels.size(); i++) {
155
         if (mModels[i])
129
         if (mModels[i])
156
             delete mModels[i];
130
             delete mModels[i];
218
 }
192
 }
219
 
193
 
220
 
194
 
221
-void lightRoom(RenderRoom *room)
195
+void lightRoom(Room &room)
222
 {
196
 {
223
-    unsigned int i;
224
-    Light *light;
225
-
226
-
227
-    for (i = 0; i < room->lights.size(); ++i)
197
+    for (unsigned int i = 0; i < room.sizeLights(); ++i)
228
     {
198
     {
229
-        light = room->lights[i];
230
-
231
-        if (!light)
232
-            continue;
199
+        Light &light = room.getLight(i);
233
 
200
 
234
         glEnable(GL_LIGHT0 + i);
201
         glEnable(GL_LIGHT0 + i);
235
 
202
 
236
-        switch (light->mType)
203
+        switch (light.mType)
237
         {
204
         {
238
             case Light::typeSpot:
205
             case Light::typeSpot:
239
-                glLightf(GL_LIGHT0 + i,  GL_SPOT_CUTOFF,    light->mCutoff);
240
-                glLightfv(GL_LIGHT0 + i, GL_POSITION,       light->mPos);
241
-                glLightfv(GL_LIGHT0 + i, GL_SPOT_DIRECTION, light->mDir);
242
-                glLightfv(GL_LIGHT0 + i, GL_DIFFUSE,        light->mColor);
206
+                glLightf(GL_LIGHT0 + i,  GL_SPOT_CUTOFF,    light.mCutoff);
207
+                glLightfv(GL_LIGHT0 + i, GL_POSITION,       light.mPos);
208
+                glLightfv(GL_LIGHT0 + i, GL_SPOT_DIRECTION, light.mDir);
209
+                glLightfv(GL_LIGHT0 + i, GL_DIFFUSE,        light.mColor);
243
                 break;
210
                 break;
244
             case Light::typePoint:
211
             case Light::typePoint:
245
             case Light::typeDirectional:
212
             case Light::typeDirectional:
247
 
214
 
248
                 // GL_QUADRATIC_ATTENUATION
215
                 // GL_QUADRATIC_ATTENUATION
249
                 // GL_LINEAR_ATTENUATION
216
                 // GL_LINEAR_ATTENUATION
250
-                glLightf(GL_LIGHT0 + i, GL_LINEAR_ATTENUATION, light->mAtt);
217
+                glLightf(GL_LIGHT0 + i, GL_LINEAR_ATTENUATION, light.mAtt);
251
 
218
 
252
-                glLightfv(GL_LIGHT0 + i, GL_DIFFUSE, light->mColor); // GL_DIFFUSE
253
-                glLightfv(GL_LIGHT0 + i, GL_POSITION, light->mPos);
219
+                glLightfv(GL_LIGHT0 + i, GL_DIFFUSE, light.mColor); // GL_DIFFUSE
220
+                glLightfv(GL_LIGHT0 + i, GL_POSITION, light.mPos);
254
                 break;
221
                 break;
255
         }
222
         }
256
     }
223
     }
381
     vec3_t curPos;
348
     vec3_t curPos;
382
     vec3_t camPos;
349
     vec3_t camPos;
383
     vec3_t atPos;
350
     vec3_t atPos;
384
-    RenderRoom *room;
385
     int index;
351
     int index;
386
 
352
 
387
     switch (mMode)
353
     switch (mMode)
518
     // Room solid pass, need to do depth sorting to avoid 2 pass render
484
     // Room solid pass, need to do depth sorting to avoid 2 pass render
519
     for (unsigned int i = 0; i < mRoomRenderList.size(); i++)
485
     for (unsigned int i = 0; i < mRoomRenderList.size(); i++)
520
     {
486
     {
521
-        room = mRoomRenderList[i];
487
+        Room &room = *mRoomRenderList[i];
522
 
488
 
523
-        if (room)
489
+        if (mFlags & Render::fGL_Lights)
524
         {
490
         {
525
-            if (mFlags & Render::fGL_Lights)
526
-            {
527
-                lightRoom(room);
528
-            }
529
-
530
-            drawRoom(room, false);
491
+            lightRoom(room);
531
         }
492
         }
493
+
494
+        drawRoom(room, false);
532
     }
495
     }
533
 
496
 
534
     // Draw all visible enities
497
     // Draw all visible enities
593
     {
556
     {
594
         for (unsigned int i = 0; i < mRoomRenderList.size(); i++)
557
         for (unsigned int i = 0; i < mRoomRenderList.size(); i++)
595
         {
558
         {
596
-            room = mRoomRenderList[i];
597
-
598
-            if (room)
599
-            {
600
-                drawRoom(room, true);
601
-            }
559
+            drawRoom(*mRoomRenderList[i], true);
602
         }
560
         }
603
     }
561
     }
604
 
562
 
658
 void Render::newRoomRenderList(int index)
616
 void Render::newRoomRenderList(int index)
659
 {
617
 {
660
     static int currentRoomId = -1;
618
     static int currentRoomId = -1;
661
-    RenderRoom *room;
662
-
663
 
619
 
664
     if (mFlags & Render::fUsePortals)
620
     if (mFlags & Render::fUsePortals)
665
     {
621
     {
666
         if (index == -1) // -1 is error, so draw room 0, for the hell of it
622
         if (index == -1) // -1 is error, so draw room 0, for the hell of it
667
         {
623
         {
668
-            room = mRooms[0];
669
-
670
             mRoomRenderList.clear();
624
             mRoomRenderList.clear();
671
-
672
-            if (room)
673
-            {
674
-                mRoomRenderList.push_back(room);
675
-            }
625
+            mRoomRenderList.push_back(&getWorld().getRoom(0));
676
         }
626
         }
677
         else
627
         else
678
         {
628
         {
680
             if (mFlags & Render::fUpdateRoomListPerFrame ||
630
             if (mFlags & Render::fUpdateRoomListPerFrame ||
681
                     currentRoomId != index)
631
                     currentRoomId != index)
682
             {
632
             {
683
-                mRoomRenderList.clear();
684
-                room = mRooms[index];
685
-                buildRoomRenderList(room);
633
+                buildRoomRenderList(getWorld().getRoom(index));
686
             }
634
             }
687
         }
635
         }
688
     }
636
     }
693
             printf("*** Room render list -> %i\n", index);
641
             printf("*** Room render list -> %i\n", index);
694
             mRoomRenderList.clear();
642
             mRoomRenderList.clear();
695
 
643
 
696
-            for (unsigned int i = 0; i < mRooms.size(); i++)
644
+            for (unsigned int i = 0; i < getWorld().sizeRoom(); i++)
697
             {
645
             {
698
-                room = mRooms[i];
699
-
700
-                if (!room || !room->room)
701
-                    continue;
702
-
703
-                if (!isVisible(room->room->bbox_min, room->room->bbox_max))
646
+                vec3_t bbox[2];
647
+                getWorld().getRoom(i).getBoundingBox(bbox);
648
+                if (!isVisible(bbox[0], bbox[1]))
704
                     continue;
649
                     continue;
705
 
650
 
706
-                //room->dist =
707
-                //mViewVolume.getDistToBboxFromNear(room->room->bbox_min,
708
-                //                                           room->room->bbox_max);
709
-
710
-                mRoomRenderList.push_back(room);
651
+                mRoomRenderList.push_back(&getWorld().getRoom(i));
711
             }
652
             }
712
         }
653
         }
713
     }
654
     }
714
 
655
 
715
-    // Depth Sort roomRenderList ( no use in that, work on portals first )
716
-    std::sort(mRoomRenderList.begin(), mRoomRenderList.end(), compareRoomDist);
717
-
718
     currentRoomId = index;
656
     currentRoomId = index;
719
 }
657
 }
720
 
658
 
721
 
659
 
722
-void Render::buildRoomRenderList(RenderRoom *rRoom)
660
+void Render::buildRoomRenderList(Room &room)
723
 {
661
 {
724
-    RenderRoom *rRoom2;
725
-
726
-
727
-    // Must exist
728
-    if (!rRoom || !rRoom->room)
729
-        return;
730
 
662
 
731
     // Must be visible
663
     // Must be visible
732
     //! \fixme Add depth sorting here - remove multipass
664
     //! \fixme Add depth sorting here - remove multipass
733
-    if (!isVisible(rRoom->room->bbox_min, rRoom->room->bbox_max))
665
+    vec3_t bbox[2];
666
+    room.getBoundingBox(bbox);
667
+    if (!isVisible(bbox[0], bbox[1]))
734
         return;
668
         return;
735
 
669
 
736
     // Must not already be cached
670
     // Must not already be cached
737
     for (unsigned int i = 0; i < mRoomRenderList.size(); i++)
671
     for (unsigned int i = 0; i < mRoomRenderList.size(); i++)
738
     {
672
     {
739
-        rRoom2 = mRoomRenderList[i];
673
+        Room &room2 = *mRoomRenderList[i];
740
 
674
 
741
-        if (rRoom2 == rRoom)
675
+        if (&room2 == &room)
742
             return;
676
             return;
743
     }
677
     }
744
 
678
 
745
-    //rRoom->dist =
746
-    //mViewVolume.getDistToBboxFromNear(rRoom->room->bbox_min,
747
-    //                                           rRoom->room->bbox_max);
748
-
749
     /* Add current room to list */
679
     /* Add current room to list */
750
-    mRoomRenderList.push_back(rRoom);
680
+    mRoomRenderList.push_back(&room);
751
 
681
 
752
     if (mFlags & Render::fOneRoom)
682
     if (mFlags & Render::fOneRoom)
753
     {
683
     {
755
     }
685
     }
756
     else if (mFlags & Render::fAllRooms) /* Are you serious? */
686
     else if (mFlags & Render::fAllRooms) /* Are you serious? */
757
     {
687
     {
758
-        for (unsigned int i = 0; i < mRooms.size(); i++)
688
+        for (unsigned int i = 0; i < getWorld().sizeRoom(); i++)
759
         {
689
         {
760
-            rRoom2 = mRooms[i];
690
+            Room &room2 = getWorld().getRoom(i);
761
 
691
 
762
-            if (rRoom2 && rRoom2 != rRoom)
692
+            if (&room2 != &room)
763
             {
693
             {
764
-                buildRoomRenderList(rRoom2);
694
+                buildRoomRenderList(room2);
765
             }
695
             }
766
         }
696
         }
767
 
697
 
769
     }
699
     }
770
 
700
 
771
     // Try to add adj rooms and their adj rooms, skip this room
701
     // Try to add adj rooms and their adj rooms, skip this room
772
-    for (unsigned int i = 1; i < rRoom->room->adjacentRooms.size(); i++)
702
+    for (unsigned int i = 1; i < room.sizeAdjacentRooms(); i++)
773
     {
703
     {
774
-        if (rRoom->room->adjacentRooms[i] < 0)
704
+        if (room.getAdjacentRoom(i) < 0)
775
             continue;
705
             continue;
776
 
706
 
777
-        rRoom2 = mRooms[rRoom->room->adjacentRooms[i]];
707
+        Room &room2 = getWorld().getRoom(room.getAdjacentRoom(i));
778
 
708
 
779
         // Mongoose 2002.03.22, Add portal visibility check here
709
         // Mongoose 2002.03.22, Add portal visibility check here
780
 
710
 
781
-        if (rRoom2 && rRoom2 != rRoom)
711
+        if (&room2 != &room)
782
         {
712
         {
783
-            buildRoomRenderList(rRoom2);
713
+            buildRoomRenderList(room2);
784
         }
714
         }
785
     }
715
     }
786
 }
716
 }
813
 
743
 
814
 void Render::drawObjects()
744
 void Render::drawObjects()
815
 {
745
 {
816
-#ifdef USING_FPS_CAMERA
817
-    vec3_t curPos;
818
-#endif
819
-    sprite_seq_t *sprite;
820
-    int frame;
821
-
822
-
823
     // Draw lara or other player model ( move to entity rendering method )
746
     // Draw lara or other player model ( move to entity rendering method )
824
     if (mFlags & Render::fViewModel && getGame().mLara && getGame().mLara->tmpHook)
747
     if (mFlags & Render::fViewModel && getGame().mLara && getGame().mLara->tmpHook)
825
     {
748
     {
827
 
750
 
828
         if (mdl)
751
         if (mdl)
829
         {
752
         {
753
+            int frame;
830
 
754
 
831
             // Mongoose 2002.03.22, Test 'idle' aniamtions
755
             // Mongoose 2002.03.22, Test 'idle' aniamtions
832
             if (!getGame().mLara->moving)
756
             if (!getGame().mLara->moving)
854
 
778
 
855
         glPushMatrix();
779
         glPushMatrix();
856
 
780
 
857
-#ifdef USING_FPS_CAMERA
858
-        getCamera().getPosition(curPos);
859
-        glTranslated(curPos[0], curPos[1], curPos[2]);
860
-        glRotated(OR_RAD_TO_DEG(getCamera().getRadianYaw()), 0, 1, 0);
861
-        glTranslated(0, 500, 1200);
862
-#else
863
         glTranslated(getGame().mLara->pos[0], getGame().mLara->pos[1], getGame().mLara->pos[2]);
781
         glTranslated(getGame().mLara->pos[0], getGame().mLara->pos[1], getGame().mLara->pos[2]);
864
         glRotated(OR_RAD_TO_DEG(getCamera().getRadianYaw()), 0, 1, 0);
782
         glRotated(OR_RAD_TO_DEG(getCamera().getRadianYaw()), 0, 1, 0);
865
-#endif
866
 
783
 
867
         drawModel(getGame().mLara->tmpHook);
784
         drawModel(getGame().mLara->tmpHook);
868
         glPopMatrix();
785
         glPopMatrix();
869
     }
786
     }
870
 
787
 
871
     // Mongoose 2002.03.22, Draw sprites after player to handle alpha
788
     // Mongoose 2002.03.22, Draw sprites after player to handle alpha
872
-    if (mFlags & Render::fSprites)
873
-    {
874
-        std::vector<sprite_seq_t *> *sprites;
875
-
876
-        sprites = getWorld().getSprites();
877
-
878
-        for (unsigned int i = 0; i < sprites->size(); i++)
879
-        {
880
-            sprite = sprites->at(i);
881
-
882
-            if (!sprite)
883
-                continue;
884
-
885
-            if (sprite->sprite && sprite->num_sprites)
886
-            {
887
-                for (int j = 0; j < sprite->num_sprites; j++)
888
-                {
889
-                    drawSprite((sprite_t *)(sprite->sprite+j));
890
-                }
891
-            }
789
+    if (mFlags & Render::fSprites) {
790
+        for (unsigned int i = 0; i < getWorld().sizeSprite(); i++) {
791
+            SpriteSequence &sprite = getWorld().getSprite(i);
792
+            for (unsigned int j = 0; j < sprite.size(); j++)
793
+                sprite.get(j).display();
892
         }
794
         }
893
     }
795
     }
894
 }
796
 }
1233
 }
1135
 }
1234
 
1136
 
1235
 
1137
 
1236
-void Render::drawRoom(RenderRoom *rRoom, bool draw_alpha)
1138
+void Render::drawRoom(Room &room, bool draw_alpha)
1237
 {
1139
 {
1238
-    room_mesh_t *room;
1239
-
1240
-
1241
-    if (!rRoom || !rRoom->room)
1242
-        return;
1243
-
1244
-    room = rRoom->room;
1245
-
1246
     if (!(mFlags & Render::fRoomAlpha) && draw_alpha)
1140
     if (!(mFlags & Render::fRoomAlpha) && draw_alpha)
1247
         return;
1141
         return;
1248
 
1142
 
1252
     mTexture.bindTextureId(0); // WHITE texture
1146
     mTexture.bindTextureId(0); // WHITE texture
1253
 
1147
 
1254
     if (!draw_alpha &&
1148
     if (!draw_alpha &&
1255
-            (mFlags & Render::fPortals || mMode == Render::modeWireframe))
1256
-    {
1257
-        portal_t *portal;
1258
-
1149
+            (mFlags & Render::fPortals || mMode == Render::modeWireframe)) {
1259
         glLineWidth(2.0);
1150
         glLineWidth(2.0);
1260
         glColor3fv(RED);
1151
         glColor3fv(RED);
1261
 
1152
 
1262
-        for (unsigned int i = 0; i < room->portals.size(); i++)
1263
-        {
1264
-            portal = room->portals[i];
1265
-
1266
-            if (!portal)
1267
-                continue;
1153
+        for (unsigned int i = 0; i < room.sizePortals(); i++) {
1154
+            Portal &portal = room.getPortal(i);
1155
+            vec3_t vertices[4];
1156
+            portal.getVertices(vertices);
1268
 
1157
 
1269
             glBegin(GL_LINE_LOOP);
1158
             glBegin(GL_LINE_LOOP);
1270
-            glVertex3fv(portal->vertices[0]);
1271
-            glVertex3fv(portal->vertices[1]);
1272
-            glVertex3fv(portal->vertices[2]);
1273
-            glVertex3fv(portal->vertices[3]);
1159
+            glVertex3fv(vertices[0]);
1160
+            glVertex3fv(vertices[1]);
1161
+            glVertex3fv(vertices[2]);
1162
+            glVertex3fv(vertices[3]);
1274
             glEnd();
1163
             glEnd();
1275
         }
1164
         }
1276
 
1165
 
1277
         glLineWidth(1.0);
1166
         glLineWidth(1.0);
1278
-
1279
-#ifdef OBSOLETE
1280
-        glColor3fv(RED);
1281
-
1282
-        for (i = 0; i < (int)room->num_boxes; ++i)
1283
-        {
1284
-            // Mongoose 2002.08.14, This is a simple test -
1285
-            //   these like portals are really planes
1286
-            glBegin(GL_QUADS);
1287
-            glVertex3fv(room->boxes[i].a.pos);
1288
-            glVertex3fv(room->boxes[i].b.pos);
1289
-            glVertex3fv(room->boxes[i].c.pos);
1290
-            glVertex3fv(room->boxes[i].d.pos);
1291
-            glEnd();
1292
-        }
1293
-#endif
1294
     }
1167
     }
1295
 
1168
 
1296
-    if (mMode == Render::modeWireframe && !draw_alpha)
1297
-    {
1298
-        draw_bbox(room->bbox_min, room->bbox_max, true);
1169
+    if (mMode == Render::modeWireframe && !draw_alpha) {
1170
+        vec3_t bbox[2];
1171
+        room.getBoundingBox(bbox);
1172
+        draw_bbox(bbox[0], bbox[1], true);
1299
     }
1173
     }
1300
 
1174
 
1301
-    glTranslated(room->pos[0], room->pos[1], room->pos[2]);
1175
+    vec3_t pos;
1176
+    room.getPos(pos);
1177
+    glTranslated(pos[0], pos[1], pos[2]);
1302
 
1178
 
1303
     // Reset since GL_MODULATE used, reset to WHITE
1179
     // Reset since GL_MODULATE used, reset to WHITE
1304
     glColor3fv(WHITE);
1180
     glColor3fv(WHITE);
1306
     switch (mMode)
1182
     switch (mMode)
1307
     {
1183
     {
1308
         case modeWireframe:
1184
         case modeWireframe:
1309
-            rRoom->mesh.mMode = Mesh::MeshModeWireframe;
1185
+            room.getMesh().mMode = Mesh::MeshModeWireframe;
1310
             break;
1186
             break;
1311
         case modeSolid:
1187
         case modeSolid:
1312
-            rRoom->mesh.mMode = Mesh::MeshModeSolid;
1188
+            room.getMesh().mMode = Mesh::MeshModeSolid;
1313
             break;
1189
             break;
1314
         default:
1190
         default:
1315
-            rRoom->mesh.mMode = Mesh::MeshModeTexture;
1191
+            room.getMesh().mMode = Mesh::MeshModeTexture;
1316
             break;
1192
             break;
1317
     }
1193
     }
1318
 
1194
 
1319
     if (draw_alpha)
1195
     if (draw_alpha)
1320
-    {
1321
-        rRoom->mesh.drawAlpha();
1322
-    }
1196
+        room.getMesh().drawAlpha();
1323
     else
1197
     else
1324
-    {
1325
-        rRoom->mesh.drawSolid();
1326
-    }
1198
+        room.getMesh().drawSolid();
1327
 
1199
 
1328
     glPopMatrix();
1200
     glPopMatrix();
1329
 
1201
 
1330
     //mTexture.bindTextureId(0);
1202
     //mTexture.bindTextureId(0);
1331
 
1203
 
1332
     // Draw other room meshes and sprites
1204
     // Draw other room meshes and sprites
1333
-    if (draw_alpha || mMode == modeWireframe || mMode == modeSolid)
1334
-    {
1335
-        if (mFlags & Render::fRoomModels)
1336
-        {
1337
-            static_model_t *mdl;
1338
-
1339
-            for (unsigned int i = 0; i < room->models.size(); i++)
1340
-            {
1341
-                mdl = room->models[i];
1342
-
1343
-                if (!mdl)
1344
-                    continue;
1345
-
1346
-                mdl->pos[0] += room->pos[0];
1347
-                mdl->pos[1] += room->pos[1];
1348
-                mdl->pos[2] += room->pos[2];
1349
-
1350
-                // Depth sort room model render list with qsort
1351
-                std::sort(room->models.begin(), room->models.end(), compareStaticModels);
1352
-
1353
-                mdl->pos[0] -= room->pos[0];
1354
-                mdl->pos[1] -= room->pos[1];
1355
-                mdl->pos[2] -= room->pos[2];
1356
-            }
1357
-
1358
-            for (unsigned int i = 0; i < room->models.size(); i++)
1359
-            {
1360
-                drawRoomModel(room->models[i]);
1205
+    if (draw_alpha || mMode == modeWireframe || mMode == modeSolid) {
1206
+        if (mFlags & Render::fRoomModels) {
1207
+            room.sortModels();
1208
+            for (unsigned int i = 0; i < room.sizeModels(); i++) {
1209
+                room.getModel(i).display();
1361
             }
1210
             }
1362
         }
1211
         }
1363
 
1212
 
1364
         // Draw other room alpha polygon objects
1213
         // Draw other room alpha polygon objects
1365
-        if (mFlags & Render::fSprites)
1366
-        {
1367
-            for (unsigned int i = 0; i < room->sprites.size(); i++)
1368
-            {
1369
-                drawSprite(room->sprites[i]);
1214
+        if (mFlags & Render::fSprites) {
1215
+            for (unsigned int i = 0; i < room.sizeSprites(); i++) {
1216
+                room.getSprite(i).display();
1370
             }
1217
             }
1371
         }
1218
         }
1372
     }
1219
     }
1373
 }
1220
 }
1374
 
1221
 
1375
 
1222
 
1376
-void Render::drawSprite(sprite_t *sprite)
1377
-{
1378
-    if (!sprite)
1379
-        return;
1380
-
1381
-    if (!isVisible(sprite->pos[0], sprite->pos[1], sprite->pos[2],
1382
-                sprite->radius))
1383
-        return;
1384
-
1385
-    glPushMatrix();
1386
-    glTranslated(sprite->pos[0], sprite->pos[1], sprite->pos[2]);
1387
-
1388
-    // Sprites must always face camera, because they have no depth  =)
1389
-    glRotated(OR_RAD_TO_DEG(getCamera().getRadianYaw()), 0, 1, 0);
1390
-
1391
-    switch (mMode)
1392
-    {
1393
-        // No vertex lighting on sprites, as far as I see in specs
1394
-        // So just draw normal texture, no case 2
1395
-        case Render::modeSolid:
1396
-            glBegin(GL_TRIANGLE_STRIP);
1397
-            glColor3f(sprite->texel[0].st[0], sprite->texel[0].st[1], 0.5);
1398
-            glVertex3fv(sprite->vertex[0].pos);
1399
-
1400
-            glColor3f(sprite->texel[1].st[0], sprite->texel[1].st[1], 0.5);
1401
-            glVertex3fv(sprite->vertex[1].pos);
1402
-
1403
-            glColor3f(sprite->texel[3].st[0], sprite->texel[3].st[1], 0.5);
1404
-            glVertex3fv(sprite->vertex[3].pos);
1405
-
1406
-            glColor3f(sprite->texel[2].st[0], sprite->texel[2].st[1], 0.5);
1407
-            glVertex3fv(sprite->vertex[2].pos);
1408
-            glEnd();
1409
-            break;
1410
-        case Render::modeWireframe:
1411
-            glColor3fv(CYAN);
1412
-            glBegin(GL_LINE_LOOP);
1413
-            glVertex3fv(sprite->vertex[0].pos);
1414
-            glVertex3fv(sprite->vertex[1].pos);
1415
-            glVertex3fv(sprite->vertex[2].pos);
1416
-            glVertex3fv(sprite->vertex[3].pos);
1417
-            glEnd();
1418
-            glColor3fv(WHITE);
1419
-            break;
1420
-        default:
1421
-            glBindTexture(GL_TEXTURE_2D, sprite->texture+1);
1422
-
1423
-            glBegin(GL_TRIANGLE_STRIP);
1424
-            glTexCoord2fv(sprite->texel[0].st);
1425
-            glVertex3fv(sprite->vertex[0].pos);
1426
-            glTexCoord2fv(sprite->texel[1].st);
1427
-            glVertex3fv(sprite->vertex[1].pos);
1428
-            glTexCoord2fv(sprite->texel[3].st);
1429
-            glVertex3fv(sprite->vertex[3].pos);
1430
-            glTexCoord2fv(sprite->texel[2].st);
1431
-            glVertex3fv(sprite->vertex[2].pos);
1432
-            glEnd();
1433
-    }
1434
-
1435
-    glPopMatrix();
1436
-}
1437
-
1438
-
1439
-void Render::drawRoomModel(static_model_t *mesh)
1440
-{
1441
-    model_mesh_t *r_mesh;
1442
-
1443
-
1444
-    if (!mesh)
1445
-        return;
1446
-
1447
-    r_mesh = getWorld().getMesh(mesh->index);
1448
-
1449
-    if (!r_mesh)
1450
-        return;
1451
-
1452
-    if (!isVisible(mesh->pos[0], mesh->pos[1], mesh->pos[2], r_mesh->radius))
1453
-        return;
1454
-
1455
-    glPushMatrix();
1456
-    glTranslated(mesh->pos[0], mesh->pos[1], mesh->pos[2]);
1457
-    glRotated(mesh->yaw, 0, 1, 0);
1458
-
1459
-    drawModelMesh(r_mesh, roomMesh);
1460
-    glPopMatrix();
1461
-}
1462
-
1463
-
1464
 void Render::tmpRenderModelMesh(model_mesh_t *r_mesh, texture_tri_t *ttri)
1223
 void Render::tmpRenderModelMesh(model_mesh_t *r_mesh, texture_tri_t *ttri)
1465
 {
1224
 {
1466
     glBegin(GL_TRIANGLES);
1225
     glBegin(GL_TRIANGLES);

+ 31
- 0
src/Room.cpp Прегледај датотеку

5
  * \author xythobuz
5
  * \author xythobuz
6
  */
6
  */
7
 
7
 
8
+#ifdef __APPLE__
9
+#include <OpenGL/gl.h>
10
+#include <OpenGL/glu.h>
11
+#else
12
+#include <GL/gl.h>
13
+#include <GL/glu.h>
14
+#endif
15
+
16
+#include <algorithm>
17
+
8
 #include "main.h"
18
 #include "main.h"
9
 #include "Room.h"
19
 #include "Room.h"
10
 
20
 
15
         pos[i] = _pos[i];
25
         pos[i] = _pos[i];
16
 }
26
 }
17
 
27
 
28
+void StaticModel::display() {
29
+    model_mesh_t *mesh = getWorld().getMesh(index);
30
+
31
+    if (!mesh)
32
+        return;
33
+
34
+    if (!getRender().isVisible(pos[0], pos[1], pos[2], mesh->radius))
35
+        return;
36
+
37
+    glPushMatrix();
38
+    glTranslated(pos[0], pos[1], pos[2]);
39
+    glRotated(yaw, 0, 1, 0);
40
+
41
+    getRender().drawModelMesh(mesh, Render::roomMesh);
42
+    glPopMatrix();
43
+}
44
+
18
 bool StaticModel::operator<(const StaticModel &other) {
45
 bool StaticModel::operator<(const StaticModel &other) {
19
     vec_t distA, distB;
46
     vec_t distA, distB;
20
     distA = getRender().mViewVolume.getDistToSphereFromNear(pos[0],
47
     distA = getRender().mViewVolume.getDistToSphereFromNear(pos[0],
83
     }
110
     }
84
 }
111
 }
85
 
112
 
113
+void Room::sortModels() {
114
+    std::sort(models.begin(), models.end());
115
+}
116
+

+ 13
- 11
src/World.cpp Прегледај датотеку

273
 int World::getRoomByLocation(int index, float x, float y, float z)
273
 int World::getRoomByLocation(int index, float x, float y, float z)
274
 {
274
 {
275
     assert(index >= 0);
275
     assert(index >= 0);
276
-    assert(index < mRooms.size());
276
+    assert(index < (int)mRooms.size());
277
     Room &room = *mRooms.at(index);
277
     Room &room = *mRooms.at(index);
278
 
278
 
279
     if (room.inBox(x, y, z))
279
     if (room.inBox(x, y, z))
303
         float x, float y, float z,
303
         float x, float y, float z,
304
         float x2, float y2, float z2) {
304
         float x2, float y2, float z2) {
305
     assert(index >= 0);
305
     assert(index >= 0);
306
-    assert(index < mRooms.size());
306
+    assert(index < (int)mRooms.size());
307
     Room &room = *mRooms.at(index);
307
     Room &room = *mRooms.at(index);
308
     vec3_t intersect, p1, p2;
308
     vec3_t intersect, p1, p2;
309
+    vec3_t vertices[4];
309
 
310
 
310
     p1[0] = x;  p1[1] = y;  p1[2] = z;
311
     p1[0] = x;  p1[1] = y;  p1[2] = z;
311
     p2[0] = x2; p2[1] = y2; p2[2] = z2;
312
     p2[0] = x2; p2[1] = y2; p2[2] = z2;
312
 
313
 
313
     for (unsigned int i = 0; i < room.sizePortals(); i++) {
314
     for (unsigned int i = 0; i < room.sizePortals(); i++) {
315
+        room.getPortal(i).getVertices(vertices);
314
         if (intersectionLinePolygon(intersect, p1, p2, //4,
316
         if (intersectionLinePolygon(intersect, p1, p2, //4,
315
-                    room.getPortal(i).getVertices()))
317
+                    vertices))
316
             return room.getPortal(i).getAdjoiningRoom();
318
             return room.getPortal(i).getAdjoiningRoom();
317
     }
319
     }
318
 
320
 
322
 
324
 
323
 int World::getSector(int room, float x, float z, float *floor, float *ceiling) {
325
 int World::getSector(int room, float x, float z, float *floor, float *ceiling) {
324
     assert(room >= 0);
326
     assert(room >= 0);
325
-    assert(room < mRooms.size());
327
+    assert(room < (int)mRooms.size());
326
     assert(floor != NULL);
328
     assert(floor != NULL);
327
     assert(ceiling != NULL);
329
     assert(ceiling != NULL);
328
 
330
 
329
     int sector = getSector(room, x, z);
331
     int sector = getSector(room, x, z);
330
 
332
 
331
-    if ((sector >= 0) && (sector < mRooms.at(room)->sizeSectors())) {
333
+    if ((sector >= 0) && (sector < (int)mRooms.at(room)->sizeSectors())) {
332
         *floor = mRooms.at(room)->getSector(sector).getFloor();
334
         *floor = mRooms.at(room)->getSector(sector).getFloor();
333
         *ceiling = mRooms.at(room)->getSector(sector).getCeiling();
335
         *ceiling = mRooms.at(room)->getSector(sector).getCeiling();
334
     }
336
     }
339
 
341
 
340
 int World::getSector(int room, float x, float z) {
342
 int World::getSector(int room, float x, float z) {
341
     assert(room >= 0);
343
     assert(room >= 0);
342
-    assert(room < mRooms.size());
344
+    assert(room < (int)mRooms.size());
343
 
345
 
344
     vec3_t pos;
346
     vec3_t pos;
345
     mRooms.at(room)->getPos(pos);
347
     mRooms.at(room)->getPos(pos);
355
 
357
 
356
 unsigned int World::getRoomInfo(int room) {
358
 unsigned int World::getRoomInfo(int room) {
357
     assert(room >= 0);
359
     assert(room >= 0);
358
-    assert(room < mRooms.size());
360
+    assert(room < (int)mRooms.size());
359
 
361
 
360
     return mRooms.at(room)->getFlags();
362
     return mRooms.at(room)->getFlags();
361
 }
363
 }
363
 
365
 
364
 bool World::isWall(int room, int sector) {
366
 bool World::isWall(int room, int sector) {
365
     assert(room >= 0);
367
     assert(room >= 0);
366
-    assert(room < mRooms.size());
368
+    assert(room < (int)mRooms.size());
367
     assert(sector >= 0);
369
     assert(sector >= 0);
368
-    assert(sector < mRooms.at(room)->sizeSectors());
370
+    assert(sector < (int)mRooms.at(room)->sizeSectors());
369
 
371
 
370
     //! \fixme is (sector > 0) correct??
372
     //! \fixme is (sector > 0) correct??
371
     return ((sector > 0) && mRooms.at(room)->getSector(sector).isWall());
373
     return ((sector > 0) && mRooms.at(room)->getSector(sector).isWall());
374
 
376
 
375
 void World::getHeightAtPosition(int index, float x, float *y, float z) {
377
 void World::getHeightAtPosition(int index, float x, float *y, float z) {
376
     assert(index >= 0);
378
     assert(index >= 0);
377
-    assert(index < mRooms.size());
379
+    assert(index < (int)mRooms.size());
378
 
380
 
379
     int sector = getSector(index, x, z);
381
     int sector = getSector(index, x, z);
380
-    if ((sector >= 0) && (sector < mRooms.at(index)->sizeSectors()))
382
+    if ((sector >= 0) && (sector < (int)mRooms.at(index)->sizeSectors()))
381
         *y = mRooms.at(index)->getSector(sector).getFloor();
383
         *y = mRooms.at(index)->getSector(sector).getFloor();
382
 }
384
 }
383
 
385
 

Loading…
Откажи
Сачувај