org.jrabbit.base.graphics.primitive
Class PrimitivePainter

java.lang.Object
  extended by org.jrabbit.base.graphics.primitive.PrimitivePainter

public class PrimitivePainter
extends java.lang.Object

A convenience class for drawing solid-color, non-textured primitive shapes. Wherever possible, display lists are used to accelerate rendering the primitives.

Author:
Chris Molini

Field Summary
private static java.util.HashMap<java.lang.Float[][],java.lang.Integer> cachedPolygons
          Additionally, accelerated polygons are cached in a list so that they can be accessed by a variety of objects.
private static int circleDLID
          The display list ID that draws a circle.
private static int rectangleDLID
          The display list ID that will draw a square.
private static java.util.HashMap<java.lang.Integer,java.lang.Integer> regPolyDLs
          The algorithm that renders regular polygons always results in an identical primitive for the same number of sides.
private static int triangleDLID
          The display list ID that will draw a triangle.
private static boolean valid
          Checks whether or not everything has been created to allow for primitive rendering.
 
Constructor Summary
PrimitivePainter()
           
 
Method Summary
static void create()
          Creates all resources needed to accelerate primitive rendering.
static int definePolygon(float[][] vertices)
          Obtains a display list that renders the polygon represented by the supplied vertices.
static int defineRegularPolygon(int numSides)
          Creates a display list that will render a polygon with the appropriate number of sides.
static void destroy()
          Wipes all contained data.
static void renderCircle()
          Renders a circle with a width and height of 1 pixel.
static void renderCircle(float width, float height)
          Renders a circle with the indicated width and height.
static void renderLine(float x1, float y1, float x2, float y2)
          Renders a line between two points.
static void renderLine(Vector2f pointA, Vector2f pointB)
          Renders a line between two points.
static void renderPath(java.lang.Iterable<Vector2f> path)
          Renders the indicated path as one continuous line.
static void renderPath(Vector2f[] path)
          Renders the indicated path as one continuous line.
private static void renderPolygon(float[][] vertices)
          Renders the polygon represented by the supplied vertices.
static void renderRectangle()
          Renders a rectangle with a width and height of 1 pixel.
static void renderRectangle(float width, float height)
          Renders a rectangle with the indicated width and height.
static void renderRegPolygon(int numSides)
          Renders a regular polygon with the indicated number of sides.
static void renderRegPolygon(int numSides, float width, float height)
          Renders a regular polygon with the indicated number of sides.
static void renderTriangle()
          Renders a triangle with a width and height of 1 pixel.
static void renderTriangle(float width, float height)
          Renders a triangle with the indicated width and height.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rectangleDLID

private static int rectangleDLID
The display list ID that will draw a square.


triangleDLID

private static int triangleDLID
The display list ID that will draw a triangle.


circleDLID

private static int circleDLID
The display list ID that draws a circle. NOTE: The circle rendered does not actually have curved edges; it is simply a 64-sided regular polygon.


valid

private static boolean valid
Checks whether or not everything has been created to allow for primitive rendering.


regPolyDLs

private static java.util.HashMap<java.lang.Integer,java.lang.Integer> regPolyDLs
The algorithm that renders regular polygons always results in an identical primitive for the same number of sides. This stores any created display lists so that they can be used for multiple requests.


cachedPolygons

private static java.util.HashMap<java.lang.Float[][],java.lang.Integer> cachedPolygons
Additionally, accelerated polygons are cached in a list so that they can be accessed by a variety of objects.

Constructor Detail

PrimitivePainter

public PrimitivePainter()
Method Detail

create

public static void create()
Creates all resources needed to accelerate primitive rendering.


renderRectangle

public static void renderRectangle()
Renders a rectangle with a width and height of 1 pixel. Obviously, this should probably be scaled up.


renderTriangle

public static void renderTriangle()
Renders a triangle with a width and height of 1 pixel. Obviously, this should probably be scaled up.


renderCircle

public static void renderCircle()
Renders a circle with a width and height of 1 pixel. Obviously, this should probably be scaled up.


renderRectangle

public static void renderRectangle(float width,
                                   float height)
Renders a rectangle with the indicated width and height.

Parameters:
width - The width of the rectangle, in pixels.
height - The height of the rectangle, in pixels.

renderTriangle

public static void renderTriangle(float width,
                                  float height)
Renders a triangle with the indicated width and height.

Parameters:
width - The width of the triangle, in pixels.
height - The height of the triangle, in pixels.

renderCircle

public static void renderCircle(float width,
                                float height)
Renders a circle with the indicated width and height.

Parameters:
width - The width of the circle, in pixels.
height - The height of the circle, in pixels.

renderLine

public static void renderLine(Vector2f pointA,
                              Vector2f pointB)
Renders a line between two points.

Parameters:
pointA - The beginning of the line.
pointB - The end of the line.

renderLine

public static void renderLine(float x1,
                              float y1,
                              float x2,
                              float y2)
Renders a line between two points.

Parameters:
x1 - The x-coordinate of the beginning of the line.
y1 - The y-coordinate of the beginning of the line.
x2 - The x-coordinate of the end of the line.
y2 - The y-coordinate of the end of the line.

renderPath

public static void renderPath(Vector2f[] path)
Renders the indicated path as one continuous line.

Parameters:
path - The array of vectors to render.

renderPath

public static void renderPath(java.lang.Iterable<Vector2f> path)
Renders the indicated path as one continuous line.

Parameters:
path - The series of vectors to render.

renderRegPolygon

public static void renderRegPolygon(int numSides)
Renders a regular polygon with the indicated number of sides. The polygon has a width and height of 1, so scaling operations should probably be applied before this call.

Parameters:
numSides - The number of sides for the polygon to have.

renderRegPolygon

public static void renderRegPolygon(int numSides,
                                    float width,
                                    float height)
Renders a regular polygon with the indicated number of sides.

Parameters:
numSides - The number of sides for the polygon to have.
width - The width of the polygon.
height - The height of the polygon.

defineRegularPolygon

public static int defineRegularPolygon(int numSides)
Creates a display list that will render a polygon with the appropriate number of sides. The width and height of the rendered polygon is 1.

Parameters:
numSides - The number of sides for the polygon to have.
Returns:
The ID of a display list that will accelerate rendering of the indicated shape.

renderPolygon

private static void renderPolygon(float[][] vertices)
Renders the polygon represented by the supplied vertices. The vertices should be centered around [0, 0]. The polygon to be rendered is considered a "triangle fan" by the graphics card, with [0, 0] as the center. Thus, the shape can be convex, but cannot curve back on itself. More complex geometry should really be custom-rendered.

Parameters:
vertices - The vertice data that describes the shape.

definePolygon

public static int definePolygon(float[][] vertices)
Obtains a display list that renders the polygon represented by the supplied vertices. The results of this method are cached for future searches. This method is bound by the same constraints as renderPolygon().

Parameters:
vertices - The vertices of the shape to render.
Returns:
The ID of a display list that will accelerate rendering of the indicated shape.

destroy

public static void destroy()
Wipes all contained data.