m3g05.mesh
Class Bezier

java.lang.Object
  extended by m3g05.mesh.Bezier

public class Bezier
extends java.lang.Object

Calculations for Bezier surfaces.

Author:
Claus Hoefele

Field Summary
private  short[] diffsS
          Buffers for storing intermediate data.
private  short[] diffsT
          Buffers for storing intermediate data.
private  short[] intermediatePointsS
          Buffers for storing intermediate data.
private  short[] intermediatePointsT
          Buffers for storing intermediate data.
private  int numVertices
          Number of vertices per curve.
static int REFLECT_X
          Reflection on the x axis.
static int REFLECT_Y
          Reflection on the y axis.
static int REFLECT_Z
          Reflection on the z axis.
private  float step1
          Pre-computed values for curve evaluation.
private  float step2
          Pre-computed values for curve evaluation.
private  float step3
          Pre-computed values for curve evaluation.
private  int steps
          Number of interpolation steps.
private  short[] tangentsS
          Buffers for storing intermediate data.
private  short[] tangentsT
          Buffers for storing intermediate data.
 
Constructor Summary
Bezier(int steps, boolean createNormals)
          Initializes class.
 
Method Summary
 void createNormals(short[] controlPoints, short[] controlIndices, short[] normals, int offset)
          Calculates normals.
 void createPositions(short[] controlPoints, short[] controlIndices, short[] positions, int offset)
          Calculates the vertex positions of a cubic Bezier surface (16 control points).
 void createTexCoords(byte[] texCoords, int offset, boolean windingCcw)
          Calculates texture coordinates.
 void createTriStrips(int offset, int[] triStrips, int[] triLengths, int triOffset, boolean windingCcw)
          Calculates triangle strips for the evaluated Bezier surface.
static void cross(short[] result, int offset, short[] lhs, int lhsOffset, short[] rhs, int rhsOffset)
          Builds the cross product of two vectors.
static void evaluateCubicCurve(short[] cpoints, int p0, int p1, int p2, int p3, short[] result, int offset, int steps, float step1, float step2, float step3)
          Evaluates a cubic Bezier curve (four control points).
static void evaluateQuadraticCurve(short[] cpoints, int p0, int p1, int p2, short[] result, int offset, int steps, float step1, float step2)
          Evaluates a quadratic Bezier curve (three control points).
static void reflect(short[] positions, int offset, int newOffset, int length, int axes)
          Reflects an array of vectors around the given axis.
static void sub(short[] result, int offset, short[] points, int lhs, int rhs)
          Subtracts two vectors.
static int verticesPerCurve(int steps)
          Returns the number of vertices for a curve that is evaluated with the given number of steps.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REFLECT_X

public static final int REFLECT_X
Reflection on the x axis.

See Also:
Constant Field Values

REFLECT_Y

public static final int REFLECT_Y
Reflection on the y axis.

See Also:
Constant Field Values

REFLECT_Z

public static final int REFLECT_Z
Reflection on the z axis.

See Also:
Constant Field Values

steps

private int steps
Number of interpolation steps.


numVertices

private int numVertices
Number of vertices per curve.


step1

private float step1
Pre-computed values for curve evaluation.


step2

private float step2
Pre-computed values for curve evaluation.


step3

private float step3
Pre-computed values for curve evaluation.


intermediatePointsS

private short[] intermediatePointsS
Buffers for storing intermediate data.


intermediatePointsT

private short[] intermediatePointsT
Buffers for storing intermediate data.


diffsS

private short[] diffsS
Buffers for storing intermediate data.


diffsT

private short[] diffsT
Buffers for storing intermediate data.


tangentsS

private short[] tangentsS
Buffers for storing intermediate data.


tangentsT

private short[] tangentsT
Buffers for storing intermediate data.

Constructor Detail

Bezier

public Bezier(int steps,
              boolean createNormals)
Initializes class. If normals are created, extra memory buffers are allocated to hold intermediate values.

Parameters:
steps - number of interpolation steps.
createNormals - true to create normals, false otherwise.
Method Detail

verticesPerCurve

public static int verticesPerCurve(int steps)
Returns the number of vertices for a curve that is evaluated with the given number of steps.

