Ejemplo n.º 1
0
bool plDynaBulletMgr::IHandleShot(plBulletMsg* bull)
{
    hsVector3 up = IRandomUp(bull->Dir());

    hsPoint3 pos = bull->From() + bull->Dir() * (bull->Range() * 0.5f);
    fCutter->SetLength(hsVector3(bull->Radius() * fScale.fX, bull->Radius() * fScale.fY, bull->Range()));
    fCutter->Set(pos, up, -bull->Dir());

    plDynaDecalInfo& info = IGetDecalInfo(uintptr_t(this), GetKey());

    if( bull->PartyTime() > 0 )
        fPartyTime = bull->PartyTime();

    double secs = hsTimer::GetSysSeconds();

    if( ICutoutTargets(secs) )
        info.fLastTime = secs;
    
    return true;
}
hsBool plDynaRippleVSMgr::IRippleFromShape(const plPrintShape* shape, hsBool force)
{
    if( !ICheckRTMat() )
        return false;

    if( !shape )
        return false;

    hsBool retVal = false;

    plDynaDecalInfo& info = IGetDecalInfo(uintptr_t(shape), shape->GetKey());

    const hsMatrix44& shapeL2W = shape->GetOwner()->GetLocalToWorld();

    plConst(float) kMinDist(2.0f);
    plConst(float) kMinTime(1.5f);
    double t = hsTimer::GetSysSeconds();
    float dt = float(t - info.fLastTime) * sRand.RandZeroToOne();
    hsBool longEnough = (dt >= kMinTime);
    hsPoint3 xlate = shapeL2W.GetTranslate();
    hsBool farEnough = (hsVector3(&info.fLastPos, &xlate).Magnitude() > kMinDist);
    if( force || longEnough || farEnough )
    {
        hsPoint3 pos = shapeL2W.GetTranslate();

        // We'll perturb the position a little so it doesn't look quite so regular,
        // but we perturb it more if we're just standing still
        hsVector3 randPert(sRand.RandMinusOneToOne(), sRand.RandMinusOneToOne(), 0);
        randPert.Normalize();
        if( !farEnough )
        {
            plConst(float) kRandPert = 0.5f;
            randPert *= kRandPert;
        }
        else
        {
            plConst(float) kRandPert = 0.15f;
            randPert *= kRandPert;
        }
        pos += randPert;

        // Are we potentially touching the water?
        float waterHeight = fWaveSetBase->GetHeight();
        if( (pos.fZ - fScale.fZ * shape->GetHeight() < waterHeight)
            &&(pos.fZ + fScale.fZ * shape->GetHeight() > waterHeight) )
        {

            hsVector3 dir(fWaveSetBase->GetWindDir());
            hsVector3 up(0.f, 0.f, 1.f);

            float wid = hsMaximum(shape->GetWidth(), shape->GetLength());
            
            plConst(float) kMaxWaterDepth(1000.f);

            hsVector3 size(wid * fScale.fX, wid * fScale.fY, kMaxWaterDepth);
            fCutter->SetLength(size);
            fCutter->Set(pos, dir, up);


            hsBool hit = ICutoutTargets(t);
            if( hit )
            {
                info.fLastTime = t;
                info.fLastPos = shapeL2W.GetTranslate();
                retVal = true;
            }
            else
            {
                retVal = false; // No-effect else just for break points.
            }
        }
    }
    return retVal;
}
hsBool plDynaTorpedoMgr::IHandleShot(plBulletMsg* bull)
{
    float partyTime = fPartyTime;

    plConst(int) kNumShots(3);
    int i;
    for( i = 0; i < kNumShots; i++ )
    {
        hsVector3 up = IRandomUp(bull->Dir());
        hsVector3 pert = bull->Dir() % up;

        plConst(float) kMaxPert(1.f);
        float maxPert = i ? kMaxPert * bull->Radius() : 0;
        pert *= sRand.RandMinusOneToOne() * maxPert * fScale.fX;

        pert += up * (sRand.RandMinusOneToOne() * maxPert * fScale.fY);

        hsPoint3 pos = bull->From() + bull->Dir() * (bull->Range() * 0.5f);
        pos += pert;

        float scaleX = bull->Radius() * fScale.fX * fInitUVW.fX;
        float scaleY = bull->Radius() * fScale.fY * fInitUVW.fY;

#if 0
        plConst(float) kMinScale(0.5f);
        if( i )
        {
            scaleX *= sRand.RandRangeF(kMinScale, 1.f);
            scaleY *= sRand.RandRangeF(kMinScale, 1.f);
        }
#elif 0
        float div = 1.f / (1.f + float(i));
        scaleX *= div;
        scaleY *= div;
#else
        plConst(float) kMinScale(0.25f);
        plConst(float) kMaxScale(0.75f);
        if( i ) 
        {
            float scale = sRand.RandRangeF(kMinScale, kMaxScale);
            scaleX *= scale;
            scaleY *= scale;
        }
#endif

        fCutter->SetLength(hsVector3(scaleX, scaleY, bull->Range()));
        fCutter->Set(pos, up, -bull->Dir());

        plDynaDecalInfo& info = IGetDecalInfo(uintptr_t(this), GetKey());

        if( bull->PartyTime() > 0 )
            fPartyTime = bull->PartyTime();

        double secs = hsTimer::GetSysSeconds();

        if( ICutoutTargets(secs) )
            info.fLastTime = secs;

        fPartyTime = 0;
    
    }
    fPartyTime = partyTime;

    return true;
}