Package org.xjge.graphics
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
-
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 thePolygon()
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 oftranslate(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
-
-
Constructor Details
-
Polygon
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 colorradius
- the radius used to determine the size of the polygoncolor
- the color to render this shape inxPos
- the x-coordinate of the shapes initial position in the viewportyPos
- the y-coordinate of the shapes initial position in the viewport
-
Polygon
Alternate version of thePolygon()
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 colorradius
- the radius used to determine the size of the polygoncolor
- the color to render this shape inposition
- 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 oftranslate(Vector2i)
.- Parameters:
x
- the x coordinate to place this shape in the windowy
- 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.
-