OpenRaider  0.1.4-dev
Open Source Tomb Raider Game Engine implementation
Entity.cpp
Go to the documentation of this file.
1 
8 #include "global.h"
9 #include "Camera.h"
10 #include "Log.h"
11 #include "World.h"
12 #include "Entity.h"
13 
14 #include <glm/gtc/matrix_transform.hpp>
15 
16 #define CACHE_SPRITE 0
17 #define CACHE_MESH 1
18 #define CACHE_MODEL 2
19 
20 bool Entity::showEntitySprites = true;
21 bool Entity::showEntityMeshes = true;
22 bool Entity::showEntityModels = true;
23 
24 void Entity::display(glm::mat4 VP) {
25  if ((cache == -1) || (cacheType == -1)) {
26  /*
27  * The order in which to look for matching objects with the same ID
28  * seems to be very important!
29  * If sprites and meshes are searched before models, many objects will
30  * be displayed wrong (eg. 'bad guy' becomes 'clothes' in tr2/boat)...
31  */
32 
33  for (int i = 0; (i < getWorld().sizeSkeletalModel()) && (cache == -1); i++) {
34  auto& s = getWorld().getSkeletalModel(i);
35  if (s.getID() == id) {
37  cache = i;
38  break;
39  }
40  }
41 
42  for (int i = 0; (i < getWorld().sizeStaticMesh()) && (cache == -1); i++) {
43  auto& s = getWorld().getStaticMesh(i);
44  if (s.getID() == id) {
46  cache = i;
47  break;
48  }
49  }
50 
51  for (int i = 0; i < getWorld().sizeSpriteSequence(); i++) {
52  auto& s = getWorld().getSpriteSequence(i);
53  if (s.getID() == id) {
55  cache = i;
56  break;
57  }
58  }
59 
62  }
63 
64  glm::mat4 translate = glm::translate(glm::mat4(1.0f), glm::vec3(pos.x, -pos.y, pos.z));
65  glm::mat4 rotate;
66  if (cacheType == 0) {
67  rotate = glm::rotate(glm::mat4(1.0f), Camera::getRotation().x, glm::vec3(0.0f, 1.0f, 0.0f));
68  } else {
69  rotate = glm::rotate(glm::mat4(1.0f), rot.y, glm::vec3(0.0f, 1.0f, 0.0f));
70  }
71  glm::mat4 model = translate * rotate;
72  glm::mat4 MVP = VP * model;
73 
74  if (cacheType == CACHE_SPRITE) {
77  } else if (cacheType == CACHE_MESH) {
78  if (showEntityMeshes)
80  } else if (cacheType == CACHE_MODEL) {
81  if (showEntityModels)
83  } else {
84  assert(false && "This should not happen...");
85  }
86 }
87 
StaticMesh & getStaticMesh(unsigned long index)
Definition: World.cpp:98
glm::vec3 rot
Definition: Entity.h:41
static bool showEntitySprites
Definition: Entity.h:48
int sprite
Definition: Entity.h:44
void display(glm::mat4 MVP, int aframe, int bframe, ShaderTexture *shaderTexture=nullptr)
World Model.
unsigned long sizeStaticMesh()
Definition: World.cpp:94
Things in the World.
World & getWorld()
Definition: main.cpp:32
Included everywhere.
int cache
Definition: Entity.h:42
int cacheType
Definition: Entity.h:42
#define CACHE_MODEL
Definition: Entity.cpp:18
unsigned long sizeSpriteSequence()
Definition: World.cpp:55
Global Logging Utility.
static bool showEntityMeshes
Definition: Entity.h:49
int frame
Definition: Entity.h:46
glm::vec3 pos
Definition: Entity.h:40
#define assert(x)
Definition: global.h:124
SpriteSequence & getSpriteSequence(unsigned long index)
Definition: World.cpp:59
int id
Definition: Entity.h:38
int animation
Definition: Entity.h:45
#define CACHE_MESH
Definition: Entity.cpp:17
SkeletalModel & getSkeletalModel(unsigned long index)
Definition: World.cpp:85
void display(glm::mat4 VP)
Definition: Entity.cpp:24
void display(glm::mat4 MVP)
Definition: StaticMesh.cpp:14
unsigned long sizeSkeletalModel()
Definition: World.cpp:81
#define assertGreaterThan(x, y)
Definition: global.h:162
static bool showEntityModels
Definition: Entity.h:50
Camera, View Frustum.
#define CACHE_SPRITE
Definition: Entity.cpp:16
static glm::vec2 getRotation()
Definition: Camera.h:29
void display(glm::mat4 MVP, int index)
Definition: Sprite.cpp:54