ich möchte ein Objekt immer um die eigene Achse drehen, also diese bei jedem Schritt auch mitrotieren.
Meine Idee ist folgende: Die gedrehten Koordinatenachsen des Objektes stehen ja in meiner MODELVIEW Matrix und zwar in der ersten Spalte die x-Achse, in der zweiten die y-Achse und in der dritten die z-Achse.
Code: Alles auswählen
glLoadIdentity( );
glTranslatef(-1.8f, 0.0f, -12.0f);
glRotatef(30.0f, 1.0f, 0.0f, 0.0f); //Um die normale X-Achse drehen (weil ja globale und lokale Objektachse übereinstimmen)
glGetFloatv(GL_MODELVIEW_MATRIX , modelview); //Modelview-Matrix holen
glRotatef(30.0f, modelview[4], modelview[5], modelview[6]); //Um die gedrehte Y-Achse des Objektes rotieren
glGetFloatv(GL_MODELVIEW_MATRIX , modelview);
glRotatef(30.0f, modelview[2], modelview[6], modelview[10]); //Und jetzt noch um die gedrehte Z-Achse drehen
//Würfel zeichnen
glBegin( GL_QUADS ); /* Draw A Quad */
glColor3f( 0.0f, 1.0f, 0.0f ); /* Set The Color To Green */
glVertex3f( 1.0f, 1.0f, -1.0f ); /* Top Right Of The Quad (Top) */
glVertex3f( -1.0f, 1.0f, -1.0f ); /* Top Left Of The Quad (Top) */
glVertex3f( -1.0f, 1.0f, 1.0f ); /* Bottom Left Of The Quad (Top) */
glVertex3f( 1.0f, 1.0f, 1.0f ); /* Bottom Right Of The Quad (Top) */
glColor3f( 1.0f, 0.5f, 0.0f ); /* Set The Color To Orange */
glVertex3f( 1.0f, -1.0f, 1.0f ); /* Top Right Of The Quad (Botm) */
glVertex3f( -1.0f, -1.0f, 1.0f ); /* Top Left Of The Quad (Botm) */
glVertex3f( -1.0f, -1.0f, -1.0f ); /* Bottom Left Of The Quad (Botm) */
glVertex3f( 1.0f, -1.0f, -1.0f ); /* Bottom Right Of The Quad (Botm) */
glColor3f( 1.0f, 0.0f, 0.0f ); /* Set The Color To Red */
glVertex3f( 1.0f, 1.0f, 1.0f ); /* Top Right Of The Quad (Front) */
glVertex3f( -1.0f, 1.0f, 1.0f ); /* Top Left Of The Quad (Front) */
glVertex3f( -1.0f, -1.0f, 1.0f ); /* Bottom Left Of The Quad (Front) */
glVertex3f( 1.0f, -1.0f, 1.0f ); /* Bottom Right Of The Quad (Front) */
glColor3f( 1.0f, 1.0f, 0.0f ); /* Set The Color To Yellow */
glVertex3f( 1.0f, -1.0f, -1.0f ); /* Bottom Left Of The Quad (Back) */
glVertex3f( -1.0f, -1.0f, -1.0f ); /* Bottom Right Of The Quad (Back) */
glVertex3f( -1.0f, 1.0f, -1.0f ); /* Top Right Of The Quad (Back) */
glVertex3f( 1.0f, 1.0f, -1.0f ); /* Top Left Of The Quad (Back) */
glColor3f( 0.0f, 0.0f, 1.0f ); /* Set The Color To Blue */
glVertex3f( -1.0f, 1.0f, 1.0f ); /* Top Right Of The Quad (Left) */
glVertex3f( -1.0f, 1.0f, -1.0f ); /* Top Left Of The Quad (Left) */
glVertex3f( -1.0f, -1.0f, -1.0f ); /* Bottom Left Of The Quad (Left) */
glVertex3f( -1.0f, -1.0f, 1.0f ); /* Bottom Right Of The Quad (Left) */
glColor3f( 1.0f, 0.0f, 1.0f ); /* Set The Color To Violet */
glVertex3f( 1.0f, 1.0f, -1.0f ); /* Top Right Of The Quad (Right) */
glVertex3f( 1.0f, 1.0f, 1.0f ); /* Top Left Of The Quad (Right) */
glVertex3f( 1.0f, -1.0f, 1.0f ); /* Bottom Left Of The Quad (Right) */
glVertex3f( 1.0f, -1.0f, -1.0f ); /* Bottom Right Of The Quad (Right) */
glEnd( ); /* Done Drawing The Quad */
Ich habe mich an diesem Tutorial orientiert: http://wiki.delphigl.com/index.php/Tuto ... hse_drehen
Gruß,
Audience