rayzor
diff src/snode.h @ 13:964f8ea5f095
missed quite a lot of things in my last commit apparently
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 12 Apr 2014 23:37:55 +0300 |
parents | |
children | a9a948809c6f |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/snode.h Sat Apr 12 23:37:55 2014 +0300 1.3 @@ -0,0 +1,85 @@ 1.4 +#ifndef SCENE_NODE_H_ 1.5 +#define SCENE_NODE_H_ 1.6 + 1.7 +#include "vector.h" 1.8 +#include "vmath.h" 1.9 +#include "quat.h" 1.10 +#include "vmathmat.h" 1.11 +#include "vmathray.h" 1.12 + 1.13 +enum NodeType { 1.14 + NODE_NULL, 1.15 + NODE_OBJECT, 1.16 + NODE_LIGHT, 1.17 + NODE_CAMERA 1.18 +}; 1.19 + 1.20 +class SceneNode { 1.21 +protected: 1.22 + char *name; 1.23 + NodeType type; 1.24 + 1.25 + Vector3 pos; 1.26 + Quat rot; 1.27 + Vector3 scale; 1.28 + Vector3 pivot; 1.29 + 1.30 + mutable Matrix4x4 xform, inv_xform; 1.31 + mutable bool xform_valid, inv_xform_valid; 1.32 + 1.33 + vector<SceneNode*> children; 1.34 + SceneNode *parent; 1.35 + 1.36 + SceneNode(const SceneNode &node) {} 1.37 + SceneNode &operator =(const SceneNode &node) { return *this; } 1.38 + 1.39 + void invalidate() const; 1.40 + virtual void calc_matrix() const; 1.41 + virtual void calc_inv_matrix() const; 1.42 + 1.43 +public: 1.44 + SceneNode(); 1.45 + virtual ~SceneNode(); 1.46 + 1.47 + virtual void set_name(const char *name); 1.48 + virtual const char *get_name() const; 1.49 + 1.50 + virtual NodeType get_type() const; 1.51 + 1.52 + virtual SceneNode *get_parent(); 1.53 + virtual const SceneNode *get_parent() const; 1.54 + 1.55 + // children management 1.56 + virtual void add_child(SceneNode *child); 1.57 + virtual void remove_child(SceneNode *child); 1.58 + 1.59 + virtual int get_children_count() const; 1.60 + virtual SceneNode *get_child(int idx); 1.61 + virtual const SceneNode *get_child(int idx) const; 1.62 + 1.63 + virtual void set_position(const Vector3 &pos); 1.64 + virtual Vector3 get_node_position() const; 1.65 + 1.66 + virtual void set_rotation(const Quat &quat); 1.67 + virtual Quat get_node_rotation() const; 1.68 + 1.69 + virtual void set_scaling(const Vector3 &scale); 1.70 + virtual Vector3 get_node_scaling() const; 1.71 + 1.72 + // these take hierarchy into account 1.73 + virtual Vector3 get_position() const; 1.74 + virtual Quat get_rotation() const; 1.75 + virtual Vector3 get_scaling() const; 1.76 + 1.77 + virtual void set_pivot(const Vector3 &pivot); 1.78 + virtual Vector3 get_pivot() const; 1.79 + 1.80 + virtual const Matrix4x4 &get_matrix() const; 1.81 + virtual const Matrix4x4 &get_inv_matrix() const; 1.82 + 1.83 + virtual void draw() const; 1.84 + 1.85 + virtual bool intersect(const Ray &ray, float *dist = 0) const; 1.86 +}; 1.87 + 1.88 +#endif /* SCENE_NODE_H_ */