Use an indexed line set factory

From JReality Wiki
Revision as of 13:55, 9 June 2009 by Gunn (Talk | contribs)

(diff) ←Older revision | view current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

Source file: Cube02

JavaDoc: IndexedLineSet

JavaDoc: IndexedLineSetFactory

Run as Java webstart

Now we'll add edges to the vertices created above which turns our geometry into an IndexedLineSet. This can be achieved by using the IndexedLineSetFactory, where we additionally specify edge indices. The edge indices are specified as an array of integers, one row per edge, and each entry in each row giving the index (0-based) into the array of vertices. We choose the indices such that we are going round the unit square in counter-clockwise direction.

An edge can have as few as 2 vertices, in which case it describes a single edge segment; edges with more entries describe connected curves consisting of a sequence of connected edge segments.

package de.jreality.tutorial;
import de.jreality.geometry.IndexedLineSetFactory;
public class Cube02 {
  public static void main(String[] args) {
    IndexedLineSetFactory ilsf = new IndexedLineSetFactory();
    double [][] vertices = new double[][] {
      {0, 0, 0}, {1, 0, 0}, {1, 1, 0}, {0, 1, 0}
    int[][] edgeIndices = new int[][]{
      {0, 1}, {1, 2}, {2, 3}, {3, 0}  
    ilsf.setVertexCount( vertices.length );
    ilsf.setVertexCoordinates( vertices );

Note that we are now calling ilsf.getIndexedLineSet() to produce geometry with our factory.

Unit square as a line set

Previous: Use a point set factory Developer Tutorial: Contents Next: Use an indexed face set factory