40 #ifndef _collidableproxy_cpp
41 #define _collidableproxy_cpp
43 #include "Physics/collidableproxy.h"
44 #include "Physics/collisionshape.h"
45 #include "Physics/physicsmanager.h"
46 #include "Physics/collisionshapemanager.h"
48 #include "stringtool.h"
50 #include "exception.h"
52 #include <btBulletDynamicsCommon.h>
103 // ScalingShape Methods
119 ATTRIBUTE_ALIGNED16(class) MEZZ_LIB ScalingShape : public btConvexShape
123 btConvexShape* ChildConvexShape;
126 btVector3 ChildScaling;
129 BT_DECLARE_ALIGNED_ALLOCATOR();
133 ScalingShape(btConvexShape* ChildShape, const btVector3& Scaling) :
134 ChildConvexShape(ChildShape),
135 ChildScaling(Scaling)
136 { this->m_shapeType = UNIFORM_SCALING_SHAPE_PROXYTYPE; }
138 virtual ~ScalingShape()
142 // Configuration Methods
145 virtual void SetChildShape(btConvexShape* ChildShape)
147 this->ChildConvexShape = ChildShape;
150 virtual btConvexShape* GetChildShape() const
152 return this->ChildConvexShape;
155 virtual void SetChildScaling(const btVector3& Scaling)
157 this->ChildScaling = Scaling;
160 virtual btVector3 GetChildScaling() const
162 return this->ChildScaling;
165 virtual const char* getName()const
167 return "UniformScalingShape";
171 // Internal Transform Methods
174 virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const
177 tmpVertex = this->ChildConvexShape->localGetSupportingVertexWithoutMargin(vec);
178 return tmpVertex * this->ChildScaling;
181 virtual btVector3 localGetSupportingVertex(const btVector3& vec)const
184 btScalar ChildMargin = this->ChildConvexShape->getMargin();
185 tmpVertex = this->ChildConvexShape->localGetSupportingVertexWithoutMargin(vec);
186 return (tmpVertex * this->ChildScaling) + btVector3(ChildMargin,ChildMargin,ChildMargin);
189 virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
191 this->ChildConvexShape->batchedUnitVectorGetSupportingVertexWithoutMargin(vectors,supportVerticesOut,numVectors);
192 for( int i = 0 ; i < numVectors ; i++ )
194 supportVerticesOut[i] *= this->ChildScaling;
198 virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const
200 btVector3 tmpInertia;
201 this->ChildConvexShape->calculateLocalInertia(mass,tmpInertia);
202 inertia = tmpInertia * this->ChildScaling;
206 // Inherited from btCollisionShape
209 virtual void getAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax) const
211 this->getAabbSlow(trans,aabbMin,aabbMax);
214 virtual void getAabbSlow(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
216 btVector3 _directions[] =
218 btVector3( 1., 0., 0.),
219 btVector3( 0., 1., 0.),
220 btVector3( 0., 0., 1.),
221 btVector3( -1., 0., 0.),
222 btVector3( 0., -1., 0.),
223 btVector3( 0., 0., -1.)
226 btVector3 _supporting[] =
228 btVector3( 0., 0., 0.),
229 btVector3( 0., 0., 0.),
230 btVector3( 0., 0., 0.),
231 btVector3( 0., 0., 0.),
232 btVector3( 0., 0., 0.),
233 btVector3( 0., 0., 0.)
236 for( int i = 0 ; i < 6 ; i++ )
238 _directions[i] = _directions[i] * t.getBasis();
241 this->batchedUnitVectorGetSupportingVertexWithoutMargin(_directions, _supporting, 6);
243 btVector3 aabbMin1(0,0,0),aabbMax1(0,0,0);
244 for ( int i = 0; i < 3; ++i )
246 aabbMax1[i] = t(_supporting[i])[i];
247 aabbMin1[i] = t(_supporting[i + 3])[i];
250 btVector3 marginVec(this->getMargin(),this->getMargin(),this->getMargin());
251 // convert to local to scale
252 aabbMin1 = ( aabbMin1 - t.getOrigin() ) * this->ChildScaling;
253 aabbMax1 = ( aabbMax1 - t.getOrigin() ) * this->ChildScaling;
255 aabbMin = ( aabbMin1 + t.getOrigin() ) - marginVec;
256 aabbMax = ( aabbMax1 + t.getOrigin() ) + marginVec;
260 virtual void setLocalScaling(const btVector3& scaling)
261 { this->SetChildScaling(scaling); }
263 virtual const btVector3& getLocalScaling() const
264 { return this->ChildScaling; }
266 virtual void setMargin(btScalar margin)
267 { this->ChildConvexShape->setMargin(margin); }
269 virtual btScalar getMargin() const
270 { return this->ChildConvexShape->getMargin(); }
272 virtual int getNumPreferredPenetrationDirections() const
273 { return this->ChildConvexShape->getNumPreferredPenetrationDirections(); }
275 virtual void getPreferredPenetrationDirection(int index, btVector3& penetrationVector) const
276 { this->ChildConvexShape->getPreferredPenetrationDirection(index,penetrationVector); }
288 CollisionGroup(Physics::CF_GenericFilter),
289 CollisionMask(Physics::CF_AllFilter)
423 Base->setCollisionFlags( Base->getCollisionFlags() & ~btCollisionObject::CF_NO_CONTACT_RESPONSE );
425 Base->setCollisionFlags( Base->getCollisionFlags() | btCollisionObject::CF_NO_CONTACT_RESPONSE );
432 return !(this->
_GetBasePhysicsObject()->getCollisionFlags() & btCollisionObject::CF_NO_CONTACT_RESPONSE);
451 Base->setCollisionFlags( Base->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT );
457 Base->setCollisionFlags( Base->getCollisionFlags() | btCollisionObject::CF_STATIC_OBJECT );
496 return Physics::AFF_AnisotropicFrictionDisabled;
498 return Physics::AFF_AnisotropicFriction;
500 return Physics::AFF_AnisotropicRollingFriction;
502 return Physics::AFF_AnisotropicFrictionDisabled;
556 btVector3 NewLoc(X,Y,Z);
573 btQuaternion NewRot(X,Y,Z,W);
653 this->
Scale(NewScale);
712 Boolean WasInWorld =
false;
714 if( !InWorldAttrib.
Empty() ) {
733 if( !PropertiesNode.
Empty() ) {
737 CurrAttrib = PropertiesNode.
GetAttribute(
"CollisionGroup");
738 if( !CurrAttrib.
Empty() )
741 CurrAttrib = PropertiesNode.
GetAttribute(
"CollisionMask");
742 if( !CurrAttrib.
Empty() )
745 CurrAttrib = PropertiesNode.
GetAttribute(
"CollisionFlags");
746 if( !CurrAttrib.
Empty() )
750 if( !CurrAttrib.
Empty() )
753 CurrAttrib = PropertiesNode.
GetAttribute(
"RollingFriction");
754 if( !CurrAttrib.
Empty() )
757 CurrAttrib = PropertiesNode.
GetAttribute(
"AnisotropicFrictionMode");
758 if( !CurrAttrib.
Empty() )
761 CurrAttrib = PropertiesNode.
GetAttribute(
"Restitution");
762 if( !CurrAttrib.
Empty() )
765 CurrAttrib = PropertiesNode.
GetAttribute(
"ActivationState");
766 if( !CurrAttrib.
Empty() )
769 CurrAttrib = PropertiesNode.
GetAttribute(
"DeactivationTime");
770 if( !CurrAttrib.
Empty() )
773 CurrAttrib = PropertiesNode.
GetAttribute(
"ContactProcessingThreshold");
774 if( !CurrAttrib.
Empty() )
779 if( !AnisotropicFrictionNode.
Empty() ) {
780 Vector3 AF(AnisotropicFrictionNode);
796 if( !ShapeNode.
Empty() ) {
799 if( !CurrAttrib.
Empty() ) {
811 {
return "CollidableProxy"; }