mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
rotate() check for zero vectors, fixed naming error in PGL.Context class
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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().
|
||||
|
||||
Reference in New Issue
Block a user