Class Cube

java.lang.Object
edu.cnu.mdi.mdi3D.item3D.Item3D
edu.cnu.mdi.mdi3D.item3D.Cube

public class Cube extends Item3D
A solid, axis-aligned cube, optionally framed and optionally rendered with Phong-style per-face lighting.
  • Field Details

    • xc

      public final float xc
    • yc

      public final float yc
    • zc

      public final float zc
    • length

      public final float length
    • _frame

      protected boolean _frame
  • Constructor Details

    • Cube

      public Cube(Panel3D panel3D, float xc, float yc, float zc, float length, Color color)
      Create an unframed cube.
      Parameters:
      panel3D - the owner 3D panel
      xc - x coordinate of the center
      yc - y coordinate of the center
      zc - z coordinate of the center
      length - side length
      color - fill color
    • Cube

      public Cube(Panel3D panel3D, float xc, float yc, float zc, float length, Color color, boolean frame)
      Create a cube, optionally framed.
      Parameters:
      panel3D - the owner 3D panel
      xc - x coordinate of the center
      yc - y coordinate of the center
      zc - z coordinate of the center
      length - side length
      color - fill color
      frame - if true, also draw a wireframe outline
  • Method Details

    • setLighted

      public void setLighted(boolean lighted)
      Enable or disable Phong-style lighting for this cube.

      When enabled, each of the six faces is drawn with its own face normal via Support3D.drawShadedRectangularSolid(com.jogamp.opengl.GLAutoDrawable, float, float, float, float, float, float, java.awt.Color, java.awt.Color, float, boolean, boolean), so shading visibly changes as the cube (or the scene around it) rotates. Disabled by default, matching the flat-colour appearance existing callers already expect.

      Parameters:
      lighted - true to enable lighting; false for flat colour
    • isLighted

      public boolean isLighted()
      Whether Phong-style lighting is enabled for this cube.
      Returns:
      true if lighting is enabled
    • draw

      public void draw(com.jogamp.opengl.GLAutoDrawable drawable)
      Description copied from class: Item3D
      The custom drawing method
      Specified by:
      draw in class Item3D
      Parameters:
      drawable - the OpenGL drawable
    • getSortPoint

      public float[] getSortPoint()
      Description copied from class: Item3D
      A representative point for transparent sorting, in world coordinates. Default is origin. Override in items with a natural center (Sphere, Cube, Cylinder, etc.).
      Overrides:
      getSortPoint in class Item3D
      Returns:
      the sort point as [x, y, z]