Sign in to follow this  
0beSt0

3rd Person Camera 'Shaking' Problem

Recommended Posts

0beSt0    133
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
Lord_Evil    680
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
0beSt0    133
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this