40 #ifndef _physicsconetwistconstraint_cpp
41 #define _physicsconetwistconstraint_cpp
43 #include "Physics/conetwistconstraint.h"
44 #include "Physics/rigidproxy.h"
46 #include "stringtool.h"
49 #include <btBulletDynamicsCommon.h>
79 if( RigidA && RigidB ) {
102 {
return this->
ConeTwist->isPastSwingLimit(); }
105 {
return this->
ConeTwist->getTwistAngle(); }
109 btTransform BTrans = this->
ConeTwist->getBFrame();
115 btTransform ATrans = this->
ConeTwist->getAFrame();
129 { this->
ConeTwist->enableMotor(Enable); }
132 {
return this->
ConeTwist->isMotorEnabled(); }
134 void ConeTwistConstraint::SetAngularOnly(
const Boole AngularOnly)
135 { this->
ConeTwist->setAngularOnly(AngularOnly); }
137 Boole ConeTwistConstraint::GetAngularOnly()
const
138 {
return this->
ConeTwist->getAngularOnly(); }
141 { this->
ConeTwist->setLimit(LimitIndex, LimitValue); }
144 { this->
ConeTwist->setLimit(SwingSpan1, SwingSpan2, TwistSpan, Softness, BiasFactor, RelaxationFactor); }
147 {
return this->
ConeTwist->getLimit(LimitIndex); }
150 {
return this->
ConeTwist->getSwingSpan1(); }
153 {
return this->
ConeTwist->getSwingSpan2(); }
156 {
return this->
ConeTwist->getTwistAngle(); }
159 {
return this->
ConeTwist->getLimitSoftness(); }
162 {
return this->
ConeTwist->getBiasFactor(); }
165 {
return this->
ConeTwist->getRelaxationFactor(); }
167 void ConeTwistConstraint::SetDamping(
const Real Damping)
168 { this->
ConeTwist->setDamping(Damping); }
170 Real ConeTwistConstraint::GetDamping()
const
171 {
return this->
ConeTwist->getDamping(); }
173 void ConeTwistConstraint::SetMaxMotorImpulse(
const Real MaxMotorImpulse)
174 { this->
ConeTwist->setMaxMotorImpulse(MaxMotorImpulse); }
176 void ConeTwistConstraint::SetMaxMotorImpulseNormalized(
const Real MaxMotorImpulse)
177 { this->
ConeTwist->setMaxMotorImpulseNormalized(MaxMotorImpulse); }
179 Boole ConeTwistConstraint::IsMaxMotorImpulseNormalized()
const
180 {
return this->
ConeTwist->isMaxMotorImpulseNormalized(); }
182 Real ConeTwistConstraint::GetMaxMotorImpulse()
const
183 {
return this->
ConeTwist->getMaxMotorImpulse(); }
185 void ConeTwistConstraint::SetFixThresh(
const Real FixThresh)
186 { this->
ConeTwist->setFixThresh(FixThresh); }
188 Real ConeTwistConstraint::GetFixThresh()
const
189 {
return this->
ConeTwist->getFixThresh(); }
191 void ConeTwistConstraint::SetMotorTarget(
const Quaternion& Quat)
192 { this->
ConeTwist->setMotorTarget( Quat.GetBulletQuaternion() ); }
194 void ConeTwistConstraint::SetMotorTargetInConstraintSpace(
const Quaternion& Quat)
195 { this->
ConeTwist->setMotorTargetInConstraintSpace( Quat.GetBulletQuaternion() ); }
207 if( Axis >= 0 && Axis < 6 ) {
209 Results.push_back(Con_Stop_ERP);
211 Results.push_back(Con_Stop_CFM);
219 Results.push_back(0);
220 Results.push_back(1);
221 Results.push_back(2);
228 Results.push_back(3);
229 Results.push_back(4);
230 Results.push_back(5);
237 if( Axis >= 0 && Axis < 3 ) {
238 return ( this->
ConeTwist->getFlags() & BT_CONETWIST_FLAGS_LIN_ERP );
239 }
else if( Axis >= 3 && Axis < 6 ) {
244 if( Axis >= 0 && Axis < 3 ) {
245 return ( this->
ConeTwist->getFlags() & BT_CONETWIST_FLAGS_LIN_CFM );
246 }
else if( Axis >= 3 && Axis < 6 ) {
247 return ( this->
ConeTwist->getFlags() & BT_CONETWIST_FLAGS_ANG_CFM );
291 if( !PropertiesNode.
Empty() ) {
293 Real ConeSwingSpan1 = 0.0;
294 Real ConeSwingSpan2 = 0.0;
295 Real ConeTwistSpan = 0.0;
296 Real ConeLimitSoftness = 1.0;
297 Real ConeBiasFactor = 0.3;
298 Real ConeRelaxationFactor = 1.0;
300 CurrAttrib = PropertiesNode.
GetAttribute(
"MotorEnabled");
301 if( !CurrAttrib.
Empty() )
304 CurrAttrib = PropertiesNode.
GetAttribute(
"AngularOnly");
305 if( !CurrAttrib.
Empty() )
306 this->SetAngularOnly( CurrAttrib.
AsBool() );
309 if( !CurrAttrib.
Empty() )
310 this->SetDamping( CurrAttrib.
AsReal() );
312 CurrAttrib = PropertiesNode.
GetAttribute(
"MaxMotorImpulse");
313 if( !CurrAttrib.
Empty() )
314 this->SetMaxMotorImpulse( CurrAttrib.
AsReal() );
316 CurrAttrib = PropertiesNode.
GetAttribute(
"FixThreshold");
317 if( !CurrAttrib.
Empty() )
318 this->SetFixThresh( CurrAttrib.
AsReal() );
321 if( !CurrAttrib.
Empty() )
322 ConeSwingSpan1 = CurrAttrib.
AsReal();
325 if( !CurrAttrib.
Empty() )
326 ConeSwingSpan2 = CurrAttrib.
AsReal();
329 if( !CurrAttrib.
Empty() )
330 ConeTwistSpan = CurrAttrib.
AsReal();
332 CurrAttrib = PropertiesNode.
GetAttribute(
"LimitSoftness");
333 if( !CurrAttrib.
Empty() )
334 ConeLimitSoftness = CurrAttrib.
AsReal();
337 if( !CurrAttrib.
Empty() )
338 ConeBiasFactor = CurrAttrib.
AsReal();
340 CurrAttrib = PropertiesNode.
GetAttribute(
"RelaxationFactor");
341 if( !CurrAttrib.
Empty() )
342 ConeRelaxationFactor = CurrAttrib.
AsReal();
344 this->
SetLimits(ConeSwingSpan1,ConeSwingSpan2,ConeTwistSpan,ConeLimitSoftness,ConeBiasFactor,ConeRelaxationFactor);
347 if( !MotorTargetNode.
Empty() ) {
349 this->SetMotorTarget(MotorTarget);
363 {
return "ConeTwistConstraint"; }
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 ...
virtual ~ConeTwistConstraint()
Class destructor.
A light-weight handle for manipulating attributes in DOM tree.
virtual Real GetTwistSpan() const
Gets the currently set value for the constraint Twist span on the X axis.
virtual void ProtoDeSerializeProperties(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite the properties of this object with it...
bool Boole
Generally acts a single bit, true or false.
ConeTwistConstraint(const UInt32 ID, RigidProxy *ProxyA, RigidProxy *ProxyB, const Transform &TransA, const Transform &TransB, PhysicsManager *Creator)
Class constructor.
bool AsBool(bool def=false) const
Attempts to convert the value of the attribute to a float and returns the results.
virtual AxisList GetValidAngularAxes() const
Get A list sorted (low to high) of all axis that operate Angularly (that lock sliding/translation) ...
virtual Boole IsMotorEnabled() const
Gets whether or not the motor is enabled.
virtual Real GetSwingSpan2() const
Gets the currently set value for the constraint Swing span on the Z axis.
virtual Real GetBiasFactor() const
Gets the strength of the force enforcing the twist limits.
Thrown when the requested identity could not be found.
virtual Real GetLimit(const Integer LimitIndex) const
Gets a constraint limit based on Index.
static String GetSerializableName()
Get the name of the the XML tag the class will leave behind as its instances are serialized.
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.
int Integer
A datatype used to represent any integer close to.
virtual void ProtoSerializeProperties(XML::Node &SelfRoot) const
Convert the properties of this class to an XML::Node ready for serialization.
Thrown when a version is accessed/parsed/required and it cannot work correctly or is missing...
virtual void SetLimits(const Real SwingSpan1, const Real SwingSpan2, const Real TwistSpan, const Real Softness=1.0, const Real BiasFactor=0.3, const Real RelaxationFactor=1.0)
Sets all constraint limits.
virtual void EnableConstraint(const Boole Enable)
Enables or disables this constraint.
virtual void ProtoSerializeProperties(XML::Node &SelfRoot) const
Convert the properties of this class to an XML::Node ready for serialization.
bool Empty() const
Is this storing anything at all?
virtual ParamList GetValidParamsOnAxis(int Axis) const
Get a sorted (low to high) list of Parameters that are valid on this Axis.
float Real
A Datatype used to represent a real floating point number.
The interface for serialization.
bool SetValue(const Char8 *rhs)
Set the value of this.
virtual btTypedConstraint * _GetConstraintBase() const
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...
btConeTwistConstraint * ConeTwist
The internal constraint that this class encapsulates.
virtual Real GetRelaxationFactor() const
Gets the strength of the force enforcing the swing limits.
virtual Transform GetPivotBTransform() const
Gets the current Rotation and Location of ProxyB.
A light-weight handle for manipulating nodes in DOM tree.
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.
bool Empty() const
Is this storing anything at all?
virtual void SetPivotBTransform(const Transform &TransB)
Sets the Position and Rotation for the second body using a Transform.
virtual void EnableMotor(const Boole Enable)
Enables (or disables) the motor of this constraint.
virtual btRigidBody * _GetPhysicsObject() const
Accessor for the internal rigid body physics proxy.
virtual Boole HasParamBeenSet(ConstraintParam Param, int Axis) const
Has the given Param on the Given Axis been set yet.
Real AsReal(Real def=0) const
Attempts to convert the value of the attribute to a Real and returns the results. ...
ConstraintParam
Used by constraints for setting some parameters.
virtual void DestroyConstraint()
Destroys the internal constraint.
virtual void SetLimit(const Integer LimitIndex, const Real LimitValue)
Sets a constraint limit based on Index.
This is a proxy from which rigid body proxys are handled.
std::vector< ConstraintParam > ParamList
Used to Store lists of param for return types.
This is simply a place for storing all the Physics Related functions.
RigidProxy * ProxA
The first Collidable this constraint applies to.
virtual Quaternion GetMotorTarget() const
virtual AxisList GetValidLinearAxes() const
Get a sorted (low to high) list of all axis that operate linearly (that lock sliding/translation) ...
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.
virtual String GetDerivedSerializableName() const
Gets the most derived serializable name of this Constraint.
The bulk of the engine components go in this namspace.
virtual Transform GetPivotATransform() const
Gets the current Rotation and Location of ProxyA.
void ProtoSerialize(XML::Node &CurrentRoot) const
Convert this class to an XML::Node ready for serialization.
Real GetTwistAngle() const
Gets the current angle of thw twist applied to the constraint.
This is used to store information about rotation in 3d space.
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.
Node AppendChild(NodeType Type=NodeElement)
Creates a Node and makes it a child of this one.
virtual Real GetSwingSpan1() const
Gets the currently set value for the constraint Swing span on the Y axis.
virtual void SetPivotATransform(const Transform &TransA)
Sets the Position and Rotation for the first body using a Transform.
std::string String
A datatype used to a series of characters.
Attribute GetAttribute(const Char8 *Name) const
Attempt to get an Attribute on this Node with a given name.
virtual Real GetLimitSoftness() const
Gets the % portion of the swing limit in which to start enforcing the limit.
virtual void CreateConstraint(RigidProxy *RigidA, RigidProxy *RigidB, const Transform &TransA, const Transform &TransB)
Creates the internal constraint.
Node GetChild(const Char8 *Name) const
Attempt to get a child Node with a given name.
Boole IsPassedSwingLimit() const
Gets whether or not the child object is outside the set limits for the constraint.