123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- /*!
- * \file src/Entity.cpp
- * \brief Things in the World
- *
- * \author xythobuz
- */
-
- #include "global.h"
- #include "Camera.h"
- #include "Log.h"
- #include "World.h"
- #include "Entity.h"
-
- #include <glm/gtc/matrix_transform.hpp>
- #include <imgui/imgui.h>
-
- #define CACHE_SPRITE 0
- #define CACHE_MESH 1
- #define CACHE_MODEL 2
-
- bool Entity::showEntitySprites = true;
- bool Entity::showEntityMeshes = false;
- bool Entity::showEntityModels = false;
-
- void Entity::find() {
- if ((cache <= -1) || (cacheType <= -1)) {
- /*
- * The order in which to look for matching objects with the same ID
- * seems to be very important!
- * If sprites and meshes are searched before models, many objects will
- * be displayed wrong (eg. 'bad guy' becomes 'clothes' in tr2/boat)...
- */
-
- for (int i = 0; (i < World::sizeSkeletalModel()) && (cache == -1); i++) {
- auto& s = World::getSkeletalModel(i);
- if (s.getID() == id) {
- cacheType = CACHE_MODEL;
- cache = i;
- break;
- }
- }
-
- for (int i = 0; (i < World::sizeStaticMesh()) && (cache == -1); i++) {
- auto& s = World::getStaticMesh(i);
- if (s.getID() == id) {
- cacheType = CACHE_MESH;
- cache = i;
- break;
- }
- }
-
- for (int i = 0; i < World::sizeSpriteSequence(); i++) {
- auto& s = World::getSpriteSequence(i);
- if (s.getID() == id) {
- cacheType = CACHE_SPRITE;
- cache = i;
- break;
- }
- }
-
- orAssertGreaterThan(cache, -1);
- orAssertGreaterThan(cacheType, -1);
- }
- }
-
- void Entity::display(glm::mat4 VP) {
- find();
-
- glm::mat4 translate = glm::translate(glm::mat4(1.0f), pos);
- glm::mat4 rotate;
- if (cacheType == CACHE_SPRITE) {
- rotate = glm::rotate(glm::mat4(1.0f), -Camera::getRotation().x, glm::vec3(0.0f, 1.0f, 0.0f));
- } else {
- rotate = glm::rotate(glm::mat4(1.0f), rot.y, glm::vec3(0.0f, 1.0f, 0.0f));
- }
- glm::mat4 model = translate * rotate;
- glm::mat4 MVP = VP * model;
-
- if (cacheType == CACHE_SPRITE) {
- if (showEntitySprites)
- World::getSpriteSequence(cache).display(MVP, sprite);
- } else if (cacheType == CACHE_MESH) {
- if (showEntityMeshes)
- World::getStaticMesh(cache).display(MVP);
- } else if (cacheType == CACHE_MODEL) {
- if (showEntityModels)
- World::getSkeletalModel(cache).display(MVP, animation, frame);
- }
- }
-
- void Entity::displayUI() {
- find();
-
- ImGui::Text("%03d", id);
- ImGui::NextColumn();
- if (cacheType == CACHE_SPRITE) {
- ImGui::Text("SpriteSequence");
- } else if (cacheType == CACHE_MESH) {
- ImGui::Text("StaticMesh");
- } else if (cacheType == CACHE_MODEL) {
- ImGui::Text("SkeletalModel");
- }
- ImGui::NextColumn();
- ImGui::Text("%03d", cache);
- ImGui::NextColumn();
- }
|