jglcore
Class JGL

java.lang.Object
  extended by jglcore.JGL

public final class JGL
extends java.lang.Object

3D display system. Based on the OpenGL model, it provides static methods to :

- Manage Java AWT/Swing Components display (multi-screening, double-buffer)
- Manage render parameters (perspective, clipping planes, cull-facing)
- Manipulate spatial transformations
- Manage materials parameters (color, shininess, full/wire frame faces)
- Manage lighting
- Display 3D primitives (triangles and lines)

WARNING : To keep maximum performances, the system doesn't support multi-threading. Operations must be sequentially called, including display Components selections.

Author:
Nicolas Devere

Field Summary
static int CCW
          Specifies that a triangle's front side is the side where points are in the counter-clockwise order (default order).
static int CW
          Specifies that a triangle's front side is the side where points are in the clockwise order.
static int XYZ
          Axis order for rotations : X, then Y, then Z.
static int XZY
          Axis order for rotations : X, then Z, then Y.
static int YXZ
          Axis order for rotations : Y, then X, then Z.
static int YZX
          Axis order for rotations : Y, then Z, then X.
static int ZXY
          Axis order for rotations : Z, then X, then Y.
static int ZYX
          Axis order for rotations : Z, then Y, then X.
 
Constructor Summary
JGL()
           
 
Method Summary
static void addClipPlane(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3)
          Adds a 3D clipping plane.
static void clearClipPlanes()
          Removes all the clipping planes.
static void displayLine(float x1, float y1, float z1, float x2, float y2, float z2)
          Displays a 3D line with its 2 points coordinates.
static void displayTriangle(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3)
          Displays a 3D triangle with its 3 points coordinates.
static java.awt.Color getColor()
          Returns the current display color.
static boolean getCullFacing()
          Returns if the cull-facing is on or off.
static float getFocal()
          Returns the current 3D->2D focal parameter.
static int getHeight()
          Returns the current display target's height (in pixels).
static boolean getLighting()
          Returns if the lighting is on or off.
static JGL_3DMatrix getMatrix()
          Returns a copy of the current matrix.
static float getScreenClip()
          Returns the current screen plane depth.
static float getShininess()
          Returns the current shininess percentage.
static boolean getSolidFace()
          Returns the current triangles's display mode : solid or wire frame.
static int getWidth()
          Returns the current display target's width (in pixels).
static void identity()
          Resets the current matrix to identity.
static void multiplyRight(JGL_3DMatrix m)
          Right-multiplies the current matrix by the specified matrix.
static void popMatrix()
          Restores the last pushed matrix as the current matrix.
static void pushMatrix()
          Pushes the current matrix in the matrix stack.
static void rotate(float angle, float x, float y, float z)
          Applies a rotation (in degrees) to the current matrix around the specified axis.
