Class Sphere

All Implemented Interfaces:
ISingleColorable, IGLRenderer, ISortableDraw
Direct Known Subclasses:
PickableSphere, SelectableSphere

public class Sphere extends Wireframeable implements ISingleColorable
Allows rendering a sphere. The position and shape of a Sphere3d is defined through its
invalid @link
setData()
method. Moreover, a Sphere3d is Wireframeable3d and support only one color that is defined trough its
invalid @link
setColor()
method.
Author:
Martin Pernollet
  • Field Details

    • position

      protected Coord3d position
    • radius

      protected float radius
    • slices

      protected int slices
    • stacks

      protected int stacks
    • color

      protected Color color
  • Constructor Details

    • Sphere

      public Sphere()
      Initialize a black sphere at the origin with a radius of 10, and slicing of 15.
    • Sphere

      public Sphere(Coord3d position, float radius, int slicing, Color color)
      Initialize a sphere with the given parameters.
  • Method Details

    • draw

      public void draw(IPainter painter)
      Description copied from class: Drawable
      Call OpenGL2 routines for rendering the object.
      Specified by:
      draw in interface IGLRenderer
      Specified by:
      draw in class Drawable
    • doDrawSphere

      protected void doDrawSphere(IPainter painter)
    • applyGeometryTransform

      public void applyGeometryTransform(Transform transform)
      Specified by:
      applyGeometryTransform in class Drawable
    • setData

      public void setData(Coord3d position, float radius, float height, int slices, int stacks)
      Set the sphere data.
      Parameters:
      position - sphere position (may be handled differently in future version)
      radius - radius of the sphere
      slices - number of vertical slices (i.e. wireframes)
      stacks - number of horizontal stacks (i.e. wireframes)
    • setPosition

      public void setPosition(Coord3d position)
      Set the position of the Sphere and the dimensions of its boundingbox. Note that this position will be use to translate the object before drawing it (meaning a glTranslate(position) is performed right after the Translate.execute).
      Parameters:
      position -
    • getPosition

      public Coord3d getPosition()
    • updateBounds

      public void updateBounds()
      Specified by:
      updateBounds in class Drawable
    • setVolume

      public void setVolume(float radius)
      Set the radius of the sphere, and the dimensions of its boundingbox.
      Parameters:
      radius - sphere radius
    • setSlicing

      public void setSlicing(int verticalWires, int horizontalWires)
      Set the sphere slicing parameters, i.e. the subtlety of the circle estimation.
      Parameters:
      verticalWires - number of vertical slices
      horizontalWires - number of horizontal slices
    • setColor

      public void setColor(Color color)
      Description copied from interface: ISingleColorable
      Set the color.
      Specified by:
      setColor in interface ISingleColorable
      Parameters:
      color - the color
    • getColor

      public Color getColor()
      Description copied from interface: ISingleColorable
      Get the color.
      Specified by:
      getColor in interface ISingleColorable
      Returns:
      color the color.
    • toString

      public String toString(int depth)
      Overrides:
      toString in class Drawable