diff --git a/core/src/processing/core/PMatrix3D.java b/core/src/processing/core/PMatrix3D.java index 2840d4ec1..4732ed6eb 100644 --- a/core/src/processing/core/PMatrix3D.java +++ b/core/src/processing/core/PMatrix3D.java @@ -229,7 +229,19 @@ public final class PMatrix3D implements PMatrix /*, PConstants*/ { public void rotate(float angle, float v0, float v1, float v2) { - // TODO should make sure this vector is normalized + float norm2 = v0 * v0 + v1 * v1 + v2 * v2; + if (norm2 < PConstants.EPSILON) { + // The vector is zero, cannot apply rotation. + return; + } + + if (Math.abs(norm2 - 1) > PConstants.EPSILON) { + // The rotation vector is not normalized. + float norm = PApplet.sqrt(norm2); + v0 /= norm; + v1 /= norm; + v2 /= norm; + } float c = cos(angle); float s = sin(angle); diff --git a/java/libraries/opengl/src/processing/opengl/PGL.java b/java/libraries/opengl/src/processing/opengl/PGL.java index 59d01b93b..76be3eb24 100644 --- a/java/libraries/opengl/src/processing/opengl/PGL.java +++ b/java/libraries/opengl/src/processing/opengl/PGL.java @@ -1135,14 +1135,14 @@ public class PGL { public class Context { - protected GLContext context; + protected GLContext glContext; Context() { - context = null; + glContext = null; } Context(GLContext context) { - this.context = context; + glContext = context; } boolean current() { @@ -1150,20 +1150,20 @@ public class PGL { } boolean equal(GLContext context) { - if (this.context == null || context == null) { + if (glContext == null || context == null) { // A null context means a still non-created resource, // so it is considered equal to the argument. return true; } else { - return this.context.hashCode() == context.hashCode(); + return glContext.hashCode() == context.hashCode(); } } int code() { - if (context == null) { + if (glContext == null) { return -1; } else { - return context.hashCode(); + return glContext.hashCode(); } } } diff --git a/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java b/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java index 7e764b095..4eae32c9a 100644 --- a/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java +++ b/java/libraries/opengl/src/processing/opengl/PGraphicsOpenGL.java @@ -1429,8 +1429,8 @@ public class PGraphicsOpenGL extends PGraphics { } else { setFramebuffer(offscreenFramebuffer); } - pgl.glDrawBuffer(PGL.GL_COLOR_ATTACHMENT0); pgl.updateOffscreen(pg.pgl); + pgl.glDrawBuffer(PGL.GL_COLOR_ATTACHMENT0); } // We are ready to go! @@ -3159,14 +3159,12 @@ public class PGraphicsOpenGL extends PGraphics { flush(); } - modelview.rotate(angle, v0, v1, v2); - invRotate(modelviewInv, angle, v0, v1, v2); - calcProjmodelview(); // Possibly cheaper than doing projmodelview.rotate() - } - - - static private void invRotate(PMatrix3D matrix, float angle, float v0, float v1, float v2) { float norm2 = v0 * v0 + v1 * v1 + v2 * v2; + if (norm2 < EPSILON) { + // The vector is zero, cannot apply rotation. + return; + } + if (Math.abs(norm2 - 1) > EPSILON) { // The rotation vector is not normalized. float norm = PApplet.sqrt(norm2); @@ -3175,6 +3173,13 @@ public class PGraphicsOpenGL extends PGraphics { v2 /= norm; } + modelview.rotate(angle, v0, v1, v2); + invRotate(modelviewInv, angle, v0, v1, v2); + calcProjmodelview(); // Possibly cheaper than doing projmodelview.rotate() + } + + + static private void invRotate(PMatrix3D matrix, float angle, float v0, float v1, float v2) { float c = PApplet.cos(-angle); float s = PApplet.sin(-angle); float t = 1.0f - c; @@ -5010,10 +5015,10 @@ public class PGraphicsOpenGL extends PGraphics { // Getting the context and capabilities from the main renderer. pg = (PGraphicsOpenGL)parent.g; pgl.initOffscreenSurface(pg.pgl); - pgl.updateOffscreen(pg.pgl); + loadTextureImpl(BILINEAR); - + // In case of reinitialization (for example, when the smooth level // is changed), we make sure that all the OpenGL resources associated // to the surface are released by calling delete().