- Mar 25, 2001
- 5,287
- 6
- 81
Baiscally I have to make a program which will create a spinning cube and then, it should take the user's input from the keyboard, and depending
from the input the program should switch perspective between parallel and perspective projections...
I was wondering if the idea I have will work...:?
original function:
So now I am modifying it like that:
Help
from the input the program should switch perspective between parallel and perspective projections...
I was wondering if the idea I have will work...:?
original function:
void myReshape(int w, int h) {
glViewport(0, 0, w, h);
/* Use a perspective view */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(w<=h) {
glFrustum(-2.0, 2.0, -2.0 * (GLfloat) h/ (GLfloat) w,
2.0* (GLfloat) h / (GLfloat) w, 2.0, 20.0);
} else {
glFrustum(-2.0, 2.0, -2.0 * (GLfloat) w/ (GLfloat) h,
2.0* (GLfloat) w / (GLfloat) h, 2.0, 20.0);
}
if (w <= h)
glOrtho(-2.0, 2.0, -2.0 * (GLfloat) h / (GLfloat) w,
2.0 * (GLfloat) h / (GLfloat) w, -10.0, 10.0);
else
glOrtho(-2.0 * (GLfloat) w / (GLfloat) h,
2.0 * (GLfloat) w / (GLfloat) h, -2.0, 2.0, -10.0, 10.0);
glMatrixMode(GL_MODELVIEW);
}
So now I am modifying it like that:
Will my modification work?void myReshape(unsigned char key, int w, int h) { // here use the extra parameter for keyboard keys
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
switch(key) { // switch to process the keyboard keys
case GLUT_KEY_N : //user presses N
/* Use a perspective view */
if(w<=h) {
glFrustum(-2.0, 2.0, -2.0 * (GLfloat) h/ (GLfloat) w,
2.0* (GLfloat) h / (GLfloat) w, 2.0, 20.0);
} else {
glFrustum(-2.0, 2.0, -2.0 * (GLfloat) w/ (GLfloat) h,
2.0* (GLfloat) w / (GLfloat) h, 2.0, 20.0);
}
break;
case GLUT_KEY_M : // user presses M
/* Use a parallel view */
if (w <= h){
glOrtho(-2.0, 2.0, -2.0 * (GLfloat) h / (GLfloat) w,
2.0 * (GLfloat) h / (GLfloat) w, -10.0, 10.0);
}else{
glOrtho(-2.0 * (GLfloat) w / (GLfloat) h,
2.0 * (GLfloat) w / (GLfloat) h, -2.0, 2.0, -10.0, 10.0);
}
break;
glMatrixMode(GL_MODELVIEW);
}
Help
