void FlightSimDemo::update() { // Find the duration of the last frame in seconds float duration = (float)TimingData::get().lastFrameDuration * 0.001f; if (duration <= 0.0f) return; // Start with no forces or acceleration. aircraft.clearAccumulators(); // Add the propeller force cyclone::Vector3 propulsion(-10.0f, 0, 0); propulsion = aircraft.getTransform().transformDirection(propulsion); aircraft.addForce(propulsion); // Add the forces acting on the aircraft. registry.updateForces(duration); // Update the aircraft's physics. aircraft.integrate(duration); // Do a very basic collision detection and response with the ground. cyclone::Vector3 pos = aircraft.getPosition(); if (pos.y < 0.0f) { pos.y = 0.0f; aircraft.setPosition(pos); if (aircraft.getVelocity().y < -10.0f) { resetPlane(); } } Application::update(); }
void FlightSimDemo::resetPlane() { aircraft.setPosition(0, 0, 0); aircraft.setOrientation(1,0,0,0); aircraft.setVelocity(0,0,0); aircraft.setRotation(0,0,0); }