|
"camera" in 3D scene |
adamk kromm
Member #5,432
January 2005
|
if i make a 3d scene with a bunch of quads and pyramids everywhere, if i make a "camera" that i can move around the world with, do i draw the scene around the origin (0,0,0) then move the camera to where i want to view then render that. or do i draw the scene as the camera as the origin? or is there another way? ---------- |
Jonatan Hedborg
Member #4,886
July 2004
|
A camera is (afaik) just a transformation. Once you have your scene ready, modify it by the inverse of the camera matrix. Ie, if your camera is at 5,0,0 - you move all world coords by -5, 0, 0.
|
adamk kromm
Member #5,432
January 2005
|
can you give an example of how to do that. because if i remember correctly i tried it with glTranslatef(...) and glRotatef(...) before i did allegro_gl_flip(), and it didnt have an effect. ---------- |
Jonatan Hedborg
Member #4,886
July 2004
|
In openGl you could use the simple void gluLookAt( GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx, GLdouble centery, GLdouble centerz, GLdouble upx, GLdouble upy, GLdouble upz ) function. But if you dont want to.. hm. well, my ogl is a bit rusty, but before you draw your scene, do a translate in the negative of the cameras position, and then a rotate in the negative of the cameras rotation. Push this and pop it for each object you want to draw.
|
adamk kromm
Member #5,432
January 2005
|
im using allegroGL which from what i understand doesnt use GLU which that function does. is there an allegrogl function to do it? ---------- |
Jonatan Hedborg
Member #4,886
July 2004
|
There is nothing preventing you from including glu and using it. Anyway, anything you can do in openGL alone, you can do in allegroGl. AFAIK.
|
Archon
Member #4,195
January 2004
|
Quote: A camera is (afaik) just a transformation. Once you have your scene ready, modify it by the inverse of the camera matrix. Ie, if your camera is at 5,0,0 - you move all world coords by -5, 0, 0. You need to transform negative to the 'camera coords' before drawing. Just remember to use glPushMatrix and glPopMatrix rather than glLoadIdentity to reset the position of the models. Quote: im using allegroGL which from what i understand doesnt use GLU which that function does. is there an allegrogl function to do it? You can use any GLU functions with AllegroGL - and I think that AllegroGL does use GLU in multiple places. |
Jonatan Hedborg
Member #4,886
July 2004
|
Right, a bit of bad wording on my part there.
|
adamk kromm
Member #5,432
January 2005
|
ok thanks guys ill see if i can get one of them to work. EDIT:: Ok, i sorta got it to work... the thing is the moving forward and backward works, but the strafing only works some times, or only if im facing certain directions. here are the parts of the code that affect the camera movement. camera struct struct CAMERA { float xoff, yoff, zoff; float xfacing, yfacing, zfacing; float xrot, yrot; int mousex, mousey; }; input routine
setting the "view" glLoadIdentity(); glRotatef(-camera->xrot, 1.0f, 0.0f, 0.0f); glRotatef(-camera->yrot, 0.0f, 1.0f, 0.0f); gluLookAt(camera->xoff,camera->yoff,camera->zoff,camera->xfacing,camera->yfacing,camera->zfacing,0,1,0);
---------- |
|