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:
tx=cx+sin(yrot)*sin(xrot)
ty=cy+cos(yrot)*sin(xrot)
tz=cz+cos(xrot)
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?
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).]
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.
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.
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.
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…