Curves Tool

Tool to design curves

1. Introduction

We have a simple tool to design curves (piecewise cubic Bezier curves). The created curves can be saved into a simple XML format and loaded into your own Castle Game Engine programs and used for any purpose (for example as a track along which something moves).

Download:

The main example how to use designed curves is inside the CGE, in examples/curves/use_designed_curve.

2. Creating and editing curves

For many commands and their key shortcuts, see the program’s menu. Use mouse to create and edit curve points:

  • Right mouse button click:

    Add new curve point. If some curve and point were selected, the new point is added to the selected curve after the selected point. Otherwise, a new new curve with one point is created. So if you want to start creating 2nd curve, just deselect all (key N) and press right mouse button.

  • Left mouse button click:

    Select control point (and it’s curve).

  • Dragging with left mouse button:

    Move selected point. Hold Shift key to move whole selected curve. The smallest drags are ignored at the begging, so we avoid accidental drags when selecting, don’t worry:)

  • Use keys + and - to smoothly zoom in/out. Use Home to reset zoom to zero.

Tip
use a reference image (menu Background→Load) to fit your curve nicely to your use. By default we show a simple image with a helpful grid.

Save and open menu commands store curves list in a simple XML file. You can use it to load your designed curves into your Castle Game Engine programs, see below.

3. Using curves in your own programs

  • Load a list of curves from XML file using the TCurveList.LoadFromFile method.

  • Or load the first curve from XML file using the simpler TCurve.LoadFromFile method.

  • Query the curve using the TCurve.Point(T) method.

  • Use T values in the range [0..1] to move along the curve. In general, you should look at the valid range for T in TCurve.TBegin and TCurve.TEnd properties, but in case of castle-curves tool — you know that TBegin is always 0 and TEnd is 1.

See the example below:

program curves_example;

{$apptype console}

uses SysUtils, CastleVectors, CastleFilesUtils, CastleCurves, CastleLog;
var
  FirstCurve: TCurve;
  Curves: TCurveList;
begin
  InitializeLog;

  FirstCurve := TCurve.LoadFromFile('castle-data:/my_curves.xml');
  try
    // That's it, you loaded the 1st curve from XML file.
    // Write some initial curve points.
    WritelnLog(FirstCurve.Point(0.0).ToString);
    WritelnLog(FirstCurve.Point(0.1).ToString);
  finally FreeAndNil(FirstCurve) end;

  { in more complicated scenarios, my_curves.xml may keep many curves
    inside. Load them like this: }

  Curves := TCurveList.Create(true { free objects });
  try
    Curves.LoadFromFile('castle-data:/my_curves.xml');
    if Curves.Count = 0 then
      raise Exception.Create('No curves defined in file');
    FirstCurve := Curves[0];
    // That's it, you have the 1st curve from XML file.
    // Write some initial curve points.
    WritelnLog(FirstCurve.Point(0.0).ToString);
    WritelnLog(FirstCurve.Point(0.1).ToString);
    WritelnLog(FirstCurve.Point(0.2).ToString);
  finally FreeAndNil(Curves) end;
end.

To improve this documentation just edit this page and create a pull request to cge-www repository.