[395] | 1 | // Copyright (C) 2014-2015 ChaosForge Ltd
|
---|
[230] | 2 | // http://chaosforge.org/
|
---|
| 3 | //
|
---|
[395] | 4 | // This file is part of Nova libraries.
|
---|
| 5 | // For conditions of distribution and use, see copying.txt file in root folder.
|
---|
| 6 |
|
---|
[230] | 7 | /**
|
---|
| 8 | * @file scene_node.hh
|
---|
| 9 | * @author Kornel Kisielewicz epyon@chaosforge.org
|
---|
| 10 | * @brief Scene node class
|
---|
| 11 | */
|
---|
| 12 |
|
---|
[395] | 13 | #ifndef NV_INTERFACE_SCENE_NODE_HH
|
---|
| 14 | #define NV_INTERFACE_SCENE_NODE_HH
|
---|
[230] | 15 |
|
---|
[395] | 16 | #include <nv/common.hh>
|
---|
[392] | 17 | #include <nv/stl/vector.hh>
|
---|
[319] | 18 | #include <nv/core/transform.hh>
|
---|
[368] | 19 | #include <nv/stl/math.hh>
|
---|
[230] | 20 | #include <nv/interface/render_state.hh>
|
---|
| 21 |
|
---|
| 22 | namespace nv
|
---|
| 23 | {
|
---|
| 24 |
|
---|
| 25 | class scene_node
|
---|
| 26 | {
|
---|
| 27 | public:
|
---|
[392] | 28 | typedef vector< scene_node* > list;
|
---|
[230] | 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 |
|
---|
[275] | 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 |
|
---|
[230] | 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(); }
|
---|
[483] | 83 | list& children() { return m_children; }
|
---|
[230] | 84 |
|
---|
| 85 | virtual ~scene_node()
|
---|
| 86 | {
|
---|
| 87 | for ( auto& child : m_children ) delete child;
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | protected:
|
---|
| 91 | transform m_transform;
|
---|
| 92 | list m_children;
|
---|
| 93 | };
|
---|
| 94 |
|
---|
| 95 | }
|
---|
| 96 |
|
---|
[395] | 97 | #endif // NV_INTERFACE_SCENE_NODE_HH
|
---|