Parameters:
steps - number of interpolation values.
Returns:
number of vertices.

createPositions

public void createPositions(short[] controlPoints,
                            short[] controlIndices,
                            short[] positions,
                            int offset)
Calculates the vertex positions of a cubic Bezier surface (16 control points).

Parameters:
controlPoints - array of control points.
controlIndices - array of indices to the control points.
positions - resulting vertex positions.
offset - offset into the positions array.

evaluateCubicCurve

public static void evaluateCubicCurve(short[] cpoints,
                                      int p0,
                                      int p1,
                                      int p2,
                                      int p3,
                                      short[] result,
                                      int offset,
                                      int steps,
                                      float step1,
                                      float step2,
                                      float step3)
Evaluates a cubic Bezier curve (four control points). Minimum of subdivisions is one, which will return the start and end points of the Bezier curve. Each additional step will increase the number of vertices by one.

Parameters:
cpoints - array with control points.
p0 - index to first control point.
p1 - index to second control point.
p2 - index to third control point.
p3 - index to fourth control point.
result - evaluated points.
offset - offset into the result array.
steps - number of interpolation steps.
step1 - pre-computed step value (1.0f/steps).
step2 - pre-computed step value (1.0f/steps*steps).
step3 - pre-computed step value (1.0f/steps*steps*steps).

createTriStrips

public void createTriStrips(int offset,
                            int[] triStrips,
                            int[] triLengths,
                            int triOffset,
                            boolean windingCcw)
Calculates triangle strips for the evaluated Bezier surface.

Parameters:
offset - offset to the array with vertex positions.
triStrips - resulting triangle strips.
triLengths - resulting triangle lengths.
triOffset - offset to the triangle arrays.
windingCcw - true to connect triangles counter-clockwise, false otherwise.

createTexCoords

public void createTexCoords(byte[] texCoords,
                            int offset,
                            boolean windingCcw)
Calculates texture coordinates.

Parameters:
texCoords - resulting texture coordinates.
offset - offset to the texture array.
windingCcw - true to connect triangles counter-clockwise, false otherwise.

createNormals

public void createNormals(short[] controlPoints,
                          short[] controlIndices,
                          short[] normals,
                          int offset)
Calculates normals.

Parameters:
controlPoints - array of control points for the Bezier surface.
controlIndices - array of indices to the control points.
normals - resulting normals.
offset - offset to the normals array.

evaluateQuadraticCurve

public static void evaluateQuadraticCurve(short[] cpoints,
                                          int p0,
                                          int p1,
                                          int p2,
                                          short[] result,
                                          int offset,
                                          int steps,
                                          float step1,
                                          float step2)
Evaluates a quadratic Bezier curve (three control points). Minimum of subdivisions is one, which will return the start and end points of the Bezier curve. Each additional step will increase the number of vertices by one.

Parameters:
cpoints - array with control points.
p0 - index to first control point.
p1 - index to second control point.
p2 - index to third control point.
result - evaluated points.
offset - offset into the result array.
steps - number of interpolation steps.
step1 - pre-computed step value (1.0f/steps).
step2 - pre-computed step value (1.0f/steps*steps).

sub

public static void sub(short[] result,
                       int offset,
                       short[] points,
                       int lhs,
                       int rhs)
Subtracts two vectors.

Parameters:
result - array for result.
offset - offset to the result array.
points - array with input vectors.
lhs - index to minuend.
rhs - index to subtrahend.

cross

public static void cross(short[] result,
                         int offset,
                         short[] lhs,
                         int lhsOffset,
                         short[] rhs,
                         int rhsOffset)
Builds the cross product of two vectors.

Parameters:
result - array for result.
offset - offset to the result array.
lhs - array for left-hand side vector.
lhsOffset - index to left-hand side vector.
rhs - array for right-hand side vector.
rhsOffset - index to right-hand side vector.

reflect

public static void reflect(short[] positions,
                           int offset,
                           int newOffset,
                           int length,
                           int axes)
Reflects an array of vectors around the given axis.

Parameters:
positions - input values.
offset - offset to input values.
newOffset - offset to the result.
length - number of vectors.
axes - reflection axes. Several can be combined with OR.