Пример #1
0
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();
}
Пример #2
0
void SailboatDemo::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.
    sailboat.clearAccumulators();

    // Add the forces acting on the boat.
    registry.updateForces(duration);

    // Update the boat's physics.
    sailboat.integrate(duration);

    // Change the wind speed.
    windspeed = windspeed * 0.9f + r.randomXZVector(1.0f);

    Application::update();
}