diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 74fa72b07..ac0bc729d 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -3797,6 +3797,30 @@ public class PGraphicsOpenGL extends PGraphics { } + static protected float matrixScale(PMatrix matrix) { + // Volumetric scaling factor that is associated to the given + // transformation matrix, which is given by the absolute value of its + // determinant: + float factor = 1; + + if (matrix != null) { + if (matrix instanceof PMatrix2D) { + PMatrix2D tr = (PMatrix2D)matrix; + float areaScaleFactor = Math.abs(tr.m00 * tr.m11 - tr.m01 * tr.m10); + factor = (float) Math.sqrt(areaScaleFactor); + } else if (matrix instanceof PMatrix3D) { + PMatrix3D tr = (PMatrix3D)matrix; + float volumeScaleFactor = + Math.abs(tr.m00 * (tr.m11 * tr.m22 - tr.m12 * tr.m21) + + tr.m01 * (tr.m12 * tr.m20 - tr.m10 * tr.m22) + + tr.m02 * (tr.m10 * tr.m21 - tr.m11 * tr.m20)); + factor = (float) Math.pow(volumeScaleFactor, 1.0f / 3.0f); + } + } + return factor; + } + + /** * Two dimensional rotation. Same as rotateZ (this is identical to a 3D * rotation along the z-axis) but included for clarity -- it'd be weird for @@ -10683,6 +10707,7 @@ public class PGraphicsOpenGL extends PGraphics { if (first < last) { int index; + float scaleFactor = matrixScale(tr); for (int i = first; i <= last; i++) { index = 4 * i; float x = lineVertices[index++]; @@ -10699,6 +10724,7 @@ public class PGraphicsOpenGL extends PGraphics { index = 4 * i; lineDirections[index++] = dx*tr.m00 + dy*tr.m01; lineDirections[index ] = dx*tr.m10 + dy*tr.m11; + lineDirections[index + 2] *= scaleFactor; } } } @@ -10707,6 +10733,7 @@ public class PGraphicsOpenGL extends PGraphics { if (first < last) { int index; + float matrixScale = matrixScale(tr); for (int i = first; i <= last; i++) { index = 4 * i; float x = pointVertices[index++]; @@ -10715,6 +10742,10 @@ public class PGraphicsOpenGL extends PGraphics { index = 4 * i; pointVertices[index++] = x*tr.m00 + y*tr.m01 + tr.m02; pointVertices[index ] = x*tr.m10 + y*tr.m11 + tr.m12; + + index = 2 * i; + pointOffsets[index++] *= matrixScale; + pointOffsets[index] *= matrixScale; } } } @@ -10780,6 +10811,7 @@ public class PGraphicsOpenGL extends PGraphics { if (first < last) { int index; + float scaleFactor = matrixScale(tr); for (int i = first; i <= last; i++) { index = 4 * i; float x = lineVertices[index++]; @@ -10801,7 +10833,8 @@ public class PGraphicsOpenGL extends PGraphics { index = 4 * i; lineDirections[index++] = dx*tr.m00 + dy*tr.m01 + dz*tr.m02; lineDirections[index++] = dx*tr.m10 + dy*tr.m11 + dz*tr.m12; - lineDirections[index ] = dx*tr.m20 + dy*tr.m21 + dz*tr.m22; + lineDirections[index++] = dx*tr.m20 + dy*tr.m21 + dz*tr.m22; + lineDirections[index] *= scaleFactor; } } } @@ -10810,6 +10843,7 @@ public class PGraphicsOpenGL extends PGraphics { if (first < last) { int index; + float matrixScale = matrixScale(tr); for (int i = first; i <= last; i++) { index = 4 * i; float x = pointVertices[index++]; @@ -10822,6 +10856,10 @@ public class PGraphicsOpenGL extends PGraphics { pointVertices[index++] = x*tr.m10 + y*tr.m11 + z*tr.m12 + w*tr.m13; pointVertices[index++] = x*tr.m20 + y*tr.m21 + z*tr.m22 + w*tr.m23; pointVertices[index ] = x*tr.m30 + y*tr.m31 + z*tr.m32 + w*tr.m33; + + index = 2 * i; + pointOffsets[index++] *= matrixScale; + pointOffsets[index] *= matrixScale; } } } @@ -11963,28 +12001,7 @@ public class PGraphicsOpenGL extends PGraphics { float transformScale() { if (-1 < transformScale) return transformScale; - - // Volumetric scaling factor that is associated to the current - // transformation matrix, which is given by the absolute value of its - // determinant: - float factor = 1; - - if (transform != null) { - if (transform instanceof PMatrix2D) { - PMatrix2D tr = (PMatrix2D)transform; - float areaScaleFactor = Math.abs(tr.m00 * tr.m11 - tr.m01 * tr.m10); - factor = (float) Math.sqrt(areaScaleFactor); - } else if (transform instanceof PMatrix3D) { - PMatrix3D tr = (PMatrix3D)transform; - float volumeScaleFactor = - Math.abs(tr.m00 * (tr.m11 * tr.m22 - tr.m12 * tr.m21) + - tr.m01 * (tr.m12 * tr.m20 - tr.m10 * tr.m22) + - tr.m02 * (tr.m10 * tr.m21 - tr.m11 * tr.m20)); - factor = (float) Math.pow(volumeScaleFactor, 1.0f / 3.0f); - } - } - - return transformScale = factor; + return transformScale = matrixScale(transform); } boolean segmentIsAxisAligned(int i0, int i1) { diff --git a/core/src/processing/opengl/PShapeOpenGL.java b/core/src/processing/opengl/PShapeOpenGL.java index b84351b2a..cb6197188 100644 --- a/core/src/processing/opengl/PShapeOpenGL.java +++ b/core/src/processing/opengl/PShapeOpenGL.java @@ -1459,6 +1459,7 @@ public class PShapeOpenGL extends PShape { tessGeo.applyMatrixOnPointGeometry(matrix, firstPointVertex, lastPointVertex); root.setModifiedPointVertices(firstPointVertex, lastPointVertex); + root.setModifiedPointAttributes(firstPointVertex, lastPointVertex); } } }