Contents

Chapters

Sections

j3d.org

[ Previous ] [ Up ] [ Next ]

The PointArray

© Justin Couch 2001

Working with point arrays is the simplest of all the primitives. Each coordinate you supply maps to exactly one point in 3D space.

Construction

Constructing a new instance of the PointArray class requires using the same style constructor as the base GeometryArray class. That is, all you need to provide it is the list of format flags and a listing of the number of points that are to be rendered.
    int format = GeometryArray.COORDINATE |
                 GeometryArray.COLOR_3;

    PointArray points = new PointArray(3, format);
Because points represent a single location in space, and points are not related to each other, the first argument can be any value. Apart from the normal restrictions, this is the total number of points held in this array. In this example, we provide 3 points and you can see those in Figure 5.

A point array image
Figure 5: A point array showing the vertex numbering

To complete the construction of your line array, you need to now specify a set of vertices. The primitive looks at each pair of vertices in the provided array and connects those as lines. So, to make a line you need to provide the array of vertices like this:
    float[] vertices =
    {
        0,   0,  0,   // v1
        0,   2,  0,   // v2
        1,   5, -3,   // v3
    };
Setting the array of vertices is just like LineArrays. Use the setCoordinates() method to change the values to the new array.
    lines.setCoordinates(0, vertices);
Again, the position index works the same as for lines. If you want to set all of the coordinates, start with a value of zero.

When working with colour values, there is nothing particularly interesting. Each colour value provided matches with one point. Because each point is an individual, there is no colour blending or any other funky stuff.