//static const Point3 MAX_POS(10, 5, 0); void PlayerEntity::onSimulation(GameTime absoluteTime, GameTime deltaTime) { // Do not call Entity::onSimulation; that will override with spline animation m_previousFrame = m_frame; simulatePose(absoluteTime, deltaTime); //m_velocity = m_frame.vectorToWorldSpace(m_desiredOSVelocity); //m_frame.translation += m_velocity * (float)deltaTime; if (!isNaN(deltaTime)) { slideMove(deltaTime); m_heading += m_desiredYawVelocity * (float)deltaTime; m_frame.rotation = Matrix3::fromAxisAngle(Vector3::unitY(), m_heading); m_headTilt = clamp(m_headTilt + m_desiredPitchVelocity, -pif()/2, pif()/2); } }
void PlayerEntity::onSimulation(SimTime absoluteTime, SimTime deltaTime) { // Do not call Entity::onSimulation; that will override with spline animation if (! (isNaN(deltaTime) || (deltaTime == 0))) { m_previousFrame = m_frame; } simulatePose(absoluteTime, deltaTime); if (deltaTime > 0) { // This particular game setup is like Afterburner, where the ship is locked // and math is simplified by not allowing true rotation. For free flight, // we'd have to actually compute the object to world transformations and // deal with the interaction between rotation and translation. Vector3 osVelocity = m_velocity;//m_frame.vectorToObjectSpace(m_velocity); // Clamp desire to what is allowed by this object's own forces, but allow // it to exceed "max velocity" due to external forces const Vector3& desiredOSImpulse = minMagnitude(m_desiredOSVelocity, m_maxOSVelocity) - osVelocity; // Clamp impulse in object space (work with impulses to avoid dividing and // then multiplying by deltaTime, which could be a small number and hurt precision). const Vector3& osImpulse = minMagnitude(desiredOSImpulse, m_maxOSAcceleration * float(deltaTime)); // Accelerate in object space osVelocity += osImpulse; m_velocity = osVelocity;//m_frame.vectorToWorldSpace(osVelocity); m_frame.translation += m_velocity * (float)deltaTime; // Tilt based on object space velocity const float maxRoll = 50 * units::degrees(); float osRoll = maxRoll * -m_velocity.x / m_maxOSVelocity.x; const float maxPitch = 45 * units::degrees(); float osPitch = maxPitch * m_velocity.y / m_maxOSVelocity.y; m_frame.rotation = Matrix3::fromAxisAngle(Vector3::unitX(), osPitch) * Matrix3::fromAxisAngle(Vector3::unitZ(), osRoll); m_frame.translation = m_frame.translation.clamp(-MAX_POS, MAX_POS); } }
void VisibleEntity::onSimulation(SimTime absoluteTime, SimTime deltaTime) { Entity::onSimulation(absoluteTime, deltaTime); simulatePose(absoluteTime, deltaTime); }