e8de11f141
git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@9 92aac97c-a6ce-11dd-a772-7fcde58d38e6
104 lines
3.5 KiB
C++
Executable File
104 lines
3.5 KiB
C++
Executable File
|
|
// Librairies
|
|
#include "Scene.h"
|
|
#include "Objects.h"
|
|
|
|
// Constructor of the class Scene
|
|
Scene::Scene() {
|
|
// Initialise the material specular color
|
|
mat_specular[0] = 1.0;
|
|
mat_specular[1] = 1.0;
|
|
mat_specular[2] = 1.0;
|
|
mat_specular[3] = 1.0;
|
|
|
|
// Initialize the material shininess
|
|
mat_shininess[0] = 50.0;
|
|
|
|
// Initialise the light source position
|
|
light_position[0] = 20.0;
|
|
light_position[1] = 9.0;
|
|
light_position[2] = 15.0;
|
|
light_position[3] = 0.0;
|
|
|
|
// Initialise the ambient color of the light
|
|
ambient_color[0] = 1.0;
|
|
ambient_color[1] = 1.0;
|
|
ambient_color[2] = 1.0;
|
|
ambient_color[3] = 0.7;
|
|
|
|
// Initialise the diffuse light color
|
|
white_light[0] = 1.0;
|
|
white_light[1] = 1.0;
|
|
white_light[2] = 1.0;
|
|
white_light[3] = 1.0;
|
|
|
|
// Initialise the camera angles
|
|
camera_angle1 = 0.0;
|
|
camera_angle2 = 0.0;
|
|
}
|
|
|
|
// Destructor of the class Scene
|
|
Scene::~Scene() {
|
|
|
|
}
|
|
|
|
// Init method
|
|
void Scene::init() {
|
|
glClearColor(0.0, 0.0, 0.0, 0.0); // Select the color for the background
|
|
glShadeModel(GL_SMOOTH);
|
|
glClearDepth(1.0);
|
|
|
|
// Lighting settings
|
|
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); // Specular color of the material
|
|
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); // Shininess of the material
|
|
glLightfv(GL_LIGHT0, GL_POSITION, light_position); // Position of the light source
|
|
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient_color); // Ambient color of the light
|
|
glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light); // Diffuse color of the light
|
|
glLightfv(GL_LIGHT0, GL_SPECULAR, white_light); // Specular color of the light
|
|
|
|
glEnable(GL_LIGHTING); // Activate the lighting
|
|
glEnable(GL_LIGHT0); // Activate a light source
|
|
glEnable(GL_DEPTH_TEST); // Activate the Depth buffer
|
|
}
|
|
|
|
// Display method
|
|
void Scene::display(const Context& context) const {
|
|
glClearColor(0,0,0,0);
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
glMatrixMode(GL_MODELVIEW);
|
|
glLoadIdentity();
|
|
|
|
// Define the position and the direction of the camera
|
|
gluLookAt(30,10,0,0,0,0,0,1,0);
|
|
|
|
// Rotation of the camera due to the mouse mouvement
|
|
glRotatef(camera_angle2, 0.0, 0.0, 1.0);
|
|
glRotatef(camera_angle1, 0.0, 1.0, 0.0);
|
|
|
|
// Draw all objects in the context
|
|
for(int i=0; i<context.getNbObjects(); ++i)
|
|
{
|
|
// Copy the active matrix on the matrix stack
|
|
glPushMatrix();
|
|
|
|
// Draw the object
|
|
context.getObject(i).draw();
|
|
|
|
// Remove the matrix on the top of the matrix stack
|
|
glPopMatrix();
|
|
}
|
|
|
|
// Change the buffers
|
|
SDL_GL_SwapBuffers();
|
|
}
|
|
|
|
// Reshape the window
|
|
void Scene::reshape(int width, int height) {
|
|
glViewport(0,0,width,height);
|
|
glMatrixMode(GL_PROJECTION); // Specify the matrix that will be modified
|
|
glLoadIdentity(); // Load the identity matrix before the transformations
|
|
gluPerspective(45.0, (float) width/height, 0.1f, 150.0f);
|
|
glMatrixMode(GL_MODELVIEW); // Specify the matrix that will be modified
|
|
glLoadIdentity(); // Load the identity matrix before the transformations
|
|
}
|