agile2d.geom
Class VertexArray

java.lang.Object
  |
  +--agile2d.geom.VertexArray
All Implemented Interfaces:
Shape

public class VertexArray
extends Object
implements Shape

A VertexArray is a special Shape, made of several simple primitives such as points, lines, triangles, quadrilaterals or convex polygons.

VertexArray manage a list of primitives and are rendered very efficiently by hardware accelerated graphics cards when they are available. A VertexArray can hold 9 types of primitives:

  1. Points: a sequence of disconnected points.
  2. Lines: a sequence of disconnected lines.
  3. Line strip: a sequence of connected lines.
  4. Line loop: a sequence of connected lines where the last vertex is connected to the first.
  5. Triangles: a sequence of disconnected triangles.
  6. Triangle strip: a connected sequence of triangles.
  7. Triangle fan: a sequence of triangles sharing the same initial point.
  8. Quads: a sequence of disconnected quadrilaterals.
  9. Quad strip: a sequence of connected quadrilaterals.
  10. Polygon: one convex polygon.

Version:
$Revision$
Author:
Jean-Daniel Fekete

Field Summary
static short MODE_INVALID
          Constant for an invalid mode
static short MODE_LINE_LOOP
          Constant for the line loop mode
static short MODE_LINE_STRIP
          Constant for the line strip mode
static short MODE_LINES
          Constant for the lines mode
static short MODE_POINTS
          Constant for the points mode
static short MODE_POLYGON
          Constant for the polygon mode
static short MODE_QUAD_STRIP
          Constant for the quad strip mode
static short MODE_QUADS
          Constant for the quads mode
static short MODE_TRIANGLE_FAN
          Constant for the triangle fan mode
static short MODE_TRIANGLE_STRIP
          Constant for the triangle strip mode
static short MODE_TRIANGLES
          Constant for the triangles mode
 
Constructor Summary
VertexArray()
          Constructor for VertexArray.
VertexArray(int reserve)
          Constructor for VertexArray.
 
Method Summary
 void addLine(float[] coords)
          Add a line.
 void addLine(float x1, float y1, float x2, float y2)
          Add a line.
 void addQuad(float[] coords)
          Add a quadrilateral.
 void addQuad(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4)
          Add a quadrilateral.
 void addRect(float x, float y, float w, float h)
          Add a quadrilateral specified as a rectangle.
 void addTriangle(float[] coords)
          Add a triangle.
 void addTriangle(float x1, float y1, float x2, float y2, float x3, float y3)
          Add a triangle.
 void addVertex(double[] coords)
          Add a vertex
 void addVertex(double x, double y)
          Add a vertex
 void addVertex(float[] coords)
          Add a vertex
 void addVertex(float x, float y)
          Add a vertex
 void clear()
          Clear the vertex.
 boolean contains(double x, double y)
           
 boolean contains(double x, double y, double w, double h)
           
 boolean contains(Point2D p)
           
 boolean contains(Rectangle2D r)
           
 void draw(Graphics g)
           
 void draw(Graphics g, VertexAttributes va)
           
 void drawSmooth(Graphics2D g, PolygonShape s, VertexAttributes ca, int index)
           
 void fill(Graphics g)
           
 void fill(Graphics g, VertexAttributes va)
           
 void fillSmooth(Graphics2D g, PolygonShape s, VertexAttributes ca, int index)
           
 Rectangle getBounds()
           
 Rectangle2D getBounds2D()
           
 int getCoordsCount()
          Return the number of coordinates.
 float[] getData()
          Return a copy of the array of coordinates.
 float[] getDataRef()
          Return the array of coordinates.
 int getMode()
          Returns the mode.
 PathIterator getPathIterator(AffineTransform at)
           
 PathIterator getPathIterator(AffineTransform at, double flatness)
           
 void getVertex(int index, float[] coords)
          Return the coordinates of a specified vertex.
 int getVertexCount()
          Return the number of vertices.
 boolean intersects(double x, double y, double w, double h)
           
 boolean intersects(Rectangle2D r)
           
