MezzanineEngine
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
Mezzanine
src
Physics
softproxy.cpp
1
// © Copyright 2010 - 2012 BlackTopp Studios Inc.
2
/* This file is part of The Mezzanine Engine.
3
4
The Mezzanine Engine is free software: you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation, either version 3 of the License, or
7
(at your option) any later version.
8
9
The Mezzanine Engine is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
13
14
You should have received a copy of the GNU General Public License
15
along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16
*/
17
/* The original authors have included a copy of the license specified above in the
18
'Docs' folder. See 'gpl.txt'
19
*/
20
/* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21
Build professional software and charge for their product.
22
23
However there are some practical restrictions, so if your project involves
24
any of the following you should contact us and we will try to work something
25
out:
26
- DRM or Copy Protection of any kind(except Copyrights)
27
- Software Patents You Do Not Wish to Freely License
28
- Any Kind of Linking to Non-GPL licensed Works
29
- Are Currently In Violation of Another Copyright Holder's GPL License
30
- If You want to change our code and not add a few hundred MB of stuff to
31
your distribution
32
33
These and other limitations could cause serious legal problems if you ignore
34
them, so it is best to simply contact us or the Free Software Foundation, if
35
you have any questions.
36
37
Joseph Toppi - toppij@gmail.com
38
John Blackwood - makoenergy02@gmail.com
39
*/
40
#ifndef _softproxy_cpp
41
#define _softproxy_cpp
42
43
#include "Physics/softproxy.h"
44
#include "Physics/physicsmanager.h"
45
46
#include "
enumerations.h
"
47
#include "
serialization.h
"
48
#include "stringtool.h"
49
50
//#include "Internal/meshtools.h.cpp"
51
52
#include <btBulletDynamicsCommon.h>
53
#include <BulletSoftBody/btSoftRigidDynamicsWorld.h>
54
55
namespace
Mezzanine
56
{
57
namespace
Physics
58
{
59
/*void _Update()
60
{
61
//Ogre::VertexData* vertexData = entity->getMesh()->getSubMesh(0)->vertexData;
62
63
// ©onst Ogre::VertexElement* posElem = vertexData->vertexDeclaration->findElementBySemantic(Ogre::VES_POSITION);
64
//Ogre::HardwareVertexBufferSharedPtr vBuffer = vertexData->vertexBufferBinding->getBuffer(posElem->getSource());
65
66
//unsigned char* vertex = static_cast<unsigned char*>(vBuffer->lock(Ogre::HardwareBuffer::HBL_NORMAL));
67
//float* pReal = NULL;
68
//for (size_t j = 0; j < vertexData->vertexCount; j++ )
69
//{
70
// posElem->baseVertexPointerToElement(vertex, &pReal);
71
// *pReal++ = this->PhysicsSoftBody->m_nodes[j].m_x.x();
72
// *pReal++ = this->PhysicsSoftBody->m_nodes[j].m_x.y();
73
// *pReal++ = this->PhysicsSoftBody->m_nodes[j].m_x.z();
74
// vertex += vBuffer->getVertexSize();
75
//}
76
//vBuffer->unlock();
77
78
//btVector3 position = this->PhysicsSoftBody->getWorldTransform().getOrigin();
79
//btQuaternion rotation = this->PhysicsSoftBody->getWorldTransform().getRotation();
80
btVector3 position = this->PhysicsSoftBody->m_clusters[0]->m_framexform.getOrigin();
81
btQuaternion rotation = this->PhysicsSoftBody->m_clusters[0]->m_framexform.getRotation();
82
this->GraphicsNode->setPosition(position.x(), position.y(), position.z());
83
this->GraphicsNode->setOrientation(rotation.w(), rotation.x(), rotation.y(), rotation.z());
84
}//*/
85
86
87
SoftProxy::SoftProxy
(
const
Real
Mass,
PhysicsManager
* Creator) :
88
CollidableProxy
(Creator),
89
PhysicsSoftBody(NULL)
90
{
91
MEZZ_EXCEPTION(
Exception::NOT_IMPLEMENTED_EXCEPTION
,
"Soft body support is still under construction and not complete."
);
92
this->
CreateSoftObject
(Mass);
93
}
94
95
SoftProxy::SoftProxy
(
const
XML::Node
& SelfRoot,
PhysicsManager
* Creator) :
96
CollidableProxy
(Creator),
97
PhysicsSoftBody(NULL)
98
{
99
MEZZ_EXCEPTION(
Exception::NOT_IMPLEMENTED_EXCEPTION
,
"Soft body support is still under construction and not complete."
);
100
this->
CreateSoftObject
(1);
101
this->
ProtoDeSerialize
(SelfRoot);
102
}
103
104
SoftProxy::~SoftProxy
()
105
{
106
if
( this->
IsInWorld
() )
107
this->
RemoveFromWorld
();
108
109
delete
this->
PhysicsSoftBody
;
110
}
111
112
void
SoftProxy::CreateSoftObject
(
const
Real
Mass)
113
{
114
/*Internal::MeshInfo CurMesh;
115
Internal::MeshTools::GetMeshVerticies(GraphicsObject,CurMesh);
116
Internal::MeshTools::GetMeshIndicies(GraphicsObject,CurMesh);
117
Internal::MeshTools::GetMeshNormals(GraphicsObject,CurMesh);
118
Internal::MeshTools::GetMeshTextures(GraphicsObject,CurMesh);
119
Internal::MeshTools::GetOtherMeshInfo(GraphicsObject,CurMesh);
120
121
this->PhysicsSoftBody = btSoftBodyHelpers::CreateFromTriMesh(Entresol::GetSingletonPtr()->GetPhysicsManager()->_GetPhysicsWorldPointer()->getWorldInfo(), &CurMesh.Verticies[0].x, &CurMesh.Indicies[0], CurMesh.ICount/3);
122
PhysicsObject=PhysicsSoftBody;
123
PhysicsObject->setUserPointer( (WorldObject*)this );
124
PhysicsShape = PhysicsSoftBody->getCollisionShape();
125
PhysicsSoftBody->setTotalMass(mass, true);
126
PhysicsSoftBody->m_cfg.collisions = btSoftBody::fCollision::CL_SS + btSoftBody::fCollision::CL_RS;
127
PhysicsSoftBody->m_cfg.piterations = 5;
128
PhysicsSoftBody->randomizeConstraints();
129
PhysicsSoftBody->generateBendingConstraints(2);
130
PhysicsSoftBody->generateClusters(20);
131
132
CreateManualMesh(CurMesh);
133
134
this->GraphicsObject = Entresol::GetSingletonPtr()->GetSceneManager()->GetGraphicsWorldPointer()->createEntity(CurMesh.Name, CurMesh.Name + "M", CurMesh.Group);
135
Ogre::Any OgreRef( (WorldObject*)this );
136
GraphicsObject->setUserAny(OgreRef);
137
138
this->PhysicsSoftBody->m_clusters[0]->m_collide = true;//*/
139
140
// CreateManualMesh
141
/*Ogre::ManualObject* ManualEntity = new Ogre::ManualObject(TheMesh.Name);
142
ManualEntity->setDynamic(true);
143
ManualEntity->estimateVertexCount(TheMesh.VCount);
144
ManualEntity->estimateIndexCount(TheMesh.ICount);
145
146
ManualEntity->begin(TheMesh.Material, TheMesh.RendOp, TheMesh.Group);
147
for( int x=0 ; x < TheMesh.VCount ; x++ )
148
{
149
ManualEntity->position(TheMesh.Verticies[x]);
150
ManualEntity->normal(TheMesh.Normals[x]);
151
ManualEntity->textureCoord(TheMesh.Textures[x]);
152
}
153
for( int y=0 ; y < TheMesh.ICount ; y++ )
154
{
155
ManualEntity->index(TheMesh.Indicies[y]);
156
}
157
ManualEntity->end();
158
ManualEntity->convertToMesh(TheMesh.Name + "M", TheMesh.Group);
159
delete ManualEntity;//*/
160
}
161
162
///////////////////////////////////////////////////////////////////////////////
163
// Utility
164
165
Mezzanine::ProxyType
SoftProxy::GetProxyType
()
const
166
{
167
return
Mezzanine::PT_Physics_SoftProxy;
168
}
169
170
void
SoftProxy::AddToWorld
()
171
{
172
if
( !this->
IsInWorld
() ) {
173
this->
Manager
->
_GetPhysicsWorldPointer
()->addSoftBody( this->
PhysicsSoftBody
, this->
CollisionGroup
, this->
CollisionMask
);
174
}
175
}
176
177
void
SoftProxy::RemoveFromWorld
()
178
{
179
if
( this->
IsInWorld
() ) {
180
this->
Manager
->
_GetPhysicsWorldPointer
()->removeSoftBody( this->
PhysicsSoftBody
);
181
}
182
}
183
184
///////////////////////////////////////////////////////////////////////////////
185
// Collision Settings
186
187
void
SoftProxy::SetCollisionShape
(
CollisionShape
* Shape)
188
{
189
// Do nothing. Soft bodies have their own shapes specific to the nodes and positions of the individual soft body.
190
}
191
192
///////////////////////////////////////////////////////////////////////////////
193
// Transform Methods
194
195
void
SoftProxy::SetLocation
(
const
Vector3
& Loc)
196
{
197
//this->PhysicsSoftBody->m_clusters[0]->m_framexform.setOrigin(Location.GetBulletVector3());
198
}
199
200
void
SoftProxy::SetLocation
(
const
Real
X,
const
Real
Y,
const
Real
Z)
201
{
202
203
}
204
205
Vector3
SoftProxy::GetLocation
()
const
206
{
207
return
Vector3
(0,0,0);
208
//Vector3 temp(this->PhysicsSoftBody->m_clusters[0]->m_framexform.getOrigin());
209
//return temp;
210
}
211
212
void
SoftProxy::SetOrientation
(
const
Quaternion
& Ori)
213
{
214
//this->PhysicsSoftBody->m_clusters[0]->m_framexform.setRotation(Rotation.GetBulletQuaternion(true));
215
}
216
217
void
SoftProxy::SetOrientation
(
const
Real
X,
const
Real
Y,
const
Real
Z,
const
Real
W)
218
{
219
220
}
221
222
Quaternion
SoftProxy::GetOrientation
()
const
223
{
224
return
Quaternion
(0,0,0,1);
225
}
226
227
void
SoftProxy::SetScale
(
const
Vector3
& Sc)
228
{
229
230
}
231
232
void
SoftProxy::SetScale
(
const
Real
X,
const
Real
Y,
const
Real
Z)
233
{
234
235
}
236
237
Vector3
SoftProxy::GetScale
()
const
238
{
239
return
Vector3
(1,1,1);
240
}
241
242
///////////////////////////////////////////////////////////////////////////////
243
// Serialization
244
245
void
SoftProxy::ProtoSerialize
(
XML::Node
& ParentNode)
const
246
{
247
XML::Node
SelfRoot = ParentNode.
AppendChild
(this->
GetDerivedSerializableName
());
248
if
( !SelfRoot.
AppendAttribute
(
"InWorld"
).
SetValue
( this->
IsInWorld
() ?
"true"
:
"false"
) ) {
249
SerializeError
(
"Create XML Attribute Values"
,
SoftProxy::GetSerializableName
(),
true
);
250
}
251
252
this->
ProtoSerializeProperties
(SelfRoot);
253
this->
ProtoSerializeShape
(SelfRoot);
254
}
255
256
void
SoftProxy::ProtoSerializeProperties
(
XML::Node
& SelfRoot)
const
257
{
258
259
}
260
261
void
SoftProxy::ProtoSeriailzeNodes
(
XML::Node
& SelfRoot)
const
262
{
263
264
}
265
266
void
SoftProxy::ProtoDeSerialize
(
const
XML::Node
& SelfRoot)
267
{
268
Boolean WasInWorld =
false
;
269
XML::Attribute
InWorldAttrib = SelfRoot.
GetAttribute
(
"InWorld"
);
270
if
( !InWorldAttrib.
Empty
() ) {
271
WasInWorld =
StringTools::ConvertToBool
( InWorldAttrib.
AsString
() );
272
}
273
274
this->
ProtoDeSerializeProperties
(SelfRoot);
275
this->
ProtoDeSerializeShape
(SelfRoot);
276
277
if
( WasInWorld ) {
278
this->
AddToWorld
();
279
}
280
}
281
282
void
SoftProxy::ProtoDeSerializeProperties
(
const
XML::Node
& SelfRoot)
283
{
284
285
}
286
287
void
SoftProxy::ProtoDeSeriailzeNodes
(
XML::Node
& SelfRoot)
const
288
{
289
290
}
291
292
String
SoftProxy::GetDerivedSerializableName
()
const
293
{
return
SoftProxy::GetSerializableName
(); }
294
295
String
SoftProxy::GetSerializableName
()
296
{
return
"SoftProxy"
; }
297
298
///////////////////////////////////////////////////////////////////////////////
299
// Internal Methods
300
301
btSoftBody*
SoftProxy::_GetPhysicsObject
()
const
302
{
return
this->
PhysicsSoftBody
; }
303
304
btCollisionObject*
SoftProxy::_GetBasePhysicsObject
()
const
305
{
return
this->
PhysicsSoftBody
; }
306
}
//Physics
307
}
//Mezzanine
308
309
#endif
Generated on Mon Jan 6 2014 20:58:05 for MezzanineEngine by
1.8.4