All Implemented Interfaces:
EventEmitterInterface, EventListener, IdempotentEventListener<GPointMovedEvent,Vector3>, CanCopy, DecomposeWhenDrawn<Triangle>, SceneObject, HasProperties

GTri represents a Triangle. What'd you expect kau.

A GTri's pivot is set to it's geometric centre between the 3 points.

Unlike the other GObjects, a GTri is a bit more complicated in that it can be defined in terms of its points or its lines. It is also where most of the "complex" engine stuff are done like depth calculations or normal calculations.

A GTri, is stored by reference like any other GObject within a Thing. it is also stored within SceneRenderer for draw ordering.

Author:
Lehlogonolo Poole
See Also:
  • Field Details

    • LegA

      protected GLine LegA
      Leg A, connected to Leg B and Leg C
    • LegB

      protected GLine LegB
      Leg B, connected to Leg A and Leg C
    • LegC

      protected GLine LegC
      Leg C, connected to Leg A and Leg B
    • winding

      protected Winding winding
      The winding of the triangle
    • doubleSided

      private boolean doubleSided
      Whether this triangle is double sided or not. If it is, it's unaffected by back-face culling. (Infinite 2d surface)
    • deletedState

      protected boolean deletedState
    • hidden

      private boolean hidden
    • renderState

      private RenderState<Triangle,GObject> renderState
    • showNorm

      public boolean showNorm
  • Constructor Details

    • GTri

      public GTri(Color c, GPoint A, GPoint B, GPoint C)
      Constructs a new GTri from 3 points.
      Parameters:
      c - The colour
      A - Point A
      B - Point B
      C - Point C
      See Also:
    • GTri

      public GTri(Color c, GLine A, GLine B, GLine C)
      Constructs a new GTri from 3 lines.
      Parameters:
      c - The colour.
      A - The first line.
      B - The second line.
      C - The third line.
    • GTri

      public GTri(Color c, GLine A, GLine B, GLine C, Winding winding)
      Constructs a new GTri from a winding and 3 lines.
      Parameters:
      c - The colour.
      A - The first line.
      B - The second line.
      C - The third line.
      winding - The winding of the triangle.
  • Method Details

    • fromRaw

      public static GTri fromRaw(String id, Color col, GLine legA, GLine legB, GLine legC)
      Constructs a GTri.
      Parameters:
      id - The id of the triangle defined by the file
      col - The colour of the triangle defined by the file
      legA - The constructed reference of the first leg
      legB - The constructed reference of the second leg
      legC - The constructed reference of the third leg
      Returns:
      A GTri
    • fromV3Raw

      public static GTri fromV3Raw(String id, Color col, GLine gLine, GLine gLine1, GLine gLine2, GPoint gPoint, GPoint gPoint1, GPoint gPoint2)
    • toTriangle

      public Triangle toTriangle()
    • toRenderState

      public RenderState<Triangle,GObject> toRenderState()
    • addProps

      private void addProps()
    • isHidden

      public boolean isHidden()
    • setHidden

      public void setHidden(boolean hidden)
    • normal

      public Vector3 normal()
      Calculates the normal vector of the triangle given three vertices.
    • getLegA

      public GLine getLegA()
      Gets Leg A
      Returns:
      GLine
    • getLegB

      public GLine getLegB()
      Gets Leg B
      Returns:
      GLine
    • getLegC

      public GLine getLegC()
      Gets Leg C
      Returns:
      GLine
    • area

      public double area()
      Calculates the area of the triangle.
      Returns:
      The area.
    • calcDepth

      public double calcDepth()
      Calculates the depth of the tri relative to the camera's forward direction.
      Returns:
      The depth value.
    • euclideanDist

      public double euclideanDist()
      Calculates the Euclidean distance from the triangle's pivot to the camera position.
      Returns:
      The Euclidean distance.
    • setWinding

      public void setWinding(GPoint A, GPoint B, GPoint C)
    • getWinding

      public Winding getWinding()
    • copy

      public void copy(CopyProperties props) throws InvalidCopyException
      Description copied from interface: CanCopy
      Copies the properties of this object based on the provided CopyProperties. The implementation should handle how the copying is performed, potentially creating a new instance or modifying an existing one.
      Specified by:
      copy in interface CanCopy
      Overrides:
      copy in class GObject
      Parameters:
      props - The properties defining how the copy operation should be performed.
      Throws:
      InvalidCopyException - If the copy operation cannot be completed due to invalid properties or state.
    • copy

      private GTri copy(GLine lnA, GLine lnB, GLine lnC, Winding winding)
    • getWindingFromCopy

      private Winding getWindingFromCopy(CopyProperties properties)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • deleteSelf

      public boolean deleteSelf()
      Description copied from class: GObject
      Deletes itself
      Overrides:
      deleteSelf in class GObject
      Returns:
      true if the object was deleted
    • isDoubleSided

      public boolean isDoubleSided()
      Checks if this triangle is double-sided. Double-sided triangles are unaffected by back-face culling.
      Returns:
      true if the triangle is double-sided, false otherwise.
    • setDoubleSided

      public void setDoubleSided(boolean doubleSided)
      Sets whether this triangle is double-sided.
      Parameters:
      doubleSided - true to make the triangle double-sided, false for single-sided.
    • getLegStream

      public Stream<GLine> getLegStream()
      Creates a stream of this triangle's edges.
      Returns:
      A stream of GLines
    • onEvent

      public void onEvent(EventType event, EventPayload properties)
      Description copied from interface: EventListener
      onEvent is called by EventEmitter via EventEmitter.broadcast(EventType, EventPayload). Allowing the emitter to call any other object that implements this.
      Specified by:
      onEvent in interface EventListener
      Overrides:
      onEvent in class GObject
      Parameters:
      event - The type of event
      properties - The given event payload
    • getDupeObjectToCheck

      public Vector3 getDupeObjectToCheck()
      Description copied from interface: IdempotentEventListener
      Returns the duplicate object that events of type T will calculate/generate.
      Specified by:
      getDupeObjectToCheck in interface IdempotentEventListener<GPointMovedEvent,Vector3>
      Returns:
      The duplicate object to check against.
    • handlePossibleDuplicates

      public void handlePossibleDuplicates(EventType type, GPointMovedEvent payload)
      Description copied from interface: IdempotentEventListener
      The handler to pass through for this specific type.
      Specified by:
      handlePossibleDuplicates in interface IdempotentEventListener<GPointMovedEvent,Vector3>
      Parameters:
      type - The type of event.
      payload - The payload given.
    • explode

      public ArrayList<GPoint> explode()
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class GObject
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class GObject
    • isDeletedState

      public boolean isDeletedState()
      Overrides:
      isDeletedState in class GObject
    • decompose

      public void decompose()
      Specified by:
      decompose in interface DecomposeWhenDrawn<Triangle>
    • getDecomposeList

      public ArrayList<RenderState<Triangle,GObject>> getDecomposeList()
      Specified by:
      getDecomposeList in interface DecomposeWhenDrawn<Triangle>
    • genericRenderStateList

      public ArrayList genericRenderStateList()
      Overrides:
      genericRenderStateList in class GObject
    • drawDist

      private void drawDist()
      Private method to draw the triangle's distance depth and normal overlays.
    • getEngineObjectType

      public EngineObject.Type getEngineObjectType()
      Specified by:
      getEngineObjectType in class GObject
    • toObject

      public EngineObject toObject()
      Overrides:
      toObject in class GObject