Class Polygon

java.lang.Object
org.xjge.graphics.Polygon

public class Polygon
extends java.lang.Object
Objects of this class can be used as part of a larger UI widget to represent a regular 2D shape such as a pentagon, hexagon, or circle by utilizing the number of sides specified through its constructor.
Since:
2.0.0
  • Field Summary

    Fields
    Modifier and Type Field Description
    Color color  
    boolean fill  
  • Constructor Summary

    Constructors
    Constructor Description
    Polygon​(int numSides, boolean fill, float radius, Color color, int xPos, int yPos)
    Creates a new n-sided polygon object which can be used to represent regular shapes and circles.
    Polygon​(int numSides, boolean fill, float radius, Color color, org.joml.Vector2i position)
    Alternate version of the Polygon() constructor.
  • Method Summary

    Modifier and Type Method Description
    void freeBuffers()
    Convenience method which frees the data buffers allocated by this class.
    void render()
    Draws the polygon using the data specified by the constructor.
    void rotate​(float angle)
    Rotates the polygon according to the angle specified.
    void translate​(int x, int y)
    Alternate version of translate(Vector2i).
    void translate​(org.joml.Vector2i position)
    Translates the polygon to the position specified.

    Methods inherited from class java.lang.Object

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

    • fill

      public boolean fill
    • color

      public Color color
  • Constructor Details

    • Polygon

      public Polygon​(int numSides, boolean fill, float radius, Color color, int xPos, int yPos)
      Creates a new n-sided polygon object which can be used to represent regular shapes and circles.
      Parameters:
      numSides - the number of sides this shape will exhibit, (5 for a pentagon, 6 for a hexagon, etc.)
      fill - if true, the shape will be filled with the specified color
      radius - the radius used to determine the size of the polygon
      color - the color to render this shape in
      xPos - the x-coordinate of the shapes initial position in the viewport
      yPos - the y-coordinate of the shapes initial position in the viewport
    • Polygon

      public Polygon​(int numSides, boolean fill, float radius, Color color, org.joml.Vector2i position)
      Alternate version of the Polygon() constructor.
      Parameters:
      numSides - the number of sides this shape will exhibit, (5 for a pentagon, 6 for a hexagon, etc.)
      fill - if true, the shape will be filled with the specified color
      radius - the radius used to determine the size of the polygon
      color - the color to render this shape in
      position - the position at which the shape will be placed initially
  • Method Details

    • translate

      public final void translate​(org.joml.Vector2i position)
      Translates the polygon to the position specified.

      NOTE: Polygons are positioned around their centerpoints.

      Parameters:
      position - the position where the shape will be placed
    • translate

      public final void translate​(int x, int y)
      Alternate version of translate(Vector2i).
      Parameters:
      x - the x coordinate to place this shape in the window
      y - the y coordinate to place this shape in the window
    • rotate

      public final void rotate​(float angle)
      Rotates the polygon according to the angle specified.
      Parameters:
      angle - the value indicating the rotation of the shape
    • render

      public void render()
      Draws the polygon using the data specified by the constructor.
    • freeBuffers

      public void freeBuffers()
      Convenience method which frees the data buffers allocated by this class.