Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 21

Thread: Interpolated Bezier Curves demo

  1. #11

    Re: Interpolated Bezier Curves demo

    Would be very interesting to use bezier idea in a 3D modelling tool.. increasing polygons of existing objects in smooth way or making new object entirely with control points. Problem is it can become slow or complicated when interpolating neighbour triangles/polygons.

    But something i did use the idea for is frame animation for 3D object. It looks better than "hard cornered" interpolation even though low frame count can result in model bending in unnatural ways.

  2. #12

    Re: Interpolated Bezier Curves demo

    My interest in them is to be able to use a drawing program like inkscape ( http://www.inkscape.org/ ) to create a gui for a game. Or draw vector graphic sprites, and use them as real vector shapes in the game.
    That way the gui / sprite is resolution indepenend. e.g. it should not matter if the sceen is 1024x768 or 1280x1024 pixels. If you convert drawings to bitmaps first you get blocky results at higher resolutions(monitors)

    And the most intersting things you draw with inkscape use splines as it as splines are part of the svg standard.

    Also i dont draw the splines directly i triangulate the shape the multiple splines define first into a (3d) mesh and render that instead. E.g. i should be able to export that mesh to an .obj or milkshape ascii file (but then it would become partly resolution depened as on higher resolution you might see lines that make the spline.
    So i keep the original vector shape as long as possibe and triangulate on loading the gui/level.

    Also i use splines for paths in my 3D Adventure Studio project. And in the editor i need to visualize them.

    Besides round shapes are nicer to look at then square or angled ones. So you have to invest in splines. But i am open for alternatives though.
    http://3das.noeska.com - create adventure games without programming

  3. #13

    Re: Interpolated Bezier Curves demo

    Quote Originally Posted by Delfi
    Why does everyone want to draw splines? in 99.9% of cases in games you want to have a object traveling along a spline, but it would need to be highly efficient spline evalutor to do that at runtime with a lot of objects.
    Well, actually, I was researching it a while back just for kicks. Now I'm looking back into it for my boat design software. Splines are easy for users to interact with and with the way I'm handling them calculating distance along them is made easy (just sum the distance for each point group).

  4. #14

    Re: Interpolated Bezier Curves demo

    Quote Originally Posted by User137
    Hi, just showing a different approach to the curve (called "catmull rom" actually but looks identical to yours). The function takes 4 parameters which are 4 vertices that form the curve. You want to draw the curve between points 2 and 3 while the end points 1 and 4 "lead the curve". If end point 1 equal to 2 or point 4 to 3, those simply show going straight to that direction.

    These functions are capable of doing that in 1,2 and 3 dimensions. (You get the idea though even if wanted to add 4th dimension )
    [pascal]type
    TVector2f = record x,y: single; end;
    TVector3f = record x,y,z: single; end;
    PVector2f = ^TVector2f;
    PVector3f = ^TVector3f;

    function CatmullCalc(const p0,p1,p2,p3,t: single): single;
    begin
    result:=0.5*( 2*p1+(p2-p0)*t +
    (2*p0-5*p1+4*p2-p3)*t*t +
    (3*p1-p0-3*p2+p3)*t*t*t );
    end;

    function Catmull2f(const a,b,c,d: PVector2f; const delta: single): TVector2f;
    begin
    result.x:=CatmullCalc(a.x, b.x, c.x, d.x, delta);
    result.y:=CatmullCalc(a.y, b.y, c.y, d.y, delta);
    end;

    procedure Catmull3f(res: PVector3f; const a,b,c,d: PVector3f; const delta: single);
    begin
    res^.x:=CatmullCalc(a.x, b.x, c.x, d.x, delta);
    res^.y:=CatmullCalc(a.y, b.y, c.y, d.y, delta);
    res^.z:=CatmullCalc(a.z, b.z, c.z, d.z, delta);
    end;[/pascal]
    Feel free to bring out a more optimal solution, i'm already passing vector pointers x_X
    Pretty neat

    Just for fun, I rewrote it slightly to add some interface consistency, and to optimise it a bit

    [pascal]type
    PVector1f = ^single;

    PVector2f = ^TVector2f;
    TVector2f = record
    x,y: single;
    end;

    PVector3f = ^TVector3f;
    TVector3f = record
    x,y,z: single;
    end;

    procedure CatmullRom1f(const p0,p1,p2,p3: PVector1f; const t: single; const p: PVector1f);
    var
    tt : single;
    ttt: single;
    begin
    tt := t * t;
    ttt := tt * t;
    p^ := 0.5 * (2*p1^+(p2^-p0^)*t + (2*p0^-5*p1^+4*p2^-p3^)*tt + (3*p1^-p0^-3*p2^+p3^)*ttt);
    end;

    procedure CatmullRom2f(const p0,p1,p2,p3: PVector2f; const t: single; const p: PVector2f);
    var
    tt : single;
    ttt: single;
    begin
    tt := t * t;
    ttt := tt * t;

    p^.x := 0.5 * (2*p1^.x+(p2^.x-p0^.x)*t + (2*p0^.x-5*p1^.x+4*p2^.x-p3^.x)*tt + (3*p1^.x-p0^.x-3*p2^.x+p3^.x)*ttt);
    p^.y := 0.5 * (2*p1^.y+(p2^.y-p0^.y)*t + (2*p0^.y-5*p1^.y+4*p2^.y-p3^.y)*tt + (3*p1^.y-p0^.y-3*p2^.y+p3^.y)*ttt);
    end;

    procedure CatmullRom3f(const p0,p1,p2,p3: PVector3f; const t: single; const p: PVector3f);
    var
    tt : single;
    ttt: single;
    begin
    tt := t * t;
    ttt := tt * t;

    p^.x := 0.5 * (2*p1^.x+(p2^.x-p0^.x)*t + (2*p0^.x-5*p1^.x+4*p2^.x-p3^.x)*tt + (3*p1^.x-p0^.x-3*p2^.x+p3^.x)*ttt);
    p^.y := 0.5 * (2*p1^.y+(p2^.y-p0^.y)*t + (2*p0^.y-5*p1^.y+4*p2^.y-p3^.y)*tt + (3*p1^.y-p0^.y-3*p2^.y+p3^.y)*ttt);
    p^.z := 0.5 * (2*p1^.z+(p2^.z-p0^.z)*t + (2*p0^.z-5*p1^.z+4*p2^.z-p3^.z)*tt + (3*p1^.z-p0^.z-3*p2^.z+p3^.z)*ttt);
    end;
    [/pascal]

    cheers,
    Paul

  5. #15

    Re: Interpolated Bezier Curves demo

    Quote Originally Posted by cragwolf
    Quote Originally Posted by jdarling
    I'll have to take a look and see if there is a difference in how your doing it and how I did it in my little test http://eonclash.com/ViewProduct.php?ProductID=25
    Looks like you're calculating it manually, while I'm relying on OpenGL evaluators to do it for me. And you're drawing a single Bezier curve, while I'm drawing a number of Bezier curves and making sure they join up smoothly. Good idea to let users move the points; I don't do that currently because I'm a little bit scared of solving (possibly large) simultaneous equations for every movement of the mouse!
    Hi gragwolf,
    If you look at this site:

    http://local.wasp.uwa.edu.au/~pbourk...bicbezier.html

    specifically the FAQ section near the bottom, it shows ways of calculating the control points for piece-wise bezier curves without solving simultaneous equations

    cheers,
    Paul

  6. #16

    Re: Interpolated Bezier Curves demo

    Quote Originally Posted by paul_nicholls
    Hi gragwolf,
    If you look at this site:

    http://local.wasp.uwa.edu.au/~pbourk...bicbezier.html

    specifically the FAQ section near the bottom, it shows ways of calculating the control points for piece-wise bezier curves without solving simultaneous equations
    That's cool, thanks. I often go to that site for graphics algorithms, but I must have missed this article somehow.
    [size=10px]"In science one tries to tell people, in such a way as to be understood by everyone, something that no one ever knew before. But in poetry, it's the exact opposite." -- Paul Dirac[/size]

  7. #17

    Re: Interpolated Bezier Curves demo

    Quote Originally Posted by cragwolf
    Quote Originally Posted by paul_nicholls
    Hi gragwolf,
    If you look at this site:

    http://local.wasp.uwa.edu.au/~pbourk...bicbezier.html

    specifically the FAQ section near the bottom, it shows ways of calculating the control points for piece-wise bezier curves without solving simultaneous equations
    That's cool, thanks. I often go to that site for graphics algorithms, but I must have missed this article somehow.
    No worries, and yeah, it was hard to find that article from the menu on that site

    BTW, here are a couple of more gems

    http://local.wasp.uwa.edu.au/~pbourk...interpolation/
    http://www.blackpawn.com/texts/splines/

    Actually, the blackpawn site has quite a few neat articles (http://www.blackpawn.com/texts/default.html)

    cheers,
    Paul

  8. #18

    Re: Interpolated Bezier Curves demo

    Quote Originally Posted by paul_nicholls
    Just for fun, I rewrote it slightly to add some interface consistency, and to optimise it a bit
    I dare claim that CatmullRom1f() would be more optimal if it didn't use variables tt,ttt However they reduce 9 multiplications in CatmullRom3f().

    Yes those are also more consistent, my libs aren't always like that Catmull3f used to be function too until i needed to make it much faster for realtime 3D graphics.

  9. #19

    Re: Interpolated Bezier Curves demo

    Hi all, if you are curious, I helped a user over on www.DevMaster.net who was wanting to use splines to smooth between points...

    I used the catmull-rom code from this thread in that thread along with some code snippets of an example project that does random points and draws a complete open/closed piece-wise c-spline curves between them

    http://www.devmaster.net/forums/showthread.php?p=69427

    So if you still weren't sure how to use catmull-rom splines, especially closed curves, go and take a look




    cheers,
    Paul

  10. #20

    Re: Interpolated Bezier Curves demo

    Nice work.
    [size=10px]"In science one tries to tell people, in such a way as to be understood by everyone, something that no one ever knew before. But in poetry, it's the exact opposite." -- Paul Dirac[/size]

Page 2 of 3 FirstFirst 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •