#104223 - DiscoStew - Wed Sep 27, 2006 6:33 am
I've been at this for a while, and even though I've only starting OpenGL in the past few days, I am getting frustrated because I am really unsure about whether or not I'm even doing this right, and I would appreciate any help that could get me pointed in the right direction if possible.
What I am trying to do in my program is make a freely moveable camera with attributes of having a 3D position and 3 axises to tilt in any direction. My problem deals with the camera position and the object positions in the scene, though I may go into other things that perhaps might be changed to help fix those problems.
As far as making the camera affected by it axis, I have the following code...
...which pretty much allows my camera to look at any angle from it's position. This seems to work until I either look straight down or straight up (which if I have read correctly creates problems unless you adjust the Up vector?), but enough of that, as I am more concerned with actual positioning.
As that function shows, I have the coordinates for the camera, as well as a place to look at that is 1 unit ahead of it, but when I go to place objects in the scene by translation, they seem to go off where the camera is, like that is where (0,0,0) is. It could be something very simple in my project that I have overlooked, but out of all the examples and tutorials I've seen, I have not seen anything that could help against this. All I want is to have my camera to not be fixed at (0,0,0), but have everything go off of that point and not the camera. Here is my actual code...
_________________
DS - It's all about DiscoStew
What I am trying to do in my program is make a freely moveable camera with attributes of having a 3D position and 3 axises to tilt in any direction. My problem deals with the camera position and the object positions in the scene, though I may go into other things that perhaps might be changed to help fix those problems.
As far as making the camera affected by it axis, I have the following code...
Code: |
gluLookAtf32( camPos.x, camPos.y, camPos.z, camPos.x, camPos.y, camPos.z - 4096, 0, 4096, 0 );
glRotatef32i( camLookAng.y, 0, 4096, 0 ); glRotatef32i( camLookAng.x, 4096, 0, 0 ); glRotatef32i( camLookAng.z, 0, 0, 4096 ); |
...which pretty much allows my camera to look at any angle from it's position. This seems to work until I either look straight down or straight up (which if I have read correctly creates problems unless you adjust the Up vector?), but enough of that, as I am more concerned with actual positioning.
As that function shows, I have the coordinates for the camera, as well as a place to look at that is 1 unit ahead of it, but when I go to place objects in the scene by translation, they seem to go off where the camera is, like that is where (0,0,0) is. It could be something very simple in my project that I have overlooked, but out of all the examples and tutorials I've seen, I have not seen anything that could help against this. All I want is to have my camera to not be fixed at (0,0,0), but have everything go off of that point and not the camera. Here is my actual code...
Code: |
int main( void )
{ *code here for initialization, cut out to not make this large* GLvector camPos = { 0, 4096, 0 }; // Set our viewport to be the same size as the screen glViewPort( 0, 0, 255, 191 ); // Specify the Clear Color and Depth glClearColor( 0, 255, 0 ); glClearDepth( 0x7FFF ); while(1) { // Reset the screen and setup the view glReset(); glMatrixMode( GL_PROJECTION ); gluPerspective( 35, 256.0 / 192.0, 0.1, 100 ); gluLookAtf32( camPos.x, camPos.y, camPos.z, camPos.x, camPos.y, camPos.z - 4096, 0, 4096, 0 ); glRotatef32i( camLookAng.y, 0, 4096, 0 ); glRotatef32i( camLookAng.x, 4096, 0, 0 ); glRotatef32i( camLookAng.z, 0, 0, 4096 ); glColor3b( 255, 255, 255 ); // Set the color..not in nehe source...ds gl default will be black // Set the current matrix to be the model matrix glMatrixMode( GL_MODELVIEW ); //Push our original Matrix onto the stack (save state) glPushMatrix(); //ds specific, several attributes can be set here glPolyFmt( POLY_ALPHA(31) | POLY_CULL_NONE ); DrawGLScene(); // Pop our Matrix from the stack (restore state) glPopMatrix( 1 ); // flush to screen glFlush(); //a handy little built in function to wait for a screen refresh swiWaitForVBlank(); } return 0; } int DrawGLScene(void) { glLoadIdentity(); glTranslate3f32( 0, 0, -8192 ); glRotatef32i(0, 0, 4096, 0); glRotatef32i(0, 4096, 0, 0); glRotatef32i(0, 0, 0, 4096); glCallList( cube ); return TRUE; // Keep Going } |
_________________
DS - It's all about DiscoStew