static void rotate(float angleX, float angleY, float angleZ, int order)
          Applies a rotation to the current matrix with the specified Euler angles, in the chosen order (the angles order is given by constants from the JGL class.
static void scale(float x, float y, float z)
          Applies a scale transformation on 3 axis to the current matrix.
static void setColor(java.awt.Color arg)
          Sets the current display color.
static void setCullFacing(boolean arg)
          Sets the cull-facing on / off.
static void setDisplayTarget(java.awt.Component arg)
          Sets the specified Java AWT/Swing Component as current display target of the system.
static void setFaceOrder(int order)
          Sets the points order of a 3D triangle.
static void setLighting(boolean arg)
          Sets the lighting on / off.
static void setLightPosition(float x, float y, float z)
          Sets the light position (defined in the current matrix).
static void setPerspective(float angle)
          Sets the perspective with the specified vision angle.
static void setScreenClip(float arg)
          Sets the abstract screen plane depth (-1 by default).
static void setShininess(float percentage)
          Sets the current shininess percentage (between 0 and 100).
static void setSolidFace(boolean arg)
          Sets triangles's display mode : solid or wire frame.
static void swapBuffers()
          Flushes display buffer on the current target.
static void translate(float x, float y, float z)
          Applies a translation to the current matrix.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CCW

public static final int CCW
Specifies that a triangle's front side is the side where points are in the counter-clockwise order (default order).

See Also:
Constant Field Values

CW

public static final int CW
Specifies that a triangle's front side is the side where points are in the clockwise order.

See Also:
Constant Field Values

XYZ

public static final int XYZ
Axis order for rotations : X, then Y, then Z.

See Also:
Constant Field Values

XZY

public static final int XZY
Axis order for rotations : X, then Z, then Y.

See Also:
Constant Field Values

YXZ

public static final int YXZ
Axis order for rotations : Y, then X, then Z.

See Also:
Constant Field Values

YZX

public static final int YZX
Axis order for rotations : Y, then Z, then X.

See Also:
Constant Field Values

ZXY

public static final int ZXY
Axis order for rotations : Z, then X, then Y.

See Also:
Constant Field Values

ZYX

public static final int ZYX
Axis order for rotations : Z, then Y, then X.

See Also:
Constant Field Values
Constructor Detail

JGL

public JGL()
Method Detail

setDisplayTarget

public static void setDisplayTarget(java.awt.Component arg)
Sets the specified Java AWT/Swing Component as current display target of the system.

Parameters:
arg - : the AWT/Swing Component

swapBuffers

public static void swapBuffers()
Flushes display buffer on the current target.


getWidth

public static int getWidth()
Returns the current display target's width (in pixels).

Returns:
the current display target's width

getHeight

public static int getHeight()
Returns the current display target's height (in pixels).

Returns:
the current display target's height

setPerspective

public static void setPerspective(float angle)
Sets the perspective with the specified vision angle. The angle (in degrees) is the one between the observer's eye, the top-left screen corner and the bottom-right screen corner. It must be between 1 and 179.

Parameters:
angle - : the vision angle

getFocal

public static float getFocal()
Returns the current 3D->2D focal parameter.

Returns:
the current focal

setScreenClip

public static void setScreenClip(float arg)
Sets the abstract screen plane depth (-1 by default). It must be a negative value.

Parameters:
arg - : the screen plane depth

getScreenClip

public static float getScreenClip()
Returns the current screen plane depth.

Returns:
the screen plane depth

addClipPlane

public static void addClipPlane(float x1,
                                float y1,
                                float z1,
                                float x2,
                                float y2,
                                float z2,
                                float x3,
                                float y3,
                                float z3)
Adds a 3D clipping plane. A plane is defined by 3 points.
The front side of the plane is the one where the points are disposed in the counter clockwise order.
6 planes max can be added.

Parameters:
x1 - : first point's X value
y1 - : first point's Y value
z1 - : first point's Z value
x2 - : second point's X value
y2 - : second point's Y value
z2 - : second point's Z value
x3 - : third point's X value
y3 - : third point's Y value
z3 - : third point's Z value

clearClipPlanes

public static void clearClipPlanes()
Removes all the clipping planes.


identity

public static void identity()
Resets the current matrix to identity.


translate

public static void translate(float x,
                             float y,
                             float z)
Applies a translation to the current matrix.

Parameters:
x - : the X axis translation value
y - : the Y axis translation value
z - : the Z axis translation value

rotate

public static void rotate(float angle,
                          float x,
                          float y,
                          float z)
Applies a rotation (in degrees) to the current matrix around the specified axis.

Parameters:
angle - : the rotation angle (in degrees)
x - : the rotation axis's X value
y - : the rotation axis's Y value
z - : the rotation axis's Z value

rotate

public static void rotate(float angleX,
                          float angleY,
                          float angleZ,
                          int order)
Applies a rotation to the current matrix with the specified Euler angles, in the chosen order (the angles order is given by constants from the JGL class. Ex : JGL.ZXY means that the matrix is rotated around Z, then X, then Y).

Parameters:
angleX - : the rotation angle around the X axis
angleY - : the rotation angle around the Y axis
angleZ - : the rotation angle around the Z axis
order - : the 3 axis rotations order

scale

public static void scale(float x,
                         float y,
                         float z)
Applies a scale transformation on 3 axis to the current matrix.

Parameters:
x - : the X axis scale value
y - : the Y axis scale value
z - : the Z axis scale value

multiplyRight

public static void multiplyRight(JGL_3DMatrix m)
Right-multiplies the current matrix by the specified matrix.

Parameters:
m - : the matrix to multiply

pushMatrix

public static void pushMatrix()
Pushes the current matrix in the matrix stack.


popMatrix

public static void popMatrix()
Restores the last pushed matrix as the current matrix.


getMatrix

public static JGL_3DMatrix getMatrix()
Returns a copy of the current matrix.

Returns:
the current transformation matrix (copy instance)

setCullFacing

public static void setCullFacing(boolean arg)
Sets the cull-facing on / off.

Parameters:
arg - : the cull-facing state

getCullFacing

public static boolean getCullFacing()
Returns if the cull-facing is on or off.

Returns:
the cull-facing state

setFaceOrder

public static void setFaceOrder(int order)
Sets the points order of a 3D triangle.
JGL.CCW : The front side of the face is the side where its points are in the counter-clockwise order (by default order).
JGL.CW : The front side of the face is the side where its points are in the clockwise order.

Parameters:
order - : the points order : JGL.CCW or JGL.CW

setSolidFace

public static void setSolidFace(boolean arg)
Sets triangles's display mode : solid or wire frame.

Parameters:
arg - : display mode (true : solid display, false : wire frame display)

getSolidFace

public static boolean getSolidFace()
Returns the current triangles's display mode : solid or wire frame.

Returns:
boolean (true : solid display, false : wire frame display)

setLighting

public static void setLighting(boolean arg)
Sets the lighting on / off.

Parameters:
arg - : the lighting state

getLighting

public static boolean getLighting()
Returns if the lighting is on or off.

Returns:
the lighting state

setLightPosition

public static void setLightPosition(float x,
                                    float y,
                                    float z)
Sets the light position (defined in the current matrix).

Parameters:
x - : light X position
y - : light Y position
z - : light Z position

setColor

public static void setColor(java.awt.Color arg)
Sets the current display color.

Parameters:
arg - : the color to set

getColor

public static java.awt.Color getColor()
Returns the current display color.

Returns:
the current color

setShininess

public static void setShininess(float percentage)
Sets the current shininess percentage (between 0 and 100). Shininess effect is available only when the lighting is on (see [JGL.set_lighting()] ).

Parameters:
percentage - : the shininess percentage

getShininess

public static float getShininess()
Returns the current shininess percentage.

Returns:
the shininess percentage

displayLine

public static void displayLine(float x1,
                               float y1,
                               float z1,
                               float x2,
                               float y2,
                               float z2)
Displays a 3D line with its 2 points coordinates.

Parameters:
x1 - : first point's X value
y1 - : first point's Y value
z1 - : first point's Z value
x2 - : second point's X value
y2 - : second point's Y value
z2 - : second point's Z value

displayTriangle

public static void displayTriangle(float x1,
                                   float y1,
                                   float z1,
                                   float x2,
                                   float y2,
                                   float z2,
                                   float x3,
                                   float y3,
                                   float z3)
Displays a 3D triangle with its 3 points coordinates.

Parameters:
x1 - : first point's X value
y1 - : first point's Y value
z1 - : first point's Z value
x2 - : second point's X value
y2 - : second point's Y value
z2 - : second point's Z value
x3 - : third point's X value
y3 - : third point's Y value
z3 - : third point's Z value