G2D Poly Object

This subset of the G2D Library provide one object and some methods to handle polygons, it also provides a method to detect collisions between 2 konvex polygons.

  • G2D.Poly:Collide(Poly2)
  • G2D.Poly:Draw()
  • G2D.Poly:New(params)
  • G2D.Poly:Project(Axis)
  • G2D.Poly:SetAnchor(anchorX, anchorY)
  • G2D.Poly:SetAngle(angle)
  • G2D.Poly:SetScale(scaleWidth, scaleHeight)
  • G2D.Poly:Translate(x, y)
  • G2D.TEST_Poly()


G2D.Poly:Collide(Poly2)

result = G2D.Poly:Collide(Poly2)

Check if the source polygon object collides with the 'Poly2' polygon object.

INPUT

  • Poly2 : Polygon object to check for collisions

OUTPUT

  • result : True if the source polygon and 'Poly2' polygon are colliding

NOTES
Note that only convex polygon can be checked using this technic.



G2D.Poly:Draw()

G2D.Poly:Draw()

Renders the polygon.



G2D.Poly:New(params)

polyObject = G2D.Poly:New(params)

Returns a new polygon object.

INPUT

  • params : A table filled with all default parameters you want to override:
    • Vertices : A table of vertices, in (x, y) format
    • Normals : A table of normals (calculated by the system)
    • VCount : Vertices count (calculated by the system)
    • Color : A table with 4 items in RGBA sequence, default { 1.0, 1.0, 1.0, 0.5 }
    • Fillemode : Rendering fillmode, default #FILLCOLOR
    • x : Horizontal coordinate, default 0
    • y : Vertical coordinate, default 0
    • ScaleW : Horizontal scaling factor, default 1
    • ScaleH : Vertical scaling factor, default 1
    • AnchorX : Horizontal anchor point, default 0
    • AnchorY : Vertical anchor point, default 0
    • Angle : Rotation angle, default 0

OUTPUT

  • polyObject : An initialized polygon object

NOTES
You need at least to provide a valide sequence of vertices.



G2D.Poly:Project(Axis)

result = G2D.Poly:Project(Axis)

Project the source point on the given 'Axis', a point object.
Returns the 'min' and 'max' values projected on the 'Axis'.

INPUT

  • Axis : A point object representing the projection axis.

OUTPUT

  • result : A table with the following fields:
    • min : The minimum value on the axis
    • max : The maximum value on the axis


G2D.Poly:SetAnchor(anchorX, anchorY)

G2D.Poly:SetAnchor(anchorX, anchorY)

Changes the current anchor point.

INPUT

  • anchorX : Optional horizontal anchor point
  • anchorY : Optional vertical anchor point


G2D.Poly:SetAngle(angle)

G2D.Poly:SetAngle(angle)

Change the rotation angle of the polygon updating all the vertices positions.

INPUT

  • angle : The rotation angle in degrees


G2D.Poly:SetScale(scaleWidth, scaleHeight)

G2D.Poly:SetScale(scaleWidth, scaleHeight)

Changes the current scaling factors.

INPUT

  • scaleWidth : New horizontal scale value
  • scaleHeight : Optional new vertical scale value

NOTES
If you don't pass a 'scaleHeight' value this function will use the 'scaleWidth' to hold the aspect ratio.



G2D.Poly:Translate(x, y)

G2D.Poly:Translate(x, y)

Translate the polygon object.

INPUT

  • x : Horizontal translate value
  • y : Vertical translate value


G2D.TEST_Poly()

G2D.TEST_Poly()

Show how to use the Poly object and test some methods.

hollywoodlibs/g2d/poly.txt · Ultima modifica: 2017/04/25 08:24 da admin
CC Attribution-Noncommercial 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0