static void render(VertexArray va, gl4java.GLFunc gl)
          Renders the VertexArray on a GL context.
static void render(VertexArray va, VertexAttributes ca, gl4java.GLFunc gl)
           
 void reserve(int size)
          Make sure enough room is allocated to store as many coordinates.
 void setMode(int primitive)
          Set the mode and clears the array.
 GeneralPath toGeneralPath()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MODE_INVALID

public static final short MODE_INVALID
Constant for an invalid mode

See Also:
Constant Field Values

MODE_POINTS

public static final short MODE_POINTS
Constant for the points mode

See Also:
Constant Field Values

MODE_LINES

public static final short MODE_LINES
Constant for the lines mode

See Also:
Constant Field Values

MODE_LINE_STRIP

public static final short MODE_LINE_STRIP
Constant for the line strip mode

See Also:
Constant Field Values

MODE_LINE_LOOP

public static final short MODE_LINE_LOOP
Constant for the line loop mode

See Also:
Constant Field Values

MODE_TRIANGLES

public static final short MODE_TRIANGLES
Constant for the triangles mode

See Also:
Constant Field Values

MODE_TRIANGLE_STRIP

public static final short MODE_TRIANGLE_STRIP
Constant for the triangle strip mode

See Also:
Constant Field Values

MODE_TRIANGLE_FAN

public static final short MODE_TRIANGLE_FAN
Constant for the triangle fan mode

See Also:
Constant Field Values

MODE_QUADS

public static final short MODE_QUADS
Constant for the quads mode

See Also:
Constant Field Values

MODE_QUAD_STRIP

public static final short MODE_QUAD_STRIP
Constant for the quad strip mode

See Also:
Constant Field Values

MODE_POLYGON

public static final short MODE_POLYGON
Constant for the polygon mode

See Also:
Constant Field Values
Constructor Detail

VertexArray

public VertexArray(int reserve)
Constructor for VertexArray.

Parameters:
reserve - available number of coords before reallocation is needer.

VertexArray

public VertexArray()
Constructor for VertexArray.

Method Detail

getVertexCount

public int getVertexCount()
Return the number of vertices.

Returns:
the number of vertices.

getCoordsCount

public int getCoordsCount()
Return the number of coordinates.

Returns:
the number of coordinates.

getData

public float[] getData()
Return a copy of the array of coordinates.

Returns:
a copy of the array of coordinates.

getDataRef

public float[] getDataRef()
Return the array of coordinates.

Returns:
the array of coordinates.

clear

public void clear()
Clear the vertex.


getMode

public int getMode()
Returns the mode.

Returns:
int

setMode

public void setMode(int primitive)
Set the mode and clears the array.

Parameters:
primitive - The mode to set

reserve

public void reserve(int size)
Make sure enough room is allocated to store as many coordinates.

Parameters:
size - the number of vertex coordinates to reserve.

addVertex

public void addVertex(double[] coords)
Add a vertex

Parameters:
coords - an array of at least two double values.

addVertex

public void addVertex(double x,
                      double y)
Add a vertex

Parameters:
x - the X coordinate
y - the Y coordinate

addVertex

public void addVertex(float[] coords)
Add a vertex

Parameters:
coords - an array of at least two float values.

addVertex

public void addVertex(float x,
                      float y)
Add a vertex

Parameters:
x - the X coordinate
y - the Y coordinate

getVertex

public void getVertex(int index,
                      float[] coords)
Return the coordinates of a specified vertex.

Parameters:
index - the specified vertex
coords - an array where the coordinates will be stored.
Throws:
ArrayIndexOutOfBoundsException - DOCUMENT ME!

addLine

public void addLine(float[] coords)
Add a line.

Parameters:
coords - the two vertices (four coordinates) of the line.

addLine

public void addLine(float x1,
                    float y1,
                    float x2,
                    float y2)
Add a line.

Parameters:
x1 - the X coordinate of the first vertex
y1 - the Y coordinate of the first vertex
x2 - the X coordinate of the second vertex
y2 - the Y coordinate of the second vertex

