ich lasse mir mit opengl eine sierpinski-pyramide zeichnen.
mit keypressed() frage ich ab ob eine taste gedrückt wird. wird eine steuertaste gedrückt, soll man das objekt von einer anderen stelle aus sehen können
w näher ran
s weiter weg
a nach links bewegen
d nach rechts bewegen
"links" nach links drehen
"rechts" nach rechts drehen
"hoch" nach oben drehen
"runter" nach unten drehen
das klappt auch schon alles ganz gut, doch leider bewegt sich das bild wenn ich auf wasd drücke leider nach +-x/+-z , ich will aber, dass es sich relativ zur "kamera" (ja, ich weiß, dass es so was nicht gibt) nach vorne hinten links rechts bewegt.
hier der code:
Code: Alles auswählen
void opengl::draw()
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//hier mus wohl noch irgendein glTranslatef hin, oder?
//aber welches, mit welchen werten?
//bahnhof
glRotatef(rotation_x, 1.0, 0.0, 0.0);
glRotatef(rotation_y, 0.0, 1.0, 0.0);
glRotatef(rotation_z, 0.0, 0.0, 1.0);
glTranslatef(translation_x, 0.0, 0.0);
glTranslatef(0.0, translation_y, 0.0);
glTranslatef(0.0, 0.0, translation_z);
//glTranslatef(0.0, 0.0, -10.0);
qglColor(Qt::white);
fkt_II(2.0);//draws siepinski
}
void opengl::keyPressEvent(QKeyEvent *event)
{
int key = event->key();
if (key == 16777234){rotation_y -= 1.0;}//links
if (key == 16777236){rotation_y += 1.0;}//rechts
if (key == 16777235){rotation_x -= 1.0;}//hoch
if (key == 16777237){rotation_x += 1.0;}//runter
if (key == 65){translation_x += 0.1;}//A
if (key == 68){translation_x -= 0.1;}//D
if (key == 87){translation_z += 0.1;}//W
if (key == 83){translation_z -= 0.1;}//S
if (key == 16777216){emit esc();}//ESC
std::cout << translation_x << "\t" << translation_y << "\t" << translation_z << std::endl;
if (rotation_x >= 360.0){rotation_x -= 360.0;}
if (rotation_x <= -360.0){rotation_x += 360.0;}
if (rotation_y >= 360.0){rotation_y -= 360.0;}
if (rotation_y <= -360.0){rotation_y += 360.0;}
updateGL();
}Vielen Dank!!!