Skip to content

Commit f122b52

Browse files
committed
added inverse matrix utility methods
1 parent 99320b9 commit f122b52

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

core/src/processing/opengl/PGraphicsOpenGL.java

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3958,9 +3958,16 @@ protected void translateImpl(float tx, float ty, float tz) {
39583958
static protected void invTranslate(PMatrix3D matrix,
39593959
float tx, float ty, float tz) {
39603960
matrix.preApply(1, 0, 0, -tx,
3961-
0, 1, 0, -ty,
3962-
0, 0, 1, -tz,
3963-
0, 0, 0, 1);
3961+
0, 1, 0, -ty,
3962+
0, 0, 1, -tz,
3963+
0, 0, 0, 1);
3964+
}
3965+
3966+
3967+
static protected void invTranslate(PMatrix2D matrix,
3968+
float tx, float ty) {
3969+
matrix.preApply(1, 0, -tx,
3970+
0, 1, -ty);
39643971
}
39653972

39663973

@@ -4049,16 +4056,21 @@ protected void rotateImpl(float angle, float v0, float v1, float v2) {
40494056
}
40504057

40514058

4052-
static private void invRotate(PMatrix3D matrix, float angle,
4053-
float v0, float v1, float v2) {
4059+
static protected void invRotate(PMatrix3D matrix, float angle,
4060+
float v0, float v1, float v2) {
40544061
float c = PApplet.cos(-angle);
40554062
float s = PApplet.sin(-angle);
40564063
float t = 1.0f - c;
40574064

40584065
matrix.preApply((t*v0*v0) + c, (t*v0*v1) - (s*v2), (t*v0*v2) + (s*v1), 0,
4059-
(t*v0*v1) + (s*v2), (t*v1*v1) + c, (t*v1*v2) - (s*v0), 0,
4060-
(t*v0*v2) - (s*v1), (t*v1*v2) + (s*v0), (t*v2*v2) + c, 0,
4061-
0, 0, 0, 1);
4066+
(t*v0*v1) + (s*v2), (t*v1*v1) + c, (t*v1*v2) - (s*v0), 0,
4067+
(t*v0*v2) - (s*v1), (t*v1*v2) + (s*v0), (t*v2*v2) + c, 0,
4068+
0, 0, 0, 1);
4069+
}
4070+
4071+
4072+
static protected void invRotate(PMatrix2D matrix, float angle) {
4073+
matrix.rotate(-angle);
40624074
}
40634075

40644076

@@ -4103,6 +4115,11 @@ static protected void invScale(PMatrix3D matrix, float x, float y, float z) {
41034115
}
41044116

41054117

4118+
static protected void invScale(PMatrix2D matrix, float x, float y) {
4119+
matrix.preApply(1/x, 0, 0, 1/y, 0, 0);
4120+
}
4121+
4122+
41064123
@Override
41074124
public void shearX(float angle) {
41084125
float t = (float) Math.tan(angle);
@@ -6690,7 +6707,7 @@ protected Object initCache(PImage img) {
66906707
if (tex == null || tex.contextIsOutdated()) {
66916708
tex = addTexture(img);
66926709
if (tex != null) {
6693-
boolean dispose = !img.loaded;
6710+
boolean dispose = img.pixels == null;
66946711
img.loadPixels();
66956712
tex.set(img.pixels, img.format);
66966713
img.setModified();

0 commit comments

Comments
 (0)