//called when a capsule shape is encounered. This will provide the two end points of the capsule //relative to the transform heirarchy and the radius of the capsule virtual void HandleCapsule(const LTVector& vPt1, const LTVector& vPt2, float fRadius, float fMassKg, float fDensityG) { m_fTotalMassKg += fMassKg; float fVolume, fSurfaceArea; LTVector vApplyAt; //determine the lenght of the capsule axis float fLength = vPt1.Dist(vPt2); if(ApplyCapsuleBuoyancy(vPt1, vPt2, fLength, fRadius, m_SurfacePlane, fVolume, vApplyAt, fSurfaceArea)) { m_fSurfaceArea += fSurfaceArea; float fWaterDensity = CalcCapsuleWaterDensity(m_fDensity, fRadius, fLength, fMassKg, fDensityG); LTVector vForce = CalcBuoyancyForceVector(m_vGravity, fWaterDensity, fVolume); if( LTIsNaN( vForce ) || vForce.MagSqr() > 1000000.0f * 1000000.0f ) { LTERROR( "Invalid force detected." ); vForce.Init( 0.0f, 10.0f, 0.0f ); } g_pLTBase->PhysicsSim()->ApplyRigidBodyForceWorldSpace(m_hRigidBody, vApplyAt, vForce); } }
void CAIMovement::SetupJump( EnumAnimMovement eMovementType ) { LTVector vOrigin = m_pAI->GetPosition(); // Calc distance for jumping up or down. // Figure out how long it takes to fly to the dest. LTFLOAT fDist; LTFLOAT fJumpTime; switch( eMovementType ) { case kAM_JumpOver: { fDist = vOrigin.Dist( m_vDest ); fJumpTime = fDist / m_pAI->GetJumpOverSpeed(); } break; case kAM_JumpUp: { // Move dest to be directly above origin. m_vDest.x = vOrigin.x; m_vDest.z = vOrigin.z; fDist = m_vDest.y - vOrigin.y; fJumpTime = fDist / m_pAI->GetJumpSpeed(); } break; case kAM_Fall: { // Move dest to be directly above origin. m_vDest.x = vOrigin.x; m_vDest.z = vOrigin.z; fDist = vOrigin.y - m_vDest.y; fJumpTime = fDist / m_pAI->GetFallSpeed(); } break; default: { AIASSERT( 0, m_pAI->GetHOBJECT(), "Unknown Movement type!" ); } break; } // Find the length of the fly animation. LTFLOAT fAnimLength = m_pAI->GetAnimationContext()->GetCurAnimationLength(); // Calculate how fast to play the fly animation. m_fAnimRate = fAnimLength / fJumpTime; m_pAI->GetAnimationContext()->SetAnimRate( m_fAnimRate ); m_bIgnoreVolumes = LTTRUE; }