no, not really… what i mean is encapsulate anything you don’t wan transformed or rotated in between gl(Push/Pop)Matrix()
#include <windows.h>
#include <GL/glut.h>
#include <stdio.h>
void init ();
void display (void);
void keyboard (unsigned char, int, int);
void draw (void);
void specialkeys (int, int, int);
void initializeMatrix ();
//int matrice[9][8];
int anglex = 0, angley = 0, anglez = 0, check = 0;
int m[16];
void main (int argc, char** argv)
{
glutInit (&argc, argv);
initializeMatrix ();
init ();
glutDisplayFunc (draw);
glutKeyboardFunc (keyboard);
glutSpecialFunc (specialkeys);
glutMainLoop();
}
void init (void)
{
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glMatrixMode (GL_MODELVIEW);
// creazione finestra
glutInitWindowSize (640, 480);
glutInitWindowPosition (100, 100);
glutCreateWindow (“Darcome”);
glClearDepth (1.0);// Depth Buffer Setup
glEnable (GL_DEPTH_TEST);// Enables Depth Testing
glDepthFunc (GL_LEQUAL);// The Type Of Depth Test To Do
glShadeModel (GL_SMOOTH);// Enable Smooth Shading
glClearColor (0.0, 0.0, 0.0, 0.0);// Black Background
glClearDepth (1.0f);// Depth Buffer Setup
glEnable (GL_DEPTH_TEST);// Enables Depth Testing
glDepthFunc (GL_LEQUAL);// The Type Of Depth Testing To Do
glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);// Really Nice Perspective Calculations
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
void display(void)
{
}
void keyboard (unsigned char key, int x, int y)
{
//termino il programma
if (key == 27) exit (0); // pressione tasto ESC
}
void draw (void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity ();
glTranslatef(0.0, -0.5, 0.0);
if (check == 0)
{
glRotatef (angley, 1.0, 0.0, 0.0);
glRotatef (anglex, 0.0, 1.0, 0.0);
}
else if (check == 1)
{
glRotatef (anglex, 0.0, 1.0, 0.0);
glRotatef (angley, 1.0, 0.0, 0.0);
}
glPushMatrix();
glLoadIdentity();
glTranslatef(0.0, -0.5, 0.0);
glBegin (GL_LINES);
glColor3f (1.0, 0.0, 0.0);
glVertex3f (-1.0, 0.0, 0.0);// asse X
glVertex3f (1.0, 0.0, 0.0);
glColor3f (0.0, 1.0, 0.0);
glVertex3f (0.0, 0.0, 0.0);// asse Y
glVertex3f (0.0, 1.8, 0.0);
glColor3f (1.0, 1.0, 0.0);
glVertex3f (0.0, 0.0, -1.0);// asse Z
glVertex3f (0.0, 0.0, 1.0);
glEnd ();
glPopMatrix();
// parete laterale sinistra della gamba sinistra
glColor3f (0.5, 0.5, 1.0);
glBegin (GL_QUADS);
glVertex3f (-0.5, 0.0, 0.5);
glVertex3f (-0.5, 0.0, -0.5);
glVertex3f (-0.5, 0.2, -0.25);
glVertex3f (-0.5, 0.2, 0.25);
glEnd ();
// parete laterale destra della gamba sinistra
glColor3f (1.0, 0.0, 0.4);
glBegin (GL_QUADS);
glVertex3f (-0.4, 0.0, 0.5);
glVertex3f (-0.4, 0.0, -0.5);
glVertex3f (-0.4, 0.2, -0.25);
glVertex3f (-0.4, 0.2, 0.25);
glEnd ();
// parte frontale posteriore della gamba sinistra
glColor3f (1.0, 0.0, 0.0);
glBegin (GL_QUADS);
glVertex3f (-0.5, 0.0, 0.5);
glVertex3f (-0.4, 0.0, 0.5);
glVertex3f (-0.4, 0.2, 0.25);
glVertex3f (-0.5, 0.2, 0.25);
glEnd ();
// parte frontale anteriore della gamba sinistra
glColor3f (1.0, 0.4, 0.0);
glBegin (GL_QUADS);
glVertex3f (-0.5, 0.0, -0.5);
glVertex3f (-0.4, 0.0, -0.5);
glVertex3f (-0.4, 0.2, -0.25);
glVertex3f (-0.5, 0.2, -0.25);
glEnd ();
// base superiore della gamba sinistra
glColor3f (0.0, 1.0, 0.3);
glBegin (GL_QUADS);
glVertex3f (-0.5, 0.2, 0.25);
glVertex3f (-0.4, 0.2, 0.25);
glVertex3f (-0.4, 0.2, -0.25);
glVertex3f (-0.5, 0.2, -0.25);
glEnd ();
// base inferiore della gamba sinistra
glColor3f (0.4, 0.5, 0.4);
glBegin (GL_QUADS);
glVertex3f (-0.5, 0.0, 0.5);
glVertex3f (-0.4, 0.0, 0.5);
glVertex3f (-0.4, 0.0, -0.5);
glVertex3f (-0.5, 0.0, -0.5);
glEnd ();
glutSwapBuffers ();
glFlush ();
}
void specialkeys (int key, int x, int y)
{
if (key == GLUT_KEY_F1) exit (0);
// rotazione dello “schermo” a destra
if (key == GLUT_KEY_RIGHT)
{
anglex = anglex - 30;
check = 1;
if (anglex == -360) anglex = 0;
draw ();
}
// rotazione dello “schermo” a sinistra
else if (key == GLUT_KEY_LEFT)
{
anglex = anglex + 30;
check = 1;
if (anglex == 360) anglex = 0;
draw ();
}
// rotazione dello “schermo” in su
else if (key == GLUT_KEY_UP)
{
angley = angley + 30;
check = 0;
if (angley == 360) angley = 0;
draw ();
}
// rotazione dello “schermo” in basso
else if (key == GLUT_KEY_DOWN)
{
angley = angley - 30;
check = 0;
if (angley == -360) angley = 0;
draw ();
}
}
void initializeMatrix ()
{
/*int i, j;
for (i = 0; i < 10; i++)
for (j = 0; j < 9; j++)
matrice[i][j] = 0;*/
}