Results 1 to 8 of 8

Thread: Bezier curve example

  1. #1

    Bezier curve example

    Hi!
    Does anybody have any nice example for using of Bezier curves in pascal.
    I would like to use this for creating 2D based vector mesh for rendering curved roads.
    I have checked the Wiki and I belive I could write the algorithm myself.
    But the only thing I can't figure out is how I could automatically determine the number of needed curve points so that distance between these points never exceds some predefined value (finding optimal number of points needed for certain curve smothness).

    I would be verry happy if someone could provide me with some examples for this as I'm pressed with time to finish my entry for 3rdd PGD challenge.

    Thanks in advance!

  2. #2
    There was discussion about it before http://www.pascalgamedevelopment.com...hlight=catmull
    and here: http://www.pascalgamedevelopment.com...ll=1#post45456

    Current implementation for Catmull-rom curve in nxPascal:
    https://code.google.com/p/nxpascal/s.../nxMath.pas#87

    3D curve in nxMath3D.pas is not so different either:
    Code:
    function Catmull(const a,b,c,d: TVector; const delta: single): TVector;
    begin
      result.x:=nxMath.Catmull(a.x, b.x, c.x, d.x, delta);
      result.y:=nxMath.Catmull(a.y, b.y, c.y, d.y, delta);
      result.z:=nxMath.Catmull(a.z, b.z, c.z, d.z, delta);
    end;
    The advantage of this kind of curve is, that you don't need any separate keypoints. The nodes on the "road path" are all the key points you need, and the curve will go through them all.

  3. #3
    OK I now use Catmull-rom implementation that Paul made but I still have problem in determining how many segments to create to get smoth result without having to many segments.
    I also plan to use these segments in vehicle behavior (no two vehicles on same segment) so I need these segments to be of certain size (between minimal and maximal segment size).
    So how do I determine how many segments do I need?

  4. #4
    I suppose it's safest to have 3 segments per corner. 1 in the middle and 1 at each side entry point.

  5. #5
    Quote Originally Posted by User137 View Post
    I suppose it's safest to have 3 segments per corner. 1 in the middle and 1 at each side entry point.
    I think you didn't undersstand me correctly.
    I wanna know if there is a way for me to calculate how many points that form the Catmull-rom curve do I need so that the distance between them would be in some minimum/maximum range.
    I need this becouse I will be using Catmull-rom function as a guideline for creating 2d mesh for road. So if I have to litle of these pints that would be clearly visible by smal straight section that form the road cruve. And if I have to many of these ponts I'm just wasting GPU time as it will increase the number of triangles that form this 2d mesh.
    In theory larger the curve the larger number of sections/curve points it requires. But how to calculate the number of these.

  6. #6
    I only answered with way to make a curve that perfectly follows a designed game road plan. Catmull scales really well, there are no min-max and you don't need any specific spacing between them, only what your game desires. Best to test it i guess to see how it works. If you have just 1 segment in the middle of a straight, and 1 segment at the ends of it, it would (propably?) come out straight "curve" there. Just try it, see if it needs 3, 4 or 5 for long straights. Also might help if you put them near the end points.

    Also to explain Catmull function to someone less familiar with it; Function takes 4 key-point parameters, and 1 float value. The float value is always in range of 0..1, and means progressive position between second and third keypoint. Sometimes calculated key-points are not looping from end to start, and so for start of a serie like that can be given the first key point twice, same for the end.
    Last edited by User137; 12-09-2013 at 07:08 PM.

  7. #7
    PGDCE Developer Carver413's Avatar
    Join Date
    Jun 2010
    Location
    Spokane,WA,Usa
    Posts
    206
    length of line divided by size of desired triangle

  8. #8
    PGDCE Developer Carver413's Avatar
    Join Date
    Jun 2010
    Location
    Spokane,WA,Usa
    Posts
    206
    after implementing the Catmull in my own works I realize that it doesn't work quite like my bezier line routine. still I believe that a simple solution can be found
    1. create a function that will convert a multi segment line into its Catmull equivalent.
    2. create a function that will allow you to interpolate to any position on a multi segment line.
    once you have those functions then it should be fairly easy to figure out the rest. I will try to work these out if I have some time tonight since I need them for my stuff. will post the results.

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
  •