0
Ich habe diesen Code erstellt, um ein Objekt zu zeichnen und es in Richtung x, y oder z entsprechend den Tastaturtasten zu verschieben.OpenGL-Funktion gibt keinen Fehler aus, funktioniert aber nicht
Es funktioniert perfekt und gibt keinen Fehler aus, aber das Objekt erscheint nur ohne Bewegung. Hier
ist der Code:
#include <GL/glut.h>
static GLint rotate = 0;
static GLint axis = 0;
static int xDegrees = 0;
static int yDegrees = 0;
static int zDegrees = 0;
static int direction = 0;
static int stop = 0;
void specialKeyboard(int axis, int x, int y)
{
switch(axis)
{
case GLUT_KEY_RIGHT:
direction = 1;
break;
case GLUT_KEY_LEFT:
direction = -1;
break;
}
}
void change(int* degrees)
{
*degrees = ((*degrees) + direction) % 360;
}
void rotate1()
{
switch(axis)
{
case '0':
change(&xDegrees);
break;
case '1':
change(&yDegrees);
break;
case '2':
change(&zDegrees);
break;
}
glutPostRedisplay();
}
void keyboard(unsigned char key, int x, int y)
{
switch(key)
{
case 'x':
axis = 0;
glutIdleFunc(rotate1);
stop = 0;
break;
case 'y':
axis = 1;
glutIdleFunc(rotate1);
stop = 0;
break;
case 'z':
axis = 2;
glutIdleFunc(rotate1);
stop = 0;
break;
case 's':
stop = !stop;
if(stop)
glutIdleFunc(NULL);
else
glutIdleFunc(rotate1);
break;
}
}
void resize(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(50., w/(double)h, 1., 10.);
glMatrixMode(GL_MODELVIEW);
}
void render()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
// Rotate the teapot
glRotatef(xDegrees, 1, 0, 0);
glRotatef(yDegrees, 0, 1, 0);
glRotatef(zDegrees, 0, 0, 1);
glColor3f(1.0, 1.0, 1.0);
glutWireTeapot(1.5);
glutSwapBuffers();
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutInitWindowSize(640, 480);
glutCreateWindow("IVI - Sesion 2");
glEnable(GL_DEPTH_TEST);
glutDisplayFunc(render);
glutReshapeFunc(resize);
glutKeyboardFunc(keyboard);
glutSpecialFunc(specialKeyboard);
glutMainLoop();
return 0;
}
Bestätigt durch 'static GLint axis = 0;' und nicht 'static GLint axis = '0';' und durch die Funktion 'keyboard', die' axis = 1; 'und nicht' axis = '1'; ' –
Yeha Ich habe es getan, aber kein Ergebnis. Immer noch das gleiche – tararam
@tataram drücken Sie x, y oder z? Die Teekanne wird durch die Ereignisse der Tastatur bewegt, sie funktioniert für mich. –