CDynamicMeshBuffer.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // Copyright (C) 2008-2012 Nikolaus Gebhardt
  2. // This file is part of the "Irrlicht Engine".
  3. // For conditions of distribution and use, see copyright notice in irrlicht.h
  4. #ifndef __C_DYNAMIC_MESHBUFFER_H_INCLUDED__
  5. #define __C_DYNAMIC_MESHBUFFER_H_INCLUDED__
  6. #include "IDynamicMeshBuffer.h"
  7. #include "CVertexBuffer.h"
  8. #include "CIndexBuffer.h"
  9. namespace irr
  10. {
  11. namespace scene
  12. {
  13. class CDynamicMeshBuffer: public IDynamicMeshBuffer
  14. {
  15. public:
  16. //! constructor
  17. CDynamicMeshBuffer(video::E_VERTEX_TYPE vertexType, video::E_INDEX_TYPE indexType)
  18. {
  19. VertexBuffer=new CVertexBuffer(vertexType);
  20. IndexBuffer=new CIndexBuffer(indexType);
  21. }
  22. //! destructor
  23. virtual ~CDynamicMeshBuffer()
  24. {
  25. if (VertexBuffer)
  26. VertexBuffer->drop();
  27. if (IndexBuffer)
  28. IndexBuffer->drop();
  29. }
  30. virtual IVertexBuffer& getVertexBuffer() const
  31. {
  32. return *VertexBuffer;
  33. }
  34. virtual IIndexBuffer& getIndexBuffer() const
  35. {
  36. return *IndexBuffer;
  37. }
  38. virtual void setVertexBuffer(IVertexBuffer *newVertexBuffer)
  39. {
  40. if (newVertexBuffer)
  41. newVertexBuffer->grab();
  42. if (VertexBuffer)
  43. VertexBuffer->drop();
  44. VertexBuffer=newVertexBuffer;
  45. }
  46. virtual void setIndexBuffer(IIndexBuffer *newIndexBuffer)
  47. {
  48. if (newIndexBuffer)
  49. newIndexBuffer->grab();
  50. if (IndexBuffer)
  51. IndexBuffer->drop();
  52. IndexBuffer=newIndexBuffer;
  53. }
  54. //! Get Material of this buffer.
  55. virtual const video::SMaterial& getMaterial() const
  56. {
  57. return Material;
  58. }
  59. //! Get Material of this buffer.
  60. virtual video::SMaterial& getMaterial()
  61. {
  62. return Material;
  63. }
  64. //! Get bounding box
  65. virtual const core::aabbox3d<f32>& getBoundingBox() const
  66. {
  67. return BoundingBox;
  68. }
  69. //! Set bounding box
  70. virtual void setBoundingBox( const core::aabbox3df& box)
  71. {
  72. BoundingBox = box;
  73. }
  74. //! Recalculate bounding box
  75. virtual void recalculateBoundingBox()
  76. {
  77. if (!getVertexBuffer().size())
  78. BoundingBox.reset(0,0,0);
  79. else
  80. {
  81. BoundingBox.reset(getVertexBuffer()[0].Pos);
  82. for (u32 i=1; i<getVertexBuffer().size(); ++i)
  83. BoundingBox.addInternalPoint(getVertexBuffer()[i].Pos);
  84. }
  85. }
  86. video::SMaterial Material;
  87. core::aabbox3d<f32> BoundingBox;
  88. private:
  89. IVertexBuffer *VertexBuffer;
  90. IIndexBuffer *IndexBuffer;
  91. };
  92. } // end namespace scene
  93. } // end namespace irr
  94. #endif