OpenRaider  0.1.4-dev
Open Source Tomb Raider Game Engine implementation
RoomData.cpp
Go to the documentation of this file.
1 
8 #include "global.h"
9 #include "Camera.h"
10 #include "World.h"
11 #include "system/Shader.h"
12 #include "RoomData.h"
13 
14 #include <glm/gtc/matrix_transform.hpp>
15 
16 void BoundingBox::display(glm::mat4 VP, glm::vec3 colorLine, glm::vec3 colorDot) {
17  std::vector<glm::vec3> verts;
18  std::vector<glm::vec3> cols;
19  std::vector<unsigned short> inds;
20 
21  for (int i = 0; i < 8; i++) {
22  verts.push_back(corner[i]);
23  cols.push_back(colorLine);
24  }
25 
26  inds.push_back(0);
27  inds.push_back(2);
28  inds.push_back(4);
29  inds.push_back(1);
30  inds.push_back(6);
31  inds.push_back(7);
32  inds.push_back(5);
33  inds.push_back(3);
34  inds.push_back(0);
35  inds.push_back(1);
36  inds.push_back(4);
37  inds.push_back(7);
38  inds.push_back(6);
39  inds.push_back(3);
40  inds.push_back(5);
41  inds.push_back(2);
42 
43  static ShaderBuffer vert, col, ind;
44  vert.bufferData(verts);
45  col.bufferData(cols);
46  ind.bufferData(inds);
47  Shader::drawGL(vert, col, ind, VP, GL_LINE_STRIP);
48 
49  cols.clear();
50  inds.clear();
51 
52  for (int i = 0; i < 8; i++) {
53  cols.push_back(colorDot);
54  inds.push_back(i);
55  }
56 
57  static ShaderBuffer vert2, col2, ind2;
58  vert2.bufferData(verts);
59  col2.bufferData(cols);
60  ind2.bufferData(inds);
61  Shader::drawGL(vert2, col2, ind2, VP, GL_POINTS);
62 }
63 
64 // ----------------------------------------------------------------------------
65 
66 StaticModel::StaticModel(glm::vec3 pos, float angle, int i) : id(i), cache(-1) {
67  glm::mat4 translate = glm::translate(glm::mat4(1.0f), glm::vec3(pos.x, -pos.y, pos.z));
68  glm::mat4 rotate = glm::rotate(glm::mat4(1.0f), angle, glm::vec3(0.0f, 1.0f, 0.0f));
69  model = translate * rotate;
70 }
71 
72 void StaticModel::display(glm::mat4 VP) {
73  if (cache < 0) {
74  for (int i = 0; i < getWorld().sizeStaticMesh(); i++) {
75  if (getWorld().getStaticMesh(i).getID() == id) {
76  cache = i;
77  }
78  }
80  }
81 
83 }
84 
85 // ----------------------------------------------------------------------------
86 
87 void RoomSprite::display(glm::mat4 VP) {
88  glm::mat4 translate = glm::translate(glm::mat4(1.0f), glm::vec3(pos.x, -pos.y, pos.z));
89  glm::mat4 rotate = glm::rotate(glm::mat4(1.0f), Camera::getRotation().x, glm::vec3(0.0f, 1.0f,
90  0.0f));
91  glm::mat4 model = translate * rotate;
92 
93  getWorld().getSprite(sprite).display(VP * model);
94 }
95 
96 // ----------------------------------------------------------------------------
97 
99  return floor;
100 }
101 
103  return ceiling;
104 }
105 
107  return wall;
108 }
109 
void display(glm::mat4 VP, glm::vec3 colorLine, glm::vec3 colorDot)
Definition: RoomData.cpp:16
bool isWall()
Definition: RoomData.cpp:106
void bufferData(int elem, int size, void *data)
Definition: Shader.cpp:18
void display(glm::mat4 VP)
Definition: RoomData.cpp:87
float getFloor()
Definition: RoomData.cpp:98
int cache
Definition: RoomData.h:58
StaticMesh & getStaticMesh(unsigned long index)
Definition: World.cpp:98
glm::vec3 corner[8]
Definition: RoomData.h:46
OpenGL Shader Implementation.
World Model.
unsigned long sizeStaticMesh()
Definition: World.cpp:94
World & getWorld()
Definition: main.cpp:32
Included everywhere.
bool wall
Definition: RoomData.h:110
void display(glm::mat4 VP)
Definition: RoomData.cpp:72
Auxiliary Room classes.
int sprite
Definition: RoomData.h:71
static void drawGL(ShaderBuffer &vertices, ShaderBuffer &uvs, glm::vec4 color, unsigned int texture, TextureStorage store=TextureStorage::SYSTEM, unsigned int mode=GL_TRIANGLES, ShaderTexture *target=nullptr, Shader &shader=textShader)
Definition: Shader.cpp:278
float ceiling
Definition: RoomData.h:109
StaticModel(glm::vec3 pos, float angle, int i)
Definition: RoomData.cpp:66
void display(glm::mat4 MVP)
Definition: Sprite.cpp:48
int getID()
Definition: StaticMesh.h:21
Sprite & getSprite(unsigned long index)
Definition: World.cpp:46
#define assertGreaterThanEqual(x, y)
Definition: global.h:170
void display(glm::mat4 MVP)
Definition: StaticMesh.cpp:14
glm::mat4 model
Definition: RoomData.h:59
glm::vec3 pos
Definition: RoomData.h:70
float getCeiling()
Definition: RoomData.cpp:102
Camera, View Frustum.
static glm::vec2 getRotation()
Definition: Camera.h:29
float floor
Definition: RoomData.h:108