Merge branch 'master' of goat:git/laserbrain_demo
[laserbrain_demo] / src / snode.h
1 #ifndef SNODE_H_
2 #define SNODE_H_
3
4 #include <vector>
5 #include "object.h"
6 #include "geom.h"
7 #include "gmath/gmath.h"
8
9 class Scene;
10
11 class SceneNode {
12 private:
13         char *name;
14
15         Vec3 pos;
16         Quat rot;
17         Vec3 scale;
18
19         std::vector<Object*> obj;
20
21         SceneNode *parent;
22         std::vector<SceneNode*> children;
23
24         Mat4 xform;
25         Mat4 inv_xform;
26
27         mutable bool local_bvol_valid;
28         mutable AABox local_bvol;
29
30 public:
31         Scene *scene;   // scene to which this node belongs
32         Mat4 dbg_xform;
33         bool visible;   // if true, objects of this node are supposed to be visible
34
35         SceneNode();
36         explicit SceneNode(Object *obj);
37         ~SceneNode();
38
39         void set_name(const char *s);
40         const char *get_name() const;
41
42         void add_child(SceneNode *node);
43         bool remove_child(SceneNode *node);
44
45         int get_num_children() const;
46         SceneNode *get_child(int idx) const;
47
48         SceneNode *get_parent() const;
49
50         SceneNode *find_object_node() const;
51
52         void add_object(Object *obj);
53         bool remove_object(Object *obj);
54
55         int get_num_objects() const;
56         Object *get_object(int idx) const;
57
58         void set_position(const Vec3 &pos);
59         void set_rotation(const Quat &rot);
60         void set_scaling(const Vec3 &scale);
61
62         const Vec3 &get_node_position() const;
63         const Quat &get_node_rotation() const;
64         const Vec3 &get_node_scaling() const;
65
66         Vec3 get_position() const;
67         Quat get_rotation() const;
68         Vec3 get_scaling() const;
69
70         const Mat4 &get_matrix() const;
71         const Mat4 &get_inv_matrix() const;
72
73         void update_node(float dt = 0.0f);
74         void update(float dt = 0.0f);
75
76         void apply_xform();
77
78         bool intersect(const Ray &ray, HitPoint *hit) const;
79
80         // cached local bounding box (all objects in this node in model space)
81         const AABox &calc_local_bounds();
82         const AABox &get_local_bounds() const;
83
84         // world bounding box of the node
85         AABox get_node_bounds() const;
86         // world bounding box of the node and it's subtree
87         AABox get_bounds() const;
88 };
89
90 #endif  // SNODE_H_