View Full Version : "Freelok" in 3D space.

02-24-2003, 09:34 AM
Well.. as some of you maybe have noticed, I'm doing a 3D village. And things have gone quite good so far (expect for some minor problems). But.. I've aquired the following description of how to do a gluLookAt() movement.

camera location: cx,cy,cz

then the target should be:

where xrot is the rotation on the x axis
and yrot is the rotation on the y axis.

Now to the problem.. I've been trying to use and implement these calculations. But the thing won't work. Well honestly I don't know HOW to use it.
I just copied the structure into the code
and used WM_CHAR for key movement where I tried to use the formulas.. but NO.
Can someone that knows how to do good cameramovement (turning on the spot) help me?
Maybe explain how to use the formula, or even better.. give me another formula and explain it?


02-24-2003, 11:34 AM
It would probably be easier just to use glRotate and glTranslate rather than moving the camera.

glRotate(xrot, 1.0, 0.0, 0.0);
glRotate(yrot, 0.0, 1.0, 0.0);
glTranslate(cx, cy, cz);

[This message has been edited by shinpaughp (edited 02-24-2003).]

02-24-2003, 08:22 PM
yeah, it's better to leave your position on
(0,0,0) an only transform and rotate or translate the enviroment.

02-24-2003, 09:07 PM
Well.. but I want to be able to move around
in my village. that's kind of the point.
I'm already using rotation, and it just isn't the same thing!


02-24-2003, 09:23 PM
Check out www.gametutorials.com (http://www.gametutorials.com) for some great camera tuts..

edit: Rotation should give your the same results as far as I know. glulookat will just take your position and look vectors and translate/rotate the world around the camera. Plus later on when you try to push your game/app/etc to the limits, those extra (co)sins wont help too much.

[This message has been edited by chxfryer (edited 02-24-2003).]

02-25-2003, 12:06 PM
Well.. the main reason to why I don't want
to use just plain rotation on the movement
is that when rotating, the whole world rotates.. right? Then I often get "stuck" inside a house that was lying in the path of the rotation.. And quite frankly. I want to be the one rotating, NOT the whole world.

02-25-2003, 11:42 PM
gluLookAt is really cumbersome for a camera system. You should use glRotate and glTranslate.
Translating/rotating the camera is exactly the same as translating/rotating the world, except the signs are opposite and the origins are different. If it isn't working right, first try switching the order of the rotate and translate, then try negating the x, y, z and rotation values.

02-26-2003, 12:02 AM
Hi !

I think there is a misunderstanding of some form here, you can't move the "camera" in OpenGL, you always transform the world around a fixed viewer, that's how OpenGL works, if you use glRotate/glTranslate or gluLookAt does not matter then end result is the same.


02-26-2003, 02:53 PM
I agree that *maybe* you should use glRotate and glTranslate... but if you're not quite comfortable with that and you want to experiment you can try calculating the coords using the rotation and translation matrices or quaternions...

The rotation matrices (if I remember right) are:

rotation around x:
| 1 0 0 0 |
| 0 cos@ -sin@ 0 |
| 0 sin@ cos@ 0 |
| 0 0 0 1 |

rotation around y:
| cos@ 0 sin@ 0 |
| 0 1 0 0 |
|-sin@ 0 cos@ 0 |
| 0 0 0 1 |

rotation around z:
| cos@ -sin@ 0 0 |
| sin@ cos@ 0 0 |
| 0 0 1 0 |
| 0 0 0 1 |

The translation matrix is:
| 1 0 0 dx |
| 0 1 0 dy |
| 0 0 1 dz |
| 0 0 0 1 |

You would concatenate the rotation/translation matrices needed...

To use the a rotation matrix your code would look like:

angle (converted to radians):
GLfloat yaw = yrot*(PI/180.0f);

Calculate the sin/cos only once:
GLfloat sinY = sinf(yaw);
GLfloat cosY = cosf(yaw);

camera location: cx,cy,cz

Rotating around y:

02-26-2003, 11:34 PM
Okay then.. I'll try out your tips.