| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- #ifndef SCENE_NODE_H
- #define SCENE_NODE_H
- #include <memory>
- #include "Vec.h"
- #include "Math.h"
- #include "Object.h"
- #include "Properties.h"
- class Material;
- class Controller;
- /// The backbone of scene. It is also an Object for memory management reasons
- class SceneNode: public Object
- {
- friend class Scene;
- public:
- enum SceneNodeType
- {
- SNT_GHOST,
- SNT_LIGHT,
- SNT_CAMERA,
- SNT_PARTICLE_EMITTER,
- SNT_MODEL
- };
- PROPERTY_RW(Transform, localTransform, getLocalTransform, setLocalTransform) ///< The transformation in local space
- PROPERTY_RW(Transform, worldTransform, getWorldTransform, setWorldTransform) ///< The transformation in world space (local combined with parent transformation)
- public:
- SceneNode* parent;
- Vec<SceneNode*> childs;
- SceneNodeType type;
- bool isCompound;
-
- SceneNode(SceneNodeType type_, SceneNode* parent = NULL);
- virtual ~SceneNode();
- virtual void init(const char*) = 0; ///< init using a script
- /// @name Updates
- /// Two separate updates happen every loop. The update happens anyway and the updateTrf only when the node is being
- /// moved
- /// @{
- virtual void update() {};
- virtual void updateTrf() {};
- /// @}
- /// @name Mess with the local transform
- /// @{
- void rotateLocalX(float angDegrees) {localTransform.rotation.rotateXAxis(angDegrees);}
- void rotateLocalY(float angDegrees) {localTransform.rotation.rotateYAxis(angDegrees);}
- void rotateLocalZ(float angDegrees) {localTransform.rotation.rotateZAxis(angDegrees);}
- void moveLocalX(float distance);
- void moveLocalY(float distance);
- void moveLocalZ(float distance);
- /// @}
- void addChild(SceneNode* node);
- void removeChild(SceneNode* node);
- private:
- void commonConstructorCode(); ///< Cause we cannot call constructor from other constructor
- void updateWorldTransform(); ///< This update happens only when the object gets moved
- };
- inline SceneNode::SceneNode(SceneNodeType type_, SceneNode* parent):
- Object(parent),
- type(type_)
- {
- commonConstructorCode();
- if(parent != NULL)
- {
- parent->addChild(this);
- }
- }
- #endif
|