6fa52ba892ee763a4db752c5e5b7825732abe326
[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         void add_object(Object *obj);
51         bool remove_object(Object *obj);
52
53         int get_num_objects() const;
54         Object *get_object(int idx) const;
55
56         void set_position(const Vec3 &pos);
57         void set_rotation(const Quat &rot);
58         void set_scaling(const Vec3 &scale);
59
60         const Vec3 &get_node_position() const;
61         const Quat &get_node_rotation() const;
62         const Vec3 &get_node_scaling() const;
63
64         Vec3 get_position() const;
65         Quat get_rotation() const;
66         Vec3 get_scaling() const;
67
68         const Mat4 &get_matrix() const;
69         const Mat4 &get_inv_matrix() const;
70
71         void update_node(float dt = 0.0f);
72         void update(float dt = 0.0f);
73
74         void apply_xform();
75
76         bool intersect(const Ray &ray, HitPoint *hit) const;
77
78         // cached local bounding box (all objects in this node in model space)
79         const AABox &calc_local_bounds();
80         const AABox &get_local_bounds() const;
81
82         // world bounding box of the node
83         AABox get_node_bounds() const;
84         // world bounding box of the node and it's subtree
85         AABox get_bounds() const;
86 };
87
88 #endif  // SNODE_H_