I have a skybox with the camera currently located in the middle. When the user presses right, i would like to get the camera to rotate right and same for left. Not too sure on the way to do this. I have started of by doing

GLvoid window_special_key(int key, int x, int y)
{
switch (key) {

case KEY_RIGHT:

glutPostRedisplay();
break;

case KEY_LEFT:

glutPostRedisplay();
break;

default:
break;
}
}

Obviously, this does nothing yet. What would be the procedure to get it to rotate? I am not sure if i am to use gluLookAt and if i do, i am not too sure what numbers i need to use. Any help would be great.

dletozeun

11-28-2008, 11:43 AM

The idea is to move to the camera position and rotate around the camera vertical axis. Say that camera position is (cx, cy, cz) and y, its vertical axis.

Before rendering the whole scene, translate of (-cx, -cy, -cz), rotate around y. In terms of Opengl calls it looks like this:

glRotatef(camera_angle, 0, y, 0);
glTranslatef(-cx, -cy, -cz);

Of course this simulates only the panning movement.

nick2price

11-28-2008, 01:16 PM

i am struggling to see what call sets up my original camera position. would it be
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);or
glViewport(0,0,width,height);

What is the original function to set up a camera position?

nick2price

11-28-2008, 01:41 PM

Sorry, i have made a slight change so that my program more resembles the example i am following, which means i have no main method but creating the window myself. So for the main class, i have changed it to

Did you compile your project as a console project or as a Win32 project?. It seems that your project is set as a console project so the "special" main function is mandatory. For this case, change it for a Win32 project and all should be fine.

nick2price

11-28-2008, 02:04 PM

I am pretty sure that i set it up as a Win32 project, and if i go configuration manager, the platform is set as Win32.

If i go to linker and set it to Windows, it actually works which is strange.

trinitrotoluene

11-28-2008, 02:11 PM

Maybe,remove the #include <GL/glut.h> you don't need it.

Edit: And add #include <GL/glu.h>

nick2price

11-28-2008, 02:21 PM

That code was abit pass me anyways, so i went back to a normal main. All i have to do now is figure out where my car is. That is why i am trying to rotate the camera, because i presume the car was placed in my skybox, but who knows.

dletozeun

11-28-2008, 11:23 PM

Sorry I can not help you about your linking problem, I am not used to Win32 programming...

gluPerspective set up the projection matrix thus, tell how the geometry is projected onto the framebuffer, saying camera field of view, near, far planes...
glViewport just tells what portion of the screen that will be drawn.
So these functions may help you to initialize your camera but does not have any relation with the camera position and orientation. You need to do this by yourself transforming the whole scene.

In ReSizeGLScene, you initialize your camera depending on window size.
In DrawGLScene before drawing the scene, you need to setup the modelview matrix relating to the camera position and orientation.
You can use your own matrices, or set it with ogl transforming functions like glRotate, glTranslate, or with gluLookAt.