GitBrincie212 / Apel-Mod

Apel is a library that brings particle animations to the table with flexible behaviour and a clean developer interface. It promises also lots of predefined shapes & paths to help the developer on their particle scene
Other
2 stars 1 forks source link

Correctly draw polygons #20

Closed DarthSharkie closed 2 months ago

DarthSharkie commented 2 months ago

The vertex references resulted in an IndexOutOfBoundsException when trying to draw the last line of the polygon. When iterating through pairs of array values, the foreach syntax cannot understand the "+1" reference and stop early. Direct indexing must be used. A benefit of direct indexing here is the ability to eliminate N allocations of Vector3f because the nextVertex being reallocated as vertex goes away.

Change the "raw" vertex computation (pre-rotation, offset, etc.) to use computeIfAbsent instead of a "check-then-act" paradigm. At the same time, make the last point equal to a copy of the first to prevent any issues with floating-point arithmetic.

Drawing the polygon will result in duplicate particles on each vertex, but they should appear to have sides / amount particles per side now rather than amount particles on each side.

Make sure defensive copies are made at appropriate times to prevent cache corruption and any further drawPos usage (e.g., in another shape).