   Splines (Camera Path)
  Hello!I want to implement a system for defining camera paths in my application. The user should be able to specify an arbitrary curve in 3D. Then the camera will automatically follow this curve from the start to end point. Furthermore the user should be able to specify if the camera always looks at a fixed point (trivially to implement) or a seperate curve for the "look at point".1. I want to implement this system with splines, where each piecewise polynom of the spline uses a cubic hermite curve. The user just specifies points of the curve and my application will automatically create a smooth parametric spline going through the defined points. The user always defines 1 curve for the "camera position" path and an optional curve for the "look at position". Do you think my approach for a "camera path" system is a good idea?2. While I understand the mathematics of a hermite curve for ONE segment (so if I have 2 points and the corresponding tangents at these points) I do not understand how I can use hermite curves for more than 1 segment. What I want: The user defines n points in 3D and I automatically calculate a parametric natural spline S (S(t) =  [x(t), y(t), z(t)]), where each segment between 2 points is a hermite curve. Could anyone exlain me what I have to do or knows a paper which explains this?Thanks!   
Your spline is always going to be made up of N-3 segements.So if you have 4 control points, you get 1 segment. 5 Control points you get 2 segments.So lets look at that case and then i'll let you extend it to 6 points, and N points.You have a function: T hermite(T a, T b, T c, T d, float time); Where T is the type to be interpolated and time is a value between 0 and 1 indicating the interpolation value between points b and c. You'll never acheive a point of a, or d, these are the out lying control points and the reason for the N-3.So you currently have:output = hermite(points[0], points[1], points[2], points[3], t);When t > 1.0, you shift all the points down one and adjust t:output = hermite(points[1], points[2], points[3], points[4], newT);Now the interpolation will be in the second segement, or between original control points c and d.To properly linearly iterpolate the whole spline, you'll need to know the length of each segment, and the total length (which i have no idea how to compute properly/efficiently).You'd then transform your spline "time" into a points index shift (1 in the example given) and a new local "time" for that spline segment. Then just call your existing hermite function.   ;  Thanks bzroom for your answer. But to be honest your posting did not help me that much.First of all: If I have n Points P I get n-1 cubic hermite curves. The first curve from P1 to P2, the second from P2 to P3 and so on.A hermite curve doesnt take 4 points as input. It takes 2 points and 2 tangent vectors. But my problem is: I just dont have the tangent vectors at the inner points. If I could automatically derive these tangent vectors I could calculate each individual hermite curve.   ;  The "tangent vectors" thing is just an alternate way of representing the control points for a hermite spline.  If p0 is your start point and p3 is your end point, then the first tangent vector points from p0 to p1.  Then your second tangent vector points from p3 to p2.  In my map editor how I do it is the user just positions these control points, but I draw lines from p0 to p1 and p3 to p2 to make it look more like it does in Max.Usually what you do for extended curves is you share the last point with your first and second curve.  So if you had 7 points (p0 - p6), p0 - p3 would define the first half of your curve and then p3 - p6 would define the second half.You might want to try playing around with this demo, helps a lot with visualizing these things. [smile]   ;  schupf: What I would suggest you use is B-splines for your camera animation.linkyThey way it works is like this:You have a list of control points, preferably stored in some sort of array. Your final camera position will be the summation of 4 control points multiplied by your parametric basis function.The code for your basis function would look something a bit like this:float camX, camY, camZ;float a, b, c, d;a = -t*t*t + 3*t*t - 3*t + 1;b = 3*t*t*t + -6*t*t + 4;c = -3*t*t*t + 3*t*t + 3*t + 1;d = t*t*t;camX = (controlPoints[i-1].x*a + controlPoints.x*b + controlPoints[i+1].x*c + controlPoints[i+2].x*d)/6.0;camY = (controlPoints[i-1].y*a + controlPoints.y*b + controlPoints[i+1].y*c + controlPoints[i+2].y*d)/6.0;camZ = (controlPoints[i-1].z*a + controlPoints.z*b + controlPoints[i+1].z*c + controlPoints[i+2].z*d)/6.0;...where 0 <= t <= 1 and 1 <= i < numControlPoints - 2; If you desire a smoother camera path, then just decrease your step value for parameter t. I.e. use a smaller floating point number.If you have more questions just post and I will be happy to help you.   ;  @MJP: I am no expert in this topic, but this is what I have understood:Hermite Curve ALWAYS use 2 points and the correspoding 2 tangent vectors as the input. See: http://www.daimi.au.dk/%7Ebbc/cg05/minor/hermite.png The parmetric hermite curve in matrix notations can then be expressed as:P(t) = T * M_h * G_h, where T is the Monom matrix [t^3,  t^2,  t,  1], M_h is the hermite basis matrix (always the same) and G_h the hermite geometry vector [P1, P2, R1, R2] (R are tangent vectors)If u have 4 points instead of 2 points and 2 tangents you are dealing with bezier curves.Thats all fine and I can easily program a system that interpolates between 2 points given these 2 points and the tangent vectors. But the problem arises if I have more (in my case an arbitrary number) points. Lets say I have 5 points from p1 to p5 and I use a natural spline, so the tangent vectors R1 at P1 and R5 at P5 are zero. If I had the tangent vectors R2, R3, R4 at the inner points I could calculate all four hermite curves. But I dont have these tangent vectors. Maybe its possible to automatically calculate the inner tangent vectors by using constraints like "the second and first derivatives of 2 adjacent curves is equal" and then using the resulting tangent vectors to piecewise calculate the hermite curves. I just cant find any paper that describes how to:/ Any explanations and/or links are highly appreciated!@jjanevski: I just searched for B-splines and it looks like a B-spline does NOT pass all input points. Thats something I definitely dont want to (I think its unintuitive for the user). I definitely want that the spline passes throught ALL the points (thats what I have chosen hermite curves).Edit: Just to be sure that you know what I mean: This applet shows what I want: http://www.frank-buss.de/spline.htmln points and the spline passes all points in a smooth way[Edited by - schupf on May 7, 2009 6:58:25 PM];  [briefly skimmed other posts...]There's two basic ways to go on this: interpolated or non-interpolated. Do you want to have a curve travel exactly through points you define? Or do you want to specify control points and have the curve do a "best fit"? If you want interpolated splines, i would recommend this paper. If you want to create a b-splines, there's lots of info out there on that already.One thing you should watch out for though with cameras: If your curve segments are irregular (and they surely will be), your camera will travel slow on short segments and fast across long segments if you are using the normal parametric parameter ("t" or "u", usually). If you want constant speed across the entire spline, you need to reparameterize by arc-length, something i'm personally too scared to attempt ;-)   