View Full Version : gluLookAt
10-15-2008, 12:57 AM
Gidday! I am trying to move the lookAt part of gluLookat around a sphere centered on the camera. I.E By left clicking I can move my lookAt point ( like left click in WoW ).
I am a little confused about how I calculate the new positions of the lookAt point after my rotations.
Lets say my EyeXYZ = (0,0,4) so 4 back from the scene. and my current lookat point is the origin.
Now lets say I rotate my LookAt point about the camera, 45 degrees on the Y axis, and 30 on the X axis. How do i calculate the new lookAtpoint whilst ensuring its distance from the camera is always the same.
Much appreaciation 2 any replies. Thankyou.
10-15-2008, 05:30 AM
Beware this is z-up (from wikipedia)
phi and theta are your x and y angles
10-15-2008, 10:00 AM
Purespider> If I am not mistaken, these coordinates are cartesian coordinates of the new target position in the camera space (before rotations) which is not necessarly aligned with the world space.
So, I think that FreshFacedNewbie need then to transform these coordinates back in world space to be usable in the gluLookAt function.
10-15-2008, 11:29 AM
You may use it as cam's position or its lookat, not changing the position at all.
If you want to have a spherical lookat "area" that calcs would just be fine.
10-15-2008, 08:18 PM
Thanks for the replies. I'm checking out some sample code atm, will post back with a small amount of code rather than an open question.
10-15-2008, 10:54 PM
Ok I've found some very cool code, most of which I understand. This has rotation on the y axis, (no up and down).
Anyone able to explain how the middle block figures out the new values?
xLookDirection *= l; //the old normalised lookat vector
yLookDirection *= l;
zLookDirection *= l;
//only ySpeed is set to 1. Both xSpeed & zSpeed = 0
//This is because we are only rotating on the y axis.
//Don't understand this block
xNewLookDirection = (CosineAngle + (1 - CosineAngle) * xSpeed) * xLookDirection;
xNewLookDirection += ((1 - CosineAngle) * xSpeed * ySpeed - zSpeed * SineAngle)* yLookDirection;
xNewLookDirection += ((1 - CosineAngle) * xSpeed * zSpeed + ySpeed * SineAngle) * zLookDirection;
zNewLookDirection = ((1 - CosineAngle) * xSpeed * zSpeed - ySpeed * SineAngle) * xLookDirection;
zNewLookDirection += ((1 - CosineAngle) * ySpeed * zSpeed + xSpeed * SineAngle) * yLookDirection;
zNewLookDirection += (CosineAngle + (1 - CosineAngle) * zSpeed) * zLookDirection;
//add new direction vector with length, to camera position to get new lookatpoint.
xView = xPos + xNewLookDirection;
zView = zPos + zNewLookDirection;
Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.