proper scene graph
[laserbrain_demo] / src / snode.h
1 #ifndef SNODE_H_
2 #define SNODE_H_
3
4 #include <vector>
5 #include "object.h"
6 #include "gmath/gmath.h"
7
8 class SceneNode {
9 private:
10         char *name;
11
12         Vec3 pos;
13         Quat rot;
14         Vec3 scale;
15
16         std::vector<Object*> obj;
17
18         SceneNode *parent;
19         std::vector<SceneNode*> children;
20
21         Mat4 xform;
22         Mat4 inv_xform;
23
24 public:
25         Mat4 dbg_xform;
26
27         SceneNode();
28         explicit SceneNode(Object *obj);
29         ~SceneNode();
30
31         void set_name(const char *s);
32         const char *get_name() const;
33
34         void add_child(SceneNode *node);
35         bool remove_child(SceneNode *node);
36
37         int get_num_children() const;
38         SceneNode *get_child(int idx) const;
39
40         SceneNode *get_parent() const;
41
42         void add_object(Object *obj);
43         bool remove_object(Object *obj);
44
45         int get_num_objects() const;
46         Object *get_object(int idx) const;
47
48         void set_position(const Vec3 &pos);
49         void set_rotation(const Quat &rot);
50         void set_scaling(const Vec3 &scale);
51
52         const Vec3 &get_node_position() const;
53         const Quat &get_node_rotation() const;
54         const Vec3 &get_node_scaling() const;
55
56         Vec3 get_position() const;
57         Quat get_rotation() const;
58         Vec3 get_scaling() const;
59
60         const Mat4 &get_matrix() const;
61         const Mat4 &get_inv_matrix() const;
62
63         void update_node(float dt = 0.0f);
64         void update(float dt = 0.0f);
65
66         bool intersect(const Ray &ray, HitPoint *hit) const;
67 };
68
69 #endif  // SNODE_H_