void ReSizeGLScene(int Width, int Height) { int xRange = 10, yRange = 10, zRange = 100; windowWidth=Width; windowHeight=Height; if (Height==0) Height=1; glViewport(0, 0, Width, Height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if(useMyOrtho) { if (Width <= Height) myOrtho (-xRange, xRange, -yRange*Height/Width, yRange*Height/Width, -zRange, zRange); else myOrtho (-xRange*Width/Height, xRange*Width/Height, -yRange, yRange, -zRange, zRange); } else { if (Width <= Height) glOrtho (-xRange, xRange, -yRange*Height/Width, yRange*Height/Width, -zRange, zRange); else glOrtho (-xRange*Width/Height, xRange*Width/Height, -yRange, yRange, -zRange, zRange); } /* glLoadIdentity(); gluPerspective(45.0f,(GLfloat)Width/(GLfloat)Height,0.1f,100.0f); */ glMatrixMode(GL_MODELVIEW); }
void updateProjection(int width, int height){ float projectionTransform[16]; glViewport( 0, 0, (GLsizei)width, (GLsizei)height ); double ratio = double(width) / double(height); glMatrixMode( GL_PROJECTION ); if( isPerspective && useGLPerspective){ // perspective and use OpenGL glPushMatrix( ); glLoadIdentity( ); gluPerspective(90.0, ratio, 1.0, 25.0); glGetFloatv(GL_PROJECTION_MATRIX, projectionTransform); glPopMatrix( ); }else if( isPerspective && !useGLPerspective ){ // perspective and do not use OpenGL myPerspective(projectionTransform, 90.0, ratio, 1.0, 25.0); }else if( !isPerspective && useGLPerspective ){ // orthographic and use OpenGL glPushMatrix( ); glLoadIdentity( ); glOrtho(-7.0, 7.0, -7.0, 7.0, 1.0, 25.0); glGetFloatv(GL_PROJECTION_MATRIX, projectionTransform); glPopMatrix( ); }else if( !isPerspective && !useGLPerspective ){ // orthographic and do not use OpenGL myOrtho(projectionTransform, -7.0, 7.0, -7.0, 7.0, 1.0, 25.0); } glLoadMatrixf(projectionTransform); }
int main() { //init vertex Vector3f v1 = Vector3f(0.3, 0.3, 0.3); Vector3f v2 = Vector3f(0.3, 0.3, 0.6); //print Vertex puts("Init Vertex"); PrintVertex(v1); PrintVertex(v2); //set Camera myLookAt(Vector3f(0.0, 0.0, 2.0), Vector3f(0.0, 0.0, 0.0), Vector3f(0.0, 1.0, 0.0)); //set Ortho myOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); //print Vertex puts("Ortho"); PrintVertex(DrawVertex(v1)); PrintVertex(DrawVertex(v2)); //set Frustum myFrustum(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); //print Vertex puts("Frustum"); PrintVertex(DrawVertex(v1)); PrintVertex(DrawVertex(v2)); getchar(); return 0; }
void adjustCamera(){ glMatrixMode( GL_PROJECTION ); glLoadIdentity(); if(curBallCamera){ if( balls.size() <=0 ){ myOrtho(cannonBaseX , cannonBaseY); } else{ myOrtho( balls[balls.size()-1]->ballX ,balls[balls.size()-1]->ballY); } } else if(cannonCamera){ myOrtho(cannonBaseX , cannonBaseY); } glMatrixMode(GL_MODELVIEW); glLoadIdentity(); }