Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix triangle() orientation in webgl mode #6263

Merged
merged 2 commits into from
Jul 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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