6 #include "VsMovableItem.h"
9 #include "VsRigidBody.h"
11 #include "VsSimulator.h"
12 #include "VsOsgUserData.h"
13 #include "VsOsgUserDataVisitor.h"
14 #include "VsDragger.h"
25 VsRigidBody::VsRigidBody()
30 m_vxCollisionGeometry = NULL;
36 for(
int i=0; i<3; i++)
40 m_vLinearVelocity[i] = 0;
41 m_vAngularVelocity[i] = 0;
42 m_vLinearAcceleration[i] = 0;
43 m_vAngularAcceleration[i] = 0;
48 VsRigidBody::~VsRigidBody()
56 {
Std_TraceMsg(0,
"Caught Error in desctructor of VsRigidBody\r\n",
"", -1,
false,
true);}
59 void VsRigidBody::SetThisPointers()
61 VsBody::SetThisPointers();
62 m_lpThisRB =
dynamic_cast<RigidBody *
>(
this);
64 THROW_TEXT_ERROR(Vs_Err_lThisPointerNotDefined, Vs_Err_strThisPointerNotDefined,
"m_lpThisRB, " + m_lpThisAB->Name());
66 m_lpThisRB->PhysicsBody(
this);
69 Vx::VxCollisionSensor* VsRigidBody::Sensor()
74 Vx::VxPart* VsRigidBody::Part()
79 Vx::VxNode VsRigidBody::GraphicsNode()
81 return m_vxGraphicNode;
84 Vx::VxCollisionGeometry *VsRigidBody::CollisionGeometry()
86 return m_vxCollisionGeometry;
89 void VsRigidBody::CollisionGeometry(Vx::VxCollisionGeometry *vxGeometry)
91 m_vxCollisionGeometry = vxGeometry;
92 Physics_FluidDataChanged();
95 CStdFPoint VsRigidBody::Physics_GetCurrentPosition()
97 if(m_vxSensor && m_lpThisMI)
99 Vx::VxReal3Ptr vPos = NULL;
100 m_vxSensor->getPosition(vPos);
101 m_lpThisMI->AbsolutePosition(vPos[0], vPos[1], vPos[2]);
102 return m_lpThisMI->AbsolutePosition();
111 void VsRigidBody::Physics_UpdateMatrix()
113 VsBody::Physics_UpdateMatrix();
116 m_lpThisRB->UpdatePhysicsPosFromGraphics();
119 void VsRigidBody::UpdatePositionAndRotationFromMatrix()
121 VsBody::UpdatePositionAndRotationFromMatrix();
124 m_lpThisRB->UpdatePhysicsPosFromGraphics();
127 void VsRigidBody::Physics_UpdateNode()
131 if(m_lpThisRB->IsContactSensor())
132 ResetSensorCollisionGeom();
133 else if(m_lpThisRB->HasStaticJoint())
134 ResetStaticCollisionGeom();
136 m_vxSensor->updateFromNode();
139 Physics_UpdateAbsolutePosition();
142 void VsRigidBody::Physics_SetColor()
145 SetColor(*m_lpThisRB->Ambient(), *m_lpThisRB->Diffuse(), *m_lpThisRB->Specular(), m_lpThisRB->Shininess());
148 void VsRigidBody::Physics_TextureChanged()
151 SetTexture(m_lpThisRB->Texture());
154 void VsRigidBody::Physics_SetFreeze(
bool bVal)
157 m_vxSensor->freeze(bVal);
160 void VsRigidBody::Physics_SetDensity(
float fltVal)
162 if(m_vxCollisionGeometry)
163 m_vxCollisionGeometry->setRelativeDensity(fltVal);
167 if(m_lpThisRB && m_lpThisRB->HasStaticJoint())
171 lpVsParent->GetBaseValues();
175 void VsRigidBody::Physics_SetMaterialID(std::string strID)
177 if(m_vxCollisionGeometry && m_lpThisAB)
179 int iMaterialID = m_lpThisAB->GetSimulator()->GetMaterialID(strID);
182 m_vxCollisionGeometry->setMaterialID(iMaterialID);
186 void VsRigidBody::Physics_SetVelocityDamping(
float fltLinear,
float fltAngular)
188 if(m_vxPart && fltLinear > 0)
189 m_vxPart->setLinearVelocityDamping(fltLinear);
191 if(m_vxPart && fltAngular > 0)
192 m_vxPart->setAngularVelocityDamping(fltAngular);
195 void VsRigidBody::Physics_SetCenterOfMass(
float fltTx,
float fltTy,
float fltTz)
199 if(fltTx != 0 || fltTy != 0 || fltTz != 0)
200 m_vxPart->setCOMOffset(fltTx, fltTy, fltTz);
204 void VsRigidBody::Physics_Resize()
207 if(m_osgNode.valid())
209 osg::Geode *osgGroup = NULL;
213 osgGroup =
dynamic_cast<osg::Geode *
>(m_osgNode.get());
216 THROW_TEXT_ERROR(Vs_Err_lNodeNotGeode, Vs_Err_strNodeNotGeode, m_lpThisAB->Name());
218 if(osgGroup && osgGroup->containsDrawable(m_osgGeometry.get()))
219 osgGroup->removeDrawable(m_osgGeometry.get());
221 m_osgGeometry.release();
224 CreateGraphicsGeometry();
226 m_osgGeometry->setName(m_lpThisAB->Name() +
"_Geometry");
229 osgGroup->addDrawable(m_osgGeometry.get());
232 if(m_osgDragger.valid())
233 m_osgDragger->SetupMatrix();
236 if(m_osgNodeGroup.valid())
239 osgVisitor->traverse(*m_osgNodeGroup);
245 ResizePhysicsGeometry();
249 Physics_SetDensity(m_lpThisRB->Density());
256 void VsRigidBody::Physics_SelectedVertex(
float fltXPos,
float fltYPos,
float fltZPos)
258 if(m_lpThisRB->IsCollisionObject() && m_osgSelVertexMT.valid())
261 osgMT.makeIdentity();
262 osgMT = osgMT.translate(fltXPos, fltYPos, fltZPos);
264 m_osgSelVertexMT->setMatrix(osgMT);
269 void VsRigidBody::ShowSelectedVertex()
271 if(m_lpThisRB && m_lpThisAB && m_lpThisRB->IsCollisionObject() && m_lpThisAB->Selected() && m_osgMT.valid() && m_osgSelVertexMT.valid())
273 if(!m_osgMT->containsNode(m_osgSelVertexMT.get()))
274 m_osgMT->addChild(m_osgSelVertexMT.get());
278 void VsRigidBody::HideSelectedVertex()
280 if(m_lpThisRB->IsCollisionObject() && m_osgMT.valid() && m_osgSelVertexMT.valid())
282 if(m_osgMT->containsNode(m_osgSelVertexMT.get()))
283 m_osgMT->removeChild(m_osgSelVertexMT.get());
287 void VsRigidBody::Physics_ResizeSelectedReceptiveFieldVertex()
289 DeleteSelectedVertex();
290 CreateSelectedVertex(m_lpThisAB->Name());
293 void VsRigidBody::Physics_FluidDataChanged()
295 if(m_vxCollisionGeometry && m_lpThisRB)
297 CStdFPoint vpCenter = m_lpThisRB->BuoyancyCenter();
298 Vx::VxReal3 vCenter = {vpCenter.x, vpCenter.y, vpCenter.z};
300 CStdFPoint vpDrag = m_lpThisRB->LinearDrag();
301 Vx::VxReal3 vDrag = {vpDrag.x, vpDrag.y, vpDrag.z};
303 float fltScale = m_lpThisRB->BuoyancyScale();
304 float fltMagnus = m_lpThisRB->Magnus();
305 bool bEnabled = m_lpThisRB->EnableFluids();
307 m_vxCollisionGeometry->setFluidInteractionData(vCenter, vDrag, fltScale, fltMagnus);
310 m_vxCollisionGeometry->setDefaultFluidInteractionForceFn();
312 m_vxCollisionGeometry->setFluidInteractionForceFn(NULL);
316 void VsRigidBody::GetBaseValues()
318 if(m_vxPart && m_lpThisRB)
324 m_lpThisRB->GetMass();
325 m_lpThisRB->GetVolume();
332 void VsRigidBody::Initialize()
349 if(m_lpThisRB && m_lpThisMI && m_lpThisAB)
351 if(m_lpThisRB->IsRoot())
352 VsBody::BuildLocalMatrix(m_lpThisAB->GetStructure()->AbsolutePosition(), m_lpThisMI->Rotation(), m_lpThisAB->Name());
354 VsBody::BuildLocalMatrix(m_lpThisMI->Position(), m_lpThisMI->Rotation(), m_lpThisAB->Name());
374 if(!m_lpThisRB->IsRoot() && m_lpParentVsMI)
375 return m_lpParentVsMI->GetMatrixTransform();
377 return GetVsSimulator()->OSGRoot();
380 void VsRigidBody::SetupPhysics()
384 if(m_vxGeometry && m_lpThisRB)
388 if(m_lpThisRB->IsContactSensor())
390 else if(m_lpThisRB->HasStaticJoint())
397 void VsRigidBody::CreateSensorPart()
399 if(m_lpThisRB && m_lpThisAB)
403 m_vxSensor =
new VxCollisionSensor;
405 m_vxSensor->setUserData((
void*) m_lpThisRB);
407 m_vxSensor->setName(m_lpThisAB->ID().c_str());
408 CollisionGeometry(m_vxSensor->addGeometry(m_vxGeometry, 0));
409 std::string strName = m_lpThisAB->ID() +
"_CollisionGeometry";
410 m_vxCollisionGeometry->setName(strName.c_str());
412 m_vxSensor->setControl(VxEntity::kControlNode);
418 SetFollowEntity(lpVsParent);
420 m_vxSensor->freeze(m_lpThisRB->Freeze());
424 void VsRigidBody::SetFollowEntity(
VsRigidBody *lpEntity)
428 m_vxSensor->setFastMoving(
true);
429 Vx::VxReal44 vOffset;
430 VxOSG::copyOsgMatrix_to_VxReal44(m_osgMT->getMatrix(), vOffset);
431 Vx::VxTransform vTM(vOffset);
433 Vx::VxCollisionSensor *vxSensor = lpEntity->Sensor();
435 m_vxSensor->followEntity(vxSensor,
true, &vTM);
439 void VsRigidBody::ResetSensorCollisionGeom()
444 SetFollowEntity(lpVsParent);
448 void VsRigidBody::CreateDynamicPart()
450 if(m_lpThisRB && m_lpThisAB)
453 m_vxPart =
new VxPart;
454 m_vxSensor = m_vxPart;
455 m_vxSensor->setUserData((
void*) m_lpThisRB);
456 int iMaterialID = m_lpThisAB->GetSimulator()->GetMaterialID(m_lpThisRB->MaterialID());
458 m_vxSensor->setName(m_lpThisAB->ID().c_str());
459 m_vxSensor->setControl(m_eControlType);
460 CollisionGeometry(m_vxSensor->addGeometry(m_vxGeometry, iMaterialID, 0, m_lpThisRB->Density()));
464 std::string strName = m_lpThisAB->ID() +
"_CollisionGeometry";
465 m_vxCollisionGeometry->setName(strName.c_str());
466 m_vxSensor->setFastMoving(
true);
469 m_vxSensor->freeze(m_lpThisRB->Freeze());
474 CStdFPoint vCOM = m_lpThisRB->CenterOfMass();
475 if(vCOM.x != 0 || vCOM.y != 0 || vCOM.z != 0)
476 m_vxPart->setCOMOffset(vCOM.x, vCOM.y, vCOM.z);
478 if(m_lpThisRB->LinearVelocityDamping() > 0)
479 m_vxPart->setLinearVelocityDamping(m_lpThisRB->LinearVelocityDamping());
481 if(m_lpThisRB->AngularVelocityDamping() > 0)
482 m_vxPart->setAngularVelocityDamping(m_lpThisRB->AngularVelocityDamping());
487 void VsRigidBody::CreateStaticPart()
489 if(m_lpThisRB && m_lpThisAB)
493 Vx::VxReal44 vOffset;
494 VxOSG::copyOsgMatrix_to_VxReal44(m_osgMT->getMatrix(), vOffset);
495 int iMaterialID = m_lpThisAB->GetSimulator()->GetMaterialID(m_lpThisRB->MaterialID());
499 Vx::VxCollisionSensor *vxSensor = lpVsParent->Sensor();
502 CollisionGeometry(vxSensor->addGeometry(m_vxGeometry, iMaterialID, vOffset, m_lpThisRB->Density()));
503 std::string strName = m_lpThisAB->ID() +
"_CollisionGeometry";
504 m_vxCollisionGeometry->setName(strName.c_str());
510 void VsRigidBody::RemoveStaticPart()
516 Vx::VxCollisionSensor *vxSensor = lpVsParent->Sensor();
517 if(vxSensor && m_vxCollisionGeometry)
518 vxSensor->removeCollisionGeometry(m_vxCollisionGeometry);
522 void VsRigidBody::ResetStaticCollisionGeom()
524 if(m_osgMT.valid() && m_lpThisRB && m_lpThisRB->Parent())
530 Vx::VxReal44 vOffset;
531 VxOSG::copyOsgMatrix_to_VxReal44(m_osgMT->getMatrix(), vOffset);
533 Vx::VxCollisionSensor *vxSensor = lpVsParent->Sensor();
534 if(vxSensor && m_vxCollisionGeometry)
535 m_vxCollisionGeometry->setRelativeTransform(vOffset);
540 void VsRigidBody::DeletePhysics()
544 if(GetVsSimulator() && GetVsSimulator()->Universe())
546 GetVsSimulator()->Universe()->removeEntity(m_vxSensor);
554 else if(m_lpThisRB->HasStaticJoint())
558 void VsRigidBody::SetBody()
560 if(m_vxSensor && m_lpThisAB)
564 osg::MatrixTransform *lpMT =
dynamic_cast<osg::MatrixTransform *
>(m_osgMT.get());
565 m_vxSensor->setNode(lpMT);
568 if(lpVsSim && lpVsSim->Universe())
569 lpVsSim->Universe()->addEntity(m_vxSensor);
573 int VsRigidBody::GetPartIndex(VxPart *vxP0, VxPart *vxP1)
581 void VsRigidBody::ProcessContacts()
583 ContactSensor *lpSensor = m_lpThisRB->GetContactSensor();
584 float fDisUnits = m_lpThisAB->GetSimulator()->DistanceUnits();
585 float fMassUnits = m_lpThisAB->GetSimulator()->MassUnits();
587 if(m_vxPart && lpSensor)
589 lpSensor->ClearCurrents();
591 Vx::VxPart::DynamicsContactIterator itd = m_vxPart->dynamicsContactBegin();
597 float fltForceMag = 0;
604 for(; itd != m_vxPart->dynamicsContactEnd(); ++itd, iCount++)
606 VxDynamicsContact *vxDyn = *itd;
607 vxDyn->getPartPair(p, p+1);
609 vxDyn->getPosition(vWorldPos);
610 WorldToBodyCoords(vWorldPos, vBodyPos);
612 iPartIdx = GetPartIndex(p[0], p[1]);
613 vxDyn->getForce(iPartIdx, vForce);
614 fltForceMag = V3_MAG(vForce) * (fMassUnits * fDisUnits);
617 lpSensor->ProcessContact(vBodyPos, fltForceMag);
622 void VsRigidBody::Physics_CollectData()
632 m_vxSensor->getTransform(vxMT);
633 VxOSG::copyVxReal44_to_OsgMatrix(m_osgWorldMatrix, vxMT);
636 m_vxSensor->getPosition(vData);
637 m_lpThisMI->AbsolutePosition(vData[0], vData[1], vData[2]);
639 m_vxSensor->getOrientationEulerAngles(vData);
640 m_lpThisMI->ReportRotation(vData[0], vData[1], vData[2]);
645 Physics_UpdateAbsolutePosition();
652 if(m_lpThisRB->GetContactSensor())
656 void VsRigidBody::Physics_CollectExtraData()
658 float fDisUnits = m_lpThisAB->GetSimulator()->DistanceUnits();
659 float fMassUnits = m_lpThisAB->GetSimulator()->MassUnits();
664 m_vxPart->getLinearVelocity(vData);
665 m_vLinearVelocity[0] = vData[0] * fDisUnits;
666 m_vLinearVelocity[1] = vData[1] * fDisUnits;
667 m_vLinearVelocity[2] = vData[2] * fDisUnits;
669 m_vxPart->getAngularVelocity(vData);
670 m_vAngularVelocity[0] = vData[0];
671 m_vAngularVelocity[1] = vData[1];
672 m_vAngularVelocity[2] = vData[2];
675 m_vxPart->getLastForceAndTorque(vData, vData2);
676 float fltRatio = fMassUnits * fDisUnits;
677 m_vForce[0] = vData[0] * fltRatio;
678 m_vForce[1] = vData[1] * fltRatio;
679 m_vForce[2] = vData[2] * fltRatio;
681 fltRatio = fMassUnits * fDisUnits * fDisUnits;
682 m_vTorque[0] = vData2[0] * fltRatio;
683 m_vTorque[1] = vData2[1] * fltRatio;
684 m_vTorque[2] = vData2[2] * fltRatio;
687 m_vxPart->getLinearAcceleration(vAccel);
688 m_vLinearAcceleration[0] = vAccel[0] * fDisUnits;
689 m_vLinearAcceleration[1] = vAccel[1] * fDisUnits;
690 m_vLinearAcceleration[2] = vAccel[2] * fDisUnits;
692 m_vxPart->getAngularAcceleration(vAccel);
693 m_vAngularAcceleration[0] = vAccel[0];
694 m_vAngularAcceleration[1] = vAccel[1];
695 m_vAngularAcceleration[2] = vAccel[2];
701 void VsRigidBody::Physics_ResetSimulation()
703 VsBody::Physics_ResetSimulation();
708 m_vxSensor->updateFromNode();
712 m_vxPart->resetDynamics();
713 m_vxPart->wakeDynamics();
717 for(
int i=0; i<3; i++)
721 m_vLinearVelocity[i] = 0;
722 m_vAngularVelocity[i] = 0;
723 m_vLinearAcceleration[i] = 0;
724 m_vAngularAcceleration[i] = 0;
728 void VsRigidBody::Physics_EnableCollision(RigidBody *lpBody)
731 THROW_ERROR(Al_Err_lBodyNotDefined, Al_Err_strBodyNotDefined);
736 THROW_PARAM_ERROR(Al_Err_lUnableToCastBodyToDesiredType, Al_Err_strUnableToCastBodyToDesiredType,
"Type",
"VsRigidBody");
741 THROW_ERROR(Al_Err_lSimulationNotDefined, Al_Err_strSimulationNotDefined);
744 if(lpVsSim->Universe()->getPairIntersectEnabled(m_vxCollisionGeometry, lpVsBody->CollisionGeometry()) ==
false)
745 lpVsSim->Universe()->enablePairIntersect(m_vxPart, lpVsBody->Sensor());
748 void VsRigidBody::Physics_DisableCollision(RigidBody *lpBody)
751 THROW_ERROR(Al_Err_lBodyNotDefined, Al_Err_strBodyNotDefined);
756 THROW_PARAM_ERROR(Al_Err_lUnableToCastBodyToDesiredType, Al_Err_strUnableToCastBodyToDesiredType,
"Type",
"VsRigidBody");
761 THROW_ERROR(Al_Err_lSimulationNotDefined, Al_Err_strSimulationNotDefined);
764 Vx::VxUniverse *lpUniv = lpVsSim->Universe();
765 if(!m_vxCollisionGeometry || !lpVsBody->CollisionGeometry())
766 THROW_PARAM_ERROR(Vs_Err_lCollisionGeomNotDefined, Vs_Err_strCollisionGeomNotDefined,
"ID", m_lpThisAB->ID());
768 if(lpUniv->getPairIntersectEnabled(m_vxCollisionGeometry, lpVsBody->CollisionGeometry()) ==
true)
769 lpUniv->disablePairIntersect(m_vxSensor, lpVsBody->Sensor());
772 float *VsRigidBody::Physics_GetDataPointer(
const std::string &strDataType)
775 RigidBody *lpBody =
dynamic_cast<RigidBody *
>(
this);
777 if(strType ==
"BODYBUOYANCY")
780 if(strType ==
"BODYDRAGFORCEX")
783 if(strType ==
"BODYDRAGFORCEY")
786 if(strType ==
"BODYDRAGFORCEZ")
789 if(strType ==
"BODYDRAGTORQUEX")
792 if(strType ==
"BODYDRAGTORQUEY")
795 if(strType ==
"BODYDRAGTORQUEZ")
798 if(strType ==
"BODYTORQUEX")
800 GetVsSimulator()->AddToExtractExtraData(m_lpThisRB);
801 return (&m_vTorque[0]);
804 if(strType ==
"BODYTORQUEY")
806 GetVsSimulator()->AddToExtractExtraData(m_lpThisRB);
807 return (&m_vTorque[1]);
810 if(strType ==
"BODYTORQUEZ")
812 GetVsSimulator()->AddToExtractExtraData(m_lpThisRB);
813 return (&m_vTorque[2]);
816 if(strType ==
"BODYFORCEX")
818 GetVsSimulator()->AddToExtractExtraData(m_lpThisRB);
819 return (&m_vForce[0]);
822 if(strType ==
"BODYFORCEY")
824 GetVsSimulator()->AddToExtractExtraData(m_lpThisRB);
825 return (&m_vForce[1]);
828 if(strType ==
"BODYFORCEZ")
830 GetVsSimulator()->AddToExtractExtraData(m_lpThisRB);
831 return (&m_vForce[2]);
834 if(strType ==
"BODYLINEARVELOCITYX")
836 GetVsSimulator()->AddToExtractExtraData(m_lpThisRB);
837 return (&m_vLinearVelocity[0]);
840 if(strType ==
"BODYLINEARVELOCITYY")
842 GetVsSimulator()->AddToExtractExtraData(m_lpThisRB);
843 return (&m_vLinearVelocity[1]);
846 if(strType ==
"BODYLINEARVELOCITYZ")
848 GetVsSimulator()->AddToExtractExtraData(m_lpThisRB);
849 return (&m_vLinearVelocity[2]);
852 if(strType ==
"BODYANGULARVELOCITYX")
854 GetVsSimulator()->AddToExtractExtraData(m_lpThisRB);
855 return (&m_vAngularVelocity[0]);
858 if(strType ==
"BODYANGULARVELOCITYY")
860 GetVsSimulator()->AddToExtractExtraData(m_lpThisRB);
861 return (&m_vAngularVelocity[1]);
864 if(strType ==
"BODYANGULARVELOCITYZ")
866 GetVsSimulator()->AddToExtractExtraData(m_lpThisRB);
867 return (&m_vAngularVelocity[2]);
873 if(strType ==
"BODYLINEARACCELERATIONX")
875 GetVsSimulator()->AddToExtractExtraData(m_lpThisRB);
876 return (&m_vLinearAcceleration[0]);
879 if(strType ==
"BODYLINEARACCELERATIONY")
881 GetVsSimulator()->AddToExtractExtraData(m_lpThisRB);
882 return (&m_vLinearAcceleration[1]);
885 if(strType ==
"BODYLINEARACCELERATIONZ")
887 GetVsSimulator()->AddToExtractExtraData(m_lpThisRB);
888 return (&m_vLinearAcceleration[2]);
891 if(strType ==
"BODYANGULARACCELERATIONX")
893 GetVsSimulator()->AddToExtractExtraData(m_lpThisRB);
894 return (&m_vAngularAcceleration[0]);
897 if(strType ==
"BODYANGULARACCELERATIONY")
899 GetVsSimulator()->AddToExtractExtraData(m_lpThisRB);
900 return (&m_vAngularAcceleration[1]);
903 if(strType ==
"BODYANGULARACCELERATIONZ")
905 GetVsSimulator()->AddToExtractExtraData(m_lpThisRB);
906 return (&m_vAngularAcceleration[2]);
909 if(strType ==
"ESTIMATEDMASS")
912 if(strType ==
"ESTIMATEDVOLUME")
918 void VsRigidBody::Physics_AddBodyForceAtLocalPos(
float fltPx,
float fltPy,
float fltPz,
float fltFx,
float fltFy,
float fltFz,
bool bScaleUnits)
920 if(m_vxPart && (fltFx || fltFy || fltFz) && !m_lpThisRB->Freeze())
925 fltF[0] = fltFx * (m_lpThisAB->GetSimulator()->InverseMassUnits() * m_lpThisAB->GetSimulator()->InverseDistanceUnits());
926 fltF[1] = fltFy * (m_lpThisAB->GetSimulator()->InverseMassUnits() * m_lpThisAB->GetSimulator()->InverseDistanceUnits());
927 fltF[2] = fltFz * (m_lpThisAB->GetSimulator()->InverseMassUnits() * m_lpThisAB->GetSimulator()->InverseDistanceUnits());
940 m_vxPart->addForceAtPosition(fltF, fltP);
944 void VsRigidBody::Physics_AddBodyForceAtWorldPos(
float fltPx,
float fltPy,
float fltPz,
float fltFx,
float fltFy,
float fltFz,
bool bScaleUnits)
946 if(m_vxPart && (fltFx || fltFy || fltFz) && !m_lpThisRB->Freeze())
951 fltF[0] = fltFx * (m_lpThisAB->GetSimulator()->InverseMassUnits() * m_lpThisAB->GetSimulator()->InverseDistanceUnits());
952 fltF[1] = fltFy * (m_lpThisAB->GetSimulator()->InverseMassUnits() * m_lpThisAB->GetSimulator()->InverseDistanceUnits());
953 fltF[2] = fltFz * (m_lpThisAB->GetSimulator()->InverseMassUnits() * m_lpThisAB->GetSimulator()->InverseDistanceUnits());
966 m_vxPart->addForceAtPosition(fltF, fltP);
970 void VsRigidBody::Physics_AddBodyTorque(
float fltTx,
float fltTy,
float fltTz,
bool bScaleUnits)
972 if(m_vxPart && (fltTx || fltTy || fltTz))
977 fltT[0] = fltTx * (m_lpThisAB->GetSimulator()->InverseMassUnits() * m_lpThisAB->GetSimulator()->InverseDistanceUnits() * m_lpThisAB->GetSimulator()->InverseDistanceUnits());
978 fltT[1] = fltTy * (m_lpThisAB->GetSimulator()->InverseMassUnits() * m_lpThisAB->GetSimulator()->InverseDistanceUnits() * m_lpThisAB->GetSimulator()->InverseDistanceUnits());
979 fltT[2] = fltTz * (m_lpThisAB->GetSimulator()->InverseMassUnits() * m_lpThisAB->GetSimulator()->InverseDistanceUnits() * m_lpThisAB->GetSimulator()->InverseDistanceUnits());
988 m_vxPart->addTorque(fltT);
992 CStdFPoint VsRigidBody::Physics_GetVelocityAtPoint(
float x,
float y,
float z)
994 CStdFPoint linVel(0,0,0);
995 Vx::VxReal3 vxLinVel = {0,0,0};
996 Vx::VxReal3 vxPoint = {x,y,z};
1001 m_vxPart->getVelocityAtPoint(vxPoint, vxLinVel);
1002 linVel.Set(vxLinVel[0], vxLinVel[1], vxLinVel[2]);
1008 float VsRigidBody::Physics_GetMass()
1014 if(m_lpThisRB && m_vxSensor && m_lpThisRB->Freeze())
1015 m_vxSensor->freeze(
false);
1018 fltMass = m_vxPart->getMass();
1020 if(m_lpThisRB && m_vxSensor && m_lpThisRB->Freeze())
1021 m_vxSensor->freeze(
true);
1026 float VsRigidBody::Physics_GetDensity()
1029 return m_lpThisRB->Density();
1034 bool VsRigidBody::Physics_HasCollisionGeometry()
1042 bool VsRigidBody::Physics_IsDefined()
1044 if(m_vxPart && m_vxSensor)
1050 bool VsRigidBody::Physics_IsGeometryDefined()
1058 void VsRigidBody::Physics_WakeDynamics()
1061 m_vxPart->wakeDynamics();
virtual osg::Group * ParentOSG()
Gets the parent osg node.
A common class for all rigid body data specific to vortex.
float m_fltEstimatedVolume
The estimated volume. See m_fltEstimatedMass desciption.
osg::ref_ptr< osg::MatrixTransform > m_osgGeometryRotationMT
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
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.
virtual void BuildLocalMatrix()
Builds the local matrix.
std::string Std_CheckString(std::string strVal)
Converts a string to upper case and trims it.
Declares the vortex structure class.