void CHUDMessage::Update() { // Sanity checks... if (!IsVisible()) return; if (m_fScale != g_pInterfaceResMgr->GetXRatio()) SetScale(g_pInterfaceResMgr->GetXRatio()); if (m_fInitTime < 0.0f) m_fInitTime = g_pLTClient->GetTime(); if (m_fDuration > 0.0f) { float fTime = GetLifetime(); if (fTime > m_fDuration) { fTime -= m_fDuration; float fAlpha = 1.0f - (fTime / m_fFadeDur); if (fAlpha <= 0.0f) { Show(LTFALSE); return; } else SetAlpha(fAlpha); } } else Show(LTFALSE); }
void CAISenseRecorder::Record(CAISense* pAISense) { CAISenseRecord* pRecord = FACTORY_NEW(CAISenseRecord); pRecord->FromSense(pAISense); pRecord->SetLifetime(g_pLTServer->GetTime() + GetLifetime(pAISense)); m_alstpSenseRecords[pAISense->GetType()].Add(pRecord); Link(pRecord->GetObject()); }
void Shuriken::Update() { double deltaTime = GLOBAL::GetInstance().GetDeltaTime(); // Update position m_position.x += (float)(m_direction.x*m_speed*deltaTime); m_position.y += (float)(m_direction.y*m_speed*deltaTime); m_position.z += (float)(m_direction.z*m_speed*deltaTime); m_rotation.y += (float)(SHURIKEN_ROTATION_SPEED*deltaTime); // Update lifetime SetLifetime((float)(GetLifetime() - deltaTime)); }
void FireBallParticles::Init(FXMVECTOR initialPos, float fireballRadius, LPCWSTR texFilename, ID3D11Device* device, FireBallParticlesProperties p) { SetProperties(p); mFireBallEffect = new ParticleEffect(); mFireBallEffect->LoadEffect(L"FX/ParticleEffect.fx", device); Vertex::InitParticleVertLayout(device, mFireBallEffect->GetTech()); BuildFireBallParticleVB(device); XMVECTOR vel; XMFLOAT3 fVel3; for (int i = 0; i < mProperties.numParticles; ++i) { FireBallParticle newParticle; vel = XMVector3Normalize(XMVectorSet(MathHelper::RandF(-1.0f, 1.0f), MathHelper::RandF(-1.0f, 1.0f), MathHelper::RandF(-1.0f, 1.0f), 0.0f)) * fireballRadius; XMStoreFloat3(&newParticle.pos, initialPos + vel); fVel3 = GetVelocity(); vel = XMVector3Normalize(XMVectorSet(fVel3.x, fVel3.y, fVel3.z, 0.0f)) * fireballRadius; XMStoreFloat3(&newParticle.vel, vel * GetSpeedMultiplier()); float pSize = GetSize(); newParticle.size.x = pSize; newParticle.size.y = pSize; newParticle.age = 0.0f; newParticle.lifetime = GetLifetime(); newParticle.tweenSegment = 0; mFireBallParticles.push_back(newParticle); } mParticlesShown = mProperties.numParticles; D3DX11CreateShaderResourceViewFromFile(device, texFilename, 0, 0, &mFBTexture, 0); BuildBlendState(device); BuildDSState(device); }
bool FireBallParticles::Update(FXMVECTOR newPos, float fireballRadius, float dt, ID3D11DeviceContext* context) { if (!mProperties.isFire || mIsAllParticlesDead) { return true; } XMVECTOR nPos = newPos; if (mTweenPoints.size() > 0) { nPos = XMLoadFloat3(&mCurrTweenPoint); UpdateCurrentTweenPoint(dt); } XMFLOAT3 fVel3; float pSize; bool isParticleStillAlive = false; for (int i = 0; i < mFireBallParticles.size(); ++i) { XMVECTOR pos = XMLoadFloat3(&mFireBallParticles[i].pos); XMVECTOR vel = XMLoadFloat3(&mFireBallParticles[i].vel); mFireBallParticles[i].age += dt; if (mProperties.isOneShot && (mFireBallParticles[i].age >= mFireBallParticles[i].lifetime)) { continue; } else if (mFireBallParticles[i].age <= mFireBallParticles[i].lifetime) { isParticleStillAlive = true; } else if (!mProperties.isOneShot && (mFireBallParticles[i].age >= mFireBallParticles[i].lifetime)) { isParticleStillAlive = true; vel = XMVector3Normalize(XMVectorSet(MathHelper::RandF(-1.0f, 1.0f), MathHelper::RandF(-1.0f, 1.0f), MathHelper::RandF(-1.0f, 1.0f), 0.0f)) * fireballRadius; XMStoreFloat3(&mFireBallParticles[i].pos, nPos + vel); fVel3 = GetVelocity(); vel = XMVector3Normalize(XMVectorSet(fVel3.x, fVel3.y, fVel3.z, 0.0f)); float speedMult = GetSpeedMultiplier(); if (MathHelper::RandF() > 0.50f) { if (MathHelper::RandF() > 0.50f) { vel.m128_f32[0] += MathHelper::RandF(-0.4f, 0.4f); //vel.m128_f32[0] *= MathHelper::RandF(-0.06f, 0.06f); //vel.m128_f32[2] *= MathHelper::RandF(-0.06f, 0.06f); } else { vel.m128_f32[2] += MathHelper::RandF(-0.4f, 0.4f); //vel.m128_f32[0] *= MathHelper::RandF(-0.06f, 0.06f); //vel.m128_f32[2] *= MathHelper::RandF(-0.06f, 0.06f); } } XMStoreFloat3(&mFireBallParticles[i].vel, vel * speedMult); pSize = GetSize(); mFireBallParticles[i].size.x = pSize; mFireBallParticles[i].size.y = pSize; mFireBallParticles[i].age = 0.0f; mFireBallParticles[i].lifetime = GetLifetime(); pos = XMLoadFloat3(&mFireBallParticles[i].pos); vel = XMLoadFloat3(&mFireBallParticles[i].vel); } if (pos.m128_f32[1] < (nPos.m128_f32[1] + (fireballRadius * 0.60f))) { XMVECTOR s1Center = nPos; float s1Radius = fireballRadius; float currOverLap = 0.0f; XMVECTOR correction = XMVectorZero(); XMVECTOR d = s1Center - pos; float distance = sqrt((d.m128_f32[0] * d.m128_f32[0]) /*+ (d.m128_f32[1] * d.m128_f32[1])*/ + (d.m128_f32[2] * d.m128_f32[2])); //Magnitude of the difference float overLap = s1Radius - distance; if (overLap > currOverLap) // Have Collision { currOverLap = overLap; correction = XMVector3Normalize(d) * currOverLap; //correct collision by moving sphere out of box } pos += correction; } pos = pos + vel; XMStoreFloat3(&mFireBallParticles[i].pos, pos); } if (isParticleStillAlive) { UpdateFireBallParticleVB(context); } else { mIsAllParticlesDead = true; if (mProperties.isOneShot) { ResetParticles(); } } return false; }