1 | // Copyright (C) 2014-2015 ChaosForge Ltd
|
---|
2 | // http://chaosforge.org/
|
---|
3 | //
|
---|
4 | // This file is part of Nova libraries.
|
---|
5 | // For conditions of distribution and use, see copying.txt file in root folder.
|
---|
6 |
|
---|
7 | /**
|
---|
8 | * @file scene_node.hh
|
---|
9 | * @author Kornel Kisielewicz epyon@chaosforge.org
|
---|
10 | * @brief Scene node class
|
---|
11 | */
|
---|
12 |
|
---|
13 | #ifndef NV_INTERFACE_SCENE_NODE_HH
|
---|
14 | #define NV_INTERFACE_SCENE_NODE_HH
|
---|
15 |
|
---|
16 | #include <nv/common.hh>
|
---|
17 | #include <nv/stl/vector.hh>
|
---|
18 | #include <nv/core/transform.hh>
|
---|
19 | #include <nv/stl/math.hh>
|
---|
20 | #include <nv/interface/render_state.hh>
|
---|
21 |
|
---|
22 | namespace nv
|
---|
23 | {
|
---|
24 |
|
---|
25 | class scene_node
|
---|
26 | {
|
---|
27 | public:
|
---|
28 | typedef vector< scene_node* > list;
|
---|
29 |
|
---|
30 | scene_node() {}
|
---|
31 |
|
---|
32 | virtual void update( uint32 ms )
|
---|
33 | {
|
---|
34 | for ( auto& child : m_children )
|
---|
35 | {
|
---|
36 | child->update( ms );
|
---|
37 | }
|
---|
38 | }
|
---|
39 |
|
---|
40 | virtual void attach( scene_node* child )
|
---|
41 | {
|
---|
42 | m_children.push_back( child );
|
---|
43 | }
|
---|
44 |
|
---|
45 | virtual void set_transform( const transform& t )
|
---|
46 | {
|
---|
47 | m_transform = t;
|
---|
48 | }
|
---|
49 |
|
---|
50 | virtual const transform& get_transform() const
|
---|
51 | {
|
---|
52 | return m_transform;
|
---|
53 | }
|
---|
54 |
|
---|
55 | virtual mat4 extract_transform_matrix() const
|
---|
56 | {
|
---|
57 | return get_transform().extract();
|
---|
58 | }
|
---|
59 |
|
---|
60 | void set_position( const vec3& p )
|
---|
61 | {
|
---|
62 | m_transform.set_position( p );
|
---|
63 | }
|
---|
64 |
|
---|
65 | void set_orientation( const quat& q )
|
---|
66 | {
|
---|
67 | m_transform.set_orientation( q );
|
---|
68 | }
|
---|
69 |
|
---|
70 | const vec3& get_position() const
|
---|
71 | {
|
---|
72 | return m_transform.get_position();
|
---|
73 | }
|
---|
74 |
|
---|
75 | const quat& get_orientation() const
|
---|
76 | {
|
---|
77 | return m_transform.get_orientation();
|
---|
78 | }
|
---|
79 |
|
---|
80 |
|
---|
81 | list::const_iterator begin() { return m_children.cbegin(); }
|
---|
82 | list::const_iterator end() { return m_children.cend(); }
|
---|
83 |
|
---|
84 | virtual ~scene_node()
|
---|
85 | {
|
---|
86 | for ( auto& child : m_children ) delete child;
|
---|
87 | }
|
---|
88 |
|
---|
89 | protected:
|
---|
90 | transform m_transform;
|
---|
91 | list m_children;
|
---|
92 | };
|
---|
93 |
|
---|
94 | }
|
---|
95 |
|
---|
96 | #endif // NV_INTERFACE_SCENE_NODE_HH
|
---|