inline void DiGravityController::Control(DiParticleElement* particleTechnique, DiParticle* particle, float timeElapsed) { DiVec3 distance = mDerivedPosition - particle->position; float length = distance.squaredLength(); float scaleVelocity = 1.0f; if (mParentElement) scaleVelocity = mParentElement->GetParticleSystemScaleVelocity(); if (length > 0 && mParentElement) { //float force = (mGravity * particle->mass * mass) / length; float force = (scaleVelocity * mGravity * particle->mass * mass) / length; particle->direction += force * distance * timeElapsed * CalculateAffectSpecialisationFactor(particle); } }
bool DiCameraHelper::Update( float elapsed ) { if (!mEnabled) { return false; } if (mStyle == CS_FREELOOK) { DiVec3 accel = DiVec3::ZERO; if (mGoingForward) { accel += mCamera->GetDirection(); } if (mGoingBack) accel -= mCamera->GetDirection(); if (mGoingRight) accel += mCamera->GetRight(); if (mGoingLeft) accel -= mCamera->GetRight(); if (mGoingUp) accel += mCamera->GetUp(); if (mGoingDown) accel -= mCamera->GetUp(); float topSpeed = mFastMove ? mTopSpeed * 20 : mTopSpeed; if (accel.squaredLength() != 0) { accel.normalise(); mVelocity += accel * topSpeed * elapsed * 10; } else { mVelocity -= mVelocity * elapsed * 10; } float tooSmall = std::numeric_limits<float>::epsilon(); if (mVelocity.squaredLength() > topSpeed * topSpeed) { mVelocity.normalise(); mVelocity *= topSpeed; } else if (mVelocity.squaredLength() < tooSmall * tooSmall) { mVelocity = DiVec3::ZERO; } if (mVelocity != DiVec3::ZERO) { mCamera->Move(mVelocity * elapsed); } } else if (mStyle == CS_SMOOTH) { if (Driver && mMousePos.x >= 0 && mMousePos.y >= 0) { DiRenderWindow* window = Driver->GetMainRenderWindow(); int x = (mMousePos.x - window->GetWidth() / 2); int y = (mMousePos.y - window->GetHeight() / 2); DiVec3 pos = mCamera->GetPosition(); pos.x += (x - pos.x) * 0.01f; pos.y += (-y - pos.y) * 0.01f; mCamera->SetPosition(pos); mCamera->LookAt(0, 0, 0); } } return true; }