DarthSharkie / 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
0 stars 0 forks source link

Polygons aren't drawing lines #25

Closed DarthSharkie closed 4 months ago

DarthSharkie commented 4 months ago

The following code is breaking (throws IndexOutOfBoundsException:

protected void connectVertices(ApelRenderer renderer, int step, Vector3f center, Vector3f[] vertices) {
    Vector3f start = vertices[0];
    int index = 1;
    Vector3f nextVertex;
    Quaternionf quaternion = new Quaternionf()
                .rotateZ(this.rotation.z)
                .rotateY(this.rotation.y)
                .rotateX(this.rotation.x);
    int lastIndex = vertices.length - 1;
    for (Vector3f vertex : vertices) {
        // Exception thrown here on the last vertex
        nextVertex = vertices[index];
        nextVertex = new Vector3f(nextVertex).rotate(quaternion).add(center);
        vertex = new Vector3f(vertex).rotate(quaternion).add(center);
        this.drawLine(renderer, vertex, nextVertex, step, this.amount);
        index++;
    }
}
DarthSharkie commented 4 months ago

Adding one to an index won't work when the loop uses the foreach syntax. When trying to iterate through pairs like this, it must use direct indexing.

Also, by reworking this to direct indexing, it is possible to eliminate N allocations of Vector3f.

DarthSharkie commented 4 months ago

Fixed in https://github.com/DarthSharkie/Apel-Mod/commit/83944e10b9488855d3c0e180ffd3cfc42f42e2ba.

DarthSharkie commented 4 months ago

Merged in https://github.com/GitBrincie212/Apel-Mod/pull/20.