r3n

Perhaps a bit of a tricky math question here...

My camera has a current position and target, and a destination position and target. I have a "process" method, which moves the position a little closer to the destination every time it's run.

This produces a smooth camera movement from point a to b... However, I want to give the user more of the scenery - as sometimes it's just looking at a wall. I plan to do this by keeping the camera target path the same, but bending the camera position path outward. Sort of like zooming out, away from the target, then back in again once the destination is reached.

I have had several attempts at this, which include adding delta values to the Z and X axis' up to 50% of the way, then subtracting the remainder, but this produces unpredictable results.

I have also tried introducing "gravity" which pulls the camera toward a position on the terrain, but this doesnt seem too stable either.

Way points was also another... but this seemed very jerky, and also unpredictable... and I'd like the path to be nice and smooth.

Has anybody had experience with doing this sort of thing Perhaps the use of geometry could be involved (I have no idea how though!).



Re: Game Technologies: Graphics Camera track bend

windozer_

r3n,

I am not sure I understand the exact effect you are trying to acheive but here is are some ideas. If you want to "pull" the camera back for a wider view, kinda like a wide-angle lens on a camera, you could use the field of view (aka. projection matrix) to manipulate the look. If you change the 2nd parameter of the D3DXMatrixPerspectiveFovLH you can achieve some change. Probably the bigger visual impact though would be to change the camera height (up vector) to raise your camera and possible a rotate function (D3DXMatrixRotationAxis) about your right vector (X Axis).

I am not sure from you post if you are allowing user input to control the player (camera) in your project, but if you are, a common theme is to have the notion of accelleration and decelleration, so if you move forward and quit moving you don't stop instantly. You can use vectors to acheive this and a "gravity" effect (which would be a negative up vector). With this you could do some calculation to determine velocity of the object and limit it when starting/stopping etc. So you can use the same routine for downward gravity motion. Along with this you would have to detect when you camera or player object is at ground level and clamp it to avoid "going underground".

In your game loop on your render or frame process you could build up these values for gravitational force and of course then what you player object force applied is (if the user was holding down the up arrow key to move forward) and the compute the difference to give you a delta velocity which you could use to apply movement to your player object. Your current camera position vector could be added to this new positon vector to give you a new location, it just a vector addition calc.

I can post code on specific areas of implemention if you need. Thanks.

Cale





Re: Game Technologies: Graphics Camera track bend

r3n

Thanks for your answer Cale.

The camera is actually automatic; the user has no control over it. Currently, I am using a "percentage from distance" to determin the speed of the camera, which acts as a kind of gravity - this works really well.

Imagine there is a room with 2 adjacent walls; and 2 points of interest are in the corner of the room on each wall... Simply moving from 1 to the other really looks quite boring as all you get to see is the corner of the room.

What I want to do is have the camera pull away from the wall, and then zoom back in again.

Any ideas based on that notion





Re: Game Technologies: Graphics Camera track bend

Bad Habit

If you¡¯re after a bit of curvature to your camera path then you could use bezier splines, you can mix them with straight lines as well.





Re: Game Technologies: Graphics Camera track bend

Jack Hoxley

Bad Habit wrote:

If you¡¯re after a bit of curvature to your camera path then you could use bezier splines, you can mix them with straight lines as well.

I second this - bezier curves, hermite splines and catmull-rom splines are all pretty easy to implement and give good results. The only slight 'problem' is that they require control points to determine the curve's shape.

Have a look around in some decent graphics textbooks - this sort of problem has been discussed 1000's and 1000's of times over the last few decades. Because there is no single correct answer (it's very context sensitive) there are a huge number of documented approaches. I don't have an exact reference, but i'm sure 1 or more of the 'game programming gems' series included methods.

hth
Jack






Re: Game Technologies: Graphics Camera track bend

r3n

Vector3 has methods CatmullRom and Hermite, perhaps I could use those to my advantage



Re: Game Technologies: Graphics Camera track bend

Jack Hoxley

r3n wrote:
Vector3 has methods CatmullRom and Hermite, perhaps I could use those to my advantage
Yes, you might as well use the provided code.

Regarding the usage of D3DX and your previous post about modifying that code - you CAN'T. Refer to my previous point about higher-order parametric curves requiring control points. Simply put: you need to provide more information to generate the curve and you can't just swap about your linear interpolation and drop in some new equations.

hth
Jack






Re: Game Technologies: Graphics Camera track bend

r3n

Hi Jack,

I've decided to use a Bezier curve as catmull-rom and hermite didn't seem to match my solution as well. I created these 2 methods to generate a coordinate on the curve where t is the desired progression. Please feel free to comment on how this may be improved! Thanks.

public static Vector3 VectorProgress(Vector3 vector1, Vector3 vector2, float progress)
{
Vector3 progressVector = Vector3.Empty;
Vector3 difference = vector1 - vector2;
difference.Multiply(progress);
return vector1 + -difference;
}

public static Vector3 Bezier(Vector3 p0, Vector3 p1, Vector3 p2, float t)
{
Vector3 q0 = VectorProgress(p0, p1, t);
Vector3 q1 = VectorProgress(p1, p2, t);
return VectorProgress(q0, q1, t);
}





Re: Game Technologies: Graphics Camera track bend

r3n

Ah, actually, I re-read your post Jack and noticed that "lerp" word. After reading up on Lerp (linear interpolation) I now realise that my VectorProgress method produces exactly the same as Vector3.Lerp. Thus, my code can be reduced to 3 lines.

public static Vector3 Bezier(Vector3 p0, Vector3 p1, Vector3 p2, float t)
{

Vector3
q0 = Vector3.Lerp(p0, p1, t);
Vector3 q1 = Vector3.Lerp(p1, p2, t);
return Vector3.Lerp(q0, q1, t);
}