void plPhysicalControllerCore::MoveActorToSim() { // Get the current position of the physical hsPoint3 curLocalPos; hsPoint3 lastLocalPos; GetPositionSim(curLocalPos); MoveKinematicToController(curLocalPos); lastLocalPos=GetLocalPosition(); fDisplacementThisStep= hsVector3(curLocalPos - lastLocalPos); fLocalPosition = curLocalPos; if(fSimLength>0.0f) fAchievedLinearVelocity=fDisplacementThisStep/fSimLength; else fAchievedLinearVelocity.Set(0.0f,0.0f,0.0f); }
void plPhysicalControllerCore::IUpdate(int numSubSteps, float alpha) { if (fEnabled) { // Update local position and acheived velocity fLastLocalPosition = fLocalPosition; GetPositionSim(fLocalPosition); hsVector3 displacement = (hsVector3)(fLocalPosition - fLastLocalPosition); fAchievedLinearVelocity = displacement / fSimLength; displacement /= (float)numSubSteps; fLastLocalPosition = fLocalPosition - displacement; hsPoint3 interpLocalPos = fLastLocalPosition + (displacement * alpha); // Update global location fLocalRotation.MakeMatrix(&fLastGlobalLoc); fLastGlobalLoc.SetTranslate(&interpLocalPos); const plCoordinateInterface* subworldCI = GetSubworldCI(); if (subworldCI) { const hsMatrix44& subL2W = subworldCI->GetLocalToWorld(); fLastGlobalLoc = subL2W * fLastGlobalLoc; fPrevSubworldW2L = subworldCI->GetWorldToLocal(); } fMovementStrategy->Update(fSimLength); ISendCorrectionMessages(true); } else { fAchievedLinearVelocity.Set(0.0f, 0.0f, 0.0f); // Update global location if in a subworld const plCoordinateInterface* subworldCI = GetSubworldCI(); if (subworldCI) { hsMatrix44 l2s = fPrevSubworldW2L * fLastGlobalLoc; const hsMatrix44& subL2W = subworldCI->GetLocalToWorld(); fLastGlobalLoc = subL2W * l2s; fPrevSubworldW2L = subworldCI->GetWorldToLocal(); ISendCorrectionMessages(); } } if (fEnableChanged) IHandleEnableChanged(); }
void plPXPhysicalControllerCore::UpdateControllerAndPhysicalRep() { if ( fKinematicActor) { if(this->fBehavingLikeAnimatedPhys) {//this means we are moving the controller and then synchnig the kin NxExtendedVec3 ControllerPos= fController->getPosition(); NxVec3 NewKinPos((NxReal)ControllerPos.x, (NxReal)ControllerPos.y, (NxReal)ControllerPos.z); if (fKinematicActor->readBodyFlag(NX_BF_KINEMATIC)) { if (plSimulationMgr::fExtraProfile) SimLog("Moving kinematic to %f,%f,%f",NewKinPos.x, NewKinPos.y, NewKinPos.z ); // use the position fKinematicActor->moveGlobalPosition(NewKinPos); } else { if (plSimulationMgr::fExtraProfile) SimLog("Setting kinematic to %f,%f,%f", NewKinPos.x, NewKinPos.y, NewKinPos.z ); fKinematicActor->setGlobalPosition(NewKinPos); } } else { NxVec3 KinPos= fKinematicActor->getGlobalPosition(); NxExtendedVec3 NewControllerPos(KinPos.x, KinPos.y, KinPos.z); if (plSimulationMgr::fExtraProfile) SimLog("Setting Controller to %f,%f,%f", NewControllerPos.x, NewControllerPos.y, NewControllerPos.z ); fController->setPosition(NewControllerPos); } hsPoint3 curLocalPos; GetPositionSim(curLocalPos); fLocalPosition = curLocalPos; } }