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