Определение состава и структуры автоматизированной системы визуализации технологических процессов, страница 7

 * This routine must be called everytime we resize our window.

 *

 *********************************************************/

void resize (int width, int height)

{

 screen_width=width; // We obtain the new screen width values and store it

 screen_height=height; // Height value

 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // We clear both the color and the depth buffer so to draw the next frame

 glViewport(0,0,screen_width,screen_height); // Viewport transformation

 glMatrixMode(GL_PROJECTION); // Projection transformation

 glLoadIdentity(); // We initialize the projection matrix as identity

 gluPerspective(45.0f,(GLfloat)screen_width/(GLfloat)screen_height,10.0f,10000.0f);

 glutPostRedisplay (); // This command redraw the scene (it calls the same routine of glutDisplayFunc)

}

/**********************************************************

 *

 * SUBROUTINE keyboard(unsigned char,int,int)

 *

 * Used to handle the keyboard input (ASCII Characters)

 *

 *********************************************************/

void keyboard (unsigned char key, int x, int y)

{

 switch (key)

 {

 case ' ':

 rotation_x_increment=0;

 rotation_y_increment=0;

 rotation_z_increment=0;

 break;

 case 'r': case 'R':

 if (filling==0)

 {

 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); // Polygon rasterization mode (polygon filled)

 filling=1;

 } 

 else

 {

 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); // Polygon rasterization mode (polygon outlined)

 filling=0;

 }

 break;

 case 'm':

 //glScaled(300.0,300.0,300.0);

 rotation_x_increment = 0;

 rotation_y_increment = 0;

 rotation_z_increment = 0;

 scale_x = scale_x*3;

 scale_y = scale_y*3;

 scale_z = scale_z *3;

 break; 

 case 'n':

 //glScaled(300.0,300.0,300.0);

 rotation_x_increment = 0;

 rotation_y_increment = 0;

 rotation_z_increment = 0;

 scale_x = scale_x *0.3;

 scale_y = scale_y * 0.3;

 scale_z = scale_z * 0.3;

 break;

 }

}

/**********************************************************

 *

 * SUBROUTINE keyboard(int,int,int)

 *

 * Used to handle the keyboard input (not ASCII Characters)

 *

 *********************************************************/

void keyboard_s (int key, int x, int y)

{

 switch (key)

 {

 case GLUT_KEY_UP:

 rotation_x_increment = rotation_x_increment +0.005;

 break;

 case GLUT_KEY_DOWN:

 rotation_x_increment = rotation_x_increment -0.005;

 break;

 case GLUT_KEY_LEFT:

 rotation_y_increment = rotation_y_increment +0.005;

 break;

 case GLUT_KEY_RIGHT:

 rotation_y_increment = rotation_y_increment -0.005;

 break;

 }

}

/**********************************************************

 *

 * SUBROUTINE display()

 *

 * This is our main rendering subroutine, called each frame

 *

 *********************************************************/

void display(void)

{

 int l_index;

 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // This clear the background color to dark blue

 glMatrixMode(GL_MODELVIEW); // Modeling transformation

 glLoadIdentity(); // Initialize the model matrix as identity

 ///

 //glTranslatef(0.0,0.0,-300); // We move the object forward (the model matrix is multiplied by the translation matrix)

 glTranslatef(0.0, 0.0, -300); // We move the object forward (the model matrix is multiplied by the translation matrix)

 rotation_x = rotation_x + rotation_x_increment;

 rotation_y = rotation_y + rotation_y_increment;

 rotation_z = rotation_z + rotation_z_increment;

 if (rotation_x > 359) rotation_x = 0;

 if (rotation_y > 359) rotation_y = 0;

 if (rotation_z > 359) rotation_z = 0;