Jump to content
  • Advertisement
Sign in to follow this  

3rd Person Camera 'Shaking' Problem

This topic is 4140 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

ok so i am having a problem with my 3rd person camera at the moment...im currently developing a space simulation game where you are in control of 1 ship, the ship is your character in the game so the camera is always focused on it...however my problem is that when you travel too far from the game world's origin (0,0,0) using a hyper speed feature i have implemented the values start to get extremely large...when the values get in the range of the 10000s and above, the ship appears to be 'shaking' now i know its not the actual ship thats shaking because i disabled some of the camera controls and it worked fine, no shaking...but once i re-enabled the camera functions, the shaking started again...i hope that makes sense im not sure if its my camera rotate code or the gluLookAt function but something is wrong somewhere and i cant seem to work it out...i suspected that it had somehting to do with the large ship position values but i cant be sure...any help is appreciated here is the code... My gluLookAt function

Vector eye(0.0f, 0.0f, 0.0f);  // Specifies The Location Of The Camera 	
Vector view(0.0f, 0.0f, 2.0f); // Specifies Where The Camera Is Pointing 		
Vector up(0.0f, 1.0f, 0.0f);   // Specifies Which Direction Is Up (Up On Y Axis)

gluLookAt(	eye.X() + playerShip.GetX(),	
		eye.Y() + playerShip.GetY(),	
		eye.Z() + playerShip.GetZ(),		
		view.X() + playerShip.GetX(), 
		view.Y() + playerShip.GetY(), 
		view.Z() + playerShip.GetZ(),		
		up.X(),	up.Y(), up.Z() );

Then i translate the ship

// Keep The Model In View
glTranslatef( camera->view.X(), 0.0f, camera->view.Z() );				
glTranslatef( playerShip.GetX(), playerShip.GetY(), playerShip.GetZ() );

Then my camera rotate code

//RotateAroundPoint(Vector center, float angle, float x, float y, float z)
RotateAroundPoint(view, mouseX, 0, 1, 0);	// Rotate Around The X Axis
RotateAroundPoint(view, mouseY, 1, 0, 0);	// Rotate Around The Y Axis

Share this post

Link to post
Share on other sites
You're right this sounds like a floating point precision problem.

One way to handle this is reducing the distance from the origin. OK, in space games you normally have vast areas with *huge* distances but you can overcome that precision issue by deviding space into sectors. There was an article about that in Game Programming Gems 4 (the topic was "Far Positions").

The approach is pretty simple:

Devide the space into sectors of acceptable size, e.g. 1000 x 1000 x 1000 units.
Then each position is represented by the sector id and an offset relative to that sector, e.g. from the center.
Since the sectors are all uniformly distributed (3D grid) you can calculate the "real" position from the sector id and the offset.
When rendering you set the "origin" to the center of the sector you are in and recalculate the positions of all visible objects expressing them as offsets from the base sector (the one you are in).
When travelling not too fast such updates of the position won't occur that frequently so it's not such a big CPU killer but you get rid of those precision problems.

I hope that helps a bit.

Share this post

Link to post
Share on other sites
ok i think that is the solution i was looking for...it sounds like it would definately solve my shaky cam problem now it jus needs implementing lol...i have been doing some reading up on 'far positions' and it sounds quite complex and unfortunately i dont have the text u mentioned...anyways i'll see how it goes...wish me luck & thanks for the tip

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!