Previous: 4.51.2.4.3. ogAvail() To the Table of Contents Next: 4.51.2.4.5. ogCircle()
4.51.2.4.3. ogAvail() Table of Contents 4.51.2.4.5. ogCircle()

- 4.51.2.4.4. -
Table of Contents
4. Standard Units
4.51. ObjGfx40 - ObjectGraphics 4.0 Unit
4.51.2. ObjGfx40 Unit Object Types
4.51.2.4. ogSurface object
4.51.2.4.4. ogBSpline()


4.51.2.4.4. ogBSpline()

Targets: MS-DOS, Win32 console


ObjGfx40 Unit

Draws a B-Spline.

Declaration:
  procedure ogBSpline(numPoints: uInt32; var points : array of ogPoint2d; segments, colour:uInt32);
Remarks:

Draws a B-Spline approximating a curve defined by the array of points. A B-Spline generally does not normally pass through the points defining it.

Segments is the number of line segments to use inbetween each point. The higher the number, the smoother the B-Spline looks, but the longer it takes to render.

See also: Sample Code:
{ogBSpline.pas}

uses
  ObjGfx40, CRT;

const MAX_NODES = 6;

var 
  i: uIn32;
  points: array [ 0..MAX_NODES-1 ] of ogPoint2d;
  dX, dY: array [ 0..MAX_NODES-1 ] of int32;

var 
  buf:^ogSurface;

begin
  randomize;

  new(buf, ogInit);
  if not screen^.ogCreate(640, 480, OG_PIXFMT_32BPP) then
    begin
      writeln('Error setting video mode');
      halt
    end;

  buf^.ogClone(screen^);
  
  with buf^ do
    for i:=0 to MAX_NODES-1 do
      begin
        Points[i].X := random(ogGetMaxX);
        Points[i].Y := random(ogGetMaxY);
        DX[i] := random(4)+1;
        DY[i] := random(4)+1;
      end;

  repeat
    buf^.ogClear(buf^.ogRGB(0,0,0));
    for i:=0 to MAX_NODES-1 do
      begin
        points[i].x := points[i].x + dX[i];
        if (points[i].x >= buf^.ogGetMaxX) or (points[i].x <= 0) then
          dX[i] := -dX[i];
       pPoints[i].y := points[i].y + dY[i];
        if (points[i].y >= buf^.ogGetMaxY) or (points[i].y <= 0) then
          dY[i] := -dY[i];
        buf^.ogFillCircle(points[i].x, points[i].y, 5, buf^.ogRGB(0,128,128));
      end;
    {Draw a spline in blue}
    buf^.ogSpline(MAX_NODES, points, 20, buf^.ogRGB(128,128,255));
    {draw a BSpline in red}
    buf^.ogBSpline(MAX_NODES, points, 20, buf^.ogRGB(255,128,128));
    screen^.ogCopy(buf^);
   until keyPressed;
   while keyPressed do readKey;
   
   dispose(buf, ogDone);
end.



Previous: 4.51.2.4.3. ogAvail() To the Table of Contents Next: 4.51.2.4.5. ogCircle()
4.51.2.4.3. ogAvail() Table of Contents 4.51.2.4.5. ogCircle()

- 4.51.2.4.4. -