Skip to main content
GameDev.net gamedev.net
🔒 Locked

gluLookAt

Started by CoMaNdore Jul 15, 2004 at 5:55 PM 2 replies 600+ views
Original Post
CoMaNdore
CoMaNdore
Okay I was reading the Camera5(strafing) tutorial on www.gametutorials.com And found out that I suddenly became unsure on some vector stuff, namely the center param in gluLookAt() When he is calculating the way to move forward he does this:

	// Get the current view vector (the direction we are looking)
	CVector3 vVector = m_vView - m_vPosition;
Where m_vPosition gets passed as eye param and m_vView as center param in gluLookAt() Now comes the part that my mind wont get, why does he have to calculate the View vector? Aint the m_vView vector the view vector? And if it's not then why are he does this ? I know my math skill in vector math is poor, so plz explain it in as plain words as possible. Entire function:

///////////////////////////////// MOVE CAMERA \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
/////
/////	This will move the camera forward or backward depending on the speed
/////
///////////////////////////////// MOVE CAMERA \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*

void CCamera::MoveCamera(float speed)
{
	// Get the current view vector (the direction we are looking)
	CVector3 vVector = m_vView - m_vPosition;


/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

	// I snuck this change in here!  We now normalize our view vector when
	// moving throughout the world.  This is a MUST that needs to be done.
	// That way you don't move faster than you strafe, since the strafe vector
	// is normalized too.
	vVector = Normalize(vVector);
	
/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *


	m_vPosition.x += vVector.x * speed;		// Add our acceleration to our position's X
	m_vPosition.z += vVector.z * speed;		// Add our acceleration to our position's Z
	m_vView.x += vVector.x * speed;			// Add our acceleration to our view's X
	m_vView.z += vVector.z * speed;			// Add our acceleration to our view's Z
}

Me
Zakwayda
Zakwayda
m_vView is a position, a point in space. vVector is a vector, a direction and distance from m_vPosition to m_vView. What he's doing is figuring out what direction you need to go to move toward m_vView (the point you're looking at), and then moving you a little ways in that direction.

At least I think that's right...I just glanced over the code.
CoMaNdore
CoMaNdore
thx, jyk

"m_vView is a position, a point in space."
Made me understand it, I was so sure m_vView was a vector but as it was represented by a Vector3.
But its a point in space, and vVector is a vector from the camera position to the center_viewpoint.
Me

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.