From a65269f07f8ca48386246f712d7acbaf41ed1478 Mon Sep 17 00:00:00 2001 From: Anselme Date: Sun, 20 Mar 2016 23:33:07 +0100 Subject: [PATCH] added lots of things to scene --- src/cameranode.cpp | 50 ----------------------------- src/cameranode.h | 39 ----------------------- src/engine.cpp | 1 - src/main.cpp | 2 +- src/scenetree.cpp | 3 +- src/scenetree.h | 79 ++++++++++++---------------------------------- 6 files changed, 23 insertions(+), 151 deletions(-) delete mode 100644 src/cameranode.cpp delete mode 100644 src/cameranode.h diff --git a/src/cameranode.cpp b/src/cameranode.cpp deleted file mode 100644 index 849cc0d..0000000 --- a/src/cameranode.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "cameranode.h" -#include - -CameraNode::CameraNode(glm::vec3 position, float yFov, float near, float far) : - m_hasMoved(true), - m_hasResized(false), - m_eye(position), - m_target(0, 0, 1), - m_yFov(yFov), - m_near(near), - m_far(far) -{ - -} - -void CameraNode::setPosition(glm::vec3 position) -{ - m_hasMoved = true; - m_eye = position; -} - -void CameraNode::setTarget(glm::vec3 target) -{ - m_hasMoved = true; - m_target = target; -} - -void CameraNode::update() -{ - if(m_hasMoved) - m_view = glm::lookAt(m_eye, m_target, glm::vec3(0, 1, 0)); - if(m_hasResized) - m_projection = glm::perspective(m_yFov, m_ratio, m_near, m_far); -} - -glm::mat4 CameraNode::getProjectionMatrix() -{ - return m_projection; -} - -glm::mat4 CameraNode::getViewMatrix() -{ - return m_view; -} - -void CameraNode::resize(int width, int height) -{ - m_hasResized = false; - m_ratio = ((float)width)/((float)height); -} diff --git a/src/cameranode.h b/src/cameranode.h deleted file mode 100644 index bd42753..0000000 --- a/src/cameranode.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef CAMERANODE_H -#define CAMERANODE_H - -#include "scenetree.h" -#include "camera.h" -#include "glm/vec3.hpp" - -class CameraNode : public SceneNode, public Camera -{ - bool m_hasMoved; - bool m_hasResized; - - glm::vec3 m_eye; - glm::vec3 m_target; - - float m_yFov; - float m_ratio; - float m_near; - float m_far; - - glm::mat4 m_projection; - glm::mat4 m_view; - -public: - CameraNode(glm::vec3 position, float yFov = 70.f, float near = 0.1f, float far = 100.f); - CameraNode(float yFov = 70.f, float near = 0.1f, float far = 100.f) : - CameraNode(glm::vec3(0), yFov, near, far) {} - - void setPosition(glm::vec3 position); - void setTarget(glm::vec3 target); - - virtual void update(); - - virtual glm::mat4 getProjectionMatrix(); - virtual glm::mat4 getViewMatrix(); - virtual void resize(int width, int height); -}; - -#endif // CAMERANODE_H diff --git a/src/engine.cpp b/src/engine.cpp index c4b3aa7..df7fb06 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -9,7 +9,6 @@ #include #include "resourcemanager.h" #include "scenetree.h" -#include "cameranode.h" Engine::Engine() : m_input(NULL), diff --git a/src/main.cpp b/src/main.cpp index eabdeb4..a8806c3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,9 +1,9 @@ #include "engine.h" #include #include "scene.h" -#include "cameranode.h" #include "resourcemanager.h" #include "sparrowrenderer.h" +#include "scenetree.h" #include "tools/graph.h" #include "tools/pathfinder.h" diff --git a/src/scenetree.cpp b/src/scenetree.cpp index b51a203..98e1ab4 100644 --- a/src/scenetree.cpp +++ b/src/scenetree.cpp @@ -27,8 +27,7 @@ SceneIterator* SceneTree::getGeometry() void SceneTree::update() { - m_objects.update(); - m_map.update(); + m_root.update(); } // Container Node diff --git a/src/scenetree.h b/src/scenetree.h index 2dea1ad..5e7b5ca 100644 --- a/src/scenetree.h +++ b/src/scenetree.h @@ -5,7 +5,12 @@ #include #include "scene.h" #include "light.h" +#include "resourcemanager.h" +/** + * @brief The SceneNode class represents a class of the game + * that will be updated or used for rendering every frame + */ class SceneNode { public: @@ -13,7 +18,9 @@ public: virtual void update() = 0; }; - +/** + * @brief The ContainerNode class represents a node which main use is to contain a collection of nodes + */ class ContainerNode : public SceneNode { public: @@ -24,6 +31,14 @@ protected: std::vector m_children; }; +/** + * @brief The CameraNode class is a scene node that can be used by the renderer + */ +class CameraNode : public Camera, SceneNode +{ + +}; + class SceneTree : public Scene { public: @@ -38,69 +53,17 @@ public: Texture* getSkybox() {return m_skybox;} void setSkybox(Texture* skybox) {m_skybox = skybox;} + void setMainCamera(const std::string &name) {m_camera = RESOURCE_GET(CameraNode, name);} + void addRootObject(const std::string &name) {m_root.addChild(name);} + private: std::string m_name; - ContainerNode m_objects; - ContainerNode m_map; + ContainerNode m_root; Texture* m_skybox; }; -//general Node +// Additionnal Nodes : -class ObjectNode : public SceneNode -{ - //add bullet rigidbody -public: - virtual void update(); -}; -class FragmentNode: public ObjectNode -{ - // TODO: later -}; - -class ItemNode: public ObjectNode -{ - // TODO: later -}; - -// Node -class GUINode : public SceneNode//, public GUIEntity -{ -public: - virtual void update(); -}; - -class PlayerNode: public SceneNode//, public FPSCamera -{ -public: - virtual void update(); -}; - -class EnvironmentNode : public SceneNode -{ -public: - virtual void update(); - // parametre skybox - // directionnal light - // parametre fog -}; - -class LightNode : public SceneNode, public Light -{ -public: - virtual void update(); - //position - //puissance - //lighting angle - //couleur -}; - -class ChunkNode: public SceneNode -{ -public: - virtual void update(); -// map -}; #endif // SCENETREE_H