图 13.19 Bézier Curve
To define a one-dimensional map, use the Map1 command.
The target argument defines what the control points represent. Values of the target argument are shown in Map1 Target Arguments and Default Values. Note that you must use the Enable command to enable the argument.
target Argument
|
|
---|---|
s texture coordinates
|
|
s, t texture coordinates
|
|
The second two arguments (u1 and u2) define the range for the map. The stride value is the number of values in each block of storage (in other words, the offset between the beginning of one control point and the beginning of the next control point). The order should equal the degree of the curve plus one. The matrix holds the control points.
For example, Map1(MAP1_VERTEX_3, 0, 1, 3, 4, <4x3 matrix>) is typical for setting the two end points and two control points to define a Bézier line.
sets up the mesh with un divisions spanning the range u1 to u2. Code is simplified by using the range 0 to 1.
actually generates the mesh from i1 to i2. The mode can be either POINT or LINE. The EvalMesh1 command makes its own Begin and End clause.
The following example script demonstrates a one-dimensional outlier. A random set of control points draws a smooth curve. Only the first and last points are on the curve. Using NPOINTS=4 results in a cubic Bézier spline.
boxwide = 500;
boxhigh = 400;
NPOINTS = 4;
For( x = 1, x <= NPOINTS, x++,
spline = Scene Box( boxwide, boxhigh );
spline << Enable( MAP1_VERTEX_3 );
For( i = 1, i <= NPOINTS, i++,
spline << End;
spline << Push Matrix;
spline << Pop Matrix;
New Window( "Spline", spline );
https://www.tinaja.com/glib/bezconn.pdf offers an explanation of connecting cubic segments so that both the slope and the rate of change match at the connection point. This example does not illustrate doing so; there is only one segment here.