java.lang.Object
dev.prozilla.pine.core.rendering.shape.Shape
All Implemented Interfaces:
Cloneable<Shape>, ColoredDrawable, Drawable, TexturedDrawable
Direct Known Subclasses:
Circle, Rect

public abstract class Shape extends Object implements TexturedDrawable, Cloneable<Shape>
Represents a shape using vertex and UV arrays which respectively represent the vertex and texture coordinates of each triangle.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    boolean
    If true, the vertex and UV arrays of this shape will be re-generated before the next draw call.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a shape that will be generated before the first draw call.
    Shape(float[] vertices, float[] uvArray)
    Creates a shape with pre-generated geometry.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds a modifier to this shape.
    abstract Shape
    Returns a new object that is equal to this object.
     
    void
    draw(Renderer renderer, TextureAsset texture, Color color, float depth)
    Draws this shape using its vertex and UV arrays.
    void
    Generates the arrays of vertices and texture coordinates for this shape and applies each modifier.
    protected abstract float[]
    Generates the UV array for this shape.
    protected abstract float[]
    Generates the vertex array for this shape.
    <M extends ShapeModifier>
    M
    getModifier(Class<M> modifierType)
    Gets the first modifier of a given type.
    void
    Removes a modifier from this shape.

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface dev.prozilla.pine.common.Cloneable

    equals

    Methods inherited from interface dev.prozilla.pine.core.rendering.shape.ColoredDrawable

    draw

    Methods inherited from interface dev.prozilla.pine.core.rendering.shape.TexturedDrawable

    draw, draw
  • Field Details

    • isDirty

      public boolean isDirty
      If true, the vertex and UV arrays of this shape will be re-generated before the next draw call.
  • Constructor Details

    • Shape

      public Shape(float[] vertices, float[] uvArray)
      Creates a shape with pre-generated geometry.
      Parameters:
      vertices - The vertex array
      uvArray - The UV array
    • Shape

      public Shape()
      Creates a shape that will be generated before the first draw call.
  • Method Details

    • generate

      public void generate()
      Generates the arrays of vertices and texture coordinates for this shape and applies each modifier.
    • generateVertices

      protected abstract float[] generateVertices()
      Generates the vertex array for this shape.

      Odd elements define the x-component of the vertex and even elements define the y-component.

      Every three vertices (or six elements) define a triangle.

      Returns:
      The array of vertices.
    • generateUVs

      protected abstract float[] generateUVs()
      Generates the UV array for this shape.

      Odd elements define the x-component of the texture coordinate and even elements define the y-component.

      Returns:
      The array of texture coordinates.
    • draw

      public void draw(Renderer renderer, TextureAsset texture, Color color, float depth)
      Draws this shape using its vertex and UV arrays.
      Specified by:
      draw in interface TexturedDrawable
      Parameters:
      renderer - The renderer
      texture - The texture to draw with
      color - The color to draw with
      depth - The depth of the entity
      See Also:
    • getModifier

      public <M extends ShapeModifier> M getModifier(Class<M> modifierType)
      Gets the first modifier of a given type.
      Type Parameters:
      M - The type of modifier
      Parameters:
      modifierType - The type of modifier to search for
      Returns:
      The modifier of the given type, or null if there is none.
    • addModifier

      public void addModifier(ShapeModifier modifier)
      Adds a modifier to this shape.
      Parameters:
      modifier - The modifier to add
    • removeModifier

      public void removeModifier(ShapeModifier modifier)
      Removes a modifier from this shape.
      Parameters:
      modifier - The modifier to remove
    • cloneWithModifiers

      public Shape cloneWithModifiers()
    • clone

      public abstract Shape clone()
      Description copied from interface: Cloneable
      Returns a new object that is equal to this object.
      Specified by:
      clone in interface Cloneable<Shape>
      Overrides:
      clone in class Object
      Returns:
      Clone of this object