Skip to content

Commit

Permalink
Merge pull request #6263 from inaridarkfox4231/triangle_orientation_fix
Browse files Browse the repository at this point in the history
fix triangle() orientation in webgl mode
  • Loading branch information
davepagurek authored Jul 10, 2023
2 parents 2d12675 + 9a6261e commit b4edf1a
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/webgl/3d_primitives.js
Original file line number Diff line number Diff line change
Expand Up @@ -1070,10 +1070,12 @@ p5.RendererGL.prototype.triangle = function(args) {
// origin appropriately.
const uMVMatrix = this.uMVMatrix.copy();
try {
// triangle orientation.
const orientation = Math.sign(x1*y2-x2*y1 + x2*y3-x3*y2 + x3*y1-x1*y3);
const mult = new p5.Matrix([
x2 - x1, y2 - y1, 0, 0, // the resulting unit X-axis
x3 - x1, y3 - y1, 0, 0, // the resulting unit Y-axis
0, 0, 1, 0, // the resulting unit Z-axis (unchanged)
0, 0, orientation, 0, // the resulting unit Z-axis (Reflect the specified order of vertices)
x1, y1, 0, 1 // the resulting origin
]).mult(this.uMVMatrix);

Expand Down

0 comments on commit b4edf1a

Please sign in to comment.