From 43b6bb65899c6afe5a3b6c9c781b82d1b7597c41 Mon Sep 17 00:00:00 2001 From: hybrid Date: Mon, 13 Aug 2007 23:33:29 +0000 Subject: [PATCH] Made the MeshBuffer an explicit member instead of a base class. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@832 dfc29bdd-3216-0410-991c-e03cc46cb475 --- source/Irrlicht/CAnimatedMeshMD2.cpp | 134 ++++----------------------- source/Irrlicht/CAnimatedMeshMD2.h | 42 +-------- 2 files changed, 23 insertions(+), 153 deletions(-) diff --git a/source/Irrlicht/CAnimatedMeshMD2.cpp b/source/Irrlicht/CAnimatedMeshMD2.cpp index 11c8945f..f1012468 100644 --- a/source/Irrlicht/CAnimatedMeshMD2.cpp +++ b/source/Irrlicht/CAnimatedMeshMD2.cpp @@ -351,94 +351,20 @@ u32 CAnimatedMeshMD2::getMeshBufferCount() const //! returns pointer to a mesh buffer IMeshBuffer* CAnimatedMeshMD2::getMeshBuffer(u32 nr) const { - return (IMeshBuffer*) this; + return const_cast(reinterpret_cast(&InterpolationBuffer)); } //! Returns pointer to a mesh buffer which fits a material -IMeshBuffer* CAnimatedMeshMD2::getMeshBuffer( const video::SMaterial &material) const +IMeshBuffer* CAnimatedMeshMD2::getMeshBuffer(const video::SMaterial &material) const { - if (Material == material) - return (IMeshBuffer*) this; + if (InterpolationBuffer.Material == material) + return const_cast(reinterpret_cast(&InterpolationBuffer)); else return 0; } -//! returns the material of this meshbuffer -const video::SMaterial& CAnimatedMeshMD2::getMaterial() const -{ - return Material; -} - - -//! returns the material of this meshbuffer -video::SMaterial& CAnimatedMeshMD2::getMaterial() -{ - return Material; -} - - - -//! returns pointer to vertices -const void* CAnimatedMeshMD2::getVertices() const -{ - return InterpolateBuffer.const_pointer(); -} - - -//! returns pointer to vertices -void* CAnimatedMeshMD2::getVertices() -{ - return InterpolateBuffer.pointer(); -} - - - -//! returns which type of vertex data is stored. -video::E_VERTEX_TYPE CAnimatedMeshMD2::getVertexType() const -{ - return video::EVT_STANDARD; -} - -//! returns the byte size (stride, pitch) of the vertex -u32 CAnimatedMeshMD2::getVertexPitch() const -{ - return sizeof ( video::S3DVertex ); -} - - - -//! returns amount of vertices -u32 CAnimatedMeshMD2::getVertexCount() const -{ - return FrameList[0].size(); -} - - - -//! returns pointer to Indices -const u16* CAnimatedMeshMD2::getIndices() const -{ - return Indices.const_pointer(); -} - - - -//! returns pointer to Indices -u16* CAnimatedMeshMD2::getIndices() -{ - return Indices.pointer(); -} - - - -//! returns amount of indices -u32 CAnimatedMeshMD2::getIndexCount() const -{ - return Indices.size(); -} - // updates the interpolation buffer void CAnimatedMeshMD2::updateInterpolationBuffer(s32 frame, s32 startFrameLoop, s32 endFrameLoop) @@ -471,7 +397,7 @@ void CAnimatedMeshMD2::updateInterpolationBuffer(s32 frame, s32 startFrameLoop, div = frame * MD2_FRAME_SHIFT_RECIPROCAL; } - video::S3DVertex* target = &InterpolateBuffer[0]; + video::S3DVertex* target = reinterpret_cast(InterpolationBuffer.getVertices()); video::S3DVertex* first = FrameList[firstFrame].pointer(); video::S3DVertex* second = FrameList[secondFrame].pointer(); @@ -489,7 +415,7 @@ void CAnimatedMeshMD2::updateInterpolationBuffer(s32 frame, s32 startFrameLoop, } //update bounding box - BoundingBox = BoxList[secondFrame].getInterpolated(BoxList[firstFrame], div); + InterpolationBuffer.setBoundingBox(BoxList[secondFrame].getInterpolated(BoxList[firstFrame], div)); } @@ -693,25 +619,25 @@ bool CAnimatedMeshMD2::loadFile(io::IReadFile* file) // create indices - Indices.reallocate(header.numVertices); + InterpolationBuffer.Indices.reallocate(header.numVertices); s16 count = TriangleCount*3; for (s16 n=0; n& CAnimatedMeshMD2::getBoundingBox() const { - return BoundingBox; + return InterpolationBuffer.BoundingBox; } //! set user axis aligned bounding box void CAnimatedMeshMD2::setBoundingBox( const core::aabbox3df& box) { - BoundingBox = box; + InterpolationBuffer.BoundingBox = box; } -//! calculates normals -void CAnimatedMeshMD2::calculateNormals() -{ - for (u32 i=0; i plane( - vtx[Indices[j]].Pos, vtx[Indices[j+1]].Pos, vtx[Indices[j+2]].Pos); - - vtx[Indices[j]].Normal = plane.Normal; - vtx[Indices[j+1]].Normal = plane.Normal; - vtx[Indices[j+2]].Normal = plane.Normal; - } - } -} - - //! Returns the type of the animated mesh. E_ANIMATED_MESH_TYPE CAnimatedMeshMD2::getMeshType() const { diff --git a/source/Irrlicht/CAnimatedMeshMD2.h b/source/Irrlicht/CAnimatedMeshMD2.h index 028d458c..a092b4c8 100644 --- a/source/Irrlicht/CAnimatedMeshMD2.h +++ b/source/Irrlicht/CAnimatedMeshMD2.h @@ -7,7 +7,7 @@ #include "IAnimatedMeshMD2.h" #include "IMesh.h" -#include "IMeshBuffer.h" +#include "CMeshBuffer.h" #include "IReadFile.h" #include "S3DVertex.h" #include "irrArray.h" @@ -18,7 +18,7 @@ namespace irr namespace scene { - class CAnimatedMeshMD2 : public IAnimatedMeshMD2, public IMesh, public IMeshBuffer + class CAnimatedMeshMD2 : public IAnimatedMeshMD2, public IMesh { public: @@ -49,36 +49,6 @@ namespace scene NULL if there is no such mesh buffer. */ virtual IMeshBuffer* getMeshBuffer( const video::SMaterial &material) const; - //! returns the material of this meshbuffer - virtual const video::SMaterial& getMaterial() const; - - //! returns the material of this meshbuffer - virtual video::SMaterial& getMaterial(); - - //! returns pointer to vertices - virtual const void* getVertices() const; - - //! returns pointer to vertices - virtual void* getVertices(); - - //! returns which type of vertex data is stored. - virtual video::E_VERTEX_TYPE getVertexType() const; - - //! returns the byte size (stride, pitch) of the vertex - virtual u32 getVertexPitch() const; - - //! returns amount of vertices - virtual u32 getVertexCount() const; - - //! returns pointer to Indices - virtual const u16* getIndices() const; - - //! returns pointer to Indices - virtual u16* getIndices(); - - //! returns amount of indices - virtual u32 getIndexCount() const; - //! returns an axis aligned bounding box virtual const core::aabbox3d& getBoundingBox() const; @@ -114,18 +84,12 @@ namespace scene //! calculates the bounding box virtual void calculateBoundingBox(); - //! calculates normals - void calculateNormals(); - - core::array Indices; core::array *FrameList; core::array > BoxList; u32 FrameCount; s32 TriangleCount; - video::SMaterial Material; - core::array InterpolateBuffer; - core::aabbox3d BoundingBox; + SMeshBuffer InterpolationBuffer; struct SFrameData {