00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef _OgreBulletCollisionsMeshToShapeConverter_H_
00031 #define _OgreBulletCollisionsMeshToShapeConverter_H_
00032
00033 #include "OgreBulletCollisionsPreRequisites.h"
00034
00035 namespace OgreBulletCollisions
00036 {
00037 class VertexIndexToShape
00038 {
00039 public:
00040 VertexIndexToShape(const Ogre::Matrix4 &transform = Ogre::Matrix4::IDENTITY);
00041 ~VertexIndexToShape();
00042
00043 Ogre::Real getRadius();
00044 Ogre::Vector3 getSize();
00045
00046
00047 SphereCollisionShape* createSphere();
00048 BoxCollisionShape* createBox();
00049 TriangleMeshCollisionShape* createTrimesh();
00050 CylinderCollisionShape* createCylinder();
00051 ConvexHullCollisionShape* createConvex();
00052 GImpactConcaveShape* createConcave();
00053 CompoundCollisionShape* createConvexDecomposition(
00054 unsigned int depth = 5
00055 , float cpercent = 5
00056 , float ppercent = 15
00057 , unsigned int maxv = 32
00058 , float skinWidth = 0.0
00059 );
00060
00061
00062 const Ogre::Vector3* getVertices();
00063 unsigned int getVertexCount();
00064 const unsigned int* getIndices();
00065 unsigned int getIndexCount();
00066
00067 protected:
00068
00069 void addStaticVertexData(const Ogre::VertexData *vertex_data);
00070
00071 void addAnimatedVertexData(const Ogre::VertexData *vertex_data,
00072 const Ogre::VertexData *blended_data,
00073 const Ogre::Mesh::IndexMap *indexMap);
00074
00075 void addIndexData(Ogre::IndexData *data, const unsigned int offset = 0);
00076
00077
00078 protected:
00079 Ogre::Vector3* mVertexBuffer;
00080 unsigned int* mIndexBuffer;
00081 unsigned int mVertexCount;
00082 unsigned int mIndexCount;
00083
00084 Ogre::Matrix4 mTransform;
00085
00086 Ogre::Real mBoundRadius;
00087 Ogre::Vector3 mBounds;
00088
00089 BoneIndex *mBoneIndex;
00090
00091 };
00092
00093 class StaticMeshToShapeConverter : public VertexIndexToShape
00094 {
00095 public:
00096
00097 StaticMeshToShapeConverter(Ogre::Renderable *rend, const Ogre::Matrix4 &transform = Ogre::Matrix4::IDENTITY);
00098 StaticMeshToShapeConverter(Ogre::Entity *entity, const Ogre::Matrix4 &transform = Ogre::Matrix4::IDENTITY);
00099 StaticMeshToShapeConverter();
00100
00101 ~StaticMeshToShapeConverter();
00102
00103 virtual void addEntity(Ogre::Entity *entity,const Ogre::Matrix4 &transform = Ogre::Matrix4::IDENTITY);
00104
00105 virtual void addMesh(const Ogre::MeshPtr &mesh, const Ogre::Matrix4 &transform = Ogre::Matrix4::IDENTITY);
00106
00107
00108 protected:
00109
00110 Ogre::Entity* mEntity;
00111 Ogre::SceneNode* mNode;
00112
00113 };
00114
00115 class AnimatedMeshToShapeConverter : public VertexIndexToShape
00116 {
00117 public:
00118
00119 AnimatedMeshToShapeConverter(Ogre::Entity *entity, const Ogre::Matrix4 &transform = Ogre::Matrix4::IDENTITY);
00120 AnimatedMeshToShapeConverter();
00121 ~AnimatedMeshToShapeConverter();
00122
00123 void addEntity(Ogre::Entity *entity,const Ogre::Matrix4 &transform = Ogre::Matrix4::IDENTITY);
00124 void addMesh(const Ogre::MeshPtr &mesh, const Ogre::Matrix4 &transform);
00125
00126 BoxCollisionShape* createAlignedBox(unsigned char bone,
00127 const Ogre::Vector3 &bonePosition,
00128 const Ogre::Quaternion &boneOrientation);
00129
00130 BoxCollisionShape* createOrientedBox(unsigned char bone,
00131 const Ogre::Vector3 &bonePosition,
00132 const Ogre::Quaternion &boneOrientation);
00133
00134 CapsuleCollisionShape* createOrientedCapsuleCollisionShape(unsigned char bone,
00135 const Ogre::Vector3 &bonePosition,
00136 const Ogre::Quaternion &boneOrientation);
00137
00138 protected:
00139
00140 bool getBoneVertices(unsigned char bone,
00141 unsigned int &vertex_count,
00142 Ogre::Vector3* &vertices,
00143 const Ogre::Vector3 &bonePosition);
00144
00145 bool getOrientedBox(unsigned char bone,
00146 const Ogre::Vector3 &bonePosition,
00147 const Ogre::Quaternion &boneOrientation,
00148 Ogre::Vector3 &extents,
00149 Ogre::Vector3 *axis,
00150 Ogre::Vector3 ¢er);
00151
00152
00153 Ogre::Entity* mEntity;
00154 Ogre::SceneNode* mNode;
00155
00156 Ogre::Vector3 *mTransformedVerticesTemp;
00157 size_t mTransformedVerticesTempSize;
00158
00159 };
00160
00161 }
00162
00163 #endif
00164
00165
00166
00167