SceneNode bounds calculation
[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
34         SceneNode();
35         explicit SceneNode(Object *obj);
36         ~SceneNode();
37
38         void set_name(const char *s);
39         const char *get_name() const;
40
41         void add_child(SceneNode *node);
42         bool remove_child(SceneNode *node);
43
44         int get_num_children() const;
45         SceneNode *get_child(int idx) const;
46
47         SceneNode *get_parent() const;
48
49         void add_object(Object *obj);
50         bool remove_object(Object *obj);
51
52         int get_num_objects() const;
53         Object *get_object(int idx) const;
54
55         void set_position(const Vec3 &pos);
56         void set_rotation(const Quat &rot);
57         void set_scaling(const Vec3 &scale);
58
59         const Vec3 &get_node_position() const;
60         const Quat &get_node_rotation() const;
61         const Vec3 &get_node_scaling() const;
62
63         Vec3 get_position() const;
64         Quat get_rotation() const;
65         Vec3 get_scaling() const;
66
67         const Mat4 &get_matrix() const;
68         const Mat4 &get_inv_matrix() const;
69
70         void update_node(float dt = 0.0f);
71         void update(float dt = 0.0f);
72
73         void apply_xform();
74
75         bool intersect(const Ray &ray, HitPoint *hit) const;
76
77         // cached local bounding box (all objects in this node in model space)
78         const AABox &calc_local_bounds();
79         const AABox &get_local_bounds() const;
80
81         // world bounding box of the node
82         AABox get_node_bounds() const;
83         // world bounding box of the node and it's subtree
84         AABox get_bounds() const;
85 };
86
87 #endif  // SNODE_H_