addTriangle

public void addTriangle(float[] coords)
Add a triangle.

Parameters:
coords - the three vertices (six coordinates) of the triangle.

addTriangle

public void addTriangle(float x1,
                        float y1,
                        float x2,
                        float y2,
                        float x3,
                        float y3)
Add a triangle.

Parameters:
x1 - the X coordinate of the first vertex
y1 - the Y coordinate of the first vertex
x2 - the X coordinate of the second vertex
y2 - the Y coordinate of the second vertex
x3 - the X coordinate of the third vertex
y3 - the Y coordinate of the third vertex

addQuad

public void addQuad(float[] coords)
Add a quadrilateral.

Parameters:
coords - the four vertices (eight coordinates) of the quad.

addQuad

public void addQuad(float x1,
                    float y1,
                    float x2,
                    float y2,
                    float x3,
                    float y3,
                    float x4,
                    float y4)
Add a quadrilateral.

Parameters:
x1 - the X coordinate of the first vertex
y1 - the Y coordinate of the first vertex
x2 - the X coordinate of the second vertex
y2 - the Y coordinate of the second vertex
x3 - the X coordinate of the third vertex
y3 - the Y coordinate of the third vertex
x4 - the X coordinate of the fourth vertex
y4 - the Y coordinate of the fourth vertex

addRect

public void addRect(float x,
                    float y,
                    float w,
                    float h)
Add a quadrilateral specified as a rectangle.

Parameters:
x - the X coordinate
y - the Y coordinate
w - the width
h - the height

contains

public boolean contains(double x,
                        double y,
                        double w,
                        double h)
Specified by:
contains in interface Shape
See Also:
Shape.contains(double, double, double, double)

contains

public boolean contains(double x,
                        double y)
Specified by:
contains in interface Shape
See Also:
Shape.contains(double, double)

contains

public boolean contains(Point2D p)
Specified by:
contains in interface Shape
See Also:
Shape.contains(Point2D)

contains

public boolean contains(Rectangle2D r)
Specified by:
contains in interface Shape
See Also:
Shape.contains(Rectangle2D)

getBounds

public Rectangle getBounds()
Specified by:
getBounds in interface Shape
See Also:
Shape.getBounds()

getBounds2D

public Rectangle2D getBounds2D()
Specified by:
getBounds2D in interface Shape
See Also:
Shape.getBounds2D()

toGeneralPath

public GeneralPath toGeneralPath()

getPathIterator

public PathIterator getPathIterator(AffineTransform at,
                                    double flatness)
Specified by:
getPathIterator in interface Shape
See Also:
Shape.getPathIterator(AffineTransform, double)

getPathIterator

public PathIterator getPathIterator(AffineTransform at)
Specified by:
getPathIterator in interface Shape
See Also:
Shape.getPathIterator(AffineTransform)

intersects

public boolean intersects(double x,
                          double y,
                          double w,
                          double h)
Specified by:
intersects in interface Shape
See Also:
Shape.intersects(double, double, double, double)

intersects

public boolean intersects(Rectangle2D r)
Specified by:
intersects in interface Shape
See Also:
Shape.intersects(Rectangle2D)

drawSmooth

public void drawSmooth(Graphics2D g,
                       PolygonShape s,
                       VertexAttributes ca,
                       int index)

draw

public void draw(Graphics g)

draw

public void draw(Graphics g,
                 VertexAttributes va)

fillSmooth

public void fillSmooth(Graphics2D g,
                       PolygonShape s,
                       VertexAttributes ca,
                       int index)

fill

public void fill(Graphics g)

fill

public void fill(Graphics g,
                 VertexAttributes va)

render

public static void render(VertexArray va,
                          gl4java.GLFunc gl)
Renders the VertexArray on a GL context.

Parameters:
va - the VertexArray
gl - the GL context

render

public static void render(VertexArray va,
                          VertexAttributes ca,
                          gl4java.GLFunc gl)


Copyright © 2002 by University of Maryland, USA All rights reserved.