예제 #1
0
bool plPXPhysical::GetAngularVelocitySim(hsVector3& vel) const
{
    bool result = false;
    if (fActor->isDynamic())
    {
        vel = plPXConvert::Vector(fActor->getAngularVelocity());
        result = true;
    }
    else
        vel.Set(0, 0, 0);

    return result;
}
예제 #2
0
void plSwimStraightCurrentRegion::GetCurrent(plPhysicalControllerCore *physical, hsVector3 &linearResult, float &angularResult, float elapsed)
{
    angularResult = 0.f;

    if (elapsed <= 0.f || GetProperty(kDisable))
    {
        linearResult.Set(0.f, 0.f, 0.f);
        return;
    }

    hsPoint3 center, pos;
    hsVector3 current = fCurrentSO->GetLocalToWorld() * hsVector3(0.f, 1.f, 0.f);
    hsScalarTriple xlate = fCurrentSO->GetLocalToWorld().GetTranslate();
    center.Set(&xlate);
    physical->GetPositionSim(pos);

    plKey worldKey = physical->GetSubworld();
    if (worldKey)
    {
        plSceneObject* so = plSceneObject::ConvertNoRef(worldKey->ObjectIsLoaded());
        hsMatrix44 w2l = so->GetWorldToLocal();
        center = w2l * center;
        current = w2l * current;
    }

    hsVector3 pos2Center(center.fX - pos.fX, center.fY - pos.fY, 0.f);
    float dist = current.InnerProduct(pos - center);
    float pullVel;
    
    if (dist <= fNearDist)
        pullVel = fNearVel;
    else if (dist >= fFarDist)
        pullVel = fFarVel;
    else
        pullVel = fNearVel + (fFarVel - fNearVel) * (dist - fNearDist) / (fFarDist - fNearDist);

    linearResult = current * pullVel;
}   
예제 #3
0
void plSwimRegionInterface::GetCurrent(plPhysicalControllerCore *physical, hsVector3 &linearResult, float &angularResult, float elapsed)
{
    linearResult.Set(0.f, 0.f, 0.f);
    angularResult = 0.f;
}
예제 #4
0
void plSwimCircularCurrentRegion::GetCurrent(plPhysicalControllerCore *physical, hsVector3 &linearResult, float &angularResult, float elapsed)
{
    if (elapsed <= 0.f || fCurrentSO == nil || GetProperty(kDisable))
    {
        linearResult.Set(0.f, 0.f, 0.f);
        angularResult = 0.f;
        return;
    }

    hsPoint3 center, pos;
    hsScalarTriple xlate = fCurrentSO->GetLocalToWorld().GetTranslate();
    center.Set(&xlate);

    plKey worldKey = physical->GetSubworld();
    if (worldKey)
    {
        plSceneObject* so = plSceneObject::ConvertNoRef(worldKey->ObjectIsLoaded());
        center = so->GetWorldToLocal() * center;
    }

    center.fZ = 0.f; // Just doing 2D

    physical->GetPositionSim(pos);
    
    hsVector3 pos2Center(center.fX - pos.fX, center.fY - pos.fY, 0.f);
    float pullVel;
    float distSq = pos2Center.MagnitudeSquared();
    if (distSq < .5)
    {
        // Don't want to pull us too close to the center, or we
        // get this annoying jitter.
        pullVel = 0.f;
    }
    else if (distSq <= fPullNearDistSq)
        pullVel = fPullNearVel;
    else if (distSq >= fPullFarDistSq)
        pullVel = fPullFarVel;
    else
        pullVel = fPullNearVel + (fPullFarVel - fPullNearVel) * (distSq - fPullNearDistSq) / (fPullFarDistSq - fPullNearDistSq);

    hsVector3 pull = pos2Center;
    pull.Normalize();
    linearResult.Set(pull.fY, -pull.fX, pull.fZ);
    
    pull *= pullVel;
    linearResult *= fRotation;
    linearResult += pull;

    hsVector3 v1 = linearResult * elapsed - pos2Center;
    hsVector3 v2 = -pos2Center;
    float invCos = v1.InnerProduct(v2) / v1.Magnitude() / v2.Magnitude();
    if (invCos > 1)
        invCos = 1;
    if (invCos < -1)
        invCos = -1;
    angularResult = acos(invCos) / elapsed;

//  hsAssert(real_finite(linearResult.fX) &&
//           real_finite(linearResult.fY) &&
//           real_finite(linearResult.fZ) &&
//           real_finite(angularResult), "Bad water current computation."); 
}