2019-02-19 16:16:13 +01:00
|
|
|
#pragma once
|
|
|
|
|
2019-03-15 16:34:17 +01:00
|
|
|
#include <chrono>
|
2019-02-19 16:16:13 +01:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <ctime>
|
|
|
|
#include <fstream>
|
2019-03-15 16:34:17 +01:00
|
|
|
#include <glm/glm.hpp>
|
|
|
|
#include <glm/gtc/type_ptr.hpp>
|
|
|
|
#include <glm/mat4x4.hpp>
|
2019-03-15 18:06:49 +01:00
|
|
|
#include <map>
|
2019-03-15 16:34:17 +01:00
|
|
|
#include <stack>
|
|
|
|
#include <stdbool.h>
|
2019-03-15 18:06:49 +01:00
|
|
|
#include <utilities/glutils.h>
|
2019-03-15 16:34:17 +01:00
|
|
|
#include <utilities/shader.hpp>
|
|
|
|
#include <vector>
|
2019-02-19 16:16:13 +01:00
|
|
|
|
2019-03-15 18:06:49 +01:00
|
|
|
using glm::vec3;
|
|
|
|
using glm::mat4;
|
|
|
|
using std::map;
|
|
|
|
using std::vector;
|
|
|
|
typedef unsigned int uint;
|
|
|
|
|
2019-02-19 16:16:13 +01:00
|
|
|
enum SceneNodeType {
|
2019-03-14 12:43:41 +01:00
|
|
|
GEOMETRY, POINT_LIGHT, SPOT_LIGHT, HUD, TEXTURED_GEOMETRY, NORMAL_TEXTURED_GEOMETRY
|
2019-02-19 16:16:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct SceneNode {
|
2019-03-15 18:06:49 +01:00
|
|
|
SceneNode(SceneNodeType type = GEOMETRY) {
|
|
|
|
position = vec3(0, 0, 0);
|
|
|
|
rotation = vec3(0, 0, 0);
|
|
|
|
scale = vec3(1, 1, 1);
|
2019-02-19 16:16:13 +01:00
|
|
|
|
2019-03-15 18:06:49 +01:00
|
|
|
referencePoint = vec3(0, 0, 0);
|
2019-02-19 16:16:13 +01:00
|
|
|
vertexArrayObjectID = -1;
|
|
|
|
VAOIndexCount = 0;
|
|
|
|
|
2019-03-15 18:06:49 +01:00
|
|
|
nodeType = type;
|
2019-02-19 16:16:13 +01:00
|
|
|
targeted_by = nullptr;
|
2019-03-14 12:43:41 +01:00
|
|
|
|
|
|
|
isIlluminated = true;
|
|
|
|
isInverted = false;
|
|
|
|
}
|
2019-03-15 18:06:49 +01:00
|
|
|
|
|
|
|
void setMesh(Mesh* mesh) {
|
|
|
|
static map<Mesh*, int> cache;
|
|
|
|
|
|
|
|
if (cache.find(mesh) == cache.end())
|
|
|
|
cache[mesh] = generateBuffer(*mesh, nodeType==NORMAL_TEXTURED_GEOMETRY);
|
|
|
|
|
|
|
|
vertexArrayObjectID = cache[mesh];
|
|
|
|
VAOIndexCount = mesh->indices.size();
|
2019-02-19 16:16:13 +01:00
|
|
|
}
|
2019-03-15 18:06:49 +01:00
|
|
|
void setTexture(PNGImage* diffuse, PNGImage* normal = nullptr) {
|
|
|
|
static map<PNGImage*, int> cache;
|
2019-02-19 16:16:13 +01:00
|
|
|
|
2019-03-15 18:06:49 +01:00
|
|
|
if (cache.find(diffuse) == cache.end()) cache[diffuse] = generateTexture(*diffuse);
|
|
|
|
diffuseTextureID = cache[diffuse];
|
|
|
|
|
|
|
|
if (!normal) return;
|
|
|
|
if (cache.find(normal) == cache.end()) cache[normal] = generateTexture(*normal);
|
|
|
|
normalTextureID = cache[normal];
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<SceneNode*> children;
|
2019-02-19 16:16:13 +01:00
|
|
|
|
|
|
|
// The node's position and rotation relative to its parent
|
2019-03-15 18:06:49 +01:00
|
|
|
vec3 position;
|
|
|
|
vec3 rotation;
|
|
|
|
vec3 scale;
|
2019-02-19 16:16:13 +01:00
|
|
|
|
2019-03-15 16:43:51 +01:00
|
|
|
// set this if the shape uses a custom shader other than the default one
|
|
|
|
Gloom::Shader* shader = nullptr;
|
|
|
|
|
2019-02-19 16:16:13 +01:00
|
|
|
// A transformation matrix representing the transformation of the node's location relative to its parent. This matrix is updated every frame.
|
2019-03-15 18:06:49 +01:00
|
|
|
mat4 MVP; // MVP
|
|
|
|
mat4 MV; // MV
|
|
|
|
mat4 MVnormal; // transpose(inverse(MV))
|
2019-02-19 16:16:13 +01:00
|
|
|
|
2019-03-15 18:06:49 +01:00
|
|
|
// The location of the node's reference point (center of rotation)
|
|
|
|
vec3 referencePoint;
|
2019-02-19 16:16:13 +01:00
|
|
|
|
2019-03-15 18:06:49 +01:00
|
|
|
// VAO IDs refering to a loaded Mesh and its length
|
2019-02-19 16:16:13 +01:00
|
|
|
int vertexArrayObjectID;
|
2019-03-15 18:06:49 +01:00
|
|
|
uint VAOIndexCount;
|
2019-03-14 12:43:41 +01:00
|
|
|
|
2019-03-15 18:06:49 +01:00
|
|
|
// textures
|
|
|
|
uint diffuseTextureID;
|
|
|
|
uint normalTextureID;
|
2019-03-14 12:43:41 +01:00
|
|
|
|
2019-03-15 18:06:49 +01:00
|
|
|
// shader flags
|
2019-03-14 12:43:41 +01:00
|
|
|
bool isIlluminated;
|
|
|
|
bool isInverted;
|
2019-02-19 16:16:13 +01:00
|
|
|
|
|
|
|
// Node type is used to determine how to handle the contents of a node
|
|
|
|
SceneNodeType nodeType;
|
|
|
|
|
|
|
|
// for lights:
|
2019-03-15 18:06:49 +01:00
|
|
|
uint lightID;
|
2019-02-19 16:16:13 +01:00
|
|
|
SceneNode* targeted_by; // spot
|
|
|
|
};
|
|
|
|
|
|
|
|
// Struct for keeping track of 2D coordinates
|
|
|
|
|
|
|
|
SceneNode* createSceneNode();
|
2019-03-14 12:43:41 +01:00
|
|
|
SceneNode* createSceneNode(SceneNodeType type);
|
2019-02-19 16:16:13 +01:00
|
|
|
void addChild(SceneNode* parent, SceneNode* child);
|
|
|
|
void printNode(SceneNode* node);
|