Hello, i would like some help please, im making a program where i got 2 objects (a solidSphere and wireTorus), the program has specified letters (u = move up, d = move down, l = move left, k = move right) where only 1 figure its suppose to move (wich it doesnt happen, the 2 objects move), i require to move only 1 object without using the methods “pushMatrix” and “popMatrix”, any ideas? Thank you in advance. Here is my code:
#include <GL/glut.h>
#include <stdio.h>
void display(void)
{
glClearColor(1.0, 1.0, 1.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1.0,0.0,1.0) ;
glutSolidSphere(.30,20,20) ;
glColor3f(0.0,0.0,1.0);
glutWireTorus(0.25,0.75, 28, 28);
glutSwapBuffers();
}
void reshape(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION); //afecta la perspectiva de la proyección
glLoadIdentity();
gluPerspective(60.0, (GLfloat)height / (GLfloat)width, 1.0, 128.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0, 1.0, 3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
}
void keyboard(char opcion) {
switch (opcion)
{
case ‘u’:
glTranslatef(0.0f,0.1f,0.0f);
break;
case ‘d’:
glTranslatef(0.0f,-0.1f,0.0f);
break;
case ‘l’:
glTranslatef(-0.1f,0.0f,0.0f);
break;
case ‘k’:
glTranslatef(0.1f,0.0f,0.0f);
break;
case ‘f’:
if (glIsEnabled(GL_CULL_FACE))
glDisable(GL_CULL_FACE);
else
glEnable(GL_CULL_FACE);
break;
case ‘r’:
glRotatef(1.0,1.0,0.0,0.0);
break;
case 't':
glRotatef(1.0,0.0,1.0,0.0);
break;
case ‘e’:
exit(0);
break;
case ‘w’:
glRotatef(10,0.0f,0.0f,-1.0f);
break;
case ‘x’:
glRotatef(10,0.0f,0.0f,1.0f);
break;
}
glutPostRedisplay();
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
glutInitWindowSize(512, 512);
glutInitWindowPosition(20, 20);
glutCreateWindow(“TRANSFORMACIONES”);
// void display(void)
glutDisplayFunc(display);
// void reshape(int width, int height)
glutReshapeFunc(reshape);
// void keyboard(char opcion)
glutKeyboardFunc(keyboard);
glutMainLoop();
return 0;
}