5af02f41fc0d99ed03f42902d40e3a169f48f44a
[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 Scene;
9
10 class SceneNode {
11 private:
12         char *name;
13
14         Vec3 pos;
15         Quat rot;
16         Vec3 scale;
17
18         std::vector<Object*> obj;
19
20         SceneNode *parent;
21         std::vector<SceneNode*> children;
22
23         Mat4 xform;
24         Mat4 inv_xform;
25
26 public:
27         Scene *scene;   // scene to which this node belongs
28         Mat4 dbg_xform;
29
30         SceneNode();
31         explicit SceneNode(Object *obj);
32         ~SceneNode();
33
34         void set_name(const char *s);
35         const char *get_name() const;
36
37         void add_child(SceneNode *node);
38         bool remove_child(SceneNode *node);
39
40         int get_num_children() const;
41         SceneNode *get_child(int idx) const;
42
43         SceneNode *get_parent() const;
44
45         void add_object(Object *obj);
46         bool remove_object(Object *obj);
47
48         int get_num_objects() const;
49         Object *get_object(int idx) const;
50
51         void set_position(const Vec3 &pos);
52         void set_rotation(const Quat &rot);
53         void set_scaling(const Vec3 &scale);
54
55         const Vec3 &get_node_position() const;
56         const Quat &get_node_rotation() const;
57         const Vec3 &get_node_scaling() const;
58
59         Vec3 get_position() const;
60         Quat get_rotation() const;
61         Vec3 get_scaling() const;
62
63         const Mat4 &get_matrix() const;
64         const Mat4 &get_inv_matrix() const;
65
66         void update_node(float dt = 0.0f);
67         void update(float dt = 0.0f);
68
69         void apply_xform();
70
71         bool intersect(const Ray &ray, HitPoint *hit) const;
72 };
73
74 #endif  // SNODE_H_