Irrlicht 3D Engine
CDynamicMeshBuffer.h
Go to the documentation of this file.
00001 // Copyright (C) 2008-2012 Nikolaus Gebhardt
00002 // This file is part of the "Irrlicht Engine".
00003 // For conditions of distribution and use, see copyright notice in irrlicht.h
00004 
00005 #ifndef __C_DYNAMIC_MESHBUFFER_H_INCLUDED__
00006 #define __C_DYNAMIC_MESHBUFFER_H_INCLUDED__
00007 
00008 #include "IDynamicMeshBuffer.h"
00009 
00010 #include "CVertexBuffer.h"
00011 #include "CIndexBuffer.h"
00012 
00013 namespace irr
00014 {
00015 namespace scene
00016 {
00017 
00018     class CDynamicMeshBuffer: public IDynamicMeshBuffer
00019     {
00020     public:
00022         CDynamicMeshBuffer(video::E_VERTEX_TYPE vertexType, video::E_INDEX_TYPE indexType)
00023         {
00024             VertexBuffer=new CVertexBuffer(vertexType);
00025             IndexBuffer=new CIndexBuffer(indexType);
00026         }
00027 
00029         virtual ~CDynamicMeshBuffer()
00030         {
00031             if (VertexBuffer)
00032                 VertexBuffer->drop();
00033             if (IndexBuffer)
00034                 IndexBuffer->drop();
00035         }
00036 
00037         virtual IVertexBuffer& getVertexBuffer() const
00038         {
00039             return *VertexBuffer;
00040         }
00041 
00042         virtual IIndexBuffer& getIndexBuffer() const
00043         {
00044             return *IndexBuffer;
00045         }
00046 
00047         virtual void setVertexBuffer(IVertexBuffer *newVertexBuffer)
00048         {
00049             if (newVertexBuffer)
00050                 newVertexBuffer->grab();
00051             if (VertexBuffer)
00052                 VertexBuffer->drop();
00053 
00054             VertexBuffer=newVertexBuffer;
00055         }
00056 
00057         virtual void setIndexBuffer(IIndexBuffer *newIndexBuffer)
00058         {
00059             if (newIndexBuffer)
00060                 newIndexBuffer->grab();
00061             if (IndexBuffer)
00062                 IndexBuffer->drop();
00063 
00064             IndexBuffer=newIndexBuffer;
00065         }
00066 
00068         virtual const video::SMaterial& getMaterial() const
00069         {
00070             return Material;
00071         }
00072 
00074         virtual video::SMaterial& getMaterial()
00075         {
00076             return Material;
00077         }
00078 
00080         virtual const core::aabbox3d<f32>& getBoundingBox() const
00081         {
00082             return BoundingBox;
00083         }
00084 
00086         virtual void setBoundingBox( const core::aabbox3df& box)
00087         {
00088             BoundingBox = box;
00089         }
00090 
00092         virtual void recalculateBoundingBox()
00093         {
00094             if (!getVertexBuffer().size())
00095                 BoundingBox.reset(0,0,0);
00096             else
00097             {
00098                 BoundingBox.reset(getVertexBuffer()[0].Pos);
00099                 for (u32 i=1; i<getVertexBuffer().size(); ++i)
00100                     BoundingBox.addInternalPoint(getVertexBuffer()[i].Pos);
00101             }
00102         }
00103 
00104         video::SMaterial Material;
00105         core::aabbox3d<f32> BoundingBox;
00106     private:
00107         IVertexBuffer *VertexBuffer;
00108         IIndexBuffer *IndexBuffer;
00109     };
00110 
00111 
00112 } // end namespace scene
00113 } // end namespace irr
00114 
00115 #endif
00116