40 #ifndef _physicsgeneric6dofconstraint_cpp
41 #define _physicsgeneric6dofconstraint_cpp
43 #include "Physics/generic6dofconstraint.h"
44 #include "Physics/rigidproxy.h"
46 #include "stringtool.h"
49 #include <btBulletDynamicsCommon.h>
92 if( RigidA && RigidB ) {
157 { this->
Generic6dof->setUseFrameOffset(FrameOffset); }
163 { this->
Generic6dof->setUseLinearReferenceFrameA(UseRefFrameA); }
166 {
return this->
Generic6dof->getUseLinearReferenceFrameA(); }
169 {
return ( Axis % 3 ); }
172 {
return ( Axis > 2 ? Axis : Axis + 3 ); }
178 { this->
Generic6dof->setLimit(Axis, Lower, Upper); }
193 { this->
Generic6dof->getTranslationalLimitMotor()->m_lowerLimit[TranslationAxis] = Limit; }
196 {
return this->
Generic6dof->getTranslationalLimitMotor()->m_lowerLimit[TranslationAxis]; }
199 { this->
Generic6dof->getTranslationalLimitMotor()->m_upperLimit[TranslationAxis] = Limit; }
202 {
return this->
Generic6dof->getTranslationalLimitMotor()->m_upperLimit[TranslationAxis]; }
307 { this->
Generic6dof->getTranslationalLimitMotor()->m_limitSoftness = Softness; }
310 {
return this->
Generic6dof->getTranslationalLimitMotor()->m_limitSoftness; }
313 { this->
Generic6dof->getTranslationalLimitMotor()->m_damping = Damping; }
316 {
return this->
Generic6dof->getTranslationalLimitMotor()->m_damping; }
319 { this->
Generic6dof->getTranslationalLimitMotor()->m_restitution = Restitution; }
322 {
return this->
Generic6dof->getTranslationalLimitMotor()->m_restitution; }
328 { this->
Generic6dof->getTranslationalLimitMotor()->m_maxMotorForce[Axis] = Force; }
334 {
return this->
Generic6dof->getTranslationalLimitMotor()->m_maxMotorForce[Axis]; }
340 { this->
Generic6dof->getTranslationalLimitMotor()->m_targetVelocity[Axis] = Velocity; }
346 {
return this->
Generic6dof->getTranslationalLimitMotor()->m_targetVelocity[Axis]; }
358 {
return this->
Generic6dof->getTranslationalLimitMotor()->m_enableMotor[Axis]; }
366 if( 0 <= Axis && 5 >= Axis ) {
367 Results.push_back(Con_Stop_ERP);
369 Results.push_back(Con_Stop_CFM);
377 Results.push_back(0);
378 Results.push_back(1);
379 Results.push_back(2);
386 Results.push_back(3);
387 Results.push_back(4);
388 Results.push_back(5);
395 if( 0 > Axis || 5 < Axis )
397 return ( Con_Stop_ERP==Param && this->
Generic6dof->getFlags() & (BT_6DOF_FLAGS_ERP_STOP << (Axis * BT_6DOF_FLAGS_AXIS_SHIFT)) ) ||
398 ( Con_Stop_CFM==Param && this->
Generic6dof->getFlags() & (BT_6DOF_FLAGS_CFM_STOP << (Axis * BT_6DOF_FLAGS_AXIS_SHIFT)) ) ||
399 (
Con_CFM==Param && this->
Generic6dof->getFlags() & (BT_6DOF_FLAGS_CFM_NORM << (Axis * BT_6DOF_FLAGS_AXIS_SHIFT)) ) ;
470 if( !PropertiesNode.
Empty() ) {
472 CurrAttrib = PropertiesNode.
GetAttribute(
"UseFrameOffset");
473 if( !CurrAttrib.
Empty() )
476 CurrAttrib = PropertiesNode.
GetAttribute(
"UseLinearReferenceFrameA");
477 if( !CurrAttrib.
Empty() )
480 CurrAttrib = PropertiesNode.
GetAttribute(
"LinearLimitSoftness");
481 if( !CurrAttrib.
Empty() )
484 CurrAttrib = PropertiesNode.
GetAttribute(
"LinearLimitDamping");
485 if( !CurrAttrib.
Empty() )
488 CurrAttrib = PropertiesNode.
GetAttribute(
"LinearLimitRestitution");
489 if( !CurrAttrib.
Empty() )
493 for(
XML::NodeIterator LinearAxesNodeIt = LinearAxesNode.
begin() ; LinearAxesNodeIt != LinearAxesNode.
end() ; ++LinearAxesNodeIt )
495 if( !(*LinearAxesNodeIt).Empty() ) {
496 if( (*LinearAxesNodeIt).GetAttribute(
"Version").AsInt() == 1 ) {
499 CurrAttrib = (*LinearAxesNodeIt).GetAttribute(
"Axis");
500 if( !CurrAttrib.
Empty() )
501 Axis = CurrAttrib.
AsInt();
503 if( Axis < 0 || Axis > 2 )
506 CurrAttrib = (*LinearAxesNodeIt).GetAttribute(
"LimitLower");
507 if( !CurrAttrib.
Empty() )
510 CurrAttrib = (*LinearAxesNodeIt).GetAttribute(
"LimitUpper");
511 if( !CurrAttrib.
Empty() )
514 CurrAttrib = (*LinearAxesNodeIt).GetAttribute(
"MotorMaxForce");
515 if( !CurrAttrib.
Empty() )
518 CurrAttrib = (*LinearAxesNodeIt).GetAttribute(
"MotorTargetVelocity");
519 if( !CurrAttrib.
Empty() )
522 CurrAttrib = (*LinearAxesNodeIt).GetAttribute(
"MotorEnabled");
523 if( !CurrAttrib.
Empty() )
530 for(
XML::NodeIterator AngularAxesNodeIt = AngularAxesNode.
begin() ; AngularAxesNodeIt != AngularAxesNode.
end() ; ++AngularAxesNodeIt )
532 if( !(*AngularAxesNodeIt).Empty() ) {
533 if( (*AngularAxesNodeIt).GetAttribute(
"Version").AsInt() == 1 ) {
536 CurrAttrib = (*AngularAxesNodeIt).GetAttribute(
"Axis");
537 if( !CurrAttrib.
Empty() )
538 Axis = CurrAttrib.
AsInt();
540 if( Axis < 0 || Axis > 5 )
545 CurrAttrib = (*AngularAxesNodeIt).GetAttribute(
"LimitLower");
546 if( !CurrAttrib.
Empty() )
549 CurrAttrib = (*AngularAxesNodeIt).GetAttribute(
"LimitUpper");
550 if( !CurrAttrib.
Empty() )
553 CurrAttrib = (*AngularAxesNodeIt).GetAttribute(
"LimitMaxForce");
554 if( !CurrAttrib.
Empty() )
557 CurrAttrib = (*AngularAxesNodeIt).GetAttribute(
"MotorTargetVelocity");
558 if( !CurrAttrib.
Empty() )
561 CurrAttrib = (*AngularAxesNodeIt).GetAttribute(
"MotorMaxForce");
562 if( !CurrAttrib.
Empty() )
565 CurrAttrib = (*AngularAxesNodeIt).GetAttribute(
"MotorDamping");
566 if( !CurrAttrib.
Empty() )
569 CurrAttrib = (*AngularAxesNodeIt).GetAttribute(
"MotorRestitution");
570 if( !CurrAttrib.
Empty() )
573 CurrAttrib = (*AngularAxesNodeIt).GetAttribute(
"MotorEnabled");
574 if( !CurrAttrib.
Empty() )
591 {
return "Generic6DofConstraint"; }
virtual Vector3 GetAngularMotorRestitution() const
Get the Restitution values for all three axis.
Translation on the Z axis.
virtual Constraint::AxisList GetValidLinearAxes() const
Get a sorted (low to high) list of all axis that operate linearly (that lock sliding/translation) ...
std::vector< int > AxisList
Used to Store lists of Int Axis for return types.
Attribute AppendAttribute(const Char8 *Name)
Creates an Attribute and puts it at the end of this Nodes attributes.
CFM values adds some small value to the main diagonal on the constraint matrix to prevent degenerate ...
A light-weight handle for manipulating attributes in DOM tree.
virtual void SetAngularLimitLower(const Vector3 &Limit)
Set the Lower limits on rotation.
virtual void SetPivotBRotation(const Quaternion &Rotation)
Sets The relative rotation of ProxB.
virtual btTypedConstraint * _GetConstraintBase() const
Get the Bullet constraint that this class encapsulates.
virtual void SetAngularMotorRestitutionOnAxis(const Real Restitution, Whole Axis)
For one Axis, set the Restitution/Bounciness/.
virtual void SetLinearLimitDamping(const Real Damping)
Set the Damping of the linear Limits.
virtual Quaternion GetPivotARotation() const
Gets the relative rotation for ProxA.
bool Boole
Generally acts a single bit, true or false.
virtual void SetAngularMotorDampingOnAxis(const Real Damping, Whole Axis)
For one Axis, set the Damping.
virtual Boole GetLinearMotorEnabledOnAxis(Whole Axis) const
Is a specific Linear motor enabled.
bool AsBool(bool def=false) const
Attempts to convert the value of the attribute to a float and returns the results.
static String GetSerializableName()
Get the name of the the XML tag the class will leave behind as its instances are serialized.
virtual Vector3 GetAngularMotorEnabled() const
Get a Vector3 with 3 zero or nonzero values that store whether or not a given rotational motor is ena...
Convenience type for loops.
virtual Vector3 GetAngularMotorMaxForce() const
Get the Max Motor Force for each Axis.
virtual void SetPivotTransforms(const Transform &TransA, const Transform &TransB)
Sets the Position and Rotation for the first and second body using a Transform.
Real X
Coordinate on the X vector.
virtual Vector3 GetPivotALocation() const
Gets the location of the pivot relative to ProxA's Center of gravity.
virtual void SetLinearMotorMaxForceOnAxis(const Real Force, Whole Axis)
For one Axis, set the Maximimum Motor Force.
Real Z
Coordinate on the Z vector.
virtual Transform GetPivotATransform() const
Gets the current Rotation and Location of ProxyA.
Convenience type for loops.
virtual Quaternion GetPivotBRotation() const
Gets the relative rotation for ProxB.
virtual void SetLinearMotorMaxForce(const Vector3 &Forces)
Set the Linear Motor Maximum force on all 3 translation axis.
virtual void SetAngularLimitMaxForceOnAxis(const Real MaxLimitForce, Whole Axis)
Set the Maximimum amount of force applied to ensure a limit on one axis is not surpassed.
virtual Vector3 GetLinearLimitLower() const
Get the Upper limits on translation.
virtual Vector3 GetAngularLimitMaxForce() const
Get the Maximimum amount of force applied to ensure limits are not surpassed.
Thrown when the requested identity could not be found.
#define MEZZ_EXCEPTION(num, desc)
An easy way to throw exceptions with rich information.
virtual void SetPivotBTransform(const Transform &TransB)
Sets the Position and Rotation for the second body using a Transform.
virtual void SetLinearMotorTargetVelocityOnAxis(const Real Velocity, Whole Axis)
For one Axis, set the target velocity of the Linear motor.
virtual Vector3 GetLinearMotorTargetVelocity() const
Get the target velocity for all Linear Axis.
virtual void SetAngularMotorDamping(const Vector3 &Dampings)
Set the Angular Motor Damping for each Angular Axis.
int Integer
A datatype used to represent any integer close to.
Boole Enabled
Whether or not the constraint is currently taking effect.
virtual void DestroyConstraint()
Destroys the internal constraint.
virtual ~Generic6DofConstraint()
Class destructor.
virtual Real GetAngularMotorDampingOnAxis(Whole Axis) const
Get the Damping for one given Axis.
Thrown when a version is accessed/parsed/required and it cannot work correctly or is missing...
virtual Vector3 GetPivotBLocation() const
Gets the location of the pivot relative to ProxB's Center of gravity.
Rotation on the Y axis, when working with only rotational Axis.
virtual void SetLimit(Whole Axis, Real Lower, Real Upper)
Change the upper and lower limit for one axis of translation or rotation limit.
virtual void SetLinearLimitRestitution(const Real Restitution)
Set the Restitution of the linear Limits.
Rotation on the X axis, when working with only rotational Axis.
virtual void EnableConstraint(const Boole Enable)
Enables or disables this constraint.
virtual Real GetLinearLimitSoftness() const
Get the Softness of the linear Limits.
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 Vector3 GetAngularLimitLower() const
Get the Upper limits on rotation.
void SetAngularLimitLowerOnAxis(const Real Limit, Whole RotationAxis)
Sets the lower rotation limit on a specific axis of the constraint.
virtual void ProtoSerializeProperties(XML::Node &SelfRoot) const
Convert the properties of this class to an XML::Node ready for serialization.
Rotation on the Z axis, when working with only rotational Axis.
virtual Transform GetPivotBTransform() const
Gets the current Rotation and Location of ProxyB.
Real GetLinearLimitLowerOnAxis(Whole TranslationAxis) const
Get a specific lower translation limit.
bool Empty() const
Is this storing anything at all?
virtual void SetAngularMotorTargetVelocityOnAxis(const Real Velocity, Whole Axis)
For one Axis, set the target velocity of the angular motor.
virtual void SetAngularLimitUpper(const Vector3 &Limit)
Set the Upper limits on rotation.
virtual void SetPivotALocation(const Vector3 &Location)
Sets The relative location of the pivot from ProxA's Center of gravity.
virtual void SetLinearLimitUpper(const Vector3 &Limit)
Set the lower limits on translation.
Boole GetUseLinearReferenceFrameA() const
Gets whether or not to perform linear math from ProxyA's perspective.
btQuaternion GetBulletQuaternion(Boole normalize=false) const
Gets a Bullet quaternion.
Real GetAngularLimitUpperOnAxis(Whole RotationAxis) const
Get a specific upper rotation limit.
virtual Vector3 GetLinearMotorEnabled() const
Get a Vector3 with 3 zero or nonzero values that store whether or not a given rotational motor is ena...
float Real
A Datatype used to represent a real floating point number.
The interface for serialization.
virtual void SetLinearLimitLower(const Vector3 &Limit)
Set the Upper limits on translation.
bool SetValue(const Char8 *rhs)
Set the value of this.
virtual void SetAngularLimitMaxForce(const Vector3 &MaxLimitForces)
Set the Maximimum amount of force applied to ensure limits are not surpassed.
virtual void SetLinearMotorEnabledOnAxis(const Boole Enabled, Whole Axis)
For one Axis, set whether or not the motor is enabled.
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 Real GetLinearLimitRestitution() const
Get the Restitution of the linear Limits.
virtual void ProtoSerializeProperties(XML::Node &SelfRoot) const
Convert the properties of this class to an XML::Node ready for serialization.
Child node iterator (a bidirectional iterator over a collection of Node)
btVector3 GetBulletVector3() const
Gets a Bullet vector3.
virtual Real GetAngularLimitMaxForceOnAxis(Whole Axis) const
Get the Maximimum amount of force applied to ensure a limit one axis is not surpassed.
A light-weight handle for manipulating nodes in DOM tree.
iterator begin() const
Get a Child node iterator that references the first child Node.
virtual Boole GetUseFrameOffset() const
Gets whether or not an offset of the constraint frame should be used to calculate internal data...
int AsInt(int def=0) const
Attempts to convert the value of the attribute to an int and returns the results. ...
uint32_t UInt32
An 32-bit unsigned integer.
virtual void SetLinearLimitSoftness(const Real Softness)
Set the Softness of the linear Limits.
virtual void SetAngularMotorRestitution(const Vector3 &Restitutions)
Set the Bounciness/Restition for rotation on all three Axis.
iterator end() const
Get a Child node iterator that references one past the last child Node.
virtual Boole HasParamBeenSet(ConstraintParam Param, int Axis) const
bool Empty() const
Is this storing anything at all?
virtual Vector3 GetAngularMotorTargetVelocity() const
Get the target velocity for all angular Axis.
btGeneric6DofConstraint * Generic6dof
The internal constraint that this class encapsulates.
Generic6DofConstraint(const UInt32 ID, RigidProxy *Prox1, PhysicsManager *Creator)
Single body inheritance constructor.
virtual btRigidBody * _GetPhysicsObject() const
Accessor for the internal rigid body physics proxy.
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.
ConstraintParam
Used by constraints for setting some parameters.
virtual Vector3 GetLinearMotorMaxForce() const
Get the Max Motor Force for each Axis.
Real GetLinearLimitUpperOnAxis(Whole TranslationAxis) const
Get a specific upper translation limit.
virtual String GetDerivedSerializableName() const
Gets the most derived serializable name of this Constraint.
virtual void SetAngularMotorEnabled(const Vector3 &Enableds)
Set whether or not the motor is enabled for all Axis Simultaneously.
virtual void SetPivotARotation(const Quaternion &Rotation)
Sets The relative rotation of ProxA.
void SetUseLinearReferenceFrameA(const Boole UseRefFrameA)
Sets whether or not to perform linear math from ProxyA's perspective.
This is a proxy from which rigid body proxys are handled.
virtual Vector3 GetAngularMotorDamping() const
Get the Damping for all Angular Axis.
std::vector< ConstraintParam > ParamList
Used to Store lists of param for return types.
virtual Real GetLinearLimitDamping() const
Get the Damping of the linear Limits.
This is simply a place for storing all the Physics Related functions.
virtual void SetPivotBLocation(const Vector3 &Location)
Sets The relative location of the pivot from ProxB's Center of gravity.
RigidProxy * ProxA
The first Collidable this constraint applies to.
virtual void SetAngularMotorMaxForce(const Vector3 &Forces)
Set the Angular Motor Maximum force on all 3 rotational axis.
Translation on the X axis.
virtual Real GetAngularMotorTargetVelocityOnAxis(Whole Axis) const
Get the Target Velocity for one axis.
virtual void SetAngularMotorTargetVelocity(const Vector3 &Velocities)
Set the Target velocity of the motor on each anuglar axis.
virtual Constraint::ParamList GetValidParamsOnAxis(int Axis) const
Get a sorted (low to high) list of Parameters that are valid on this Axis.
Convenience type for loops.
virtual Boole GetAngularMotorEnabledOnAxis(Whole Axis) const
Is a specific rotational motor enabled.
This is used to represent a point in space, or a vector through space.
virtual void SetLinearMotorEnabled(const Vector3 &Enableds)
Set whether or not the motor is enabled for all Linear Axis Simultaneously.
virtual void ProtoDeSerialize(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite this object with it.
virtual void SetAngularMotorMaxForceOnAxis(const Real Force, Whole Axis)
For one Axis, set the Maximimum Motor Force.
void SetAngularLimitUpperOnAxis(const Real Limit, Whole RotationAxis)
Sets the upper rotation limit on a specific axis of the constraint.
RigidProxy * ProxB
The second Collidable this constraint applies to.
virtual Whole ConvertAngularTo6Axis(const Whole Axis) const
Convert an angular Axis from a 3 digit range to a full 6 digit range.
virtual Real GetAngularMotorMaxForceOnAxis(Whole Axis) const
Get the Max motor Force on a certain Axis.
The bulk of the engine components go in this namspace.
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Real GetAngularLimitLowerOnAxis(Whole RotationAxis) const
Get a specific lower rotation limit.
virtual Vector3 GetAngularLimitUpper() const
Get the Power limits on rotation.
virtual void CreateConstraint(RigidProxy *RigidA, RigidProxy *RigidB, const Transform &TransA, const Transform &TransB)
Creates the internal constraint.
This is used to store information about rotation in 3d space.
void SetLinearLimitLowerOnAxis(const Real Limit, Whole TranslationAxis)
Sets the lower linear limit on a specific axis of the constraint.
virtual Real GetLinearMotorMaxForceOnAxis(Whole Axis) const
Get the Max motor Force on a certain Axis.
Translation on the Y axis.
void SerializeError(const String &FailedTo, const String &ClassName, Boole SOrD)
Simply does some string concatenation, then throws an Exception.
Node AppendChild(NodeType Type=NodeElement)
Creates a Node and makes it a child of this one.
virtual void SetPivotATransform(const Transform &TransA)
Sets the Position and Rotation for the first body using a Transform.
virtual void SetUseFrameOffset(const Boole FrameOffset)
Sets whether or not an offset of the constraint frame should be used to calculate internal data...
std::string String
A datatype used to a series of characters.
virtual Whole ConvertFrom6AxisTo3Axis(const Whole Axis) const
Convert an Axis from a full 6 digit range to a 3 digit range.
virtual Real GetLinearMotorTargetVelocityOnAxis(Whole Axis) const
Get the Target Velocity for one axis.
virtual void SetAngularMotorEnabledOnAxis(const Boole Enabled, Whole Axis)
For one Axis, set whether or not the motor is enabled.
virtual Constraint::AxisList GetValidAngularAxes() const
Get A list sorted (low to high) of all axis that operate Angularly (that lock sliding/translation) ...
Attribute GetAttribute(const Char8 *Name) const
Attempt to get an Attribute on this Node with a given name.
virtual Real GetAngularMotorRestitutionOnAxis(Whole Axis) const
Get the Restitution/Bounciness for a single Axis.
virtual Vector3 GetLinearLimitUpper() const
Get the lower limits on translation.
virtual void SetLinearMotorTargetVelocity(const Vector3 &Velocities)
Set the Target velocity of the motor on each anuglar axis.
Convenience type for loops.
Node GetChild(const Char8 *Name) const
Attempt to get a child Node with a given name.
void SetLinearLimitUpperOnAxis(const Real Limit, Whole TranslationAxis)
Sets the upper linear limit on a specific axis of the constraint.