// ************************************************ // IntersectTest.cpp // Intersection test sample // // Author: Marcio Serolli Pinho // Email: pinho@inf.pucrs.br // Homepages: // http://www.smallvr.org // http://grv.inf.pucrs.br // http://www.inf.pucrs.br/~pinho // // Porto Alegre, Brazil, 2002. // ************************************************ #ifdef WIN32 #include #endif #include // SmallVR header file #include "SmVR.h" float WindowRatio; SmVR_CPoint User(0,0,10); // Root Object to represent the entire scene SmVR_CGeometricObject *RootObject; // Object data struct SmVR_CPoint Tri[3] = { SmVR_CPoint(0,0,0), SmVR_CPoint(10,0,0), SmVR_CPoint(10,10,0) }; // ********************************************************************** // int DrawTest(void *p) // // ********************************************************************** int DrawTest(void *p) { int i; // Draw a triangle glBegin (GL_TRIANGLES); glColor3f(1,0,0); for (i=0;i<3;i++) { glVertex3f(Tri[i].X, Tri[i].Y, Tri[i].Z); } glEnd(); return 1; } // ********************************************************************** // void PosicUser() // // // ********************************************************************** void PosicUser() { // Set the clipping volume glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(90,WindowRatio,0.01,200); // Set the user Position glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(User.X,User.Y, User.Z, User.X,User.Y, User.Z-3, 0.0f,1.0f,0.0f); } // ********************************************************************** // void reshape( int w, int h ) // trata o redimensionamento da janela OpenGL // // ********************************************************************** void reshape( int w, int h ) { // Prevent a divide by zero, when window is too short // (you cant make a window of zero width). if(h == 0) h = 1; WindowRatio = 1.0f * w / h; // Reset the coordinate system before modifying glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Set the viewport to be the entire window glViewport(0, 0, w, h); PosicUser(); } // ********************************************************************** // void display( void ) // // // ********************************************************************** void display( void ) { glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); PosicUser(); glMatrixMode(GL_MODELVIEW); RootObject->Render(); glutSwapBuffers(); } // ********************************************************************** // void keyboard ( unsigned char key, int x, int y ) // // ********************************************************************** void keyboard ( unsigned char key, int x, int y ) { switch ( key ) { case 27: exit(0); break; } } // ********************************************************************** // void init(void) // Inicializa os parāmetros globais de OpenGL // // ********************************************************************** void init(void) { glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Fundo de tela preto glColorMaterial ( GL_FRONT, GL_AMBIENT_AND_DIFFUSE ); glShadeModel(GL_SMOOTH); glColorMaterial ( GL_FRONT, GL_AMBIENT_AND_DIFFUSE ); glEnable(GL_DEPTH_TEST); glEnable ( GL_CULL_FACE ); } // ********************************************************************** // void main ( int argc, char** argv ) // // // ********************************************************************** void main ( int argc, char** argv ) { SmVR_CGeometricObject *TestObject; SmVR_CPoint aux; // GLUT initialization glutInit ( &argc, argv ); glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);// | GLUT_DOUBLE | GLUT_RGBA ); glutInitWindowPosition (0,0); glutInitWindowSize ( 700, 500 ); glutCreateWindow ( "SmallVR Test" ); // initialize OpenGL parameters init (); // initialize the library RootObject = SmVR_Init(NULL); // Create a new object TestObject = new SmVR_CGeometricObject("Test Object", DrawTest); // Add the object to the scene RootObject->AddChild(TestObject); TestObject->TranslateBy(-5,0,0); TestObject->GetPointInOCS(Tri[0],&aux,RootObject); printf("Ponto : (%6.3f, %6.3f, %6.3f)\n", aux.X, aux.Y, aux.Z); TestObject->GetPointInOCS(Tri[1],&aux,RootObject); printf("Ponto : (%6.3f, %6.3f, %6.3f)\n", aux.X, aux.Y, aux.Z); TestObject->GetPointInOCS(Tri[2],&aux,RootObject); printf("Ponto : (%6.3f, %6.3f, %6.3f)\n", aux.X, aux.Y, aux.Z); // GLUT stuff glutDisplayFunc ( display ); glutReshapeFunc ( reshape ); glutKeyboardFunc ( keyboard ); glutIdleFunc ( display ); glutMainLoop ( ); }