Followers 0

# [Solved]Smooth Camera

## 15 posts in this topic

Hi and happy new year,

I want to create a smooth camera for my application like Kodu's camera, any one has any information or idea how can I do that???

indeed my camera works fine but isn't smooth.

Thanks.

0

##### Share on other sites

I don't know how Kodu's camera works, but my best bet would be to use a lerp with some damping/springiness applied to it.

You are likely to find plenty of examples if you search for "Smooth camera movement using X" where X stands for the language/engine/framework/something you are using.

0

##### Share on other sites
Smooth hm, sounds like you may want to use slerping for rotation, and lerping for movement. I've never looked at Kudo's camera, but thats what I would do if I wanted to smooth anything.
0

##### Share on other sites

but my best bet would be to use a lerp with some damping/springiness applied to it.

Thanks Rld_ I tried to use Lerp but I couldn't get acceptable smoothness.

0

##### Share on other sites

I don't know about Kodu's camera system. However, linear interpolation gives smoothness between key values, but it does not do so when key values are crossed. You need to use another interpolation scheme. Which exactly depends on which kind and degree of smoothness you want. There are 2 (not mutual exclusive) types: Geometric continuity Gn and parametric continuity Cn

G0 means that the the segments on both sides of a key just join; G1 means that they join and their tangents are equal in direction; if both tangents are also equal in magnitude then they are C1 continuous; if the direction and magnitude are equal in the n-th derivative then they are Cn continuous.

So why all this? Lerp gives you G0 / C0 continuity. But you don't want the direction change, so you want at least G1 continuity. Is this sufficient? Probably not, because if you don't have C1 continuity, the position of the camera is smooth but its speed is not. Further, if you don't have C2 continuity the acceleration of the camera will not be smooth when crossing key values.

That said, there are some parametric cubic curves / splines that may do what you want. Hermite and Bezier splines both have C0 / G0 continuity, so they are smooth inside their span but jump as Lerp does when going to the next span. Catmull-Rom and Kochanek-Bartels splines both have  C1 / G1 continuity. And both uniform and non-uniform B-splines have C2 / G2 continuity.

2

##### Share on other sites

Thanks haegarr ,very nice but it is very theortical .

0

##### Share on other sites

Thanks haegarr ,very nice but it is very theortical .

Well, I don't know how you are currently doing things, so a concrete answer requires more details...

What I meant so far is that if you do interpolation on the fly, i.e. you have not continuous animation paths at hand but just supporting points, then the smoothness depends on the interpolation function you use. There are many interpolation functions out there. So far you seem to use a linear polynomial. That has problems at the supporting points because although the position is continuous when crossing the point, the orientation (and other parameters) has not. Using another interpolation function like the said splines (which are essentially cubic polynomials) does suiting the problem better, depending on the type of spline.

The above suggestion is based on the fact in a previous post linear interpolation was mentioned and you have tried it with no satisfactorily success. If your problem is related to something else, then please tell us.

0

##### Share on other sites

Let me give you more detail, I have a strategic camera that look from a distance above of a terrain, by holding mouse button and moving the mouse camera can move toward x and z, because of discontinuity in reading mouse position the camera movement will be discontinuity.

0

##### Share on other sites

Has the camera approximately pass through all the intermediate support points drawn by the mouse sampling? E.g. if you "draw" a right angles gesture with the mouse, should the camera move more-or-less right angled, too, or should it move in a wide arc, or should it move from its own current position immediately to the position marked by the mouse (i.e. ignoring intermediate support points because they are obsoleted), ever with a smooth motion in mind, of course?

0

##### Share on other sites

E.g. if you "draw" a right angles gesture with the mouse, should the camera move more-or-less right angled, too, or should it move in a wide arc, or should it move from its own current position immediately to the position marked by the mouse (i.e. ignoring intermediate support points because they are obsoleted), ever with a smooth motion in mind, of course?

It should move from current position to next mouse position with more right angle.

I use Catmull-Rom interpolation for my smooth camera class:
http://mtnphil.wordpress.com/2012/09/13/smooth-camera-movement-for-replay/

Thanks phil_t I will check it.

0

##### Share on other sites
http://sol.gfxile.net/interpolation/

Let me give you more detail, I have a strategic camera that look from a distance above of a terrain, by holding mouse button and moving the mouse camera can move toward x and z, because of discontinuity in reading mouse position the camera movement will be discontinuity.

A simple way to handle this is to have the camera be translated with the following:

float p = 0.1
float threshold = 0.001

vector3 smoothOffset = ( target.position - camera.position ) * p
smoothOffset = ( ( smoothOffset.length() > threshold ) ? smoothOffset : target.position )

camera.move( smoothOffset )


The bigger the difference between 'targetPosition' and 'currentPosition,' the faster the camera will move. The smaller the difference, the slower it will move. This produces a fast-in, ease-out behaviour, which is quite common.
The 'p' value controls how fast it arrives at the 'targetPosition.' Note that with any value below '1.0' the camera will never exactly reach the "limit" target position, so you can implement a snapping to the target position so that it does. Edited by Kryzon
1

##### Share on other sites

Well, three kinds of sources that may cause discontinuities come to my mind. Let's assume a mouse movement in a slight arc.

1.) Crossing a support point requires the movement immediately before and after the point to be identical. That means continuity and is already mentioned in the posts above.

2.) Due to "jitter" in using the mouse, the sampled points may lie slightly left or right of the wanted arc. I don't assume real outliers there, so outlier rejection is probably not necessary. *If* such aberrations are noticeable, some kind of curve fitting has to be done: I.e. you don't require the support points to be touched but approximated only.

3.) Due to temporarily irregular sampling w.r.t. the mouse movement speed, the path segments from one support point to the next are irregular. Moving on an interpolated path with a fixed time per segment means a different speed per segment. This can be overcome with a re-parametrization for the movement, i.e. the length of the segments is measured and the position is then calculated considering a given speed.

Edited by haegarr
1

##### Share on other sites

I wrote the camera code in Kodu so I can tell you exactly what it's doing.

Really !?

I love this camera,it's very smooth and nice, now i'm a little busy i'll check your method and tell you the response .

Thanks.

0

##### Share on other sites

Thanks a lot Scoy.

It worked very fine now I have a smooth camera!!!

And also I have no question to ask every thing was clear.

Thank you again.

Edited by hossainiir
0

## Create an account

Register a new account