Contents

Chapters

Sections

j3d.org

[ Previous ] [ Up ] [ Next ]

The LineStripArray

© Justin Couch 2000-2004

The LineStripArray primitive expands on the basic LineArray by allowing you to describe a collection of lines that form a continuous item without needing to repeat vertices in the provided coordinate collection. If you take a look back at Figure 4, you'll notice that, in order to have a continuous line, the shared vertex had to be declared twice - as vertices 3 and 8 in the array of coordinates. With a LineStripArray, that problem is eliminated.

To do this, the LineStripArray (and all of the other strip-based primitives) introduces another piece of required data - the length of a strip. A strip is how many coordinates to link together in a single primitive that use shared vertices. In the non-strip primitives, the coordinate vertices were read out of the array directly. Each group was read sequentially in a multiple according to the primitive type (line, point, triangle etc). The strip-based geometry now uses an extra variable to tell the renderer how many of those coordinates should be linked together to form a single line, before starting the next line.

Construction

Construction of a line strip array starts with the same basic setup as for line arrays, although with a different class name. You still need to tell it what data you're going to be providing, and how many vertices will be set. In addition to these basic requirements, a new parameter is added to the constructor for LineStripArray - an array of strip counts for the individual lines. So, let's start with a simple example that creates a single strip with two segments in it:
    int format = GeometryArray.COORDINATE |
                 GeometryArray.COLOR_3;

	int[] strip_counts = { 3 };

    LineStripArray lines = new LineStripArray(8, format, strip_counts);
The strip_count variable is an array of ints that describe how many vertices to use from the array for the given line. Since each line must have at least a start and end vertex, the values in this array should always be greater than or equal to 2. Each value in the array indicates a new line. In the example above, we are telling Java3D to create a single line that has three vertices - a start, end and a single intermediate point, which would create a line that looked like Figure 10.

A line strip array image
Figure 9: A line strip array showing the vertex numbering for a single strip of 3 vertices

After calling the constructor, you already have provided almost all the required information. All you need to do now is provide the coordinates. This is no different to the non-strip versions of the primitives, so just call setCoordinates() like you have for the others and you'll end up with the lines appearing on screen.

    float[] vertices =
    {
        0,   0,  0,   // v1
        0,   2,  0,   // v2
        1,   5, -3,   // v3
    };

    lines.setCoordinates(0, vertices);
Just remember that the number of vertices provided must be at least equivalent to the sum of the lengths of all the strips. For example, if you provided a strip count array with the values { 3, 5, 2 } your coordinate array must have at least 10 vertices declared. More than that really doesn't matter as Java3D will ignore the extras, but it must have at least the minimum amount. Also, the number of coordinates value provided to the constructor must have a value of the same amount at least too. It's fine to tell Java3D that you have 12 coordinates in the constructor, provide the numStripCount array with a total of 10 vertices and then an array with 17 vertex values. In the end, all you'll get are those 10 vertices from the strips, and nothing else.