8 #include "VsMovableItem.h"
11 #include "VsMotorizedJoint.h"
12 #include "VsRigidBody.h"
14 #include "VsHingeLimit.h"
17 #include "VsSimulator.h"
18 #include "VsOsgUserData.h"
19 #include "VsOsgUserDataVisitor.h"
20 #include "VsDragger.h"
72 {
Std_TraceMsg(0,
"Caught Error in desctructor of VsHinge\r\n",
"", -1,
false,
true);}
77 Hinge::EnableLimits(bVal);
96 void VsHinge::SetAlpha()
109 void VsHinge::DeleteJointGraphics()
118 if(lpUpperLimit && lpUpperLimit->FlapTranslateMT())
m_osgJointMT->removeChild(lpUpperLimit->FlapTranslateMT());
119 if(lpLowerLimit && lpLowerLimit->FlapTranslateMT())
m_osgJointMT->removeChild(lpLowerLimit->FlapTranslateMT());
120 if(lpPosFlap && lpPosFlap->FlapTranslateMT())
m_osgJointMT->removeChild(lpPosFlap->FlapTranslateMT());
147 CStdFPoint vPos(0, 0, 0), vRot(VX_PI/2, 0, 0);
160 m_osgCylinderMat->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(0.1, 0.1, 0.1, 1));
161 m_osgCylinderMat->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(1, 0.25, 1, 1));
162 m_osgCylinderMat->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(0.25, 0.25, 0.25, 1));
164 m_osgCylinderSS->setMode(GL_BLEND, osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON);
178 lpPosFlap->
LimitPos(Hinge::JointPosition());
185 m_osgJointMT->addChild(lpUpperLimit->FlapTranslateMT());
186 m_osgJointMT->addChild(lpLowerLimit->FlapTranslateMT());
193 m_osgParent = ParentOSG();
195 if(m_osgParent.valid())
198 CStdFPoint vPos(0, 0, 0), vRot(VX_PI/2, 0, 0);
199 vPos.Set(0, 0, 0); vRot.Set(0, VX_PI/2, 0);
212 SetVisible(m_lpThisMI->IsVisible());
215 m_osgParent->addChild(m_osgRoot.get());
218 Physics_UpdateAbsolutePosition();
223 osgVisitor->traverse(*m_osgMT);
227 void VsHinge::DeletePhysics()
232 if(GetVsSimulator() && GetVsSimulator()->Universe())
234 GetVsSimulator()->Universe()->removeConstraint(
m_vxHinge);
245 void VsHinge::SetupPhysics()
251 THROW_ERROR(Al_Err_lParentNotDefined, Al_Err_strParentNotDefined);
254 THROW_ERROR(Al_Err_lChildNotDefined, Al_Err_strChildNotDefined);
258 THROW_ERROR(Vs_Err_lUnableToConvertToVsRigidBody, Vs_Err_strUnableToConvertToVsRigidBody);
262 THROW_ERROR(Vs_Err_lUnableToConvertToVsRigidBody, Vs_Err_strUnableToConvertToVsRigidBody);
264 CStdFPoint vGlobal = this->GetOSGWorldCoords();
267 VxOSG::copyOsgMatrix_to_VxReal44(this->GetOSGWorldMatrix(), vMT);
268 Vx::VxTransform vTrans(vMT);
270 vTrans.getRotationEulerAngles(vxRot);
272 CStdFPoint vLocalRot(vxRot[0], vxRot[1], vxRot[2]);
274 VxVector3 pos((
double) vGlobal.x, (
double) vGlobal.y, (
double) vGlobal.z);
275 VxVector3 axis = NormalizeAxis(vLocalRot);
277 m_vxHinge =
new VxHinge(lpVsParent->Part(), lpVsChild->Part(), pos.v, axis.v);
280 GetVsSimulator()->Universe()->addConstraint(
m_vxHinge);
295 m_iCoordID =
m_vxHinge->kAngularCoordinate;
301 VsJoint::Initialize();
310 #pragma region DataAccesMethods
312 float *VsHinge::GetDataPointer(
const std::string &strDataType)
317 if(strType ==
"JOINTROTATION")
319 else if(strType ==
"JOINTPOSITION")
321 else if(strType ==
"JOINTACTUALVELOCITY")
323 else if(strType ==
"JOINTFORCE")
325 else if(strType ==
"JOINTROTATIONDEG")
327 else if(strType ==
"JOINTDESIREDPOSITIONDEG")
329 else if(strType ==
"JOINTDESIREDVELOCITY")
331 else if(strType ==
"JOINTSETVELOCITY")
333 else if(strType ==
"JOINTDESIREDPOSITION")
335 else if(strType ==
"JOINTSETPOSITION")
337 else if(strType ==
"ENABLE")
339 else if(strType ==
"MOTORFORCETOAX")
341 else if(strType ==
"MOTORFORCETOAY")
343 else if(strType ==
"MOTORFORCETOAZ")
345 else if(strType ==
"MOTORFORCETOBX")
347 else if(strType ==
"MOTORFORCETOBY")
349 else if(strType ==
"MOTORFORCETOBZ")
351 else if(strType ==
"MOTORTORQUETOAX")
353 else if(strType ==
"MOTORTORQUETOAY")
355 else if(strType ==
"MOTORTORQUETOAZ")
357 else if(strType ==
"MOTORTORQUETOBX")
359 else if(strType ==
"MOTORTORQUETOBY")
361 else if(strType ==
"MOTORTORQUETOBZ")
363 else if(strType ==
"CONTACTCOUNT")
364 THROW_PARAM_ERROR(Al_Err_lMustBeContactBodyToGetCount, Al_Err_strMustBeContactBodyToGetCount,
"JointID",
m_strName);
367 lpData = Hinge::GetDataPointer(strDataType);
368 if(lpData)
return lpData;
370 THROW_TEXT_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType,
"JointID: " + STR(
m_strName) +
" DataType: " + strDataType);
376 bool VsHinge::SetData(
const std::string &strDataType,
const std::string &strValue,
bool bThrowError)
378 if(VsJoint::Physics_SetData(strDataType, strValue))
381 if(Hinge::SetData(strDataType, strValue,
false))
386 THROW_PARAM_ERROR(Al_Err_lInvalidDataType, Al_Err_strInvalidDataType,
"Data Type", strDataType);
391 void VsHinge::QueryProperties(CStdPtrArray<TypeProperty> &aryProperties)
393 VsJoint::Physics_QueryProperties(aryProperties);
394 Hinge::QueryProperties(aryProperties);
396 aryProperties.Add(
new TypeProperty(
"JointRotation", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
397 aryProperties.Add(
new TypeProperty(
"JointPosition", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
398 aryProperties.Add(
new TypeProperty(
"JointActualVelocity", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
399 aryProperties.Add(
new TypeProperty(
"JointForce", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
400 aryProperties.Add(
new TypeProperty(
"JointRotationDeg", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
401 aryProperties.Add(
new TypeProperty(
"JointDesiredVelocity", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
402 aryProperties.Add(
new TypeProperty(
"JointSetVelocity", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
403 aryProperties.Add(
new TypeProperty(
"JointDesiredPosition", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
404 aryProperties.Add(
new TypeProperty(
"JointDesiredPositionDeg", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
405 aryProperties.Add(
new TypeProperty(
"JointSetPosition", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
406 aryProperties.Add(
new TypeProperty(
"Enable", AnimatPropertyType::Boolean, AnimatPropertyDirection::Get));
407 aryProperties.Add(
new TypeProperty(
"MotorForceToAX", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
408 aryProperties.Add(
new TypeProperty(
"MotorForceToAY", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
409 aryProperties.Add(
new TypeProperty(
"MotorForceToAZ", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
410 aryProperties.Add(
new TypeProperty(
"MotorForceToBX", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
411 aryProperties.Add(
new TypeProperty(
"MotorForceToBY", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
412 aryProperties.Add(
new TypeProperty(
"MotorForceToBZ", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
413 aryProperties.Add(
new TypeProperty(
"MotorTorqueToAX", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
414 aryProperties.Add(
new TypeProperty(
"MotorTorqueToAY", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
415 aryProperties.Add(
new TypeProperty(
"MotorTorqueToAZ", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
416 aryProperties.Add(
new TypeProperty(
"MotorTorqueToBX", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
417 aryProperties.Add(
new TypeProperty(
"MotorTorqueToBY", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
418 aryProperties.Add(
new TypeProperty(
"MotorTorqueToBZ", AnimatPropertyType::Float, AnimatPropertyDirection::Get));
float CylinderHeight()
Gets the height of the cylinder used to display the hinge in the environment.
virtual void DisableCollision(RigidBody *lpBody)
Disables collision between the past-in object and this object.
virtual void EnableCollision(RigidBody *lpBody)
Enables collision between the past-in object and this object.
virtual float LimitPos()
Gets the limit position.
virtual void SetupGraphics()
Sets up the graphics for the joint.
virtual void CreateJoint()
Creates the joint.
float m_fltNullReport
This is used to report back 0 from GetDataPointer for items that are not supported in vortex...
A common class for all rigid body data specific to vortex.
virtual void Alpha(float fltA)=0
Sets the alpha color value for this constraint.
osg::ref_ptr< osg::MatrixTransform > m_osgCylinderMT
The osg cylinder matrix transform.
float m_fltEnabled
This is used for reporting the enabled state in a GetDataPointer call.
osg::ref_ptr< osg::Material > m_osgCylinderMat
The osg cylinder material.
ConstraintLimit * m_lpUpperLimit
Upper limit constring pointer.
virtual void CreateJointGraphics()
Creates the default ball graphics.
virtual void IsShowPosition(bool bVal)
Sets whether this contstraint is actually just being used to show the current position of the joint...
osg::Geometry * CreateConeGeometry(float height, float topradius, float botradius, int sides, bool doSide, bool doTop, bool doBottom)
virtual void StepSimulation()
Step the simulation for this object.
virtual ~VsHinge()
Destructor.
std::string m_strID
The unique Id for this object.
float m_fltRotationDeg
The rotation of the hinge in degrees.
float CylinderRadius()
Gets the radius cylinder of the cylinder used to display the hinge in the environment.
float m_fltDesiredPositionDeg
The desired rotation of the hinge in degrees.
virtual void SetupGraphics()
Sets up the graphics for the constraint.
osg::ref_ptr< osg::Geode > m_osgCylinderGeode
The osg cylinder geode.
virtual bool EnableMotor()
Tells if the motor is enabled.
VsHinge()
Default constructor.
RigidBody * m_lpChild
The child rigid body for this joint.
bool m_bEnableLimits
If true then any ConstraintLimits for this joint are enabled.
Vx::VxHinge * m_vxHinge
The vortex hinge class.
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
ConstraintLimit * m_lpLowerLimit
Lower limit constring pointer.
Declares the vortex hinge class.
virtual void CreateCylinderGraphics()
Creates the cylinder graphics.
void Std_TraceMsg(const int iLevel, std::string strMessage, std::string strSourceFile, int iSourceLine, bool bLogToFile, bool bPrintHeader)
Traces a message to the debugger window.
float m_fltForce
The current force being applied to the joint by the motor.
osg::ref_ptr< osg::Geometry > m_osgCylinder
The osg cylinder geometry.
osg::ref_ptr< osg::MatrixTransform > m_osgJointMT
The osg joint matrix transform.
osg::ref_ptr< osg::StateSet > m_osgCylinderSS
The osg cylinder state set.
float m_fltReportSetPosition
This is the variable that is reported to AnimatLab on what the set position was.
virtual void SetLimitPos()=0
Sets the limit position using the current value set within the object.
ConstraintLimit * m_lpPosFlap
Pointer to a constraint that is used to represent the position flap.
float m_fltAlpha
The current alpha transparency for this body part.
float m_fltReportSetVelocity
This is the variable that is reported to AnimatLab on what the set veloicty was.
virtual void SetVelocityToDesired()
Sets the desired velocity to use for the motor.
virtual float JointPosition()
Gets the joint position.
virtual void DeleteGraphics()=0
Deletes up the graphics for the constraint.
virtual void Color(float fltR, float fltG, float fltB, float fltA)
Sets the color to use when displaying this contraint.
virtual void IsLowerLimit(bool bVal)
Sets whether this is a lower limit or not..
std::string Std_CheckString(std::string strVal)
Converts a string to upper case and trims it.
virtual void UpdateData()
Called to collect any body data for this part.
virtual bool EnableLimits()
Tells if ConstraintLimits are enabled.
std::string m_strName
The name for this object.
Declares the vortex structure class.