40 #ifndef _physicshingeconstraint_cpp
41 #define _physicshingeconstraint_cpp
43 #include "Physics/hingeconstraint.h"
44 #include "Physics/rigidproxy.h"
46 #include "stringtool.h"
49 #include <btBulletDynamicsCommon.h>
88 if( this->
Hinge == NULL ) {
89 if( RigidA && RigidB ) {
99 if( this->
Hinge == NULL ) {
100 if( RigidA && RigidB ) {
111 if( this->
Hinge != NULL ) {
144 {
return Vector3(this->
Hinge->getAFrame().getOrigin()); }
147 {
return Vector3(this->
Hinge->getBFrame().getOrigin()); }
168 {
return this->
Hinge->getHingeAngle(); }
171 { this->
Hinge->setUseFrameOffset(FrameOffset); }
174 {
return this->
Hinge->getUseFrameOffset(); }
177 { this->
Hinge->setUseReferenceFrameA(UseReferenceFrameA); }
180 {
return this->
Hinge->getUseReferenceFrameA(); }
186 { this->
Hinge->setLimit(Low, High, Softness, BiasFactor, RelaxationFactor); }
189 {
return this->
Hinge->getLowerLimit(); }
192 {
return this->
Hinge->getUpperLimit(); }
195 {
return this->
Hinge->getLimitSoftness(); }
198 {
return this->
Hinge->getLimitBiasFactor(); }
201 {
return this->
Hinge->getLimitRelaxationFactor(); }
207 { this->
Hinge->enableAngularMotor(EnableMotor, TargetVelocity, MaxMotorImpulse); }
210 { this->
Hinge->enableMotor(EnableMotor); }
213 {
return this->
Hinge->getEnableAngularMotor(); }
216 { this->
Hinge->setMaxMotorImpulse(MaxMotorImpulse); }
219 {
return this->
Hinge->getMaxMotorImpulse(); }
222 { this->
Hinge->setMotorTargetVelocity(TargetVelocity); }
225 {
return this->
Hinge->getMotorTargetVelosity(); }
231 { this->
Hinge->setMotorTarget(TargetAngle,Delta); }
239 if( -1 == Axis || 5 == Axis ) {
240 Results.push_back(Con_Stop_ERP);
242 Results.push_back(Con_Stop_CFM);
250 Results.push_back(-1);
257 Results.push_back(5);
264 if ( -1!=Axis && 5!=Axis )
266 return ( Con_Stop_ERP==Param && this->
Hinge->getFlags() & BT_HINGE_FLAGS_ERP_STOP ) ||
267 ( Con_Stop_CFM==Param && this->
Hinge->getFlags() & BT_HINGE_FLAGS_CFM_STOP ) ||
268 (
Con_CFM==Param && this->
Hinge->getFlags() & BT_HINGE_FLAGS_CFM_NORM ) ;
305 if( !PropertiesNode.
Empty() ) {
308 Real LimitHigh = 0.0;
309 Real LimitSoftness = 0.9;
310 Real LimitBiasFactor = 0.3;
311 Real LimitRelaxationFactor = 1.0;
313 CurrAttrib = PropertiesNode.
GetAttribute(
"UseFrameOffset");
314 if( !CurrAttrib.
Empty() )
317 CurrAttrib = PropertiesNode.
GetAttribute(
"UseReferenceFrameA");
318 if( !CurrAttrib.
Empty() )
322 if( !CurrAttrib.
Empty() )
323 LimitLow = CurrAttrib.
AsReal();
326 if( !CurrAttrib.
Empty() )
327 LimitHigh = CurrAttrib.
AsReal();
329 CurrAttrib = PropertiesNode.
GetAttribute(
"LimitSoftness");
330 if( !CurrAttrib.
Empty() )
331 LimitSoftness = CurrAttrib.
AsReal();
333 CurrAttrib = PropertiesNode.
GetAttribute(
"LimitBiasFactor");
334 if( !CurrAttrib.
Empty() )
335 LimitBiasFactor = CurrAttrib.
AsReal();
337 CurrAttrib = PropertiesNode.
GetAttribute(
"LimitRelaxationFactor");
338 if( !CurrAttrib.
Empty() )
339 LimitRelaxationFactor = CurrAttrib.
AsReal();
341 this->
SetLimits(LimitLow,LimitHigh,LimitSoftness,LimitBiasFactor,LimitRelaxationFactor);
343 CurrAttrib = PropertiesNode.
GetAttribute(
"MotorEnabled");
344 if( !CurrAttrib.
Empty() )
347 CurrAttrib = PropertiesNode.
GetAttribute(
"MaxMotorImpulse");
348 if( !CurrAttrib.
Empty() )
351 CurrAttrib = PropertiesNode.
GetAttribute(
"MotorTargetVelocity");
352 if( !CurrAttrib.
Empty() )
366 {
return "HingeConstraint"; }
372 {
return this->
Hinge; }
virtual Constraint::AxisList GetValidAngularAxes() const
Get A list sorted (low to high) of all axis that operate Angularly (that lock sliding/translation) ...
std::ostream & operator<<(std::ostream &stream, const Mezzanine::LinearInterpolator< T > &Lint)
Used to Serialize an Mezzanine::LinearInterpolator to a human readable stream.
virtual void ProtoSerializeProperties(XML::Node &SelfRoot) const
Convert the properties of this class to an XML::Node ready for serialization.
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 void SetAPivotRotation(const Quaternion &Rotation)
A light-weight handle for manipulating attributes in DOM tree.
virtual Real GetLimitLow() const
Return the Lower Limit of the hinge.
bool Boole
Generally acts a single bit, true or false.
virtual Vector3 GetPivotBLocation() const
Gets the location of the pivot relative to ProxB's Center of gravity.
bool AsBool(bool def=false) const
Attempts to convert the value of the attribute to a float and returns the results.
virtual Real GetLimitRelaxationFactor() const
Return the Relaxation Factor of the hinge.
virtual Real GetLimitHigh() const
Return the Upper Limit of the hinge.
virtual Boole GetUseFrameOffset() const
Gets whether or not an offset of the constraint frame should be used to calculate internal data...
virtual void SetMaxMotorImpulse(const Real MaxMotorImpulse)
Sets the maximum amount of force the motor is to apply.
virtual Real GetLimitSoftness() const
Return the Softness of the hinge.
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...
virtual void SetPivotBTransform(const Transform &TransB)
Thrown when a version is accessed/parsed/required and it cannot work correctly or is missing...
virtual btTypedConstraint * _GetConstraintBase() const
Get the Bullet constraint that this class encapsulates.
virtual Boole GetUseReferenceFrameA() const
Gets whether or not to perform linear math from ProxyA's perspective.
virtual Constraint::AxisList GetValidLinearAxes() const
Get a sorted (low to high) list of all axis that operate linearly (that lock sliding/translation) ...
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 void SetUseFrameOffset(const Boole FrameOffset)
Sets whether or not an offset of the constraint frame should be used to calculate internal data...
btQuaternion GetBulletQuaternion(Boole normalize=false) const
Gets a Bullet quaternion.
virtual Real GetMotorTargetVelocity() const
Get the Target Velocity.
virtual Boole GetMotorEnabled() const
Is this motor on this hinge enabled?
float Real
A Datatype used to represent a real floating point number.
The interface for serialization.
virtual void SetUseReferenceFrameA(const Boole UseRefFrameA)
Sets whether or not to perform linear math from ProxyA's perspective.
bool SetValue(const Char8 *rhs)
Set the value of this.
HingeConstraint(const UInt32 ID, RigidProxy *ProxyA, RigidProxy *ProxyB, const Vector3 &PivotInA, const Vector3 &PivotInB, const Vector3 &AxisInA, const Vector3 &AxisInB, PhysicsManager *Creator)
Convenience axis constructor.
virtual void ProtoDeSerializeProperties(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite the properties of this object with it...
btVector3 GetBulletVector3() const
Gets a Bullet vector3.
A light-weight handle for manipulating nodes in DOM tree.
virtual void SetPivotATransform(const Transform &TransA)
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 String GetDerivedSerializableName() const
Gets the most derived serializable name of this Constraint.
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. ...
ConstraintParam
Used by constraints for setting some parameters.
virtual Transform GetPivotBTransform() const
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 void SetMotorTargetVelocity(const Real TargetVelocity)
Desired angular velocity of the motor.
virtual Boole HasParamBeenSet(ConstraintParam Param, int Axis) const
virtual void SetMotorTarget(const Quaternion &QuatAInB, const Real Delta)
Sets a Target Velocity, indirectly using the angle stored in a quaternion.
std::istream & DeSerialize(std::istream &Stream, T &Converted)
Deserialize the next xml tag in the stream into a specific in memory class instance.
virtual void EnableMotor(const Boole EnableMotor, const Real TargetVelocity, const Real MaxMotorImpulse)
Enables(or Disables) the motor on the hinge and sets it's parameters.
virtual Vector3 GetPivotALocation() const
Gets the location of the pivot relative to ProxA's Center of gravity.
This is a proxy from which rigid body proxys are handled.
virtual void SetPivotALocation(const Vector3 &Location)
Sets The relative location of the pivot from ProxA's Center of gravity.
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 void SetPivotBLocation(const Vector3 &Location)
Sets The relative location of the pivot from ProxB's Center of gravity.
This is a constraint to be used to restrict the movement between two objects to angular rotation on a...
static String GetSerializableName()
Get the name of the the XML tag the class will leave behind as its instances are serialized.
virtual void CreateConstraint(RigidProxy *RigidA, RigidProxy *RigidB, const Transform &TransA, const Transform &TransB)
Creates the internal constraint.
This is used to represent a point in space, or a vector through space.
virtual void ProtoDeSerialize(const XML::Node &SelfRoot)
Take the data stored in an XML Node and overwrite this object with it.
virtual void DestroyConstraint()
Destroys the internal constraint.
RigidProxy * ProxB
The second Collidable this constraint applies to.
virtual Constraint::ParamList GetValidParamsOnAxis(int Axis) const
Get a sorted (low to high) list of Parameters that are valid on this Axis.
The bulk of the engine components go in this namspace.
std::istream & operator>>(std::istream &stream, Mezzanine::LinearInterpolator< T > &Lint)
Used to de-serialize an Mezzanine::LinearInterpolator from a stream.
virtual void SetMotorEnabled(const Boole EnableMotor)
Enables(or Disables) the motor on the hinge.
virtual Real GetHingeAngle()
Gets the current angle of the hinge.
virtual Real GetMaxMotorImpulse() const
Retrieve the maximimum value that the acceleration of the motor can be increased. ...
virtual void SetAxis(const Vector3 &AxisInA)
Sets the axis on which this constraint acts.
virtual Quaternion GetBPivotRotation() const
virtual Transform GetPivotATransform() const
This is used to store information about rotation in 3d space.
virtual Real GetLimitBiasFactor() const
Return the bias factor of the hinge (Not entirely certain hat this on is)
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.
std::string String
A datatype used to a series of characters.
virtual void SetLimits(const Real Low, const Real High, const Real Softness=0.9, const Real BiasFactor=0.3, const Real RelaxationFactor=1.0)
Sets the angle limits of the constraint in radians.
Attribute GetAttribute(const Char8 *Name) const
Attempt to get an Attribute on this Node with a given name.
virtual void SetPivotTransforms(const Transform &TransA, const Transform &TransB)
Sets the Position and Rotation for the first and second body using a Transform.
virtual ~HingeConstraint()
Class destructor.
btHingeConstraint * Hinge
Bullet constraint that this class encapsulates.
Node GetChild(const Char8 *Name) const
Attempt to get a child Node with a given name.
virtual Quaternion GetAPivotRotation() const
virtual void SetBPivotRotation(const Quaternion &Rotation)