OpenMW
libs/openengine/bullet/BtOgreGP.h
Go to the documentation of this file.
00001 /*
00002  * =====================================================================================
00003  *
00004  *       Filename:  BtOgreGP.h
00005  *
00006  *    Description:  The part of BtOgre that handles information transfer from Ogre to
00007  *                  Bullet (like mesh data for making trimeshes).
00008  *
00009  *        Version:  1.0
00010  *        Created:  27/12/2008 03:29:56 AM
00011  *
00012  *         Author:  Nikhilesh (nikki)
00013  *
00014  * =====================================================================================
00015  */
00016 
00017 #ifndef _BtOgrePG_H_
00018 #define _BtOgrePG_H_
00019 
00020 #include "btBulletDynamicsCommon.h"
00021 #include "BtOgreExtras.h"
00022 
00023 #include <OgreMatrix4.h>
00024 #include <OgreMesh.h>
00025 #include <OgreVector3.h>
00026 
00027 namespace BtOgre {
00028 
00029 typedef std::map<unsigned char, Vector3Array*> BoneIndex;
00030 typedef std::pair<unsigned short, Vector3Array*> BoneKeyIndex;
00031 
00032 class VertexIndexToShape
00033 {
00034 public:
00035     VertexIndexToShape(const Ogre::Matrix4 &transform = Ogre::Matrix4::IDENTITY);
00036     ~VertexIndexToShape();
00037 
00038     Ogre::Real getRadius();
00039     Ogre::Vector3 getSize();
00040 
00041 
00042     btSphereShape* createSphere();
00043     btBoxShape* createBox();
00044     btBvhTriangleMeshShape* createTrimesh();
00045     btCylinderShape* createCylinder();
00046     btConvexHullShape* createConvex();
00047 
00048     const Ogre::Vector3* getVertices();
00049     unsigned int getVertexCount();
00050     const unsigned int* getIndices();
00051     unsigned int getIndexCount();
00052 
00053 protected:
00054 
00055     void addStaticVertexData(const Ogre::VertexData *vertex_data);
00056 
00057     void addAnimatedVertexData(const Ogre::VertexData *vertex_data,
00058                                const Ogre::VertexData *blended_data,
00059                                const Ogre::Mesh::IndexMap *indexMap);
00060 
00061     void addIndexData(Ogre::IndexData *data, const unsigned int offset = 0);
00062 
00063 
00064 protected:
00065     Ogre::Vector3*      mVertexBuffer;
00066     unsigned int*       mIndexBuffer;
00067     unsigned int        mVertexCount;
00068     unsigned int        mIndexCount;
00069 
00070     Ogre::Matrix4       mTransform;
00071 
00072     Ogre::Real          mBoundRadius;
00073     Ogre::Vector3       mBounds;
00074 
00075     BoneIndex           *mBoneIndex;
00076 
00077     Ogre::Vector3       mScale;
00078 };
00079 
00080 //For static (non-animated) meshes.
00081 class StaticMeshToShapeConverter : public VertexIndexToShape
00082 {
00083 public:
00084 
00085     StaticMeshToShapeConverter(Ogre::Renderable *rend, const Ogre::Matrix4 &transform = Ogre::Matrix4::IDENTITY);
00086     StaticMeshToShapeConverter(Ogre::Entity *entity,   const Ogre::Matrix4 &transform = Ogre::Matrix4::IDENTITY);
00087     StaticMeshToShapeConverter();
00088 
00089     ~StaticMeshToShapeConverter();
00090 
00091     void addEntity(Ogre::Entity *entity,const Ogre::Matrix4 &transform = Ogre::Matrix4::IDENTITY);
00092 
00093     void addMesh(const Ogre::MeshPtr &mesh, const Ogre::Matrix4 &transform = Ogre::Matrix4::IDENTITY);
00094 
00095 
00096 protected:
00097 
00098     Ogre::Entity*       mEntity;
00099     Ogre::SceneNode*    mNode;
00100 };
00101 
00102 //For animated meshes.
00103 class AnimatedMeshToShapeConverter : public VertexIndexToShape
00104 {
00105 public:
00106 
00107     AnimatedMeshToShapeConverter(Ogre::Entity *entity, const Ogre::Matrix4 &transform = Ogre::Matrix4::IDENTITY);
00108     AnimatedMeshToShapeConverter();
00109     ~AnimatedMeshToShapeConverter();
00110 
00111     void addEntity(Ogre::Entity *entity,const Ogre::Matrix4 &transform = Ogre::Matrix4::IDENTITY);
00112     void addMesh(const Ogre::MeshPtr &mesh, const Ogre::Matrix4 &transform);
00113 
00114     btBoxShape* createAlignedBox(unsigned char bone,
00115             const Ogre::Vector3 &bonePosition,
00116             const Ogre::Quaternion &boneOrientation);
00117 
00118     btBoxShape* createOrientedBox(unsigned char bone,
00119             const Ogre::Vector3 &bonePosition,
00120             const Ogre::Quaternion &boneOrientation);
00121 
00122 protected:
00123 
00124     bool getBoneVertices(unsigned char bone,
00125             unsigned int &vertex_count,
00126             Ogre::Vector3* &vertices,
00127             const Ogre::Vector3 &bonePosition);
00128 
00129     bool getOrientedBox(unsigned char bone,
00130             const Ogre::Vector3 &bonePosition,
00131             const Ogre::Quaternion &boneOrientation,
00132             Ogre::Vector3 &extents,
00133             Ogre::Vector3 *axis,
00134             Ogre::Vector3 &center);
00135 
00136     Ogre::Entity*       mEntity;
00137     Ogre::SceneNode*    mNode;
00138 
00139     Ogre::Vector3       *mTransformedVerticesTemp;
00140     size_t               mTransformedVerticesTempSize;
00141 };
00142 
00143 }
00144 
00145 #endif