Class Support3D

java.lang.Object
edu.cnu.mdi.mdi3D.panel.Support3D

public class Support3D extends Object
A stateless library of OpenGL drawing primitives for the MDI 3D framework.

All methods are static and accept a GLAutoDrawable (or a raw GL2 context for lower-level helpers) plus the geometry and colour parameters needed to produce output. No instance is required.

Coordinate conventions

All geometry is expressed in the caller's current model-view coordinate system. Packed coordinate arrays always follow the layout:

   [x₀, y₀, z₀,  x₁, y₁, z₁,  ...]
 
so every three consecutive floats describe one point and coords.length / 3 gives the point count.

Colour and alpha

Every drawing method accepts Color values whose alpha component is honoured: a fully-opaque colour has alpha 255 and a fully transparent colour has alpha 0. Pass null where a colour is documented as optional to suppress that drawing pass.

Line width

Methods that accept a lineWidth parameter set glLineWidth before drawing and restore it to 1f afterwards. The caller's current line width is therefore clobbered; this is consistent with the rest of the framework.

Thread safety

All methods must be called from the JOGL GL thread (typically inside a GLEventListener callback). The shared glut field and the internal GLU / GLUquadric singletons are not thread-safe; do not call these methods concurrently from multiple GL contexts.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static com.jogamp.opengl.util.gl2.GLUT
    Shared GLUT utility instance used for stroke fonts, solid/wire primitives, and other GLUT geometry helpers.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    drawCone(com.jogamp.opengl.GLAutoDrawable drawable, float x1, float y1, float z1, float x2, float y2, float z2, float radius, Color color)
    Draws a solid cone with its base centred at (x1, y1, z1) and its tip at (x2, y2, z2).
    static void
    drawLine(com.jogamp.opengl.GLAutoDrawable drawable, double x1, double y1, double z1, double x2, double y2, double z2, Color color, float lineWidth)
    Draws a line segment between two explicit double endpoints.
    static void
    drawLine(com.jogamp.opengl.GLAutoDrawable drawable, float[] p0, float[] p1, Color color, float lineWidth)
    Draws a line segment between two endpoints supplied as float[3] arrays.
    static void
    drawLine(com.jogamp.opengl.GLAutoDrawable drawable, float[] coords, Color color, float lineWidth)
    Draws a line segment from a packed six-element coordinate array.
    static void
    drawLine(com.jogamp.opengl.GLAutoDrawable drawable, float x1, float y1, float z1, float ux, float uy, float uz, float length, Color color, float lineWidth)
    Draws a line segment from a start point along a unit-vector direction for a given length.
    static void
    drawLine(com.jogamp.opengl.GLAutoDrawable drawable, float x1, float y1, float z1, float x2, float y2, float z2, Color color, float lineWidth)
    Draws a line segment between two explicit float endpoints.
    static void
    drawLine(com.jogamp.opengl.GLAutoDrawable drawable, float x1, float y1, float z1, float x2, float y2, float z2, Color color1, Color color2, float lineWidth)
    Draws a line segment rendered in two alternating stipple colours.
    static void
    drawMarker(com.jogamp.opengl.GLAutoDrawable drawable, float x, float y, float z, Color markerColor, float markerSize, boolean circular, String label, float fontSize, Color fontColor)
    Draws a labelled marker: a point accompanied by a text label rendered in screen space below it.
    static void
    drawPoint(com.jogamp.opengl.GLAutoDrawable drawable, double x, double y, double z, Color color, float size, boolean circular)
    Draws a single point at double-precision coordinates.
    static void
    drawPoint(com.jogamp.opengl.GLAutoDrawable drawable, float x, float y, float z, Color color, float size)
    Draws a single point rendered as a point sprite.
    static void
    drawPoint(com.jogamp.opengl.GLAutoDrawable drawable, float x, float y, float z, Color color, float size, boolean circular)
    Draws a single point at float coordinates.
    static void
    drawPoints(com.jogamp.opengl.GLAutoDrawable drawable, float[] coords, Color color, float size, boolean circular)
    Draws a set of points from a packed coordinate array.
    static void
    drawPoints(com.jogamp.opengl.GLAutoDrawable drawable, float[] coords, Color fill, Color frame, float size, boolean circular)
    Draws a set of points with an optional contrasting frame ring.
    static void
    drawPolyLine(com.jogamp.opengl.GLAutoDrawable drawable, float[] coords, int livePoints, Color color, float lineWidth)
    Draws an open polyline using only the first livePoints vertices of a (possibly oversized) coordinate buffer.
    static void
    drawPolyLine(com.jogamp.opengl.GLAutoDrawable drawable, float[] coords, Color color, float lineWidth)
    Draws an open polyline connecting all vertices in a packed coordinate array.
    static void
    drawPolyLine(com.jogamp.opengl.GLAutoDrawable drawable, float[] coords, Color color1, Color color2, float lineWidth)
    Draws an open polyline rendered in two alternating stipple colours.
    static void
    drawQuad(com.jogamp.opengl.GLAutoDrawable drawable, float[] coords, int index1, int index2, int index3, int index4, Color color, float lineWidth, boolean frame)
    Draws a single quad addressed by four vertex indices into a shared coordinate array, with an optional frame in a darker shade.
    static void
    drawQuads(com.jogamp.opengl.GLAutoDrawable drawable, float[] coords, Color color, float lineWidth, boolean frame)
    Draws a batch of quads from a packed coordinate array, with an optional frame drawn in a darker shade of the fill colour.
    static void
    drawQuads(com.jogamp.opengl.GLAutoDrawable drawable, float[] coords, Color color, Color lineColor, float lineWidth)
    Draws a batch of quads from a packed coordinate array with an independent frame colour.
    static void
    drawRectangularSolid(com.jogamp.opengl.GLAutoDrawable drawable, float xc, float yc, float zc, float xw, float yw, float zw, Color fc, float lineWidth, boolean frame)
    Draws a solid axis-aligned rectangular box centred at (xc, yc, zc) with a frame in a darker shade of the fill colour.
    static void
    drawRectangularSolid(com.jogamp.opengl.GLAutoDrawable drawable, float xc, float yc, float zc, float xw, float yw, float zw, Color fc, Color lc, float lineWidth, boolean frame)
    Draws a solid axis-aligned rectangular box centred at (xc, yc, zc) with an independent frame colour.
    static void
    drawShadedQuad(com.jogamp.opengl.GLAutoDrawable drawable, float[] coords, Color fillColor, Color lineColor, float lineWidth, boolean enableLighting)
    Draws a batch of quads from a packed coordinate array with optional Phong-style lighting.
    static void
    drawShadedRectangularSolid(com.jogamp.opengl.GLAutoDrawable drawable, float xc, float yc, float zc, float xw, float yw, float zw, Color fc, Color lc, float lineWidth, boolean frame, boolean enableLighting)
    Draws a solid axis-aligned rectangular box with optional Phong-style lighting.
    static void
    drawShadedTube(com.jogamp.opengl.GLAutoDrawable drawable, float x1, float y1, float z1, float x2, float y2, float z2, float radius, Color color, boolean enableLighting)
    Draws an open-ended cylindrical tube between two points, with optional Phong-style lighting.
    static void
    drawSphericalPolygon(com.jogamp.opengl.GLAutoDrawable drawable, float radius, float[] coords, Color lineColor, Color fillColor, float lineWidth)
    Draws a filled and/or outlined spherical polygon defined by vertices in spherical coordinates.
    static void
    drawTriangle(com.jogamp.opengl.GLAutoDrawable drawable, float[] coords, int index1, int index2, int index3, Color color, float lineWidth, boolean frame)
    Draws a single triangle addressed by three vertex indices into a shared coordinate array, with an optional frame in a darker shade.
    static void
    drawTriangles(com.jogamp.opengl.GLAutoDrawable drawable, float[] coords, Color color, float lineWidth, boolean frame)
    Draws a batch of triangles from a packed coordinate array.
    static void
    drawTube(com.jogamp.opengl.GLAutoDrawable drawable, float x1, float y1, float z1, float x2, float y2, float z2, float radius, Color color)
    Draws a solid cylindrical tube between two endpoints.
    static float[]
    oneToFourTriangle(float[] coords)
    Splits a triangle given as a self-contained 9-element array into four smaller triangles by connecting its three edge midpoints.
    static float[]
    oneToFourTriangle(float[] coords, int index)
    Splits one triangle — addressed by a triple index into a packed array — into four by connecting its three edge midpoints.
    static void
    setColor(com.jogamp.opengl.GL2 gl, Color color)
    Sets the current OpenGL drawing colour from an AWT Color.
    static void
    solidShadedSphere(com.jogamp.opengl.GLAutoDrawable drawable, float x, float y, float z, float radius, int slices, int stacks, Color color, boolean enableLighting)
    Draws a solid sphere with optional Phong-style lighting.
    static void
    solidSphere(com.jogamp.opengl.GLAutoDrawable drawable, float x, float y, float z, float radius, int slices, int stacks, Color color)
    Draws a solid (filled) sphere centred at (x, y, z).
    static void
    solidSphereShell(com.jogamp.opengl.GLAutoDrawable drawable, float cx, float cy, float cz, float innerRadius, float outerRadius, int slices, int stacks, Color color)
    Draws a solid spherical shell — a sphere with a hollow interior — by rendering an outer surface, an inner surface with inverted normals, and a connecting band of quads along each horizontal latitude strip.
    static float[]
    toArray(float... v)
    Convenience factory that converts a varargs list of float values into a float[].
    static float[]
    triangulateTriangle(float[] coords, int level)
    Subdivides a triangle into 4^level smaller triangles by recursively connecting edge midpoints.
    static void
    wireSphere(com.jogamp.opengl.GLAutoDrawable drawable, float x, float y, float z, float radius, int slices, int stacks, Color color)
    Draws a wireframe sphere centred at (x, y, z).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • glut

      public static com.jogamp.opengl.util.gl2.GLUT glut
      Shared GLUT utility instance used for stroke fonts, solid/wire primitives, and other GLUT geometry helpers.

      This field is public so that callers can invoke GLUT methods not directly wrapped by this class (e.g. glut.glutBitmapCharacter(...)). It must only be used from the GL thread.

  • Constructor Details

    • Support3D

      public Support3D()
  • Method Details

    • drawPoints

      public static void drawPoints(com.jogamp.opengl.GLAutoDrawable drawable, float[] coords, Color color, float size, boolean circular)
      Draws a set of points from a packed coordinate array.

      All points are drawn with the same colour and pixel size. Pass circular = true to enable GL_POINT_SMOOTH, which asks the driver to rasterise each point as a circle rather than a square; support is driver-dependent.

      Parameters:
      drawable - the OpenGL drawable
      coords - packed point coordinates as [x, y, z, x, y, z, ...]; null or empty arrays are silently ignored
      color - the point colour
      size - the point diameter in pixels
      circular - true to request round (smooth) points; false for square points
    • drawPoints

      public static void drawPoints(com.jogamp.opengl.GLAutoDrawable drawable, float[] coords, Color fill, Color frame, float size, boolean circular)
      Draws a set of points with an optional contrasting frame ring.

      When frame is non-null, each point is drawn twice: first at full size in the frame colour to create an outline, then at size - 2 pixels in the fill colour on top. When frame is null this is equivalent to drawPoints(GLAutoDrawable, float[], Color, float, boolean).

      Parameters:
      drawable - the OpenGL drawable
      coords - packed point coordinates as [x, y, z, x, y, z, ...]; null or empty arrays are silently ignored
      fill - the inner fill colour
      frame - the outer frame colour, or null for no frame
      size - the outer point diameter in pixels; the inner fill is drawn at size - 2
      circular - true to request round (smooth) points
    • drawPoint

      public static void drawPoint(com.jogamp.opengl.GLAutoDrawable drawable, double x, double y, double z, Color color, float size, boolean circular)
      Draws a single point at double-precision coordinates.

      The coordinates are cast to float before submission to OpenGL.

      Parameters:
      drawable - the OpenGL drawable
      x - the x coordinate
      y - the y coordinate
      z - the z coordinate
      color - the point colour
      size - the point diameter in pixels
      circular - true to request round (smooth) points
    • drawPoint

      public static void drawPoint(com.jogamp.opengl.GLAutoDrawable drawable, float x, float y, float z, Color color, float size, boolean circular)
      Draws a single point at float coordinates.
      Parameters:
      drawable - the OpenGL drawable
      x - the x coordinate
      y - the y coordinate
      z - the z coordinate
      color - the point colour
      size - the point diameter in pixels
      circular - true to request round (smooth) points
    • drawMarker

      public static void drawMarker(com.jogamp.opengl.GLAutoDrawable drawable, float x, float y, float z, Color markerColor, float markerSize, boolean circular, String label, float fontSize, Color fontColor)
      Draws a labelled marker: a point accompanied by a text label rendered in screen space below it.

      The label is drawn using GLUT's STROKE_ROMAN vector font, projected into a temporary 2D orthographic overlay so its pixel size remains constant regardless of zoom. The text is centred horizontally on the marker's screen x and positioned markerSize/2 + 3 pixels below its screen y.

      Note: depth testing is temporarily disabled while the label is drawn so that it is never occluded by scene geometry.

      Parameters:
      drawable - the OpenGL drawable
      x - the x coordinate of the marker in world space
      y - the y coordinate of the marker in world space
      z - the z coordinate of the marker in world space
      markerColor - the colour of the point marker (the point itself is not drawn by this method; pass to drawPoint(GLAutoDrawable, float, float, float, Color, float, boolean) separately if required)
      markerSize - the pixel diameter of the marker, used only for computing the label offset
      circular - true to request round (smooth) point rendering
      label - the text string to display; must not be null
      fontSize - scaling factor applied to the GLUT stroke font; values around 0.07f–0.15f produce readable results in typical scenes
      fontColor - the colour of the rendered text
    • drawPoint

      public static void drawPoint(com.jogamp.opengl.GLAutoDrawable drawable, float x, float y, float z, Color color, float size)
      Draws a single point rendered as a point sprite.

      Point sprites (GL_POINT_SPRITE) allow a texture to be mapped onto a point primitive. This overload enables the sprite state, draws the point, then leaves sprite state enabled for the caller to manage. If no texture is bound, the point will appear as a solid-coloured square.

      Parameters:
      drawable - the OpenGL drawable
      x - the x coordinate
      y - the y coordinate
      z - the z coordinate
      color - the point colour
      size - the point sprite size in pixels
    • wireSphere

      public static void wireSphere(com.jogamp.opengl.GLAutoDrawable drawable, float x, float y, float z, float radius, int slices, int stacks, Color color)
      Draws a wireframe sphere centred at (x, y, z).

      The sphere is rendered using GLUT's glutWireSphere, which approximates the surface with longitude/latitude line strips.

      Parameters:
      drawable - the OpenGL drawable
      x - x coordinate of the centre
      y - y coordinate of the centre
      z - z coordinate of the centre
      radius - radius in model-space units
      slices - number of subdivisions around the Z axis (longitude lines); higher values produce a smoother appearance
      stacks - number of subdivisions along the Z axis (latitude bands); higher values produce a smoother appearance
      color - the wire colour
    • solidSphere

      public static void solidSphere(com.jogamp.opengl.GLAutoDrawable drawable, float x, float y, float z, float radius, int slices, int stacks, Color color)
      Draws a solid (filled) sphere centred at (x, y, z).

      The sphere is rendered using GLUT's glutSolidSphere with flat shading and no lighting. For a shaded appearance see solidShadedSphere(com.jogamp.opengl.GLAutoDrawable, float, float, float, float, int, int, java.awt.Color, boolean).

      Parameters:
      drawable - the OpenGL drawable
      x - x coordinate of the centre
      y - y coordinate of the centre
      z - z coordinate of the centre
      radius - radius in model-space units
      slices - number of subdivisions around the Z axis
      stacks - number of subdivisions along the Z axis
      color - the fill colour
    • solidShadedSphere

      public static void solidShadedSphere(com.jogamp.opengl.GLAutoDrawable drawable, float x, float y, float z, float radius, int slices, int stacks, Color color, boolean enableLighting)
      Draws a solid sphere with optional Phong-style lighting.

      When enableLighting is true, GL_LIGHT0 is configured as a directional light at (1, 1, 1) with white diffuse and specular components, and a material with shininess 50 is applied. The lighting and material state are restored (lighting disabled) after drawing. When enableLighting is false the sphere is drawn with flat colour, identical to solidSphere(com.jogamp.opengl.GLAutoDrawable, float, float, float, float, int, int, java.awt.Color).

      Parameters:
      drawable - the OpenGL drawable
      x - x coordinate of the centre
      y - y coordinate of the centre
      z - z coordinate of the centre
      radius - radius in model-space units
      slices - number of subdivisions around the Z axis
      stacks - number of subdivisions along the Z axis
      color - the sphere colour; also used as the material diffuse colour when lighting is enabled
      enableLighting - true to enable a directional GL_LIGHT0 and Phong materials; false for flat colour
    • solidSphereShell

      public static void solidSphereShell(com.jogamp.opengl.GLAutoDrawable drawable, float cx, float cy, float cz, float innerRadius, float outerRadius, int slices, int stacks, Color color)
      Draws a solid spherical shell — a sphere with a hollow interior — by rendering an outer surface, an inner surface with inverted normals, and a connecting band of quads along each horizontal latitude strip.
      Parameters:
      drawable - the OpenGL drawable
      cx - x coordinate of the centre
      cy - y coordinate of the centre
      cz - z coordinate of the centre
      innerRadius - the radius of the hollow interior; must be less than outerRadius
      outerRadius - the outer surface radius
      slices - number of subdivisions around the Z axis (longitude); higher values give a smoother silhouette
      stacks - number of subdivisions along the Z axis (latitude); higher values give a smoother silhouette
      color - the shell colour
    • drawRectangularSolid

      public static void drawRectangularSolid(com.jogamp.opengl.GLAutoDrawable drawable, float xc, float yc, float zc, float xw, float yw, float zw, Color fc, float lineWidth, boolean frame)
      Draws a solid axis-aligned rectangular box centred at (xc, yc, zc) with a frame in a darker shade of the fill colour.

      Equivalent to calling drawRectangularSolid(GLAutoDrawable, float, float, float, float, float, float, Color, Color, float, boolean) with lc = null (the frame colour defaults to fc.darker()).

      Parameters:
      drawable - the OpenGL drawable
      xc - x coordinate of the box centre
      yc - y coordinate of the box centre
      zc - z coordinate of the box centre
      xw - total width along the X axis
      yw - total width along the Y axis
      zw - total width along the Z axis
      fc - the fill colour for all six faces
      lineWidth - the frame line width in pixels
      frame - true to draw a wireframe outline over the filled faces
    • drawRectangularSolid

      public static void drawRectangularSolid(com.jogamp.opengl.GLAutoDrawable drawable, float xc, float yc, float zc, float xw, float yw, float zw, Color fc, Color lc, float lineWidth, boolean frame)
      Draws a solid axis-aligned rectangular box centred at (xc, yc, zc) with an independent frame colour.

      All six faces are filled with fc. When frame is true a wireframe outline is superimposed using lc; if lc is null the frame is drawn in fc.darker().

      Parameters:
      drawable - the OpenGL drawable
      xc - x coordinate of the box centre
      yc - y coordinate of the box centre
      zc - z coordinate of the box centre
      xw - total width along the X axis
      yw - total width along the Y axis
      zw - total width along the Z axis
      fc - the fill colour for all six faces
      lc - the frame (outline) colour, or null to use fc.darker()
      lineWidth - the frame line width in pixels
      frame - true to draw a wireframe outline over the filled faces
    • drawShadedRectangularSolid

      public static void drawShadedRectangularSolid(com.jogamp.opengl.GLAutoDrawable drawable, float xc, float yc, float zc, float xw, float yw, float zw, Color fc, Color lc, float lineWidth, boolean frame, boolean enableLighting)
      Draws a solid axis-aligned rectangular box with optional Phong-style lighting.

      When enableLighting is true, GL_LIGHT0 is configured the same way as in solidShadedSphere(com.jogamp.opengl.GLAutoDrawable, float, float, float, float, int, int, java.awt.Color, boolean): a directional light at (1, 1, 1) with white diffuse/specular components, and a material with shininess 50. Each of the six faces is submitted with its own axis-aligned face normal (via glNormal3f) so the fixed-function lighting pipeline shades each face independently as the box rotates. The lighting and material state are restored (lighting disabled) after drawing. When enableLighting is false, the box is drawn with flat colour, identical to drawRectangularSolid(com.jogamp.opengl.GLAutoDrawable, float, float, float, float, float, float, java.awt.Color, float, boolean).

      Parameters:
      drawable - the OpenGL drawable
      xc - x coordinate of the box centre
      yc - y coordinate of the box centre
      zc - z coordinate of the box centre
      xw - total width along the X axis
      yw - total width along the Y axis
      zw - total width along the Z axis
      fc - the fill colour for all six faces; also used as the material diffuse colour when lighting is enabled
      lc - the frame (outline) colour, or null to use fc.darker()
      lineWidth - the frame line width in pixels
      frame - true to draw a wireframe outline over the filled faces
      enableLighting - true to enable a directional GL_LIGHT0 and Phong materials; false for flat colour
    • drawQuads

      public static void drawQuads(com.jogamp.opengl.GLAutoDrawable drawable, float[] coords, Color color, float lineWidth, boolean frame)
      Draws a batch of quads from a packed coordinate array, with an optional frame drawn in a darker shade of the fill colour.

      Equivalent to drawQuads(GLAutoDrawable, float[], Color, Color, float) with lineColor = frame ? color.darker() : null.

      Parameters:
      drawable - the OpenGL drawable
      coords - packed quad vertices as [x, y, z, ...]; every 12 floats (4 vertices × 3 coordinates) describe one quad
      color - the fill colour
      lineWidth - the frame line width in pixels
      frame - true to draw a wireframe outline around each quad
    • drawQuads

      public static void drawQuads(com.jogamp.opengl.GLAutoDrawable drawable, float[] coords, Color color, Color lineColor, float lineWidth)
      Draws a batch of quads from a packed coordinate array with an independent frame colour.

      All vertices in coords are submitted as a single GL_QUADS primitive. When lineColor is non-null, each group of four vertices is additionally drawn as a closed GL_LINE_STRIP to produce a per-quad outline.

      Parameters:
      drawable - the OpenGL drawable
      coords - packed quad vertices as [x, y, z, ...]; every 12 floats describe one quad
      color - the fill colour
      lineColor - the frame colour, or null for no frame
      lineWidth - the frame line width in pixels
    • drawShadedQuad

      public static void drawShadedQuad(com.jogamp.opengl.GLAutoDrawable drawable, float[] coords, Color fillColor, Color lineColor, float lineWidth, boolean enableLighting)
      Draws a batch of quads from a packed coordinate array with optional Phong-style lighting.

      Each group of four vertices (one quad) is submitted as its own GL_QUADS call with a single face normal computed via the cross product of its first two edges, so flat quads at arbitrary orientations — not just axis-aligned ones — shade correctly as the scene rotates. This is the batch counterpart to drawRectangularSolid(com.jogamp.opengl.GLAutoDrawable, float, float, float, float, float, float, java.awt.Color, float, boolean)'s per-face normals, generalized to a quad of any orientation.

      When enableLighting is true, lighting is set up exactly as in solidShadedSphere(com.jogamp.opengl.GLAutoDrawable, float, float, float, float, int, int, java.awt.Color, boolean). When false, this behaves like drawQuads(GLAutoDrawable, float[], Color, Color, float).

      Parameters:
      drawable - the OpenGL drawable
      coords - packed quad vertices as [x, y, z, ...]; every 12 floats describe one quad
      fillColor - the fill colour; also used as the material diffuse colour when lighting is enabled
      lineColor - the frame (outline) colour, or null for no frame
      lineWidth - the frame line width in pixels
      enableLighting - true to enable a directional GL_LIGHT0 and Phong materials; false for flat colour
    • drawQuad

      public static void drawQuad(com.jogamp.opengl.GLAutoDrawable drawable, float[] coords, int index1, int index2, int index3, int index4, Color color, float lineWidth, boolean frame)
      Draws a single quad addressed by four vertex indices into a shared coordinate array, with an optional frame in a darker shade.

      The indices are "triple indices": index k refers to the point at coords[3k], coords[3k+1], coords[3k+2].

      Parameters:
      drawable - the OpenGL drawable
      coords - the shared coordinate pool as [x, y, z, ...]
      index1 - triple index of the first vertex
      index2 - triple index of the second vertex
      index3 - triple index of the third vertex
      index4 - triple index of the fourth vertex
      color - the fill colour
      lineWidth - the frame line width in pixels
      frame - true to outline the quad in color.darker()
    • drawTriangles

      public static void drawTriangles(com.jogamp.opengl.GLAutoDrawable drawable, float[] coords, Color color, float lineWidth, boolean frame)
      Draws a batch of triangles from a packed coordinate array.

      Every 9 floats in coords describe one triangle ([x1,y1,z1, x2,y2,z2, x3,y3,z3]). Each triangle is drawn by delegating to drawTriangle(GLAutoDrawable, float[], int, int, int, Color, float, boolean).

      Parameters:
      drawable - the OpenGL drawable
      coords - packed triangle vertices as [x, y, z, ...]; length must be a multiple of 9
      color - the fill colour
      lineWidth - the frame line width in pixels
      frame - true to outline each triangle in color.darker()
    • drawTriangle

      public static void drawTriangle(com.jogamp.opengl.GLAutoDrawable drawable, float[] coords, int index1, int index2, int index3, Color color, float lineWidth, boolean frame)
      Draws a single triangle addressed by three vertex indices into a shared coordinate array, with an optional frame in a darker shade.

      The indices are "triple indices": index k refers to the point at coords[3k], coords[3k+1], coords[3k+2].

      Parameters:
      drawable - the OpenGL drawable
      coords - the shared coordinate pool as [x, y, z, ...]
      index1 - triple index of the first vertex
      index2 - triple index of the second vertex
      index3 - triple index of the third vertex
      color - the fill colour
      lineWidth - the frame line width in pixels
      frame - true to outline the triangle in color.darker()
    • triangulateTriangle

      public static float[] triangulateTriangle(float[] coords, int level)
      Subdivides a triangle into 4^level smaller triangles by recursively connecting edge midpoints.

      At level = 1 the input triangle is split into 4. At level = 2 each of those 4 is split again, yielding 16, and so on. The resulting triangles lie in the same plane as the original (no projection onto a sphere is applied); for spherical subdivision, normalise the vertices after calling this method.

      Parameters:
      coords - the input triangle as [x1, y1, z1, x2, y2, z2, x3, y3, z3]
      level - subdivision depth; values less than 1 return coords unchanged; each level multiplies the triangle count by 4
      Returns:
      a packed coordinate array containing all output triangles in the same [x, y, z, ...] layout; length is 9 * 4^max(level,0)
    • oneToFourTriangle

      public static float[] oneToFourTriangle(float[] coords, int index)
      Splits one triangle — addressed by a triple index into a packed array — into four by connecting its three edge midpoints.

      The result is returned as a new packed array of 36 floats (4 triangles × 3 vertices × 3 coordinates). The winding order of the four output triangles matches the winding order of the input.

      Parameters:
      coords - the packed coordinate array containing at least 3 * (index + 3) floats
      index - triple index of the first vertex of the triangle to split; vertices are at triple indices index, index+1, index+2
      Returns:
      a 36-element array containing the four output triangles
    • oneToFourTriangle

      public static float[] oneToFourTriangle(float[] coords)
      Splits a triangle given as a self-contained 9-element array into four smaller triangles by connecting its three edge midpoints.

      Equivalent to oneToFourTriangle(float[], int) with index = 0.

      Parameters:
      coords - the triangle as [x1, y1, z1, x2, y2, z2, x3, y3, z3]; must have length ≥ 9
      Returns:
      a 36-element array containing the four output triangles
    • drawLine

      public static void drawLine(com.jogamp.opengl.GLAutoDrawable drawable, float x1, float y1, float z1, float ux, float uy, float uz, float length, Color color, float lineWidth)
      Draws a line segment from a start point along a unit-vector direction for a given length.

      The endpoint is computed as (x1 + length*ux, y1 + length*uy, z1 + length*uz) and the call delegates to drawLine(GLAutoDrawable, float, float, float, float, float, float, Color, float).

      Parameters:
      drawable - the OpenGL drawable
      x1 - x coordinate of the start point
      y1 - y coordinate of the start point
      z1 - z coordinate of the start point
      ux - x component of the unit direction vector
      uy - y component of the unit direction vector
      uz - z component of the unit direction vector
      length - the length of the line segment in model-space units
      color - the line colour
      lineWidth - the line width in pixels
    • drawLine

      public static void drawLine(com.jogamp.opengl.GLAutoDrawable drawable, float x1, float y1, float z1, float x2, float y2, float z2, Color color, float lineWidth)
      Draws a line segment between two explicit float endpoints.
      Parameters:
      drawable - the OpenGL drawable
      x1 - x coordinate of the first endpoint
      y1 - y coordinate of the first endpoint
      z1 - z coordinate of the first endpoint
      x2 - x coordinate of the second endpoint
      y2 - y coordinate of the second endpoint
      z2 - z coordinate of the second endpoint
      color - the line colour
      lineWidth - the line width in pixels
    • drawLine

      public static void drawLine(com.jogamp.opengl.GLAutoDrawable drawable, double x1, double y1, double z1, double x2, double y2, double z2, Color color, float lineWidth)
      Draws a line segment between two explicit double endpoints.

      The coordinates are cast to float before submission to OpenGL.

      Parameters:
      drawable - the OpenGL drawable
      x1 - x coordinate of the first endpoint
      y1 - y coordinate of the first endpoint
      z1 - z coordinate of the first endpoint
      x2 - x coordinate of the second endpoint
      y2 - y coordinate of the second endpoint
      z2 - z coordinate of the second endpoint
      color - the line colour
      lineWidth - the line width in pixels
    • drawLine

      public static void drawLine(com.jogamp.opengl.GLAutoDrawable drawable, float[] p0, float[] p1, Color color, float lineWidth)
      Draws a line segment between two endpoints supplied as float[3] arrays.
      Parameters:
      drawable - the OpenGL drawable
      p0 - first endpoint as [x, y, z]; must have length ≥ 3
      p1 - second endpoint as [x, y, z]; must have length ≥ 3
      color - the line colour
      lineWidth - the line width in pixels
    • drawLine

      public static void drawLine(com.jogamp.opengl.GLAutoDrawable drawable, float[] coords, Color color, float lineWidth)
      Draws a line segment from a packed six-element coordinate array.
      Parameters:
      drawable - the OpenGL drawable
      coords - the line as [x1, y1, z1, x2, y2, z2]; must have length ≥ 6
      color - the line colour
      lineWidth - the line width in pixels
    • drawLine

      public static void drawLine(com.jogamp.opengl.GLAutoDrawable drawable, float x1, float y1, float z1, float x2, float y2, float z2, Color color1, Color color2, float lineWidth)
      Draws a line segment rendered in two alternating stipple colours.

      The segment is drawn twice using GL_LINE_STIPPLE: once with pattern 0x00FF (first half solid) in color1, and once with pattern 0xFF00 (second half solid) in color2. Either colour may be null to suppress that pass. The combined effect produces a two-colour dashed appearance.

      Parameters:
      drawable - the OpenGL drawable
      x1 - x coordinate of the first endpoint
      y1 - y coordinate of the first endpoint
      z1 - z coordinate of the first endpoint
      x2 - x coordinate of the second endpoint
      y2 - y coordinate of the second endpoint
      z2 - z coordinate of the second endpoint
      color1 - the first stipple colour, or null to skip
      color2 - the second stipple colour, or null to skip
      lineWidth - the line width in pixels
    • drawPolyLine

      public static void drawPolyLine(com.jogamp.opengl.GLAutoDrawable drawable, float[] coords, Color color, float lineWidth)
      Draws an open polyline connecting all vertices in a packed coordinate array.

      Every three consecutive floats describe one vertex. At least two vertices are required for visible output; the method does not guard against fewer.

      Parameters:
      drawable - the OpenGL drawable
      coords - packed vertex coordinates as [x, y, z, ...]
      color - the line colour
      lineWidth - the line width in pixels
    • drawPolyLine

      public static void drawPolyLine(com.jogamp.opengl.GLAutoDrawable drawable, float[] coords, int livePoints, Color color, float lineWidth)
      Draws an open polyline using only the first livePoints vertices of a (possibly oversized) coordinate buffer.

      This overload exists to avoid trimming a backing buffer to its live length before drawing — the caller supplies the count explicitly. It is used by Trajectory3D to achieve zero-copy append semantics. If livePoints is less than 2, nothing is drawn.

      Parameters:
      drawable - the OpenGL drawable
      coords - the coordinate buffer as [x, y, z, ...]; may be larger than 3 * livePoints; only indices [0, 3 * livePoints) are read
      livePoints - the number of valid vertices to draw; values less than 2 produce no output
      color - the line colour
      lineWidth - the line width in pixels
    • drawPolyLine

      public static void drawPolyLine(com.jogamp.opengl.GLAutoDrawable drawable, float[] coords, Color color1, Color color2, float lineWidth)
      Draws an open polyline rendered in two alternating stipple colours.

      The polyline is drawn twice using GL_LINE_STIPPLE: once with pattern 0x00FF in color1 and once with pattern 0xFF00 in color2. Either colour may be null to suppress that pass.

      Parameters:
      drawable - the OpenGL drawable
      coords - packed vertex coordinates as [x, y, z, ...]
      color1 - the first stipple colour, or null to skip
      color2 - the second stipple colour, or null to skip
      lineWidth - the line width in pixels
    • drawCone

      public static void drawCone(com.jogamp.opengl.GLAutoDrawable drawable, float x1, float y1, float z1, float x2, float y2, float z2, float radius, Color color)
      Draws a solid cone with its base centred at (x1, y1, z1) and its tip at (x2, y2, z2).

      The cone is oriented along the vector from base to tip using a single glRotatef call. The rotation axis degenerates when the direction vector is exactly parallel to the Z axis; a small epsilon (1e-5) is applied to the Z component to avoid this in practice.

      Parameters:
      drawable - the OpenGL drawable
      x1 - x coordinate of the base centre
      y1 - y coordinate of the base centre
      z1 - z coordinate of the base centre
      x2 - x coordinate of the tip
      y2 - y coordinate of the tip
      z2 - z coordinate of the tip
      radius - radius of the base circle in model-space units
      color - the cone colour
    • drawTube

      public static void drawTube(com.jogamp.opengl.GLAutoDrawable drawable, float x1, float y1, float z1, float x2, float y2, float z2, float radius, Color color)
      Draws a solid cylindrical tube between two endpoints.

      The tube is rendered as a GLU cylinder oriented along the vector from (x1,y1,z1) to (x2,y2,z2) with 50 radial subdivisions and no end caps. The same axis-alignment approach as drawCone(com.jogamp.opengl.GLAutoDrawable, float, float, float, float, float, float, float, java.awt.Color) is used; the same Z-axis epsilon applies.

      Parameters:
      drawable - the OpenGL drawable
      x1 - x coordinate of the first end
      y1 - y coordinate of the first end
      z1 - z coordinate of the first end
      x2 - x coordinate of the second end
      y2 - y coordinate of the second end
      z2 - z coordinate of the second end
      radius - the tube radius in model-space units
      color - the tube colour
    • drawShadedTube

      public static void drawShadedTube(com.jogamp.opengl.GLAutoDrawable drawable, float x1, float y1, float z1, float x2, float y2, float z2, float radius, Color color, boolean enableLighting)
      Draws an open-ended cylindrical tube between two points, with optional Phong-style lighting.

      Behaves exactly like drawTube(com.jogamp.opengl.GLAutoDrawable, float, float, float, float, float, float, float, java.awt.Color) except that when enableLighting is true, the shared GLU quadric is told to generate smooth per-vertex normals (GLU_SMOOTH) via gluQuadricNormals, and lighting/material state is applied around the gluCylinder call the same way solidShadedSphere(com.jogamp.opengl.GLAutoDrawable, float, float, float, float, int, int, java.awt.Color, boolean) does. The quadric's normal mode is restored to GLU_NONE afterward so unlit callers of drawTube(com.jogamp.opengl.GLAutoDrawable, float, float, float, float, float, float, float, java.awt.Color) are unaffected.

      No end caps are drawn, matching drawTube(com.jogamp.opengl.GLAutoDrawable, float, float, float, float, float, float, float, java.awt.Color).

      Parameters:
      drawable - the OpenGL drawable
      x1 - x coordinate of the first endpoint
      y1 - y coordinate of the first endpoint
      z1 - z coordinate of the first endpoint
      x2 - x coordinate of the second endpoint
      y2 - y coordinate of the second endpoint
      z2 - z coordinate of the second endpoint
      radius - tube radius
      color - the tube colour; also used as the material diffuse colour when lighting is enabled
      enableLighting - true to enable a directional GL_LIGHT0 and Phong materials; false for flat colour
    • drawSphericalPolygon

      public static void drawSphericalPolygon(com.jogamp.opengl.GLAutoDrawable drawable, float radius, float[] coords, Color lineColor, Color fillColor, float lineWidth)
      Draws a filled and/or outlined spherical polygon defined by vertices in spherical coordinates.

      The polygon vertices are supplied in spherical coordinates as alternating (theta, phi) pairs in radians, where theta is the polar angle from the positive Z axis ([0, π]) and phi is the azimuthal angle in the XY plane ([-π, π]). They are converted internally to Cartesian coordinates on the surface of a sphere of the given radius.

      The fill is drawn as a GL_POLYGON primitive; the outline is drawn as a GL_LINE_LOOP. Either pass may be suppressed by passing null for the corresponding colour.

      Parameters:
      drawable - the OpenGL drawable
      radius - the sphere radius on whose surface the polygon is drawn
      coords - spherical coordinate pairs as [theta0, phi0, theta1, phi1, ...]; length must be even
      lineColor - the outline colour, or null for no outline
      fillColor - the fill colour, or null for no fill
      lineWidth - the outline line width in pixels
    • setColor

      public static void setColor(com.jogamp.opengl.GL2 gl, Color color)
      Sets the current OpenGL drawing colour from an AWT Color.

      All four components (red, green, blue, alpha) are normalised from the AWT range [0, 255] to the OpenGL range [0.0, 1.0] and submitted via glColor4f.

      Parameters:
      gl - the GL2 context
      color - the AWT colour to apply; must not be null
    • toArray

      public static float[] toArray(float... v)
      Convenience factory that converts a varargs list of float values into a float[].

      This is syntactic sugar for building inline coordinate arrays:

         Support3D.drawPolyLine(drawable,
             Support3D.toArray(0f, 0f, 0f,  1f, 0f, 0f,  1f, 1f, 0f),
             Color.WHITE, 1f);
       
      Parameters:
      v - the float values; may be empty
      Returns:
      the same values as a float[]; the array is the varargs array itself, so no copy is made