TDT4230_final_project/src/sceneGraph.hpp

82 lines
1.9 KiB
C++
Raw Normal View History

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>
#include <stack>
#include <stdbool.h>
#include <utilities/shader.hpp>
#include <vector>
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 {
SceneNode() {
position = glm::vec3(0, 0, 0);
rotation = glm::vec3(0, 0, 0);
scale = glm::vec3(1, 1, 1);
referencePoint = glm::vec3(0, 0, 0);
vertexArrayObjectID = -1;
VAOIndexCount = 0;
nodeType = GEOMETRY;
targeted_by = nullptr;
2019-03-14 12:43:41 +01:00
isIlluminated = true;
isInverted = false;
}
SceneNode(SceneNodeType type) : SceneNode() {
nodeType = type;
2019-02-19 16:16:13 +01:00
}
std::vector<SceneNode*> children;
// The node's position and rotation relative to its parent
glm::vec3 position;
glm::vec3 rotation;
glm::vec3 scale;
// 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 16:26:31 +01:00
glm::mat4 MVP; // MVP
glm::mat4 MV; // MV
glm::mat4 MVnormal; // transpose(inverse(MV))
2019-02-19 16:16:13 +01:00
// The location of the node's reference point
glm::vec3 referencePoint;
// The ID of the VAO containing the "appearance" of this SceneNode.
int vertexArrayObjectID;
unsigned int VAOIndexCount;
2019-03-14 12:43:41 +01:00
unsigned int diffuseTextureID;
unsigned int normalTextureID;
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:
unsigned int lightID;
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);