OpenRaider  0.1.4-dev
Open Source Tomb Raider Game Engine implementation
Room.cpp
Go to the documentation of this file.
1 
8 #include "global.h"
9 #include "Log.h"
10 #include "Room.h"
11 
12 #include <glm/gtc/matrix_transform.hpp>
13 #include <glm/gtx/intersect.hpp>
14 
15 bool Room::showBoundingBox = false;
16 bool Room::showRoomModels = true;
17 bool Room::showRoomSprites = true;
18 bool Room::showRoomGeometry = true;
19 
20 Room::Room(glm::vec3 _pos, BoundingBox* _bbox, RoomMesh* _mesh, unsigned int f,
21  int a, int x, int z, int i) : pos(_pos), bbox(_bbox), mesh(_mesh), flags(f),
22  alternateRoom(a), numXSectors(x), numZSectors(z), roomIndex(i) {
23  model = glm::translate(glm::mat4(1.0f), pos);
24 }
25 
26 void Room::display(glm::mat4 VP) {
27  glm::mat4 MVP = VP * model;
28 
29  if (showRoomGeometry)
30  mesh->display(MVP);
31 
32  if (showRoomModels) {
33  for (auto& m : models) {
34  m->display(VP);
35  }
36  }
37 
38  if (showRoomSprites) {
39  for (auto& s : sprites) {
40  s->display(VP);
41  }
42  }
43 
44  if (showBoundingBox)
45  bbox->display(VP, glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(1.0f, 0.0f, 1.0f));
46 }
47 
48 bool Room::isWall(unsigned long sector) {
49  assertLessThan(sector, sectors.size());
50 
52  return ((sector > 0) && sectors.at(sector)->isWall());
53 }
54 
55 long Room::getSector(float x, float z, float* floor, float* ceiling) {
56  assert(floor != nullptr);
57  assert(ceiling != nullptr);
58 
59  long sector = getSector(x, z);
60 
61  if ((sector >= 0) && (sector < (long)sectors.size())) {
62  *floor = sectors.at(sector)->getFloor();
63  *ceiling = sectors.at(sector)->getCeiling();
64  }
65 
66  return sector;
67 }
68 
69 long Room::getSector(float x, float z) {
70  long sector = (((((int)x - (int)pos[0]) / 1024) *
71  numZSectors) + (((int)z - (int)pos[2]) / 1024));
72 
73  if (sector < 0)
74  return -1;
75 
76  return sector;
77 }
78 
79 void Room::getHeightAtPosition(float x, float* y, float z) {
80  long sector = getSector(x, z);
81  if ((sector >= 0) && (sector < (long)sectors.size()))
82  *y = sectors.at(sector)->getFloor();
83 }
84 
85 int Room::getAdjoiningRoom(float x, float y, float z,
86  float x2, float y2, float z2) {
87  glm::vec3 orig(x, y, z);
88  glm::vec3 dir(x2 - x, y2 - y, z2 - z);
89  glm::vec3 intersect;
90 
91  for (unsigned long i = 0; i < portals.size(); i++) {
92  if ((glm::intersectLineTriangle(orig, dir, portals.at(i)->getVertex(0),
93  portals.at(i)->getVertex(1),
94  portals.at(i)->getVertex(2), intersect))
95  || (glm::intersectLineTriangle(orig, dir, portals.at(i)->getVertex(0),
96  portals.at(i)->getVertex(3),
97  portals.at(i)->getVertex(1), intersect)))
98  return portals.at(i)->getAdjoiningRoom();
99  }
100 
101  return -1;
102 }
103 
void getHeightAtPosition(float x, float *y, float z)
Definition: Room.cpp:79
bool isWall(unsigned long sector)
Definition: Room.cpp:48
std::unique_ptr< RoomMesh > mesh
Definition: Room.h:70
static bool showRoomGeometry
Definition: Room.h:86
Included everywhere.
std::vector< std::unique_ptr< StaticModel > > models
Definition: Room.h:79
Global Logging Utility.
#define assert(x)
Definition: global.h:124
static bool showBoundingBox
Definition: Room.h:83
std::unique_ptr< BoundingBox > bbox
Definition: Room.h:69
long getSector(float x, float z, float *floor, float *ceiling)
Definition: Room.cpp:55
glm::mat4 model
Definition: Room.h:68
std::vector< std::unique_ptr< Sector > > sectors
Definition: Room.h:81
std::vector< std::unique_ptr< RoomSprite > > sprites
Definition: Room.h:78
#define assertLessThan(x, y)
Definition: global.h:146
Room(glm::vec3 _pos, BoundingBox *_bbox, RoomMesh *_mesh, unsigned int f, int a, int x, int z, int i)
Definition: Room.cpp:20
void display(glm::mat4 VP)
Definition: Room.cpp:26
static bool showRoomModels
Definition: Room.h:84
Room in World.
glm::vec3 pos
Definition: Room.h:67
std::vector< std::unique_ptr< Portal > > portals
Definition: Room.h:80
int numZSectors
Definition: Room.h:75
int getAdjoiningRoom(float x, float y, float z, float x2, float y2, float z2)
Definition: Room.cpp:85
static bool showRoomSprites
Definition: Room.h:85