Jump to content
  • Advertisement
Sign in to follow this  

Camera Troubles / gluLookAt

This topic is 4317 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all, So I've decided to attempt to rewrite my camera class using quaternions, but am running into some difficulties getting my transformations to behave correctly. Currently, I'm only attempting to implement movement along the view vector, and strafing to ensure that this is setup properly before I move on. Movement along the view vector works fine, but when I try to strafe, it seems to rotate the scene towards the eyepoint, rather than moving along the local right axis of the camera. Here's my code for calculating my local right axis and moving:
fVec3 fCamera::CalculateStrafe()
	// retrieve our current orientation matrix
	fMatrix4x4 orient;
	fQuaternion quat = GetOrientation();

	return fVec3( orient[0], orient[1], orient[2] );

// Method:    Strafe
// FullName:  fCamera::Strafe
// Access:    public 
// Returns:   void
// Description: Moves the camera along the camera's local right axis
// Parameter: const int& direction
//			The direction to move the camera
//			    : 1 for RIGHT
//			    : -1 for LEFT
void fCamera::Strafe( const int& direction )
	fVec3 strafe_dir = CalculateStrafe();
	Normalize(&strafe_dir, &strafe_dir);

	strafe_dir *= (float)direction * m_move_speed;

	UpdateLocalPosition( strafe_dir );

	m_lookat_point += strafe_dir * Clock::TimeLastFrame();

Later in the application, when I attempt to render, I retrieve the parameters for gluLookAt as follows:
fMatrix4x4 fSceneGraph::GetActiveCameraOrientation()
	fMatrix4x4 ret;

	// retrieve our camera's position and orientation
	fQuaternion orient = m_active_camera->GetOrientation();
	fVec3 pos = m_active_camera->GetWorldPosition();

	// convert the camera's current orientation into matrix form

	fVec3 lookat = m_active_camera->GetLookAt();

	ret[8] = lookat.x;
	ret[9] = lookat.y ;
	ret[10] = lookat.z;

	// append our position into the translational component of our orientation matrix
	ret[12] = pos.x;
	ret[13] = pos.y;
	ret[14] = pos.z;
	ret[15] = 1.f;

	return ret;


	fMatrix4x4 camera_orient = gpApp->SCENEGRAPH->GetActiveCameraOrientation();
	gluLookAt( camera_orient[12], camera_orient[13], camera_orient[14],
			   camera_orient[8], camera_orient[9], camera_orient[10],
			   camera_orient[4], camera_orient[5], camera_orient[6] );

I'm really not sure what could be going wrong here. Any help is greatly appreciated. I can also post more code or screenshots if that will help. *Note: As a debug aide, I drew the world coordinate axis' and found that when I strafe left or right, I never can see the z-axis (the one facing directly into the camera). So it would seem my camera position is never changing, although I am specifying it and passing my updated camera position to gluLookAt. I have stepped through and also confirmed that both my lookat point and position are changing when I strafe, so I'm even more confused.* Thanks again!

Share this post

Link to post
Share on other sites
Problem solved. Turns out the error wasn't in any of the camera code, but rather how I was passing the concatenated modelviewprojection matrix to my shaders. Turns out I was multiplying my modelviewprojection matrix in the reverse order than I needed for OpenGL. It's always the small mistakes that get you!

[Edited by - dfranzi on February 14, 2007 2:31:36 PM]

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!