Class Sphere

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

public class Sphere extends Item3D
A solid sphere, optionally with drawn latitude/longitude gridlines and optional Phong-style lighting.
  • Constructor Details

    • Sphere

      public Sphere(Panel3D panel3D, float x, float y, float z, float radius, Color color)
      Constructor for a Sphere item in 3D space.
      Parameters:
      panel3D - The parent 3D panel
      x - X coordinate of the center
      y - Y coordinate of the center
      z - Z coordinate of the center
      radius - Radius of the sphere
      color - Color of the sphere
  • Method Details

    • setCenter

      public void setCenter(float x, float y, float z)
      Set the center of the sphere.
      Parameters:
      x - X coordinate
      y - Y coordinate
      z - Z coordinate
    • setResolution

      public void setResolution(int slices, int stacks)
      Set the resolution of the sphere. Higher values for slices and stacks result in a smoother sphere.
      Parameters:
      slices - Number of slices (longitude divisions)
      stacks - Number of stacks (latitude divisions)
    • setGridlines

      public void setGridlines(float[] theta, float[] phi)
      Set the gridlines for the sphere.
      Parameters:
      theta - Array of polar angles [0, π]
      phi - Array of azimuthal angles [-π, π]
    • setGridColor

      public void setGridColor(Color gridColor)
      Set the color of the gridlines.
      Parameters:
      gridColor - The gridline color
    • setLighted

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

      When enabled, the sphere is drawn via Support3D.solidShadedSphere(GLAutoDrawable, float, float, float, float, int, int, Color, boolean) with a fixed directional light, so its shading visibly changes as the sphere (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 sphere.
      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]