fork download
  1. #ifndef __C_GRID_SCENE_NODE_H__
  2. #define __C_GRID_SCENE_NODE_H__
  3.  
  4. #include "irrlicht.h"
  5.  
  6. //! Grid scene node
  7. /*! If you need a grid on the XY or ZY axis, simply rotate this node by 90
  8. degrees in the appropiate axis.
  9. This node creates an XZ grid by default, which should be fine for normal use.
  10. Axis Lines are a default Red and Blue for the X and Z axis respectively.
  11.  
  12. Please note that the internal meshbuffer used for the grid has a max size of 65535 indices.
  13.  
  14. Code is based on the class from here: http://i...content-available-to-author-only...e.net/forum/viewtopic.php?f=9&t=24938
  15. Thanks goes to MasterGod for helping to clean up the code and for a few bug fixes.
  16.  
  17. Additional thanks to:
  18. JP for optimising the rendering.
  19. Vins for fixing a nasty crash bug and optimising memory usage.
  20. */
  21.  
  22. class CGridSceneNode : public irr::scene::ISceneNode
  23. {
  24. public:
  25.  
  26. enum EAlign
  27. {
  28. CENTER,
  29. MIN_X_MIN_Y
  30. };
  31.  
  32. struct SGrid
  33. {
  34. friend class CGridSceneNode;
  35.  
  36. SGrid();
  37. ~SGrid();
  38.  
  39. SGrid(const SGrid& other);
  40. SGrid& operator=(const SGrid& other);
  41.  
  42. void setVisible(bool visible)
  43. {
  44. IsVisible = visible;
  45. }
  46.  
  47. bool isVisible() const
  48. {
  49. return IsVisible;
  50. }
  51.  
  52. //! If size/spacing doesn't have a modulo of 0 we need to align the grid inside the given size
  53. void setAlignment(EAlign align);
  54.  
  55. //! return grid alignment inside space
  56. EAlign getAlignment() const;
  57.  
  58. //! Sets Spacing
  59. void setSpacing(irr::f32 newspacing);
  60.  
  61. //! Returns the Spacing of the grid
  62. irr::f32 getSpacing() const;
  63.  
  64. //! Sets size
  65. void setSize(const irr::core::dimension2df& newsize);
  66.  
  67. //! Returns the total size of the grid
  68. const irr::core::dimension2df& getSize() const;
  69.  
  70. //! lines are drawn with some offset
  71. void setOffset(const irr::core::vector3df& offset);
  72.  
  73. //! get line offset
  74. const irr::core::vector3df& getOffset() const;
  75.  
  76. //! Sets the general grid color
  77. void setGridColor(irr::video::SColor newcolor);
  78.  
  79. //! Returns the grid color
  80. irr::video::SColor getGridColor() const;
  81.  
  82. //! Set the maximal distance the grid can have to the camera to still be rendered
  83. void setMaxRenderDistance(irr::f32 dist);
  84.  
  85. //! Get the maximal distance the grid can have to the camera to still be rendered
  86. irr::f32 getMaxRenderDistance() const;
  87.  
  88. //! Set a new material
  89. void setMaterial(const irr::video::SMaterial& newMaterial);
  90. const irr::video::SMaterial& getMaterial() const;
  91. irr::video::SMaterial& getMaterial();
  92.  
  93. const irr::core::aabbox3d<irr::f32>& getBoundingBox() const;
  94.  
  95. protected:
  96. //! rebuild the grid
  97. void regenerateMesh(const CGridSceneNode* const gridNode);
  98. void setDefaultMaterial();
  99.  
  100. // render this grid
  101. void render(irr::video::IVideoDriver* driver);
  102.  
  103. bool canUseGridLine(irr::f32 pos, bool axisX, const CGridSceneNode* const gridNode);
  104. irr::core::vector3df calcGridStart() const;
  105.  
  106. bool IsVisible;
  107. EAlign Alignment;
  108. irr::f32 Spacing;
  109. irr::core::dimension2df Size;
  110. irr::core::vector3df Offset;
  111. irr::video::SColor GridColor;
  112. irr::f32 MaxRenderDist; // grid not rendered when distance of the gridplane to the camera is larger
  113. bool GridDirty; // grid settings have been changed and all grids need to regenerate the mesh.
  114. mutable bool BoundingBoxDirty; // boundingbox was changed, CGridSceneNode needs to recalculate it's boundingbox
  115. irr::scene::IDynamicMeshBuffer * MeshBuffer;
  116. };
  117.  
  118. //! Constructor
  119. CGridSceneNode(irr::scene::ISceneNode* parent, irr::scene::ISceneManager* smgr, irr::s32 id = -1, irr::u32 numGrids=1);
  120.  
  121. //! Will create a copy of this scenenode and it's settings
  122. virtual CGridSceneNode* clone(irr::scene::ISceneNode* newParent = 0, irr::scene::ISceneManager* newSceneManager = 0);
  123.  
  124. //! Pre-Register stuff
  125. virtual void OnRegisterSceneNode();
  126.  
  127. //! Render our grid using 3D lines stored inside the internal meshbuffer
  128. virtual void render();
  129.  
  130. //! Returns our bounding box
  131. virtual const irr::core::aabbox3d<irr::f32>& getBoundingBox() const;
  132.  
  133. //! Returns the total number of materials (identical to number of grids)
  134. virtual irr::u32 getMaterialCount() const;
  135.  
  136. //! Returns the only material
  137. virtual irr::video::SMaterial& getMaterial(irr::u32 i);
  138.  
  139. // ! get the number of grids in this node
  140. irr::u32 getNumberOfGrids() const;
  141.  
  142. //! add a new grid and return it's index
  143. irr::u32 addGrid();
  144.  
  145. //! remove an existing grid
  146. void removeGrid(irr::u32 index);
  147.  
  148. //! access a grid
  149. //* Note: reference no longer valid when grids are added/removed */
  150. SGrid& getGrid(irr::u32 index);
  151.  
  152. //! access a grid
  153. //* Note: reference no longer valid when grids are added/removed */
  154. const SGrid& getGrid(irr::u32 index) const;
  155.  
  156. //! Sets the size for all grids
  157. void setGridsSize(const irr::core::dimension2df& newsize);
  158.  
  159.  
  160. protected:
  161. bool hasDirtyBoundingBox() const;
  162. bool hasDirtyGrid() const;
  163. void regenerateMeshes();
  164. void rebuildBoundingBox();
  165.  
  166. private:
  167.  
  168. irr::core::aabbox3d<irr::f32> BoundingBox;
  169. irr::core::array<SGrid> Grids;
  170. };
  171.  
  172. #endif // __C_GRID_SCENE_NODE_H__
  173.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty