Sign in to follow this  

Trying to get constant speed

Recommended Posts

I am having some trouble figuring this out. Basically i have set up a bunch of predetermined positions on the map which i visit in some predinfined order. The camera follows the path specified. It will go to one position which i set by the center of the gluLookAt() function. The center is the direction my camera is moving. My move function is this:
void Camera::MoveForward( void )
	eye.x += (center.x - eye.x) / step;
	//eye.y += (center.y - eye.y) / step;
	eye.z += (center.z - eye.z) / step;

	center.x += (center.x  - eye.x) / step;
	//center.y += (center.y - eye.y) / step;
	center.z += (center.z - eye.z) / step;
I have commented out the y positions because i do not want it to change. A am also increasing the center position so the camera will not slow down when it gets near the position it's going to. Once it gets to that position i update the center to the next position and it continues. Now my problem is if i have say 3 positions (p1, p2, p3) i want to camera to go to. It will start at p1->p2->p3. And say the distance between p1 and p2 is 10 and the distance between p2 and p3 is 20. This means that the camera will move from p2 to p3 faster than it moved from p1 to p2. How should i fix this problem? I am thinking i should have the center position always a constant distance away from my eye position and in the direction of the next position on the map to visit. How would i do this?

Share this post

Link to post
Share on other sites
You have the right idea. What you do is take the vector (center - eye), and normalize it. You can then multiply by the speed you want. That way no matter what direction the vector is facing, it's always the same length and your camera moves at the same speed. However, you won't be able to use a constant number of steps anymore, because longer distances will take more steps at a constant speed. The step size should be changed for each segment of the path to be the distance between the two path points divided by the speed of the camera.

Share this post

Link to post
Share on other sites
You need to parameterize the curve w.r.t. time. You look like you might have already done this with your step variable. I don't really understand what you're doing with the center and eye variables - I imagine its something like

gluLookAt(eye.x, eye.y, eye.z,center.x, center.y, center.z,0,1,0);

I think what you want is something like a camera panning across a terrain in a path defined by various points. You have a couple options - you can track the center and eye points using bezier curves. Bezier curves are nice because you can create some smooth movement without creating a lot of closely spaced points.

You can just implement a short parameterization calculation. A little messier, but it gets the job done. For each point p[n] determine the distance between p[n] and p[n+1]. Divide the distance by the number of time steps tha you plan to have between each point, and that's the amount that you need to increment at each MoveForward() call. You'll have to calculate the increment for each variable center.x, center.y, ..., eye.y, eye.z

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