mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
removing angleMode, changing camera setup
This commit is contained in:
+23
-26
@@ -738,7 +738,8 @@ public class PApplet extends Applet
|
||||
|
||||
} catch (InvocationTargetException ite) {
|
||||
String msg = ite.getTargetException().getMessage();
|
||||
if (msg.indexOf("no jogl in java.library.path") != -1) {
|
||||
if ((msg != null) &&
|
||||
(msg.indexOf("no jogl in java.library.path") != -1)) {
|
||||
throw new RuntimeException(openglError);
|
||||
} else {
|
||||
ite.getTargetException().printStackTrace();
|
||||
@@ -986,16 +987,20 @@ public class PApplet extends Applet
|
||||
|
||||
//System.out.println("done attempting setup");
|
||||
//System.out.println("out of try");
|
||||
g.postSetup(); // FIXME
|
||||
//g.postSetup(); // FIXME
|
||||
|
||||
} catch (RuntimeException e) {
|
||||
//System.out.println("runtime extends " + e);
|
||||
//System.out.println("catching a cold " + e.getMessage());
|
||||
if (e.getMessage().indexOf(NEW_RENDERER) != -1) {
|
||||
String msg = e.getMessage();
|
||||
if ((msg != null) &&
|
||||
(e.getMessage().indexOf(NEW_RENDERER) != -1)) {
|
||||
//System.out.println("got new renderer");
|
||||
return;
|
||||
//continue; // will this work?
|
||||
|
||||
} else {
|
||||
//e.printStackTrace(System.out);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
@@ -2052,39 +2057,43 @@ public class PApplet extends Applet
|
||||
|
||||
|
||||
public final float sin(float angle) {
|
||||
if ((g != null) && (g.angleMode == DEGREES)) angle *= DEG_TO_RAD;
|
||||
//if ((g != null) && (g.angleMode == DEGREES)) angle *= DEG_TO_RAD;
|
||||
return (float)Math.sin(angle);
|
||||
}
|
||||
|
||||
public final float cos(float angle) {
|
||||
if ((g != null) && (g.angleMode == DEGREES)) angle *= DEG_TO_RAD;
|
||||
//if ((g != null) && (g.angleMode == DEGREES)) angle *= DEG_TO_RAD;
|
||||
return (float)Math.cos(angle);
|
||||
}
|
||||
|
||||
public final float tan(float angle) {
|
||||
if ((g != null) && (g.angleMode == DEGREES)) angle *= DEG_TO_RAD;
|
||||
//if ((g != null) && (g.angleMode == DEGREES)) angle *= DEG_TO_RAD;
|
||||
return (float)Math.tan(angle);
|
||||
}
|
||||
|
||||
|
||||
public final float asin(float value) {
|
||||
return ((g != null) && (g.angleMode == DEGREES)) ?
|
||||
((float)Math.asin(value) * RAD_TO_DEG) : (float)Math.asin(value);
|
||||
//return ((g != null) && (g.angleMode == DEGREES)) ?
|
||||
//((float)Math.asin(value) * RAD_TO_DEG) : (float)Math.asin(value);
|
||||
return (float)Math.asin(value);
|
||||
}
|
||||
|
||||
public final float acos(float value) {
|
||||
return ((g != null) && (g.angleMode == DEGREES)) ?
|
||||
((float)Math.acos(value) * RAD_TO_DEG) : (float)Math.acos(value);
|
||||
//return ((g != null) && (g.angleMode == DEGREES)) ?
|
||||
//((float)Math.acos(value) * RAD_TO_DEG) : (float)Math.acos(value);
|
||||
return (float)Math.acos(value);
|
||||
}
|
||||
|
||||
public final float atan(float value) {
|
||||
return ((g != null) && (g.angleMode == DEGREES)) ?
|
||||
((float)Math.atan(value) * RAD_TO_DEG) : (float)Math.atan(value);
|
||||
//return ((g != null) && (g.angleMode == DEGREES)) ?
|
||||
// ((float)Math.atan(value) * RAD_TO_DEG) : (float)Math.atan(value);
|
||||
return (float)Math.atan(value);
|
||||
}
|
||||
|
||||
public final float atan2(float a, float b) {
|
||||
return ((g != null) && (g.angleMode == DEGREES)) ?
|
||||
((float)Math.atan2(a, b) * RAD_TO_DEG) : (float)Math.atan2(a, b);
|
||||
//return ((g != null) && (g.angleMode == DEGREES)) ?
|
||||
//((float)Math.atan2(a, b) * RAD_TO_DEG) : (float)Math.atan2(a, b);
|
||||
return (float)Math.atan2(a, b);
|
||||
}
|
||||
|
||||
|
||||
@@ -5081,12 +5090,6 @@ v PApplet.this.stop();
|
||||
}
|
||||
|
||||
|
||||
public void postSetup() {
|
||||
if (recorder != null) recorder.postSetup();
|
||||
g.postSetup();
|
||||
}
|
||||
|
||||
|
||||
public void hint(int which) {
|
||||
if (recorder != null) recorder.hint(which);
|
||||
g.hint(which);
|
||||
@@ -5505,12 +5508,6 @@ v PApplet.this.stop();
|
||||
}
|
||||
|
||||
|
||||
public void angleMode(int mode) {
|
||||
if (recorder != null) recorder.angleMode(mode);
|
||||
g.angleMode(mode);
|
||||
}
|
||||
|
||||
|
||||
public void rotate(float angle) {
|
||||
if (recorder != null) recorder.rotate(angle);
|
||||
g.rotate(angle);
|
||||
|
||||
+15
-17
@@ -158,7 +158,7 @@ public class PGraphics extends PImage implements PConstants {
|
||||
public float m00, m01, m02;
|
||||
public float m10, m11, m12;
|
||||
|
||||
public int angleMode;
|
||||
//public int angleMode;
|
||||
|
||||
static final int MATRIX_STACK_DEPTH = 32;
|
||||
float matrixStack[][] = new float[MATRIX_STACK_DEPTH][16];
|
||||
@@ -196,8 +196,7 @@ public class PGraphics extends PImage implements PConstants {
|
||||
};
|
||||
|
||||
protected PMatrix bezierBasis =
|
||||
new PMatrix(RADIANS,
|
||||
-1, 3, -3, 1,
|
||||
new PMatrix(-1, 3, -3, 1,
|
||||
3, -6, 3, 0,
|
||||
-3, 3, 0, 0,
|
||||
1, 0, 0, 0);
|
||||
@@ -435,7 +434,7 @@ public class PGraphics extends PImage implements PConstants {
|
||||
rectMode(CORNER);
|
||||
ellipseMode(CENTER);
|
||||
//arcMode(CENTER);
|
||||
angleMode(RADIANS);
|
||||
//angleMode(RADIANS);
|
||||
|
||||
// no current font
|
||||
textFont = null;
|
||||
@@ -449,8 +448,8 @@ public class PGraphics extends PImage implements PConstants {
|
||||
/**
|
||||
* do anything that needs doing after setup before draw
|
||||
*/
|
||||
public void postSetup() {
|
||||
}
|
||||
//public void postSetup() {
|
||||
//}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
@@ -985,10 +984,10 @@ public class PGraphics extends PImage implements PConstants {
|
||||
y = b - d/2f;
|
||||
}
|
||||
|
||||
if (angleMode == DEGREES) {
|
||||
start = start * DEG_TO_RAD;
|
||||
stop = stop * DEG_TO_RAD;
|
||||
}
|
||||
//if (angleMode == DEGREES) {
|
||||
//start = start * DEG_TO_RAD;
|
||||
//stop = stop * DEG_TO_RAD;
|
||||
//}
|
||||
// before running a while loop like this,
|
||||
// make sure it will exit at some point.
|
||||
if (Float.isInfinite(start) || Float.isInfinite(stop)) return;
|
||||
@@ -1209,12 +1208,11 @@ public class PGraphics extends PImage implements PConstants {
|
||||
}
|
||||
|
||||
// hack here to get PGraphics2 working
|
||||
curveToBezierMatrix = new PMatrix(RADIANS,
|
||||
c[0][0], c[0][1], c[0][2], c[0][3],
|
||||
curveToBezierMatrix = new PMatrix(c[0][0], c[0][1], c[0][2], c[0][3],
|
||||
c[1][0], c[1][1], c[1][2], c[1][3],
|
||||
c[2][0], c[2][1], c[2][2], c[2][3],
|
||||
c[3][0], c[3][1], c[3][2], c[3][3]);
|
||||
curveToBezierMatrix.preApplyMatrix(bezierBasisInverse);
|
||||
curveToBezierMatrix.preApply(bezierBasisInverse);
|
||||
|
||||
// multiply the basis and forward diff matrices together
|
||||
// saves much time since this needn't be done for each curve
|
||||
@@ -1806,9 +1804,9 @@ public class PGraphics extends PImage implements PConstants {
|
||||
}
|
||||
|
||||
|
||||
public void angleMode(int mode) {
|
||||
angleMode = mode;
|
||||
}
|
||||
//public void angleMode(int mode) {
|
||||
//angleMode = mode;
|
||||
//}
|
||||
|
||||
|
||||
/**
|
||||
@@ -1818,7 +1816,7 @@ public class PGraphics extends PImage implements PConstants {
|
||||
* And they might kick our a-- for the confusion.
|
||||
*/
|
||||
public void rotate(float angle) {
|
||||
if (angleMode == DEGREES) angle *= DEG_TO_RAD;
|
||||
//if (angleMode == DEGREES) angle *= DEG_TO_RAD;
|
||||
|
||||
float c = (float) Math.cos(angle);
|
||||
float s = (float) Math.sin(angle);
|
||||
|
||||
+159
-57
@@ -32,13 +32,16 @@ import java.awt.image.*;
|
||||
public class PGraphics3 extends PGraphics {
|
||||
|
||||
// modelview matrix
|
||||
public PMatrix modelview = new PMatrix(RADIANS, MATRIX_STACK_DEPTH);
|
||||
public PMatrix modelview; // = new PMatrix(MATRIX_STACK_DEPTH);
|
||||
|
||||
public PMatrix camera; // = new PMatrix();
|
||||
public PMatrix inverseCamera; // = new PMatrix();
|
||||
|
||||
// ........................................................
|
||||
// Lighting-related variables
|
||||
|
||||
// inverse model matrix
|
||||
public PMatrix inverseModelview = new PMatrix(RADIANS, MATRIX_STACK_DEPTH);
|
||||
public PMatrix inverseModelview; // = new PMatrix(MATRIX_STACK_DEPTH);
|
||||
|
||||
// store the facing direction to speed rendering
|
||||
boolean useBackfaceCulling = false;
|
||||
@@ -58,7 +61,7 @@ public class PGraphics3 extends PGraphics {
|
||||
|
||||
// ........................................................
|
||||
|
||||
public int cameraMode;
|
||||
//public int cameraMode;
|
||||
|
||||
// perspective setup
|
||||
public float cameraFOV;
|
||||
@@ -66,13 +69,15 @@ public class PGraphics3 extends PGraphics {
|
||||
public float cameraNear, cameraFar;
|
||||
public float cameraAspect;
|
||||
|
||||
// This is turned on at beginCamera, and off at endCamera
|
||||
// Currently we don't support nested begin/end cameras.
|
||||
// If we wanted to, this variable would have to become a stack.
|
||||
/**
|
||||
* This is turned on at beginCamera, and off at endCamera
|
||||
* Currently we don't support nested begin/end cameras.
|
||||
* If we wanted to, this variable would have to become a stack.
|
||||
*/
|
||||
public boolean manipulatingCamera;
|
||||
|
||||
// projection matrix
|
||||
public PMatrix projection = new PMatrix(RADIANS);
|
||||
public PMatrix projection = new PMatrix();
|
||||
|
||||
// These two matrices always point to either the modelview
|
||||
// or the inverseModelview, but they are swapped during
|
||||
@@ -241,6 +246,7 @@ public class PGraphics3 extends PGraphics {
|
||||
forwardTransform = modelview;
|
||||
reverseTransform = inverseModelview;
|
||||
//resize(iwidth, iheight);
|
||||
//projection = new PMatrix();
|
||||
}
|
||||
|
||||
|
||||
@@ -298,7 +304,23 @@ public class PGraphics3 extends PGraphics {
|
||||
// reset the cameraMode if PERSPECTIVE or ORTHOGRAPHIC
|
||||
// will just be ignored if CUSTOM, the user's hosed anyways
|
||||
//System.out.println("setting cameraMode to " + cameraMode);
|
||||
if (this.cameraMode != CUSTOM) cameraMode(this.cameraMode);
|
||||
//if (this.cameraMode != CUSTOM) cameraMode(this.cameraMode);
|
||||
|
||||
// making this again here because things are weird
|
||||
projection = new PMatrix();
|
||||
modelview = new PMatrix(MATRIX_STACK_DEPTH);
|
||||
inverseModelview = new PMatrix(MATRIX_STACK_DEPTH);
|
||||
|
||||
camera = new PMatrix();
|
||||
inverseCamera = new PMatrix();
|
||||
|
||||
// set up the default camera
|
||||
camera();
|
||||
|
||||
// defaults to perspective, if the user has setup up their
|
||||
// own projection, they'll need to fix it after resize anyway.
|
||||
// this helps the people who haven't set up their own projection.
|
||||
perspective();
|
||||
}
|
||||
|
||||
|
||||
@@ -326,6 +348,7 @@ public class PGraphics3 extends PGraphics {
|
||||
triangle = new PTriangle(this);
|
||||
}
|
||||
|
||||
|
||||
public void clearLights() {
|
||||
lightCount = 0;
|
||||
light[0] = false;
|
||||
@@ -333,16 +356,21 @@ public class PGraphics3 extends PGraphics {
|
||||
light[i] = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void defaultLights() {
|
||||
clearLights();
|
||||
createAmbientLight(60);
|
||||
createDirectionalLight(80, 80, 80, 0, 0, -1);
|
||||
}
|
||||
|
||||
|
||||
public void beginFrame() {
|
||||
super.beginFrame();
|
||||
|
||||
modelview.set(camera);
|
||||
inverseModelview.set(inverseCamera);
|
||||
|
||||
if (lights) {
|
||||
defaultLights();
|
||||
}
|
||||
@@ -385,12 +413,14 @@ public class PGraphics3 extends PGraphics {
|
||||
super.endFrame();
|
||||
}
|
||||
|
||||
/*
|
||||
public void angleMode(int mode) {
|
||||
super.angleMode(mode);
|
||||
modelview.angleMode(mode);
|
||||
inverseModelview.angleMode(mode);
|
||||
projection.angleMode(mode);
|
||||
}
|
||||
*/
|
||||
|
||||
public void defaults() {
|
||||
super.defaults();
|
||||
@@ -399,7 +429,8 @@ public class PGraphics3 extends PGraphics {
|
||||
forwardTransform = modelview;
|
||||
reverseTransform = inverseModelview;
|
||||
|
||||
cameraMode(PERSPECTIVE);
|
||||
//cameraMode(PERSPECTIVE);
|
||||
perspective();
|
||||
|
||||
//System.out.println("PGraphics3.defaults()");
|
||||
// easiest for beginners
|
||||
@@ -422,10 +453,11 @@ public class PGraphics3 extends PGraphics {
|
||||
/**
|
||||
* do anything that needs doing after setup before draw
|
||||
*/
|
||||
public void postSetup() {
|
||||
modelview.storeResetValue();
|
||||
inverseModelview.storeResetValue();
|
||||
}
|
||||
//public void postSetup() {
|
||||
//modelview.storeResetValue();
|
||||
//inverseModelview.storeResetValue();
|
||||
//}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -2298,23 +2330,23 @@ public class PGraphics3 extends PGraphics {
|
||||
throw new RuntimeException("too many calls to pop() " +
|
||||
"(and not enough to push)");
|
||||
}
|
||||
// Do this to the inverse regardless of the lights to keep stack pointers
|
||||
// in sync
|
||||
// Do this to the inverse regardless of the lights
|
||||
// to keep stack pointers in sync
|
||||
inverseModelview.pop();
|
||||
}
|
||||
|
||||
|
||||
public void resetProjection() {
|
||||
projection.reset();
|
||||
}
|
||||
//public void resetProjection() {
|
||||
//projection.reset();
|
||||
//}
|
||||
|
||||
/**
|
||||
* Load identity as the transform/model matrix.
|
||||
* Same as glLoadIdentity().
|
||||
*/
|
||||
public void resetMatrix() {
|
||||
forwardTransform.reset();
|
||||
reverseTransform.reset();
|
||||
forwardTransform.identity(); //reset();
|
||||
reverseTransform.identity(); //reset();
|
||||
}
|
||||
|
||||
|
||||
@@ -2328,15 +2360,15 @@ public class PGraphics3 extends PGraphics {
|
||||
float n20, float n21, float n22, float n23,
|
||||
float n30, float n31, float n32, float n33) {
|
||||
|
||||
forwardTransform.applyMatrix(n00, n01, n02, n03,
|
||||
n10, n11, n12, n13,
|
||||
n20, n21, n22, n23,
|
||||
n30, n31, n32, n33);
|
||||
forwardTransform.apply(n00, n01, n02, n03,
|
||||
n10, n11, n12, n13,
|
||||
n20, n21, n22, n23,
|
||||
n30, n31, n32, n33);
|
||||
|
||||
reverseTransform.invApplyMatrix(n00, n01, n02, n03,
|
||||
n10, n11, n12, n13,
|
||||
n20, n21, n22, n23,
|
||||
n30, n31, n32, n33);
|
||||
reverseTransform.invApply(n00, n01, n02, n03,
|
||||
n10, n11, n12, n13,
|
||||
n20, n21, n22, n23,
|
||||
n30, n31, n32, n33);
|
||||
}
|
||||
|
||||
|
||||
@@ -2364,6 +2396,7 @@ public class PGraphics3 extends PGraphics {
|
||||
*
|
||||
* Note that this setting gets nuked if resize() is called.
|
||||
*/
|
||||
/*
|
||||
public void cameraMode(int mode) {
|
||||
resetProjection();
|
||||
modelview.identity();
|
||||
@@ -2383,13 +2416,14 @@ public class PGraphics3 extends PGraphics {
|
||||
|
||||
cameraMode = mode; // this doesn't do much
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Set matrix mode to the camera matrix (instead of
|
||||
* the current transformation matrix). This means applyMatrix,
|
||||
* resetMatrix, etc. will affect the camera.
|
||||
*
|
||||
* <P>
|
||||
* This loads identity into the projection matrix, so if you want
|
||||
* to start with a resonable default projection, you may want to
|
||||
* call cameraMode(PERSPECTIVE); or something between begin and end.
|
||||
@@ -2398,14 +2432,13 @@ public class PGraphics3 extends PGraphics {
|
||||
if (manipulatingCamera) {
|
||||
throw new RuntimeException("cannot call beginCamera while already "+
|
||||
"in camera manipulation mode");
|
||||
}
|
||||
else {
|
||||
projection.identity();
|
||||
} else {
|
||||
//projection.identity();
|
||||
manipulatingCamera = true;
|
||||
forwardTransform = inverseModelview;
|
||||
reverseTransform = modelview;
|
||||
cameraMode = CUSTOM;
|
||||
}
|
||||
forwardTransform = inverseCamera; //inverseModelview;
|
||||
reverseTransform = camera; //modelview;
|
||||
//cameraMode = CUSTOM;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2429,8 +2462,19 @@ public class PGraphics3 extends PGraphics {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Same as gluOrtho(). Implementation based on Mesa's matrix.c
|
||||
* Calls ortho() for Processing's standard orthographic projection.
|
||||
*/
|
||||
public void ortho() {
|
||||
ortho(0, width, 0, height, -10, 10);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Similar to gluOrtho(), but wipes out the current projection matrix.
|
||||
* <P>
|
||||
* Implementation partially based on Mesa's matrix.c.
|
||||
*/
|
||||
public void ortho(float left, float right,
|
||||
float bottom, float top,
|
||||
@@ -2443,10 +2487,45 @@ public class PGraphics3 extends PGraphics {
|
||||
float ty = -(top + bottom) / (top - bottom);
|
||||
float tz = -(far + near) / (far - near);
|
||||
|
||||
projection.applyMatrix(x, 0, 0, tx,
|
||||
0, y, 0, ty,
|
||||
0, 0, z, tz,
|
||||
0, 0, 0, 1);
|
||||
projection.set(x, 0, 0, tx,
|
||||
0, y, 0, ty,
|
||||
0, 0, z, tz,
|
||||
0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calls camera() with Processing's standard camera setup.
|
||||
*/
|
||||
public void camera() {
|
||||
beginCamera();
|
||||
resetMatrix();
|
||||
lookat(cameraX, cameraY, cameraZ,
|
||||
cameraX, cameraY, 0,
|
||||
0, 1, 0);
|
||||
endCamera();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Similar to gluLookAt(), however it first clears the current
|
||||
* camera settings.
|
||||
*/
|
||||
public void camera(float eyeX, float eyeY, float eyeZ,
|
||||
float centerX, float centerY, float centerZ,
|
||||
float upX, float upY, float upZ) {
|
||||
beginCamera();
|
||||
resetMatrix();
|
||||
lookat(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ);
|
||||
endCamera();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Calls perspective() with Processing's standard coordinate setup.
|
||||
*/
|
||||
public void perspective() {
|
||||
perspective(cameraFOV, cameraAspect, cameraNear, cameraFar);
|
||||
}
|
||||
|
||||
|
||||
@@ -2467,24 +2546,28 @@ public class PGraphics3 extends PGraphics {
|
||||
|
||||
|
||||
/**
|
||||
* Same as glFrustum(). Implementation based on the explanation
|
||||
* in the OpenGL reference book.
|
||||
* Same as glFrustum(), except that it wipes out (rather than
|
||||
* multiplies against) the current perspective matrix.
|
||||
* <P>
|
||||
* Implementation based on the explanation in the OpenGL blue book.
|
||||
*/
|
||||
public void frustum(float left, float right, float bottom,
|
||||
float top, float znear, float zfar) {
|
||||
//System.out.println("frustum: " + left + " " + right + " " +
|
||||
// bottom + " " + top + " " + znear + " " + zfar);
|
||||
projection.applyMatrix((2*znear)/(right-left), 0, (right+left)/(right-left), 0,
|
||||
0, (2*znear)/(top-bottom), (top+bottom)/(top-bottom), 0,
|
||||
0, 0, -(zfar+znear)/(zfar-znear),-(2*zfar*znear)/(zfar-znear),
|
||||
0, 0, -1, 0);
|
||||
//System.out.println(projection);
|
||||
projection.set((2*znear)/(right-left), 0, (right+left)/(right-left), 0,
|
||||
0, (2*znear)/(top-bottom), (top+bottom)/(top-bottom), 0,
|
||||
0, 0, -(zfar+znear)/(zfar-znear),-(2*zfar*znear)/(zfar-znear),
|
||||
0, 0, -1, 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Same as gluLookat(). Implementation based on Mesa's glu.c
|
||||
* Same as gluLookat().
|
||||
* <P>
|
||||
* This should only be called inside of a beginCamera/endCamera pair.
|
||||
* <P>
|
||||
* Implementation based on Mesa's glu.c
|
||||
*/
|
||||
|
||||
// TODO: deal with this. Lookat must ALWAYS apply to the modelview
|
||||
// regardless of the camera manipulation mode.
|
||||
public void lookat(float eyeX, float eyeY, float eyeZ,
|
||||
@@ -2527,6 +2610,15 @@ public class PGraphics3 extends PGraphics {
|
||||
y2 /= mag;
|
||||
}
|
||||
|
||||
// just does an apply to the main matrix,
|
||||
// since that'll be copied out on endCamera
|
||||
applyMatrix(x0, x1, x2, 0,
|
||||
y0, y1, y2, 0,
|
||||
z0, z1, z2, 0,
|
||||
0, 0, 0, 1);
|
||||
translate(eyeX, eyeY, eyeZ);
|
||||
|
||||
/*
|
||||
modelview.invApplyMatrix(x0, x1, x2, 0,
|
||||
y0, y1, y2, 0,
|
||||
z0, z1, z2, 0,
|
||||
@@ -2538,15 +2630,25 @@ public class PGraphics3 extends PGraphics {
|
||||
z0, z1, z2, 0,
|
||||
0, 0, 0, 1);
|
||||
inverseModelview.translate(eyeX, eyeY, eyeZ);
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Print the current camera (or "perspective") matrix.
|
||||
* Print the current projection matrix.
|
||||
*/
|
||||
public void printProjection() {
|
||||
projection.print();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Print the current camera matrix.
|
||||
*/
|
||||
public void printCamera() {
|
||||
projection.print();
|
||||
camera.print();
|
||||
}
|
||||
|
||||
|
||||
@@ -3204,17 +3306,17 @@ public class PGraphics3 extends PGraphics {
|
||||
}
|
||||
|
||||
private final float sin(float angle) {
|
||||
if (angleMode == DEGREES) angle *= DEG_TO_RAD;
|
||||
//if (angleMode == DEGREES) angle *= DEG_TO_RAD;
|
||||
return (float)Math.sin(angle);
|
||||
}
|
||||
|
||||
private final float cos(float angle) {
|
||||
if (angleMode == DEGREES) angle *= DEG_TO_RAD;
|
||||
//if (angleMode == DEGREES) angle *= DEG_TO_RAD;
|
||||
return (float)Math.cos(angle);
|
||||
}
|
||||
|
||||
private final float tan(float angle) {
|
||||
if (angleMode == DEGREES) angle *= DEG_TO_RAD;
|
||||
//if (angleMode == DEGREES) angle *= DEG_TO_RAD;
|
||||
return (float)Math.tan(angle);
|
||||
}
|
||||
}
|
||||
|
||||
+45
-55
@@ -8,9 +8,6 @@ public final class PMatrix implements PConstants {
|
||||
public float m20, m21, m22, m23;
|
||||
public float m30, m31, m32, m33;
|
||||
|
||||
int angleMode;
|
||||
|
||||
//float tmpx, tmpy, tmpz, tmpw;
|
||||
float reset[];
|
||||
|
||||
final static int DEFAULT_STACK_DEPTH = 0;
|
||||
@@ -19,27 +16,23 @@ public final class PMatrix implements PConstants {
|
||||
float stack[][];
|
||||
|
||||
|
||||
public PMatrix(int angleMode) {
|
||||
this.angleMode = angleMode;
|
||||
public PMatrix() {
|
||||
set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
||||
maxStackDepth = DEFAULT_STACK_DEPTH;
|
||||
}
|
||||
|
||||
|
||||
public PMatrix(int angleMode, int stackDepth) {
|
||||
this.angleMode = angleMode;
|
||||
public PMatrix(int stackDepth) {
|
||||
set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
||||
stack = new float[stackDepth][16];
|
||||
maxStackDepth = stackDepth;
|
||||
}
|
||||
|
||||
|
||||
public PMatrix(int angleMode,
|
||||
float m00, float m01, float m02, float m03,
|
||||
public PMatrix(float m00, float m01, float m02, float m03,
|
||||
float m10, float m11, float m12, float m13,
|
||||
float m20, float m21, float m22, float m23,
|
||||
float m30, float m31, float m32, float m33) {
|
||||
this.angleMode = angleMode;
|
||||
set(m00, m01, m02, m03,
|
||||
m10, m11, m12, m13,
|
||||
m20, m21, m22, m23,
|
||||
@@ -51,11 +44,7 @@ public final class PMatrix implements PConstants {
|
||||
// Make a copy of a matrix. We copy the stack depth,
|
||||
// but we don't make a copy of the stack or the stack pointer.
|
||||
public PMatrix(PMatrix src) {
|
||||
angleMode = src.angleMode;
|
||||
set(src.m00, src.m01, src.m02, src.m03,
|
||||
src.m10, src.m11, src.m12, src.m13,
|
||||
src.m20, src.m21, src.m22, src.m23,
|
||||
src.m30, src.m31, src.m32, src.m33);
|
||||
set(src);
|
||||
maxStackDepth = src.maxStackDepth;
|
||||
stack = new float[maxStackDepth][16];
|
||||
}
|
||||
@@ -154,6 +143,14 @@ public final class PMatrix implements PConstants {
|
||||
}
|
||||
|
||||
|
||||
public void set(PMatrix src) {
|
||||
set(src.m00, src.m01, src.m02, src.m03,
|
||||
src.m10, src.m11, src.m12, src.m13,
|
||||
src.m20, src.m21, src.m22, src.m23,
|
||||
src.m30, src.m31, src.m32, src.m33);
|
||||
}
|
||||
|
||||
|
||||
public void set(float m00, float m01, float m02, float m03,
|
||||
float m10, float m11, float m12, float m13,
|
||||
float m20, float m21, float m22, float m23,
|
||||
@@ -182,10 +179,10 @@ public final class PMatrix implements PConstants {
|
||||
}
|
||||
|
||||
public void invTranslate(float tx, float ty, float tz) {
|
||||
preApplyMatrix(1, 0, 0, -tx,
|
||||
0, 1, 0, -ty,
|
||||
0, 0, 1, -tz,
|
||||
0, 0, 0, 1);
|
||||
preApply(1, 0, 0, -tx,
|
||||
0, 1, 0, -ty,
|
||||
0, 0, 1, -tz,
|
||||
0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -195,28 +192,28 @@ public final class PMatrix implements PConstants {
|
||||
public void rotateX(float angle) {
|
||||
float c = cos(angle);
|
||||
float s = sin(angle);
|
||||
applyMatrix(1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1);
|
||||
apply(1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
public void invRotateX(float angle) {
|
||||
float c = cos(-angle);
|
||||
float s = sin(-angle);
|
||||
preApplyMatrix(1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1);
|
||||
preApply(1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
public void rotateY(float angle) {
|
||||
float c = cos(angle);
|
||||
float s = sin(angle);
|
||||
applyMatrix(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1);
|
||||
apply(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
public void invRotateY(float angle) {
|
||||
float c = cos(-angle);
|
||||
float s = sin(-angle);
|
||||
preApplyMatrix(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1);
|
||||
preApply(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -237,14 +234,14 @@ public final class PMatrix implements PConstants {
|
||||
public void rotateZ(float angle) {
|
||||
float c = cos(angle);
|
||||
float s = sin(angle);
|
||||
applyMatrix(c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
||||
apply(c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
public void invRotateZ(float angle) {
|
||||
float c = cos(-angle);
|
||||
float s = sin(-angle);
|
||||
preApplyMatrix(c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
||||
preApply(c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -258,7 +255,7 @@ public final class PMatrix implements PConstants {
|
||||
float s = sin(angle);
|
||||
float t = 1.0f - c;
|
||||
|
||||
applyMatrix((t*v0*v0) + c, (t*v0*v1) - (s*v2), (t*v0*v2) + (s*v1), 0,
|
||||
apply((t*v0*v0) + c, (t*v0*v1) - (s*v2), (t*v0*v2) + (s*v1), 0,
|
||||
(t*v0*v1) + (s*v2), (t*v1*v1) + c, (t*v1*v2) - (s*v0), 0,
|
||||
(t*v0*v2) - (s*v1), (t*v1*v2) + (s*v0), (t*v2*v2) + c, 0,
|
||||
0, 0, 0, 1);
|
||||
@@ -272,7 +269,7 @@ public final class PMatrix implements PConstants {
|
||||
float s = sin(-angle);
|
||||
float t = 1.0f - c;
|
||||
|
||||
preApplyMatrix((t*v0*v0) + c, (t*v0*v1) - (s*v2), (t*v0*v2) + (s*v1), 0,
|
||||
preApply((t*v0*v0) + c, (t*v0*v1) - (s*v2), (t*v0*v2) + (s*v1), 0,
|
||||
(t*v0*v1) + (s*v2), (t*v1*v1) + c, (t*v1*v2) - (s*v0), 0,
|
||||
(t*v0*v2) - (s*v1), (t*v1*v2) + (s*v0), (t*v2*v2) + c, 0,
|
||||
0, 0, 0, 1);
|
||||
@@ -280,33 +277,33 @@ public final class PMatrix implements PConstants {
|
||||
|
||||
|
||||
public void scale(float s) {
|
||||
applyMatrix(s, 0, 0, 0, 0, s, 0, 0, 0, 0, s, 0, 0, 0, 0, 1);
|
||||
apply(s, 0, 0, 0, 0, s, 0, 0, 0, 0, s, 0, 0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
public void invScale(float s) {
|
||||
preApplyMatrix(1/s, 0, 0, 0, 0, 1/s, 0, 0, 0, 0, 1/s, 0, 0, 0, 0, 1);
|
||||
preApply(1/s, 0, 0, 0, 0, 1/s, 0, 0, 0, 0, 1/s, 0, 0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
public void scale(float sx, float sy) {
|
||||
applyMatrix(sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
||||
apply(sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
public void invScale(float sx, float sy) {
|
||||
preApplyMatrix(1/sx, 0, 0, 0, 0, 1/sy, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
||||
preApply(1/sx, 0, 0, 0, 0, 1/sy, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
// OPTIMIZE: same as above
|
||||
public void scale(float x, float y, float z) {
|
||||
applyMatrix(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1);
|
||||
apply(x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
public void invScale(float x, float y, float z) {
|
||||
preApplyMatrix(1/x, 0, 0, 0, 0, 1/y, 0, 0, 0, 0, 1/z, 0, 0, 0, 0, 1);
|
||||
preApply(1/x, 0, 0, 0, 0, 1/y, 0, 0, 0, 0, 1/z, 0, 0, 0, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -314,13 +311,13 @@ public final class PMatrix implements PConstants {
|
||||
float n10, float n11, float n12, float n13,
|
||||
float n20, float n21, float n22, float n23,
|
||||
float n30, float n31, float n32, float n33) {
|
||||
applyMatrix(n00, n01, n02, n03, n10, n11, n12, n13,
|
||||
apply(n00, n01, n02, n03, n10, n11, n12, n13,
|
||||
n20, n21, n22, n23, n30, n31, n32, n33);
|
||||
}
|
||||
|
||||
|
||||
public void preApplyMatrix(PMatrix lhs) {
|
||||
preApplyMatrix(lhs.m00, lhs.m01, lhs.m02, lhs.m03,
|
||||
public void preApply(PMatrix lhs) {
|
||||
preApply(lhs.m00, lhs.m01, lhs.m02, lhs.m03,
|
||||
lhs.m10, lhs.m11, lhs.m12, lhs.m13,
|
||||
lhs.m20, lhs.m21, lhs.m22, lhs.m23,
|
||||
lhs.m30, lhs.m31, lhs.m32, lhs.m33);
|
||||
@@ -328,7 +325,7 @@ public final class PMatrix implements PConstants {
|
||||
|
||||
|
||||
// for inverse operations, like multiplying the matrix on the left
|
||||
public void preApplyMatrix(float n00, float n01, float n02, float n03,
|
||||
public void preApply(float n00, float n01, float n02, float n03,
|
||||
float n10, float n11, float n12, float n13,
|
||||
float n20, float n21, float n22, float n23,
|
||||
float n30, float n31, float n32, float n33) {
|
||||
@@ -360,43 +357,42 @@ public final class PMatrix implements PConstants {
|
||||
}
|
||||
|
||||
|
||||
public boolean invApplyMatrix(PMatrix rhs) {
|
||||
public boolean invApply(PMatrix rhs) {
|
||||
PMatrix copy = new PMatrix(rhs);
|
||||
PMatrix inverse = copy.invert();
|
||||
if (inverse == null) return false;
|
||||
preApplyMatrix(inverse);
|
||||
preApply(inverse);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public boolean invApplyMatrix(float n00, float n01, float n02, float n03,
|
||||
public boolean invApply(float n00, float n01, float n02, float n03,
|
||||
float n10, float n11, float n12, float n13,
|
||||
float n20, float n21, float n22, float n23,
|
||||
float n30, float n31, float n32, float n33) {
|
||||
PMatrix copy = new PMatrix(0,
|
||||
n00, n01, n02, n03,
|
||||
PMatrix copy = new PMatrix(n00, n01, n02, n03,
|
||||
n10, n11, n12, n13,
|
||||
n20, n21, n22, n23,
|
||||
n30, n31, n32, n33);
|
||||
PMatrix inverse = copy.invert();
|
||||
if (inverse == null) return false;
|
||||
preApplyMatrix(inverse);
|
||||
preApply(inverse);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public void applyMatrix(PMatrix rhs) {
|
||||
applyMatrix(rhs.m00, rhs.m01, rhs.m02, rhs.m03,
|
||||
public void apply(PMatrix rhs) {
|
||||
apply(rhs.m00, rhs.m01, rhs.m02, rhs.m03,
|
||||
rhs.m10, rhs.m11, rhs.m12, rhs.m13,
|
||||
rhs.m20, rhs.m21, rhs.m22, rhs.m23,
|
||||
rhs.m30, rhs.m31, rhs.m32, rhs.m33);
|
||||
}
|
||||
|
||||
|
||||
public void applyMatrix(float n00, float n01, float n02, float n03,
|
||||
float n10, float n11, float n12, float n13,
|
||||
float n20, float n21, float n22, float n23,
|
||||
float n30, float n31, float n32, float n33) {
|
||||
public void apply(float n00, float n01, float n02, float n03,
|
||||
float n10, float n11, float n12, float n13,
|
||||
float n20, float n21, float n22, float n23,
|
||||
float n30, float n31, float n32, float n33) {
|
||||
|
||||
float r00 = m00*n00 + m01*n10 + m02*n20 + m03*n30;
|
||||
float r01 = m00*n01 + m01*n11 + m02*n21 + m03*n31;
|
||||
@@ -617,10 +613,6 @@ public final class PMatrix implements PConstants {
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
public void angleMode(int angleMode) {
|
||||
this.angleMode = angleMode;
|
||||
}
|
||||
|
||||
private final float max(float a, float b) {
|
||||
return (a > b) ? a : b;
|
||||
}
|
||||
@@ -630,12 +622,10 @@ public final class PMatrix implements PConstants {
|
||||
}
|
||||
|
||||
private final float sin(float angle) {
|
||||
if (angleMode == DEGREES) angle *= DEG_TO_RAD;
|
||||
return (float)Math.sin(angle);
|
||||
}
|
||||
|
||||
private final float cos(float angle) {
|
||||
if (angleMode == DEGREES) angle *= DEG_TO_RAD;
|
||||
return (float)Math.cos(angle);
|
||||
}
|
||||
}
|
||||
|
||||
+10
-2
@@ -2,14 +2,21 @@
|
||||
X fix double key events
|
||||
X fix mrj.version security error on the pc
|
||||
X set() fixes for PGraphics2 and setImpl inside PGraphics
|
||||
X remove angleMode (also from PMatrix classes)
|
||||
|
||||
|
||||
_ detect problems with caps (really a problem with the ves61r kids)
|
||||
|
||||
|
||||
_ make get/getImpl for PGraphics/PGraphics2
|
||||
_ make sure there's a loadPixels/updatePixels in PGraphics2
|
||||
_ rewrite getImpl/setImpl inside opengl
|
||||
_ make screen space fonts use get/set as well?
|
||||
_ too much to debug on their own
|
||||
_ unfortunately tint not set with setImpl, but...
|
||||
|
||||
_ get/set doesn't use tint at all
|
||||
_ (meaning that it's not so good for fonts)
|
||||
|
||||
_ apply tint() to textures as well
|
||||
_ otherwise no good way to color textures
|
||||
@@ -35,14 +42,12 @@ _ maybe fill() should set diffuse, and sep call to ambient() sets ambient?
|
||||
X removed it
|
||||
_ remove/rename postSetup() stuff from PGraphics/PApplet
|
||||
_ what's up with resetLights?
|
||||
_ angleMode stuff is kinda overkill
|
||||
_ move dot() to the bottom w/ the other math
|
||||
_ add PLight object to avoid method overflow
|
||||
_ preApplyMatrix, invApplyMatrix?
|
||||
_ applyMatrixPre and applyMatrixIn
|
||||
_ rotateXInv is ugly..
|
||||
_ irotateX?, papplyMatrix?
|
||||
_ angleMode shouldn't be the first param
|
||||
|
||||
_ fix the flicker in java2d mode
|
||||
X is it because the lock was taken off (g) in PApplet?
|
||||
@@ -172,6 +177,7 @@ _ Stroking a rect() leaves the upper right pixel off.
|
||||
|
||||
|
||||
api questions
|
||||
_ remove angleMode() ?
|
||||
_ rename video.Camera to video.Video ?
|
||||
_ what to call firstMouse, implement rightMouse?
|
||||
_ should nf() handle commas as well?
|
||||
@@ -211,6 +217,8 @@ _ since needs to render to screen as well
|
||||
text api solutions
|
||||
_ store the font name in the vlw font file (at the end)
|
||||
o could include multiple names for multi platforms
|
||||
_ danger of this setup is that it may run much nicer for the author
|
||||
_ i.e. with the font installed, and then super slow for their users
|
||||
_ is getFontList returning a different set of fonts from device2d?
|
||||
_ or is it only those with ps names?
|
||||
_ createFont() with a .ttf does a create font internally (1.3+ only)
|
||||
|
||||
Reference in New Issue
Block a user