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"
52 #include <btBulletDynamicsCommon.h>
97 // ScalingShape Methods
113 ATTRIBUTE_ALIGNED16(class) MEZZ_LIB ScalingShape : public btConvexShape
117 btConvexShape* ChildConvexShape;
120 btVector3 ChildScaling;
123 BT_DECLARE_ALIGNED_ALLOCATOR();
127 ScalingShape(btConvexShape* ChildShape, const btVector3& Scaling) :
128 ChildConvexShape(ChildShape),
129 ChildScaling(Scaling)
130 { this->m_shapeType = UNIFORM_SCALING_SHAPE_PROXYTYPE; }
132 virtual ~ScalingShape()
136 // Configuration Methods
139 virtual void SetChildShape(btConvexShape* ChildShape)
141 this->ChildConvexShape = ChildShape;
144 virtual btConvexShape* GetChildShape() const
146 return this->ChildConvexShape;
149 virtual void SetChildScaling(const btVector3& Scaling)
151 this->ChildScaling = Scaling;
154 virtual btVector3 GetChildScaling() const
156 return this->ChildScaling;
159 virtual const char* getName()const
161 return "UniformScalingShape";
165 // Internal Transform Methods
168 virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const
171 tmpVertex = this->ChildConvexShape->localGetSupportingVertexWithoutMargin(vec);
172 return tmpVertex * this->ChildScaling;
175 virtual btVector3 localGetSupportingVertex(const btVector3& vec)const
178 btScalar ChildMargin = this->ChildConvexShape->getMargin();
179 tmpVertex = this->ChildConvexShape->localGetSupportingVertexWithoutMargin(vec);
180 return (tmpVertex * this->ChildScaling) + btVector3(ChildMargin,ChildMargin,ChildMargin);
183 virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
185 this->ChildConvexShape->batchedUnitVectorGetSupportingVertexWithoutMargin(vectors,supportVerticesOut,numVectors);
186 for( int i = 0 ; i < numVectors ; i++ )
188 supportVerticesOut[i] *= this->ChildScaling;
192 virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const
194 btVector3 tmpInertia;
195 this->ChildConvexShape->calculateLocalInertia(mass,tmpInertia);
196 inertia = tmpInertia * this->ChildScaling;
200 // Inherited from btCollisionShape
203 virtual void getAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax) const
205 this->getAabbSlow(trans,aabbMin,aabbMax);
208 virtual void getAabbSlow(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
210 btVector3 _directions[] =
212 btVector3( 1., 0., 0.),
213 btVector3( 0., 1., 0.),
214 btVector3( 0., 0., 1.),
215 btVector3( -1., 0., 0.),
216 btVector3( 0., -1., 0.),
217 btVector3( 0., 0., -1.)
220 btVector3 _supporting[] =
222 btVector3( 0., 0., 0.),
223 btVector3( 0., 0., 0.),
224 btVector3( 0., 0., 0.),
225 btVector3( 0., 0., 0.),
226 btVector3( 0., 0., 0.),
227 btVector3( 0., 0., 0.)
230 for( int i = 0 ; i < 6 ; i++ )
232 _directions[i] = _directions[i] * t.getBasis();
235 this->batchedUnitVectorGetSupportingVertexWithoutMargin(_directions, _supporting, 6);
237 btVector3 aabbMin1(0,0,0),aabbMax1(0,0,0);
238 for ( int i = 0; i < 3; ++i )
240 aabbMax1[i] = t(_supporting[i])[i];
241 aabbMin1[i] = t(_supporting[i + 3])[i];
244 btVector3 marginVec(this->getMargin(),this->getMargin(),this->getMargin());
245 // convert to local to scale
246 aabbMin1 = ( aabbMin1 - t.getOrigin() ) * this->ChildScaling;
247 aabbMax1 = ( aabbMax1 - t.getOrigin() ) * this->ChildScaling;
249 aabbMin = ( aabbMin1 + t.getOrigin() ) - marginVec;
250 aabbMax = ( aabbMax1 + t.getOrigin() ) + marginVec;
254 virtual void setLocalScaling(const btVector3& scaling)
255 { this->SetChildScaling(scaling); }
257 virtual const btVector3& getLocalScaling() const
258 { return this->ChildScaling; }
260 virtual void setMargin(btScalar margin)
261 { this->ChildConvexShape->setMargin(margin); }
263 virtual btScalar getMargin() const
264 { return this->ChildConvexShape->getMargin(); }
266 virtual int getNumPreferredPenetrationDirections() const
267 { return this->ChildConvexShape->getNumPreferredPenetrationDirections(); }
269 virtual void getPreferredPenetrationDirection(int index, btVector3& penetrationVector) const
270 { this->ChildConvexShape->getPreferredPenetrationDirection(index,penetrationVector); }
282 CollisionGroup(Physics::CF_GenericFilter),
283 CollisionMask(Physics::CF_AllFilter)
292 CollisionGroup(Physics::CF_GenericFilter),
293 CollisionMask(Physics::CF_AllFilter)
431 Base->setCollisionFlags( Base->getCollisionFlags() & ~btCollisionObject::CF_NO_CONTACT_RESPONSE );
433 Base->setCollisionFlags( Base->getCollisionFlags() | btCollisionObject::CF_NO_CONTACT_RESPONSE );
439 {
return !(this->
_GetBasePhysicsObject()->getCollisionFlags() & btCollisionObject::CF_NO_CONTACT_RESPONSE); }
453 Base->setCollisionFlags( Base->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT );
459 Base->setCollisionFlags( Base->getCollisionFlags() | btCollisionObject::CF_STATIC_OBJECT );
492 return Physics::AFF_AnisotropicFrictionDisabled;
494 return Physics::AFF_AnisotropicFriction;
496 return Physics::AFF_AnisotropicRollingFriction;
498 return Physics::AFF_AnisotropicFrictionDisabled;
544 btVector3 NewLoc(X,Y,Z);
561 btQuaternion NewRot(X,Y,Z,W);
641 this->
Scale(NewScale);
694 if( !PropertiesNode.
Empty() ) {
698 CurrAttrib = PropertiesNode.
GetAttribute(
"CollisionGroup");
699 if( !CurrAttrib.
Empty() )
702 CurrAttrib = PropertiesNode.
GetAttribute(
"CollisionMask");
703 if( !CurrAttrib.
Empty() )
706 CurrAttrib = PropertiesNode.
GetAttribute(
"CollisionFlags");
707 if( !CurrAttrib.
Empty() )
711 if( !CurrAttrib.
Empty() )
714 CurrAttrib = PropertiesNode.
GetAttribute(
"RollingFriction");
715 if( !CurrAttrib.
Empty() )
718 CurrAttrib = PropertiesNode.
GetAttribute(
"AnisotropicFrictionMode");
719 if( !CurrAttrib.
Empty() )
722 CurrAttrib = PropertiesNode.
GetAttribute(
"Restitution");
723 if( !CurrAttrib.
Empty() )
726 CurrAttrib = PropertiesNode.
GetAttribute(
"ActivationState");
727 if( !CurrAttrib.
Empty() )
730 CurrAttrib = PropertiesNode.
GetAttribute(
"DeactivationTime");
731 if( !CurrAttrib.
Empty() )
734 CurrAttrib = PropertiesNode.
GetAttribute(
"ContactProcessingThreshold");
735 if( !CurrAttrib.
Empty() )
740 if( !AnisotropicFrictionNode.
Empty() ) {
741 Vector3 AF(AnisotropicFrictionNode);
757 if( !ShapeNode.
Empty() ) {
760 if( !CurrAttrib.
Empty() ) {
772 {
return "CollidableProxy"; }
virtual Int16 GetCollisionMask() const
Gets the object's collision mask.
This is the base class for all collision shapes.
virtual void Yaw(const Real Angle)
Rotate the object around the Y axis.
Attribute AppendAttribute(const Char8 *Name)
Creates an Attribute and puts it at the end of this Nodes attributes.
virtual Real GetDeactivationTime() const
Gets the current deactivation time for this object.
virtual void Pitch(const Real Angle)
Rotate the object around the X axis.
Indicates the class is a MultiSphereCollisionShape.
virtual ~CollidableProxy()
Class Destructor.
A light-weight handle for manipulating attributes in DOM tree.
virtual void ProtoDeSerializeShape(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite the shape of this object with it.
virtual void SetRollingFriction(const Real Friction)
Sets the rolling friction coefficient.
bool Boole
Generally acts a single bit, true or false.
virtual void Rotate(const Vector3 &Axis, const Real Angle)
Rotates the object from it's existing rotation.
virtual Int16 GetCollisionGroup() const
Gets the objects collision group.
virtual void SetActivationState(const Physics::ActivationState State, Boole Force=false)
Sets the activation state of the world object.
Real X
Coordinate on the X vector.
virtual Real GetRestitution() const
Gets the World Object restitution coefficient.
Indicates the class is a ConeCollisionShape.
Real Z
Coordinate on the Z vector.
Indicates the class is a StaticMeshCollisionShape.
PhysicsManager * Manager
This is a pointer to the physics manager that created and owns this proxy.
virtual void SetCollisionMask(const Int16 Mask)
Sets the collision mask of this proxy, which determines which groups it will collide with...
Thrown when the requested identity could not be found.
virtual void ProtoSerializeImpl(XML::Node &SelfRoot) const
Implementation method for serializing additional sets of data.
Node GetFirstChild() const
Get the first child Node of this Node.
#define MEZZ_EXCEPTION(num, desc)
An easy way to throw exceptions with rich information.
virtual Boole IsAnisotropicFrictionModeSet(const Whole Mode) const
Gets whether or not anisotropic friction is being used in a specified mode.
virtual Boole IsStaticOrKinematic() const
Checks if the object is either static or kinematic.
int Integer
A datatype used to represent any integer close to.
virtual Real GetFriction() const
Gets the sliding friction coefficient.
Real Y
The Y component of the Axis.
virtual Boole IsActive() const
Checks if the object is active in the simulation.
Thrown when a version is accessed/parsed/required and it cannot work correctly or is missing...
virtual Vector3 GetLocation() const
Gets this objects current location.
virtual Vector3 GetScaling() const
Gets the current scaling being applied to the collision shape.
Indicates the class is a DynamicMeshCollisionShape.
const Char8 * AsString(const Char8 *def="") const
Attempts to convert the value of the attribute to a String and returns the results.
virtual btCollisionShape * _GetInternalShape() const
Gets the internal shape pointer this collision shape is based on.
virtual WorldManager * GetCreator() const
Gets a pointer to this proxies creator.
virtual Boole IsKinematic() const
Is the object kinematic.
virtual void ProtoDeSerializeProperties(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite the properties of this object with it...
ActivationState
This is used by physics proxies to monitor and set their physics activation.
bool Empty() const
Is this storing anything at all?
virtual void SetLocation(const Vector3 &Loc)
Sets the location of this object in parent space.
This implements the exception hiearchy for Mezzanine.
virtual void Roll(const Real Angle)
Rotate the object around the Z axis.
Indicates the class is a CompoundCollisionShape.
float Real
A Datatype used to represent a real floating point number.
The interface for serialization.
virtual Real GetRollingFriction() const
Gets the rolling friction coefficient.
bool SetValue(const Char8 *rhs)
Set the value of this.
Whole AsWhole(Whole def=0) const
Attempts to convert the value of the attribute to a Whole and returns the results.
static CollisionShapeManager * GetSingletonPtr()
Fetches a pointer to the singleton.
virtual Vector3 GetScale() const
Gets the scaling currently being applied to this object.
virtual void SetOrientation(const Quaternion &Ori)
Sets the orientation of this object in parent space.
virtual void SetRestitution(const Real &Restitution)
Sets the restitution coefficient.
virtual void RemoveFromWorld()=0
Unhooks this proxy from it's respective world.
Int16 CollisionGroup
The classifications pertaining to this object in regards to collisions.
Indicates the class is a SphereCollisionShape.
virtual Boole IsStatic() const
Is the object static.
btVector3 GetBulletVector3() const
Gets a Bullet vector3.
A light-weight handle for manipulating nodes in DOM tree.
virtual void ProtoDeSerializeImpl(const XML::Node &SelfRoot)
Implementation method for deseriailizing additional sets of data.
virtual Vector3 GetAnisotropicFriction() const
Gets the anisotropic friction factor.
Real W
Rotation on the Axis X, Y and Z defined.
virtual String GetDerivedSerializableName() const
Gets the most derived serializable name of this WorldProxy.
int AsInt(int def=0) const
Attempts to convert the value of the attribute to an int and returns the results. ...
This is the base class for proxy objects belonging to the various 3D subsystems.
uint32_t UInt32
An 32-bit unsigned integer.
virtual void ProtoSerializeProperties(XML::Node &SelfRoot) const
Convert the properties of this class to an XML::Node ready for serialization.
CollidableProxy(PhysicsManager *Creator)
XML-assist Constructor.
virtual void _SetContactProcessingThreshold(const Real Threshold)
Sets the maximum distance to be considered for processing collisions with this object.
static Vector3 Unit_Y()
Gets a vector representing the Y unit of a Vector3.
virtual void ProtoSerializeShape(XML::Node &SelfRoot) const
Convert the shape of this class to an XML::Node ready for serialization.
bool Empty() const
Is this storing anything at all?
virtual void SetScale(const Vector3 &Sc)
Sets the scaling to be applied to this object.
virtual void AddToWorld()=0
Performs all the necessary task to ensure this object is connected to it's respective world and ready...
ShapeType
This enum describes what kind of shape you are currently working with.
Real AsReal(Real def=0) const
Attempts to convert the value of the attribute to a Real and returns the results. ...
Real Y
Coordinate on the Y vector.
Indicates the class is a CylinderCollisionShape.
virtual void SetKinematic()
Sets the state of the object to Kinematic.
CollisionShape * ProxyShape
The physics shape of this proxy.
virtual void SetCollisionGroup(const Int16 Group)
Sets which collision group this proxy belongs to, which determines it's collision behavior...
virtual Quaternion GetOrientation() const
Gets this objects current orientation.
virtual btCollisionObject * _GetBasePhysicsObject() const =0
Accessor for the internal physics object.
static String GetSerializableName()
Get the name of the the XML tag the proxy class will leave behind as its instances are serialized...
This is the base class for all managers that belong to a single world instance.
virtual Boole GetCollisionResponse() const
Will this respond to 3d collisions.
int16_t Int16
An 16-bit integer.
static Vector3 Unit_X()
Gets a vector representing the X unit of a Vector3.
This is simply a place for storing all the Physics Related functions.
virtual void SetScaling(const Vector3 &Scaling)
Scales the collision shape on each of it's axes.
A container for the metrics of time relevant for the timer class.
virtual void SetFriction(const Real Friction)
Sets the sliding friction coefficient.
virtual void SetCollisionResponse(Boole Enable)
Sets the World Object to be able to collide with other objects in the world.
static Vector3 Unit_Z()
Gets a vector representing the Z unit of a Vector3.
Indicates the class is a BoxCollisionShape.
This is used to represent a point in space, or a vector through space.
virtual AxisAlignedBox GetAABB() const
Gets this proxies AABB.
virtual void Translate(const Vector3 &Trans)
Moves this object from it's current location.
virtual Integer _GetBroadphaseUniqueID() const
Gets the unique ID assigned to the internal object.
virtual Physics::ActivationState GetActivationState() const
Gets the current activation state of this proxy.
virtual void SetDeactivationTime(const Real Time)
Sets the amount of time this object needs to have no forces enacted upon it to be deactivated...
virtual void Scale(const Vector3 &Scale)
Scales the object from it's current size.
The bulk of the engine components go in this namspace.
virtual Whole GetCollisionFlags() const
Gets the collection of flags that help determine collision response for this object.
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
virtual Boole IsInWorld() const
Gets whether or not this object is inside of it's world.
Int16 CollisionMask
Stores the kind of World Objects that can collide with each other.
virtual void ProtoSerializeImpl(XML::Node &SelfRoot) const
Implementation method for serializing additional sets of data.
virtual Physics::AnisotropicFrictionFlags GetAnisotropicFrictionMode() const
Gets the current Anisotropic friction mode being applied to this proxy.
virtual void SetCollisionShape(CollisionShape *Shape)
Sets the collision shape to be used.
Real X
The X component of the Axis.
virtual void SetCollisionFlags(const Whole Flags)
Sets the collection of flags that help determine collision response for this object.
This is used to store information about rotation in 3d space.
virtual void SetStatic()
Sets the state of the object to Static.
void SerializeError(const String &FailedTo, const String &ClassName, Boole SOrD)
Simply does some string concatenation, then throws an Exception.
virtual void ProtoSerializeProperties(XML::Node &SelfRoot) const
Convert the properties of this class to an XML::Node ready for serialization.
Node AppendChild(NodeType Type=NodeElement)
Creates a Node and makes it a child of this one.
virtual void SetCollisionGroupAndMask(const Int16 Group, const Int16 Mask)
Set the collision group and mask for the proxy to determine what it should collide with...
Real Z
The Z component of the Axis.
std::string String
A datatype used to a series of characters.
AnisotropicFrictionFlags
This is used by physics proxies to help determine the behavior of it's anistropic friction behavior...
virtual CollisionShape * GetCollisionShape() const
Gets the collision shape currently in use by this object.
virtual Real _GetContactProcessingThreshold() const
Gets the maximum distance to be considered for processing collisions with this object.
Attribute GetAttribute(const Char8 *Name) const
Attempt to get an Attribute on this Node with a given name.
Indicates the class is a CapsuleCollisionShape.
Indicates the class is a ConvexHullCollisionShape.
void ProtoSerialize(XML::Node &CurrentRoot) const
Convert this class to an XML::Node ready for serialization.
Node GetChild(const Char8 *Name) const
Attempt to get a child Node with a given name.
virtual void ProtoDeSerializeProperties(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite the properties of this object with it...
virtual const String & GetName() const
Gets the name of this shape.
virtual void ProtoDeSerializeImpl(const XML::Node &SelfRoot)
Implementation method for deseriailizing additional sets of data.
virtual void SetAnisotropicFriction(const Vector3 &Friction, const Whole Mode)
Sets the anisotropic friction factor.
This is a utility class used to represent the Axis-Aligned Bounding Boxes of objects in various subsy...