
Moving around with glulookat()...
Hi,
To move around in a world before, I was just using gltranslat(), and glrotate() with a heading that i would increase or decrease when the mouse is moved, and used some trig to move with this heading.
but with glulookat, you no longer have an angle that you are facing, so what is the best way to move around a world with glulookat?
i do have an idea in the back of my head, but i don''t think it will work
thanks,
Jack

Direction Vectors & parametric equations.
gluLookAt(camPos.x,camPos.y,camPos.z,
PointLookingAt.x,PointLookingAt.y,PointLookingAt.z,
0,1,0);
store your camera position and the point the camera is looking at in an array, then to move the camera in a certain direction by 1 unit:
// Calculate Direction Vector
DirectionVector.x = PointLookingAt.x - CamPos.x
DirectionVector.y = PointLookingAt.y - CamPos.y
DirectionVector.z = PointLookingAt.z - CamPos.z
// Find Length of DirectionVector
Mag = SquareRoot((DirectionVector.x*DirectionVector.x)+(DirectionVector.y*DirectionVector.y)+(DirectionVector.z*DirectionVector.z))
// Make DirectionVector into a unit vector (of length 1 unit)
DirectionVector.x = DirectionVector.x / Mag
DirectionVector.y = DirectionVector.y / Mag
DirectionVector.z = DirectionVector.z / Mag
// Update Camera location
CamPos.x = CamPos.x + 1*DirectionVector.x
CamPos.y = CamPos.y + 1*DirectionVector.y
CamPos.z = CamPos.z + 1*DirectionVector.z
// Update Point Co-ords which the camera is looking at
PointLookingAt.x = PointLookingAt.x + 1*DirectionVector.x
PointLookingAt.y = PointLookingAt.y + 1*DirectionVector.y
PointLookingAt.z = PointLookingAt.z + 1*DirectionVector.z
this moves you one unit in the direction of DirectionVector, thus you could rotate the DirectionVector and move in a different direction.
"You are just as irritating to me as an irrational term that accidentially creeps into your equation and cannot be factorized out."
gluLookAt(camPos.x,camPos.y,camPos.z,
PointLookingAt.x,PointLookingAt.y,PointLookingAt.z,
0,1,0);
store your camera position and the point the camera is looking at in an array, then to move the camera in a certain direction by 1 unit:
// Calculate Direction Vector
DirectionVector.x = PointLookingAt.x - CamPos.x
DirectionVector.y = PointLookingAt.y - CamPos.y
DirectionVector.z = PointLookingAt.z - CamPos.z
// Find Length of DirectionVector
Mag = SquareRoot((DirectionVector.x*DirectionVector.x)+(DirectionVector.y*DirectionVector.y)+(DirectionVector.z*DirectionVector.z))
// Make DirectionVector into a unit vector (of length 1 unit)
DirectionVector.x = DirectionVector.x / Mag
DirectionVector.y = DirectionVector.y / Mag
DirectionVector.z = DirectionVector.z / Mag
// Update Camera location
CamPos.x = CamPos.x + 1*DirectionVector.x
CamPos.y = CamPos.y + 1*DirectionVector.y
CamPos.z = CamPos.z + 1*DirectionVector.z
// Update Point Co-ords which the camera is looking at
PointLookingAt.x = PointLookingAt.x + 1*DirectionVector.x
PointLookingAt.y = PointLookingAt.y + 1*DirectionVector.y
PointLookingAt.z = PointLookingAt.z + 1*DirectionVector.z
this moves you one unit in the direction of DirectionVector, thus you could rotate the DirectionVector and move in a different direction.
"You are just as irritating to me as an irrational term that accidentially creeps into your equation and cannot be factorized out."
I do a similar thing, but i store the direction vector as unit length instead.
Here's my simple camera class that wraps gluLookAt().
Call cCamera::MoveCameraPosition() and pass which keys are down, along with the number of ticks passed since you last called it, and it will compute a unit length direction vector. Call cCamera::SetDirectionVector() to set the view matrix using these values. This enables you to compute the new position, and only move there if your collision routines say its ok.
Just make a simple header file for it, with the position and angle values and proc defs etc... or whatever
Here's the code:
Have FUN!!
FatalXC
Edited by - FatalXC on July 5, 2001 8:39:21 AM
Here's my simple camera class that wraps gluLookAt().
Call cCamera::MoveCameraPosition() and pass which keys are down, along with the number of ticks passed since you last called it, and it will compute a unit length direction vector. Call cCamera::SetDirectionVector() to set the view matrix using these values. This enables you to compute the new position, and only move there if your collision routines say its ok.
Just make a simple header file for it, with the position and angle values and proc defs etc... or whatever
Here's the code:
|
Have FUN!!
FatalXC
Edited by - FatalXC on July 5, 2001 8:39:21 AM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement