Bezier curve describing (camera) path

Started by
5 comments, last by Zakwayda 15 years, 1 month ago
Hey there, I am working on a little prototype using a bezier curve to determine the path objects will traverse. In my prototype i use this bezier curve to control the camera movement in my scene. This movement across the bezier works fine now. My question is the following. I want the camera position on the curve to adjust itself to the position of the player in the scene. To illustrate look at the following image: I marked the top-left and bottom-right positions in the scene to illustrate where the camera should be. How would i be able to calculate the positioning of the camera relative to the player position? Thanks in advance, Ted de Vries
Advertisement
Hi,

If I understand correctly you want the camera to point to the user.

Well I would say the camera is made up of a view vectors

RightX UpX BackX 0
RightY UpY BackY 0
RightZ UpZ BackZ 0
OffsetX OffsetY OffsetZ 1


So the upvector remains unchanged
The offset vector comes from the point of the bezier curve
The Camara locaion minus the user location is the Back vector
The right vector then follows from the Up and Back vector (should make an angle of 90 degrees with both (or just the normalized back vector rotated -90 degrees).

I assume the camera would be untransformed lookig in negative Z direction with X on the right and Y pointing up.

Didn't test it though.


Ron AF Greve
Maybe i wasn't clear enough on what i wanted.

I want to calculate the position on the bezier curve depending on the position of the player in the level.

What i want to achieve with this system is predetermine the movement of the main camera in a level. And make it follow the movement of the player.
Use a Bezier that is in the players local space, and use players local to world transform on the Bezier curve as well.
Do you perhaps want the camera to stay on the Bezier path at all times, but to point towards the player, and to be as close to the player as possible while still staying on the path?
jyk,

Yes! That is exactly what i want to achieve.
Quote:Yes! That is exactly what i want to achieve.
Ok, the first step is find the parametric value corresponding to the point on the Bezier curve closest to the player position. Unfortunately, this problem isn't entirely trivial. There's a solution described in one of the original 'Graphics Gems' book, and Google should return quite a few hits for 'closest point on Bezier curve'. With a little digging, you should be able to find some pre-existing code online or elsewhere.

There may be cases where two or more points on the curve are equally close to the player. In these cases, pick the value of t that is closest to the camera's current t value (we're not worrying about re-parameterizing right now - just working with t directly should be close enough).

Now you have the camera's current t, and the target t, which gives you the current position and the target position. Computing the target orientation is fairly trivial, and can be solved easily using the atan2() function if the problem is expressed in 2-d. You can now interpolate between the two values of t and the two orientations as you see fit, so that the camera doesn't 'snap' instantly to the new transform (although, depending on the circumstances, the 'snapping' behavior may be acceptable).

This topic is closed to new replies.

Advertisement