Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


[Solved]Smooth Camera


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
15 replies to this topic

#1 hossainiir   Members   -  Reputation: 1043

Like
0Likes
Like

Posted 09 January 2014 - 03:26 AM

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.


خلیج تا ابد فارس

Persian Gulf


Sponsor:

#2 Rld_   Members   -  Reputation: 1601

Like
0Likes
Like

Posted 09 January 2014 - 03:36 AM

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.



#3 Solid_Spy   Members   -  Reputation: 566

Like
0Likes
Like

Posted 09 January 2014 - 03:42 AM

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.

#4 hossainiir   Members   -  Reputation: 1043

Like
0Likes
Like

Posted 09 January 2014 - 03:47 AM


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.


خلیج تا ابد فارس

Persian Gulf


#5 haegarr   Crossbones+   -  Reputation: 5234

Like
2Likes
Like

Posted 09 January 2014 - 04:52 AM

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.



#6 hossainiir   Members   -  Reputation: 1043

Like
0Likes
Like

Posted 09 January 2014 - 09:07 AM

Thanks haegarr ,very nice but it is very theortical .


خلیج تا ابد فارس

Persian Gulf


#7 haegarr   Crossbones+   -  Reputation: 5234

Like
0Likes
Like

Posted 09 January 2014 - 09:49 AM


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.



#8 hossainiir   Members   -  Reputation: 1043

Like
0Likes
Like

Posted 09 January 2014 - 10:43 AM

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.


خلیج تا ابد فارس

Persian Gulf


#9 haegarr   Crossbones+   -  Reputation: 5234

Like
0Likes
Like

Posted 09 January 2014 - 11:06 AM

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?



#10 phil_t   Crossbones+   -  Reputation: 4852

Like
2Likes
Like

Posted 09 January 2014 - 11:54 AM

I use Catmull-Rom interpolation for my smooth camera class:

http://mtnphil.wordpress.com/2012/09/13/smooth-camera-movement-for-replay/



#11 hossainiir   Members   -  Reputation: 1043

Like
0Likes
Like

Posted 09 January 2014 - 12:14 PM


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.


خلیج تا ابد فارس

Persian Gulf


#12 Kryzon   Prime Members   -  Reputation: 3433

Like
1Likes
Like

Posted 09 January 2014 - 01:21 PM

There's this article on interpolation methods:
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, 10 January 2014 - 12:29 PM.


#13 haegarr   Crossbones+   -  Reputation: 5234

Like
1Likes
Like

Posted 10 January 2014 - 02:12 AM

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, 10 January 2014 - 02:14 AM.


#14 scoy6   Members   -  Reputation: 132

Like
6Likes
Like

Posted 10 January 2014 - 01:41 PM

Hi,

 

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

Internally the camera keeps track of 4 things: a focus point (the "at" point where you are looking), a yaw rotation angle around this point, a pitch angle and a distance from the focus point.  Each frame these values are then translated into the At and From positions needed to create the camera matrix.  We use a field of view angle of 1.0 radians.

 

Each of these 4 values (at, yaw, pitch, distance) has two variables associated with it, its current value and its desired value.  The current value is used to calculate the camera matrix.  The desired value is what is set by the code (due to programmatic control or user input).  We then lerp each from the current value toward the desired value.

 

A lot of the "feel" of the Kodu camera is due to choosing the correct lerp value.  The code uses 5.0f * FrameSeconds, where FrameSeconds is the number of seconds for the current frame( 1/fps ).  If we're tracking multiple characters we slow this down a bit.  If the user is using touch input we speed it up a bit.  It's all about getting the right feel.

 

A simplified version of the Update code looks like this:

            float secs = Time.WallClockFrameSeconds;

            float blend = 5.0f * secs;
            blend = Math.Min(blend, 1.0f);

            currentPosition = MathHelper.Lerp(currentPosition, desiredPosition, blend);
            currentPitch = MathHelper.Lerp(currentPitch, desiredPitch, blend);
            currentYaw = MathHelper.Lerp(currentYaw, desiredYaw, blend);
            currentDistance = MathHelper.Lerp(currentDistance, desiredDistance, blend);

            // Calc camera matrix based on "current" values.

Let me know how this works out for you.

 

scoy

 

 



#15 hossainiir   Members   -  Reputation: 1043

Like
0Likes
Like

Posted 11 January 2014 - 12:28 AM

Thanks haegarr for reply,

 


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 .

Also i have some more question about this camera that i'll ask them.

 

Thanks.


خلیج تا ابد فارس

Persian Gulf


#16 hossainiir   Members   -  Reputation: 1043

Like
0Likes
Like

Posted 11 January 2014 - 12:21 PM

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.

biggrin.png


Edited by hossainiir, 11 January 2014 - 02:31 PM.

خلیج تا ابد فارس

Persian Gulf





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS