bool psEffectAnchor::Update(csTicks elapsed)
{
    if(animLength < 10)
        animLength = 10;

    life += (float)elapsed;
    if(life > animLength)
        life = fmod(life,animLength);
    if(!life)
        life += animLength;

    if(keyFrames->GetSize() == 0)
        return true;

    currKeyFrame = FindKeyFrameByTime(life);
    nextKeyFrame = currKeyFrame+1;
    if(nextKeyFrame >= keyFrames->GetSize())
        nextKeyFrame = 0;

    // TOTARGET
    objTargetOffset = lerpVec(
                          csVector3(keyFrames->Get(currKeyFrame)->actions[psEffectAnchorKeyFrame::KA_TOTARGET_X],
                                    keyFrames->Get(currKeyFrame)->actions[psEffectAnchorKeyFrame::KA_TOTARGET_Y],
                                    keyFrames->Get(currKeyFrame)->actions[psEffectAnchorKeyFrame::KA_TOTARGET_Z]),
                          csVector3(keyFrames->Get(nextKeyFrame)->actions[psEffectAnchorKeyFrame::KA_TOTARGET_X],
                                    keyFrames->Get(nextKeyFrame)->actions[psEffectAnchorKeyFrame::KA_TOTARGET_Y],
                                    keyFrames->Get(nextKeyFrame)->actions[psEffectAnchorKeyFrame::KA_TOTARGET_Z]),
                          keyFrames->Get(currKeyFrame)->time, keyFrames->Get(nextKeyFrame)->time, life);

    TransformOffset(objTargetOffset);


    // POSITION
    objOffset = lerpVec(csVector3(keyFrames->Get(currKeyFrame)->actions[psEffectAnchorKeyFrame::KA_POS_X],
                                  keyFrames->Get(currKeyFrame)->actions[psEffectAnchorKeyFrame::KA_POS_Y],
                                  keyFrames->Get(currKeyFrame)->actions[psEffectAnchorKeyFrame::KA_POS_Z]),
                        csVector3(keyFrames->Get(nextKeyFrame)->actions[psEffectAnchorKeyFrame::KA_POS_X],
                                  keyFrames->Get(nextKeyFrame)->actions[psEffectAnchorKeyFrame::KA_POS_Y],
                                  keyFrames->Get(nextKeyFrame)->actions[psEffectAnchorKeyFrame::KA_POS_Z]),
                        keyFrames->Get(currKeyFrame)->time, keyFrames->Get(nextKeyFrame)->time, life);

    // adjust position by direction if there is one
    if(dir == DT_TARGET)
        objOffset = targetTransf * csVector3(-objOffset.x, objOffset.y, -objOffset.z);
    else if(dir == DT_ORIGIN)
        objOffset = posTransf * csVector3(-objOffset.x, objOffset.y, -objOffset.z);


    mesh->GetMovable()->SetPosition(objEffectPos + objBasePos + objTargetOffset + objOffset);
    //mesh->GetMovable()->SetTransform(matBase);
    mesh->GetMovable()->UpdateMove();

    return true;
}
bool psEffectObjSound::Update(csTicks elapsed)
{
    if (!anchor || !anchor->IsReady()) // wait for anchor to be ready
        return true;

    life += elapsed;
    if (life > animLength && killTime <= 0)
    {
        life %= animLength;
        if (!life)
            life += animLength;
    }

    if (killTime > 0)
    {
        killTime -= elapsed;
        if (killTime <= 0)
            return false;
    }

    if (!isAlive && life >= birth)
    {
        isAlive = true;

        iSoundControl* effectSndCtrl = soundManager->GetSndCtrl(iSoundManager::EFFECT_SNDCTRL);
        soundID = soundManager->PlaySound(soundName, true, effectSndCtrl,
                                          csVector3(0,0,0), csVector3(0,0,0), minDistSquared, maxDistSquared);
    }

    csVector3 soundPos = anchorMesh->GetMovable()->GetPosition();

    if (keyFrames->GetSize() > 0)
    {
        currKeyFrame = FindKeyFrameByTime(life);
        nextKeyFrame = (currKeyFrame + 1) % keyFrames->GetSize();

        // position
        soundPos += LERP_VEC_KEY(KA_POS,LERP_FACTOR);
    }

    // if the sound is not active the sound manager does nothing
    soundManager->SetSoundSource(soundID, soundPos);

    return true;
}
bool psEffectAnchorSocket::Update(csTicks elapsed)
{
    if(!isReady)
    {
        if(!mesh || !mesh->GetMovable())  //not valid anchor. so tell pseffect to remove us.
            return false;

        if(initPos == mesh->GetMovable()->GetFullPosition())
            return true;
        isReady = true;
    }

    life += (float)elapsed;
    if(life > animLength)
        life = fmod(life,animLength);
    if(!life)
        life += animLength;

    if(keyFrames->GetSize() == 0)
        return true;

    currKeyFrame = FindKeyFrameByTime(life);
    nextKeyFrame = currKeyFrame + 1;
    if(nextKeyFrame >= keyFrames->GetSize())
        nextKeyFrame = 0;

    // POSITION
    objOffset = lerpVec(csVector3(keyFrames->Get(currKeyFrame)->actions[psEffectAnchorKeyFrame::KA_POS_X],
                                  keyFrames->Get(currKeyFrame)->actions[psEffectAnchorKeyFrame::KA_POS_Y],
                                  keyFrames->Get(currKeyFrame)->actions[psEffectAnchorKeyFrame::KA_POS_Z]),
                        csVector3(keyFrames->Get(nextKeyFrame)->actions[psEffectAnchorKeyFrame::KA_POS_X],
                                  keyFrames->Get(nextKeyFrame)->actions[psEffectAnchorKeyFrame::KA_POS_Y],
                                  keyFrames->Get(nextKeyFrame)->actions[psEffectAnchorKeyFrame::KA_POS_Z]),
                        keyFrames->Get(currKeyFrame)->time, keyFrames->Get(nextKeyFrame)->time, life);
    csMatrix3 mat;
    mat.Identity();
    socket->SetSecondaryTransform(meshID, csReversibleTransform(mat, objOffset));

    return true;
}
Пример #4
0
bool psEffectObj::Update(csTicks elapsed)
{
    if (!anchor || !anchor->IsReady() || !anchorMesh->GetMovable()->GetSectors()->GetCount()) // wait for anchor to be ready
        return true;

    const static csMatrix3 UP_FIX(1,0,0,   0,0,1,  0,1,0);
    const static csMatrix3 billboardFix = csXRotMatrix3(-3.14f/2.0f);

    iMovable* anchorMovable = anchorMesh->GetMovable();
    iMovable* meshMovable = mesh->GetMovable();

    csVector3 anchorPosition = anchorMovable->GetFullPosition();

    life += elapsed;
    if (life > animLength && killTime <= 0)
    {
        life %= animLength;
        if (!life)
        {
            life += animLength;
        }
    }

    isAlive |= (life >= birth);

    if (isAlive)
    {
        meshMovable->SetSector(anchorMovable->GetSectors()->Get(0));
        meshMovable->SetPosition(anchorPosition);
        if (dir == DT_NONE)
        {
            matBase = anchorMovable->GetFullTransform().GetT2O();
        }
    }

    csMatrix3 matTransform;
    if (keyFrames->GetSize() == 0)
    {
        if (dir == DT_CAMERA)
        {
            // note that this is *very* expensive
            csVector3 camDir = -view->GetCamera()->GetTransform().GetO2TTranslation() 
                             + anchorPosition;
            csReversibleTransform rt;
            rt.LookAt(camDir, csVector3(0.f,1.f,0.f));
            matBase = rt.GetT2O() * UP_FIX;
        }
        else if (dir == DT_BILLBOARD)
        {
            matBase = view->GetCamera()->GetTransform().GetT2O() * billboardFix;
        }

        baseScale = scale;
        matTransform = matBase / baseScale;
    }
    else
    {
        currKeyFrame = FindKeyFrameByTime(life);
        nextKeyFrame = (currKeyFrame + 1) % keyFrames->GetSize();

        // grab and lerp values - expensive
        float lerpfactor = LERP_FACTOR;
        csVector3 lerpRot = LERP_VEC_KEY(KA_ROT,lerpfactor);
        csVector3 lerpSpin = LERP_VEC_KEY(KA_SPIN,lerpfactor);
        csVector3 objOffset = LERP_VEC_KEY(KA_POS,lerpfactor);

        // calculate rotation from lerped values - expensive
        csMatrix3 matRot = csZRotMatrix3(lerpRot.z) * csYRotMatrix3(lerpRot.y) * csXRotMatrix3(lerpRot.x);
        if (dir != DT_CAMERA && dir != DT_BILLBOARD)
        {
            matRot *= matBase;
        }

        // calculate new position
        csVector3 newPos = matRot * csVector3(-objOffset.x, objOffset.y, -objOffset.z);

        if (dir == DT_CAMERA)
        {
            // note that this is *very* expensive - again
            csVector3 camDir = -view->GetCamera()->GetTransform().GetO2TTranslation() 
                             + anchorPosition + newPos;
            csReversibleTransform rt;
            rt.LookAt(camDir, csVector3(sinf(lerpSpin.y),cosf(lerpSpin.y),0.f));
            matBase = rt.GetT2O() * UP_FIX;
            newPos = rt.GetT2O() * newPos;

            // rotate and spin should have no effect on the transform when we want it to face the camera
            matTransform = matBase;
        }
        else if (dir == DT_BILLBOARD)
        {
            matBase = view->GetCamera()->GetTransform().GetT2O() * billboardFix;
            matTransform = matBase;
        }
        else
        {
            matTransform = matRot;
            matTransform *= csZRotMatrix3(lerpSpin.z) * csYRotMatrix3(lerpSpin.y) * csXRotMatrix3(lerpSpin.x);
        }

        // SCALE
        baseScale = LERP_KEY(KA_SCALE,lerpfactor) * scale;
        matTransform /= baseScale;
    
        // adjust position
        meshMovable->SetPosition(anchorPosition+newPos);
    }

    // set new transform
    meshMovable->SetTransform(matTransform);
    meshMovable->UpdateMove();

    if (killTime > 0)
    {
        killTime -= elapsed;
        if (killTime <= 0)
            return false;
    }

    return true;
}