void FlightSimDemo::resetPlane() { aircraft.setPosition(0, 0, 0); aircraft.setOrientation(1,0,0,0); aircraft.setVelocity(0,0,0); aircraft.setRotation(0,0,0); }
void SailboatDemo::display() { // Clear the view port and set the camera direction glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); cyclone::Vector3 pos = sailboat.getPosition(); cyclone::Vector3 offset(4.0f, 0, 0); offset = sailboat.getTransform().transformDirection(offset); gluLookAt(pos.x+offset.x, pos.y+5.0f, pos.z+offset.z, pos.x, pos.y, pos.z, 0.0, 1.0, 0.0); glColor3f(0.6f,0.6f,0.6f); int bx = int(pos.x); int bz = int(pos.z); glBegin(GL_QUADS); for (int x = -20; x <= 20; x++) for (int z = -20; z <= 20; z++) { glVertex3f(bx+x-0.1f, 0, bz+z-0.1f); glVertex3f(bx+x-0.1f, 0, bz+z+0.1f); glVertex3f(bx+x+0.1f, 0, bz+z+0.1f); glVertex3f(bx+x+0.1f, 0, bz+z-0.1f); } glEnd(); // Set the transform matrix for the aircraft cyclone::Matrix4 transform = sailboat.getTransform(); GLfloat gl_transform[16]; transform.fillGLArray(gl_transform); glPushMatrix(); glMultMatrixf(gl_transform); // Draw the boat glColor3f(0,0,0); drawBoat(); glPopMatrix(); char buffer[256]; sprintf( buffer, "Speed %.1f", sailboat.getVelocity().magnitude() ); glColor3f(0,0,0); renderText(10.0f, 24.0f, buffer); sprintf( buffer, "Sail Control: %.1f", sail_control ); renderText(10.0f, 10.0f, buffer); }
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 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(); }
void FlightSimDemo::display() { // Clear the view port and set the camera direction glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); cyclone::Vector3 pos = aircraft.getPosition(); cyclone::Vector3 offset(4.0f+aircraft.getVelocity().magnitude(), 0, 0); offset = aircraft.getTransform().transformDirection(offset); gluLookAt(pos.x+offset.x, pos.y+5.0f, pos.z+offset.z, pos.x, pos.y, pos.z, 0.0, 1.0, 0.0); glColor3f(0.6f,0.6f,0.6f); int bx = int(pos.x); int bz = int(pos.z); glBegin(GL_QUADS); for (int x = -20; x <= 20; x++) for (int z = -20; z <= 20; z++) { glVertex3f(bx+x-0.1f, 0, bz+z-0.1f); glVertex3f(bx+x-0.1f, 0, bz+z+0.1f); glVertex3f(bx+x+0.1f, 0, bz+z+0.1f); glVertex3f(bx+x+0.1f, 0, bz+z-0.1f); } glEnd(); // Set the transform matrix for the aircraft cyclone::Matrix4 transform = aircraft.getTransform(); GLfloat gl_transform[16]; transform.fillGLArray(gl_transform); glPushMatrix(); glMultMatrixf(gl_transform); // Draw the aircraft glColor3f(0,0,0); drawAircraft(); glPopMatrix(); glColor3f(0.8f, 0.8f, 0.8f); glPushMatrix(); glTranslatef(0, -1.0f - pos.y, 0); glScalef(1.0f, 0.001f, 1.0f); glMultMatrixf(gl_transform); drawAircraft(); glPopMatrix(); char buffer[256]; sprintf( buffer, "Altitude: %.1f | Speed %.1f", aircraft.getPosition().y, aircraft.getVelocity().magnitude() ); glColor3f(0,0,0); renderText(10.0f, 24.0f, buffer); sprintf( buffer, "Left Wing: %.1f | Right Wing: %.1f | Rudder %.1f", left_wing_control, right_wing_control, rudder_control ); renderText(10.0f, 10.0f, buffer); }