1 | /*************************************************************************** |
---|
2 | |
---|
3 | This source file is part of OGREBULLET |
---|
4 | (Object-oriented Graphics Rendering Engine Bullet Wrapper) |
---|
5 | For the latest info, see http://www.ogre3d.org/phpBB2addons/viewforum.php?f=10 |
---|
6 | |
---|
7 | Copyright (c) 2007 tuan.kuranes@gmail.com (Use it Freely, even Statically, but have to contribute any changes) |
---|
8 | |
---|
9 | |
---|
10 | |
---|
11 | This program is free software; you can redistribute it and/or modify it under |
---|
12 | the terms of the GPL General Public License with runtime exception as published by the Free Software |
---|
13 | Foundation; either version 2 of the License, or (at your option) any later |
---|
14 | version. |
---|
15 | |
---|
16 | This program is distributed in the hope that it will be useful, but WITHOUT |
---|
17 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
---|
18 | FOR A PARTICULAR PURPOSE. See the GPL General Public License with runtime exception for more details. |
---|
19 | |
---|
20 | You should have received a copy of the GPL General Public License with runtime exception along with |
---|
21 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
---|
22 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
---|
23 | http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
24 | ----------------------------------------------------------------------------- |
---|
25 | */ |
---|
26 | #ifndef _OgreBulletCollisionsMeshToShapeConverter_H_ |
---|
27 | #define _OgreBulletCollisionsMeshToShapeConverter_H_ |
---|
28 | |
---|
29 | #include "OgreBulletCollisionsPreRequisites.h" |
---|
30 | |
---|
31 | namespace OgreBulletCollisions |
---|
32 | { |
---|
33 | class VertexIndexToShape |
---|
34 | { |
---|
35 | public: |
---|
36 | VertexIndexToShape(const Ogre::Matrix4 &transform = Ogre::Matrix4::IDENTITY); |
---|
37 | ~VertexIndexToShape(); |
---|
38 | |
---|
39 | Ogre::Real getRadius(); |
---|
40 | Ogre::Vector3 getSize(); |
---|
41 | |
---|
42 | |
---|
43 | SphereCollisionShape* createSphere(); |
---|
44 | BoxCollisionShape* createBox(); |
---|
45 | TriangleMeshCollisionShape* createTrimesh(); |
---|
46 | CylinderCollisionShape* createCylinder(); |
---|
47 | ConvexHullCollisionShape* createConvex(); |
---|
48 | |
---|
49 | |
---|
50 | const Ogre::Vector3* getVertices(); |
---|
51 | unsigned int getVertexCount(); |
---|
52 | const unsigned int* getIndices(); |
---|
53 | unsigned int getIndexCount(); |
---|
54 | |
---|
55 | protected: |
---|
56 | |
---|
57 | void addStaticVertexData(const Ogre::VertexData *vertex_data); |
---|
58 | |
---|
59 | void addAnimatedVertexData(const Ogre::VertexData *vertex_data, |
---|
60 | const Ogre::VertexData *blended_data, |
---|
61 | const Ogre::Mesh::IndexMap *indexMap); |
---|
62 | |
---|
63 | void addIndexData(Ogre::IndexData *data, const unsigned int offset = 0); |
---|
64 | |
---|
65 | |
---|
66 | protected: |
---|
67 | Ogre::Vector3* mVertexBuffer; |
---|
68 | unsigned int* mIndexBuffer; |
---|
69 | unsigned int mVertexCount; |
---|
70 | unsigned int mIndexCount; |
---|
71 | |
---|
72 | Ogre::Matrix4 mTransform; |
---|
73 | |
---|
74 | Ogre::Real mBoundRadius; |
---|
75 | Ogre::Vector3 mBounds; |
---|
76 | |
---|
77 | BoneIndex *mBoneIndex; |
---|
78 | |
---|
79 | }; |
---|
80 | |
---|
81 | class StaticMeshToShapeConverter : public VertexIndexToShape |
---|
82 | { |
---|
83 | public: |
---|
84 | |
---|
85 | StaticMeshToShapeConverter(Ogre::Renderable *rend, const Ogre::Matrix4 &transform = Ogre::Matrix4::IDENTITY); |
---|
86 | StaticMeshToShapeConverter(Ogre::Entity *entity, const Ogre::Matrix4 &transform = Ogre::Matrix4::IDENTITY); |
---|
87 | StaticMeshToShapeConverter(); |
---|
88 | |
---|
89 | ~StaticMeshToShapeConverter(); |
---|
90 | |
---|
91 | void addEntity(Ogre::Entity *entity,const Ogre::Matrix4 &transform = Ogre::Matrix4::IDENTITY); |
---|
92 | |
---|
93 | void addMesh(const Ogre::MeshPtr &mesh, const Ogre::Matrix4 &transform = Ogre::Matrix4::IDENTITY); |
---|
94 | |
---|
95 | |
---|
96 | protected: |
---|
97 | |
---|
98 | Ogre::Entity* mEntity; |
---|
99 | Ogre::SceneNode* mNode; |
---|
100 | |
---|
101 | }; |
---|
102 | |
---|
103 | class AnimatedMeshToShapeConverter : public VertexIndexToShape |
---|
104 | { |
---|
105 | public: |
---|
106 | |
---|
107 | AnimatedMeshToShapeConverter(Ogre::Entity *entity, const Ogre::Matrix4 &transform = Ogre::Matrix4::IDENTITY); |
---|
108 | AnimatedMeshToShapeConverter(); |
---|
109 | ~AnimatedMeshToShapeConverter(); |
---|
110 | |
---|
111 | void addEntity(Ogre::Entity *entity,const Ogre::Matrix4 &transform = Ogre::Matrix4::IDENTITY); |
---|
112 | void addMesh(const Ogre::MeshPtr &mesh, const Ogre::Matrix4 &transform); |
---|
113 | |
---|
114 | BoxCollisionShape* createAlignedBox(unsigned char bone, |
---|
115 | const Ogre::Vector3 &bonePosition, |
---|
116 | const Ogre::Quaternion &boneOrientation); |
---|
117 | |
---|
118 | BoxCollisionShape* createOrientedBox(unsigned char bone, |
---|
119 | const Ogre::Vector3 &bonePosition, |
---|
120 | const Ogre::Quaternion &boneOrientation); |
---|
121 | |
---|
122 | CapsuleCollisionShape* createOrientedCapsuleCollisionShape(unsigned char bone, |
---|
123 | const Ogre::Vector3 &bonePosition, |
---|
124 | const Ogre::Quaternion &boneOrientation); |
---|
125 | |
---|
126 | protected: |
---|
127 | |
---|
128 | bool getBoneVertices(unsigned char bone, |
---|
129 | unsigned int &vertex_count, |
---|
130 | Ogre::Vector3* &vertices, |
---|
131 | const Ogre::Vector3 &bonePosition); |
---|
132 | |
---|
133 | bool getOrientedBox(unsigned char bone, |
---|
134 | const Ogre::Vector3 &bonePosition, |
---|
135 | const Ogre::Quaternion &boneOrientation, |
---|
136 | Ogre::Vector3 &extents, |
---|
137 | Ogre::Vector3 *axis, |
---|
138 | Ogre::Vector3 ¢er); |
---|
139 | |
---|
140 | |
---|
141 | Ogre::Entity* mEntity; |
---|
142 | Ogre::SceneNode* mNode; |
---|
143 | |
---|
144 | Ogre::Vector3 *mTransformedVerticesTemp; |
---|
145 | size_t mTransformedVerticesTempSize; |
---|
146 | |
---|
147 | }; |
---|
148 | |
---|
149 | } |
---|
150 | |
---|
151 | #endif |
---|
152 | |
---|
153 | |
---|
154 | |
---|
155 | |
---|