SceneGraph.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. Copyright (c) 2013 Daniele Bartolini, Michele Rossi
  3. Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
  4. Permission is hereby granted, free of charge, to any person
  5. obtaining a copy of this software and associated documentation
  6. files (the "Software"), to deal in the Software without
  7. restriction, including without limitation the rights to use,
  8. copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the
  10. Software is furnished to do so, subject to the following
  11. conditions:
  12. The above copyright notice and this permission notice shall be
  13. included in all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  16. OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  19. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. #pragma once
  24. #include "Types.h"
  25. #include "Mat4.h"
  26. #include "List.h"
  27. #include "IdTable.h"
  28. #include "HeapAllocator.h"
  29. namespace crown
  30. {
  31. #define MAX_NODES 1024
  32. typedef Id NodeId;
  33. class SceneGraph
  34. {
  35. public:
  36. SceneGraph();
  37. NodeId create_node(const Vec3& pos, const Quat& rot);
  38. void destroy_node(NodeId id);
  39. void link(NodeId child, NodeId parent);
  40. void unlink(NodeId child);
  41. void set_local_position(NodeId node, const Vec3& pos);
  42. void set_local_rotation(NodeId node, const Quat& rot);
  43. void set_local_pose(NodeId node, const Mat4& pose);
  44. Vec3 local_position(NodeId node) const;
  45. Quat local_rotation(NodeId node) const;
  46. Mat4 local_pose(NodeId node) const;
  47. Vec3 world_position(NodeId node) const;
  48. Quat world_rotation(NodeId node) const;
  49. Mat4 world_pose(NodeId node) const;
  50. void update();
  51. private:
  52. HeapAllocator m_allocator;
  53. // Sparse table of nodes
  54. IdTable<MAX_NODES> m_nodes;
  55. // Conversion from sparse table to packed array
  56. uint32_t m_sparse_to_packed[MAX_NODES];
  57. // Packed arrays of transforms
  58. List<Mat4> m_world_poses;
  59. List<Mat4> m_local_poses;
  60. List<int32_t> m_parents;
  61. };
  62. } // namespace crown