bool psEffectObjMesh::Update(csTicks elapsed) { if (!anchor || !anchor->IsReady()) // wait for anchor to be ready return true; if (!psEffectObj::Update(elapsed)) return false; if (keyFrames->GetSize() == 0) return true; // COLOUR float lerpfactor = LERP_FACTOR; csVector3 lerpColour = LERP_VEC_KEY(KA_COLOUR,lerpfactor); mesh->GetMeshObject()->SetColor(csColor(lerpColour.x, lerpColour.y, lerpColour.z)); // ALPHA if (mixmode == CS_FX_ALPHA) { float lerpAlpha = LERP_KEY(KA_ALPHA,lerpfactor); sprState->SetMixMode(CS_FX_SETALPHA(lerpAlpha)); } return true; }
bool psEffectObjSpire::Update(csTicks elapsed) { if(!anchor || !anchor->IsReady()) // wait for anchor to be ready return true; if(!psEffectObj::Update(elapsed)) return false; //float scale = 1; float topScale = 1; float height = 1; float padding = 1; if(keyFrames->GetSize() > 0) { // COLOUR float lerpfactor = LERP_FACTOR; csVector3 lerpColour = LERP_VEC_KEY(KA_COLOUR,lerpfactor); float lerpAlpha = LERP_KEY(KA_ALPHA,lerpfactor); for(int a=0; a<vertCount; ++a) colour[a].Set(lerpColour.x, lerpColour.y, lerpColour.z, lerpAlpha); topScale = LERP_KEY(KA_TOPSCALE,lerpfactor); height = LERP_KEY(KA_HEIGHT,lerpfactor); padding = LERP_KEY(KA_PADDING,lerpfactor); } CalculateData(shape, segments, vert, texel, topScale, height, padding); 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 psEffectObjStar::Update(csTicks elapsed) { if (!anchor || !anchor->IsReady()) // wait for anchor to be ready return true; if (!psEffectObj::Update(elapsed)) return false; float topScale = 1.0f; float height = 1.0f; csVector3 lerpColour = csVector3(1,1,1); float lerpAlpha = 1; if (keyFrames->GetSize() > 0) { // COLOUR float lerpfactor = LERP_FACTOR; lerpColour = LERP_VEC_KEY(KA_COLOUR,lerpfactor); lerpAlpha = LERP_KEY(KA_ALPHA,lerpfactor); topScale = LERP_KEY(KA_TOPSCALE,lerpfactor); height = LERP_KEY(KA_HEIGHT,lerpfactor); } for (int b=0; b<segments; ++b) { // vertex data csVector3 ray = rays[b] * height; vert[b*3 ].Set(0, 0, 0); vert[b*3+1].Set(perp[b] * -topScale + ray); vert[b*3+2].Set(perp[b] * topScale + ray); colour[b*3 ].Set(lerpColour.x, lerpColour.y, lerpColour.z, lerpAlpha); colour[b*3+1].Set(lerpColour.x, lerpColour.y, lerpColour.z, lerpAlpha); colour[b*3+2].Set(lerpColour.x, lerpColour.y, lerpColour.z, lerpAlpha); } return true; }
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; }