40 #ifndef _physicsconstraint_cpp
41 #define _physicsconstraint_cpp
43 #include "Physics/constraint.h"
44 #include "Physics/physicsenumerations.h"
45 #include "Physics/physicsmanager.h"
46 #include "Physics/rigidproxy.h"
48 #include "actormanager.h"
51 #include "stringtool.h"
55 #include <btBulletDynamicsCommon.h>
56 #include <BulletSoftBody/btSoftRigidDynamicsWorld.h>
72 case Con_Stop_ERP:
return String(
"Con_Stop_ERP");
74 case Con_Stop_CFM:
return String(
"Con_Stop_CFM");
101 {
return Con_Stop_ERP; }
106 {
return Con_Stop_CFM; }
123 case '-':
return -1;
break;
124 case '0':
return 0;
break;
125 case '1':
return 1;
break;
126 case '2':
return 2;
break;
127 case '3':
return 3;
break;
128 case '4':
return 4;
break;
129 case '5':
return 5;
break;
145 AllowCollisions(true),
154 AllowCollisions(true),
167 AllowCollisions(true),
189 if( Enable != this->
Enabled ) {
209 {
return this->
ProxA; }
212 {
return this->
ProxB; }
221 Lin.insert(Lin.end(),Ang.begin(),Ang.end());
222 std::sort(Lin.begin(),Lin.end());
232 if( Supported.size() ) {
233 return ( std::find(Supported.begin(),Supported.end(),Param) != Supported.end() );
244 if( AllAxis.size() ) {
247 if( AllAxis.size() > 1 ) {
248 for( AxisList::iterator AxisIter = AllAxis.begin() + 1 ; AllAxis.end() != AxisIter; ++AxisIter )
250 for(
int ParamID = Results.size() ; ParamID <= 0 ; --ParamID )
253 Results.erase( Results.begin()+ParamID );
259 sort(Results.begin(),Results.end());
285 if( PropertiesNode.AppendAttribute(
"Version").SetValue(
"1") &&
286 PropertiesNode.AppendAttribute(
"ID").SetValue( this->
ConstraintID ) &&
288 PropertiesNode.AppendAttribute(
"AllowCollisions").SetValue( this->
GetAllowCollisions() ) )
302 for( AxisList::iterator AxisIter = AllAxis.begin() ; AllAxis.end() != AxisIter ; ++AxisIter )
304 XML::Node OverrideNode = GlobalOverridesNode.AppendChild(
"ParamOverride");
307 for( ParamList::iterator ParamIter = AxisParams.begin() ; AxisParams.end() != ParamIter; ++ParamIter )
310 if( OverrideNode.AppendAttribute(
"Version").SetValue(
"1") &&
311 OverrideNode.AppendAttribute(
"Axis").SetValue( *AxisIter ) &&
313 OverrideNode.AppendAttribute(
"Value").SetValue( this->
GetParam(*ParamIter,*AxisIter) ) )
333 XML::Attribute CurrAttrib;
336 if( !PropertiesNode.Empty() ) {
337 if(PropertiesNode.GetAttribute(
"Version").AsInt() == 1) {
338 CurrAttrib = PropertiesNode.GetAttribute(
"ID");
339 if( !CurrAttrib.Empty() )
340 this->
ConstraintID = static_cast<UInt32>( CurrAttrib.AsUint() );
342 CurrAttrib = PropertiesNode.GetAttribute(
"AllowCollisions");
343 if( !CurrAttrib.Empty() )
346 CurrAttrib = PropertiesNode.GetAttribute(
"Enabled");
347 if( !CurrAttrib.Empty() )
359 XML::Attribute CurrAttrib;
362 if( !OverridesNode.Empty() ) {
363 if( OverridesNode.GetAttribute(
"Version").AsInt() == 1 ) {
364 for( XML::NodeIterator OverrideNodeIt = OverridesNode.begin() ; OverrideNodeIt != OverridesNode.end() ; ++OverrideNodeIt )
366 if( (*OverrideNodeIt).GetAttribute(
"Version").AsInt() == 1 ) {
369 Real OverrideValue = 0.0;
371 CurrAttrib = (*OverrideNodeIt).GetAttribute(
"Axis");
372 if( !CurrAttrib.Empty() )
373 Axis = CurrAttrib.AsInt();
375 CurrAttrib = (*OverrideNodeIt).GetAttribute(
"Param");
376 if( !CurrAttrib.Empty() )
377 Param = CurrAttrib.AsUint();
379 CurrAttrib = (*OverrideNodeIt).GetAttribute(
"Value");
380 if( !CurrAttrib.Empty() )
381 OverrideValue = CurrAttrib.AsReal();
384 this->
SetParam(static_cast<ConstraintParam>(Param),OverrideValue,Axis);
397 {
return "Constraint"; }
std::ostream & operator<<(std::ostream &stream, const Mezzanine::LinearInterpolator< T > &Lint)
Used to Serialize an Mezzanine::LinearInterpolator to a human readable stream.
Constraint(const UInt32 ID, PhysicsManager *Creator)
Zero body constructor.
virtual Boole GetAllowCollisions() const
Gets whether or not collisions can/will occur between the two constrained bodies. ...
virtual Boole IsConstraintEnabled() const
Gets whether or not this constraint is enabled.
std::vector< int > AxisList
Used to Store lists of Int Axis for return types.
ConstraintParam StringAsConstraintParam(String Param)
Convert A string that might be ConstraintParam to one.
virtual ~Constraint()
Class destructor.
CFM values adds some small value to the main diagonal on the constraint matrix to prevent degenerate ...
const int ConstraintParamCount
How many ConstraintParam Exist.
virtual ParamList GetValidParamsOnAxis(int Axis) const =0
Get a sorted (low to high) list of Parameters that are valid on this Axis.
bool Boole
Generally acts a single bit, true or false.
virtual Real GetParam(ConstraintParam Param, int Axis=-1) const
Gets value of constraint parameters.
virtual void SetActivationState(const Physics::ActivationState State, Boole Force=false)
Sets the activation state of the world object.
static String GetSerializableName()
Get the name of the the XML tag the class will leave behind as its instances are serialized.
UInt32 ConstraintID
The unique ID used to identify this constraint.
virtual void SetParam(ConstraintParam Param, Real Value, int Axis=-1)
Provides override of constraint parameters.
virtual void ProtoDeSerializeGlobalOverrides(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite the global overrides of this object with it...
Thrown when the requested identity could not be found.
#define MEZZ_EXCEPTION(num, desc)
An easy way to throw exceptions with rich information.
std::ostream & Serialize(std::ostream &Stream, const T &Converted, const String &Indent=String(""))
Convert any class that supports serialization or has a serializer to a string of chars in a stream...
int Integer
A datatype used to represent any integer close to.
Boole Enabled
Whether or not the constraint is currently taking effect.
virtual void SetAllowCollisions(const Boole Allow)
Sets whether collisions between the two constrained bodies should occur.
Thrown when a version is accessed/parsed/required and it cannot work correctly or is missing...
virtual void ProtoSerialize(XML::Node &ParentNode) const
Convert this class to an XML::Node ready for serialization.
virtual void EnableConstraint(const Boole Enable)
Enables or disables this constraint.
String ConstraintParamAsString(ConstraintParam Param)
Get a Constraint Parameter as a String.
PhysicsManager * Manager
This is a pointer to the physics manager that created and owns this constraint.
This is the base class for all constraints supported.
virtual void ProtoSerializeProperties(XML::Node &SelfRoot) const
Convert the properties of this class to an XML::Node ready for serialization.
This implements the exception hiearchy for Mezzanine.
virtual Boole IsParamValidOnAxis(ConstraintParam Param, int Axis) const
Is a certain Parameter valid on a certain axis.
virtual void ProtoDeSerializeInitData(const XML::Node &SelfRoot)=0
Take the data stored in an XML Node and initializes a new internal object with it.
int char4ToAxis(char it)
used to help convert string to the axis they indicate
float Real
A Datatype used to represent a real floating point number.
The interface for serialization.
virtual btTypedConstraint * _GetConstraintBase() const =0
Get the Bullet constraint that this class encapsulates.
virtual void ProtoDeSerializeProperties(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite the properties of this object with it...
A light-weight handle for manipulating nodes in DOM tree.
uint32_t UInt32
An 32-bit unsigned integer.
virtual RigidProxy * GetProxyB() const
Gets the second Proxy this constraint applies to.
ConstraintParam
Used by constraints for setting some parameters.
virtual void ProtoSerializeInitData(XML::Node &SelfRoot) const =0
Convert the data needed to initialize this class to an XML::Node ready for serialization.
btSoftRigidDynamicsWorld * _GetPhysicsWorldPointer()
This returns a pointer to the bullet physics world. This is for internal use only.
virtual AxisList GetValidAngularAxes() const =0
Get A list sorted (low to high) of all axis that operate Angularly (that lock sliding/translation) ...
std::istream & DeSerialize(std::istream &Stream, T &Converted)
Deserialize the next xml tag in the stream into a specific in memory class instance.
std::vector< ConstraintParam > ParamList
Used to Store lists of param for return types.
virtual AxisList GetValidLinearAxes() const =0
Get a sorted (low to high) list of all axis that operate linearly (that lock sliding/translation) ...
Thrown when parameters are checked at runtime and found invalid.
RigidProxy * ProxA
The first Collidable this constraint applies to.
virtual Boole HasParamBeenSet(ConstraintParam Param, int Axis) const =0
Has the given Param on the Given Axis been set yet.
virtual ParamList GetValidParams() const
Get A sorted (low to high) list of Parameters that are valid on all Axis.
virtual void ProtoDeSerialize(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite this object with it.
RigidProxy * ProxB
The second Collidable this constraint applies to.
The bulk of the engine components go in this namspace.
Boole AllowCollisions
Whether or not collisions will be allowed to occure between the constrained bodies.
std::istream & operator>>(std::istream &stream, Mezzanine::LinearInterpolator< T > &Lint)
Used to de-serialize an Mezzanine::LinearInterpolator from a stream.
virtual UInt32 GetConstraintID() const
Gets the unique ID of this constraint.
ERP values adjust how fast the errors in the constraints are reduced.
void SerializeError(const String &FailedTo, const String &ClassName, Boole SOrD)
Simply does some string concatenation, then throws an Exception.
virtual void ProtoSerializeGlobalOverrides(XML::Node &SelfRoot) const
Convert the global overrides of this class to an XML::Node ready for serialization.
virtual String GetDerivedSerializableName() const =0
Gets the most derived serializable name of this Constraint.
std::string String
A datatype used to a series of characters.
virtual RigidProxy * GetProxyA() const
Gets the first Proxy this constraint applies to.
virtual AxisList GetValidAxes() const
Get a sorted (low to high) list of All Valid Axis.