// robotyka.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <gl\glut.h>
#include <gl\gl.h> // Biblioteka OpenGL
#include <gl\glu.h> // Biblioteka Utility
#include <gl\glaux.h> // Biblioteka AUX
//I n i c j a c j a sceny polega na ustawieniu koloru t ª a ( g lCl e a rCo l o r )
void init ( )
{
/* Czarny k o l o r c zys z c z ¡ cy */
glClearColor ( 0.0, 0.0 , 0.0 , 0.0 ) ;
//¤ Biaªy k o l o r rysowania ¤/
glColor3f ( 1.0 , 1.0 , 1.0 ) ;
//¤ Widok ortogonalny ¤/
//¤ kwadrat 2x2 o ±rodku w pocz¡tku ukªadu wspóªrzednych ¤/
glMatrixMode (GL_PROJECTION) ;
glLoadIdentity ( ) ;
//glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 );
gluPerspective(45,4/3,1,1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0,0.0,5.0, 0.0,0.0,-1.0, 0.0f,1.0f,0.0f);
}
//2.3.2 funkcja wy±wietlaj¡ca
void display ( void )
{
//¤ c z y s z c z e n i e okna ¤/
glClear (GL_COLOR_BUFFER_BIT) ;
/* t u t a j nale»y umi e ± c i ¢ kod
lub wywoªanie f u n k c j i r u s u j a c e j prymitywy
*/
//glPushMatrix();
glColor3f ( 1.0 , 0.0 , 0.0 ) ;
glBegin (GL_LINES) ; //os x (czerwony)
glVertex3f ( 0.0 , 0.0, 0.0);
glVertex3f ( 1.0 , 0.0, 0.0 ) ;
//glVertex3f ( 0.5 , 0.5 , 0.0) ;
//glVertex3f ( 0.5 , -0.5, 0.0);
glEnd ( ) ;
glColor3f ( 0.0 , 1.0 , 0.0 ) ;
glBegin (GL_LINES) ; //os y (zielony)
glVertex3f ( 0.0 , 0.0, 0.0);
glVertex3f ( 0.0 , 1.0, 0.0 ) ;
glEnd ( ) ;
glColor3f ( 0.0 , 0.0 , 1.0 ) ;
glBegin (GL_LINES) ; //os z (niebieski)
glVertex3f ( 0.0 , 0.0, 0.0);
glVertex3f ( 0.0 , 0.0, 1.0 ) ;
glEnd ( ) ;
//glPopMatrix();
///////////drugi uklad wspolrzednych
//glPushMatrix();
glColor3f ( 1.0 , 1.0 , 0.0 ) ;
glBegin (GL_LINES) ; //os n (zolty)
glVertex3f ( 0.0 , 0.0, 0.0);
glVertex3f ( 0.5 , 0.0, 0.0 ) ;
//glVertex3f ( 0.5 , 0.5 , 0.0) ;
//glVertex3f ( 0.5 , -0.5, 0.0);
glEnd ( ) ;
glColor3f ( 0.0 , 1.0 , 1.0 ) ;
glBegin (GL_LINES) ; //os o (jasnoniebieski)
glVertex3f ( 0.0 , 0.0, 0.0);
glVertex3f ( 0.0 , 0.5, 0.0 ) ;
glEnd ( ) ;
glColor3f ( 1.0 , 0.0 , 1.0 ) ;
glBegin (GL_LINES) ; //os a (sexi rozowy)
glVertex3f ( 0.0 , 0.0, 0.0);
glVertex3f ( 0.0 , 0.0, 0.5 ) ;
glEnd ( ) ;
//glPushMatrix();
glRotatef(45,0.0,1.0,1.0); /////////// <<<<<<<<<<<<<<<
//glPopMatrix();
//¤ wy±wietl scen¦ ¤/
glFlush ( ) ;
}
static void Key( unsigned char key , int x_d, int y_d)
{
switch ( key ) {
case ' 1 ' :
// zrób co± gdy k l awi s z '1 '
//glRotatef(45,0.0,0.0,1.0);
//glFlush();
glutPostRedisplay ( ) ;
break ;
case ' 2 ' :
// zrób cos gdy k l awi s z '2 '
glutPostRedisplay ( ) ;
break ;
case 27 :
// zako«cz gdy ' esc '
exit ( 0 ) ;
}
}
int main ( int argc , char* argv [ ] )
{
// i n i c j a c j a GLUT
glutInit (&argc , argv ) ;
// i n i c j a c j a OpenGL
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB) ;
//Tworzenie okna
glutInitWindowSize ( 800 , 600 ) ;
glutInitWindowPosition ( 0,0 ) ;
glutCreateWindow (" Przyklad " ) ;
//Powi¡zanie z funkc j ¡ wy±wi e t l a j ¡ c ¡
glutDisplayFunc ( display ) ;
//Powi¡zanie z funkc j ¡ obsªuguj¡ca kl awi a tur ¦
glutKeyboardFunc (Key ) ;
// i n i c j a c j a sceny
init ( ) ;
// uruchomienie gªównej p ¦ t l i programu
glutMainLoop ( ) ;
return 0 ;
}
mam taki problem, że linie które narysowałem nie chcą sie obrócić, dopiero gdy np zminimalizuje okno
I drugie pytanie: jak obrócić tylko ten drugi układ współrzędnych? W teori rozumiem, że przed nim powinienem dac glpushmatrix, a potem na końcu glpopmatrix, ale cos nie działa (w ogóle sie nie obraca nic)