Skip to content

Commit b71ed5a

Browse files
committed
fix for PMatrix3D.mult() when vectors are identical (issue 921)
1 parent 36fedaf commit b71ed5a

File tree

3 files changed

+30
-29
lines changed

3 files changed

+30
-29
lines changed

android/core/src/processing/core/PMatrix3D.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*
44
Part of the Processing project - http://processing.org
55
6-
Copyright (c) 2005-10 Ben Fry and Casey Reas
6+
Copyright (c) 2005-12 Ben Fry and Casey Reas
77
88
This library is free software; you can redistribute it and/or
99
modify it under the terms of the GNU Lesser General Public
@@ -26,7 +26,7 @@
2626
/**
2727
* 4x4 matrix implementation.
2828
*/
29-
public class PMatrix3D implements PMatrix /*, PConstants*/ {
29+
public final class PMatrix3D implements PMatrix /*, PConstants*/ {
3030

3131
public float m00, m01, m02, m03;
3232
public float m10, m11, m12, m13;
@@ -232,16 +232,16 @@ public void rotate(float angle, float v0, float v1, float v2) {
232232
if (norm2 < PConstants.EPSILON) {
233233
// The vector is zero, cannot apply rotation.
234234
return;
235-
}
236-
235+
}
236+
237237
if (Math.abs(norm2 - 1) > PConstants.EPSILON) {
238238
// The rotation vector is not normalized.
239239
float norm = PApplet.sqrt(norm2);
240240
v0 /= norm;
241241
v1 /= norm;
242242
v2 /= norm;
243-
}
244-
243+
}
244+
245245
float c = cos(angle);
246246
float s = sin(angle);
247247
float t = 1.0f - c;
@@ -425,9 +425,9 @@ public PVector mult(PVector source, PVector target) {
425425
if (target == null) {
426426
target = new PVector();
427427
}
428-
target.x = m00*source.x + m01*source.y + m02*source.z + m03;
429-
target.y = m10*source.x + m11*source.y + m12*source.z + m13;
430-
target.z = m20*source.x + m21*source.y + m22*source.z + m23;
428+
target.set(m00*source.x + m01*source.y + m02*source.z + m03,
429+
m10*source.x + m11*source.y + m12*source.z + m13,
430+
m20*source.x + m21*source.y + m22*source.z + m23);
431431
// float tw = m30*source.x + m31*source.y + m32*source.z + m33;
432432
// if (tw != 0 && tw != 1) {
433433
// target.div(tw);
@@ -775,19 +775,19 @@ public void print() {
775775
//////////////////////////////////////////////////////////////
776776

777777

778-
private final float max(float a, float b) {
778+
static private final float max(float a, float b) {
779779
return (a > b) ? a : b;
780780
}
781781

782-
private final float abs(float a) {
782+
static private final float abs(float a) {
783783
return (a < 0) ? -a : a;
784784
}
785785

786-
private final float sin(float angle) {
786+
static private final float sin(float angle) {
787787
return (float) Math.sin(angle);
788788
}
789789

790-
private final float cos(float angle) {
790+
static private final float cos(float angle) {
791791
return (float) Math.cos(angle);
792792
}
793793
}

core/src/processing/core/PMatrix3D.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
/*
44
Part of the Processing project - http://processing.org
55
6-
Copyright (c) 2005-08 Ben Fry and Casey Reas
6+
Copyright (c) 2005-12 Ben Fry and Casey Reas
77
88
This library is free software; you can redistribute it and/or
99
modify it under the terms of the GNU Lesser General Public
10-
License as published by the Free Software Foundation; either
11-
version 2.1 of the License, or (at your option) any later version.
10+
License version 2.1 as published by the Free Software Foundation.
1211
1312
This library is distributed in the hope that it will be useful,
1413
but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -426,9 +425,9 @@ public PVector mult(PVector source, PVector target) {
426425
if (target == null) {
427426
target = new PVector();
428427
}
429-
target.x = m00*source.x + m01*source.y + m02*source.z + m03;
430-
target.y = m10*source.x + m11*source.y + m12*source.z + m13;
431-
target.z = m20*source.x + m21*source.y + m22*source.z + m23;
428+
target.set(m00*source.x + m01*source.y + m02*source.z + m03,
429+
m10*source.x + m11*source.y + m12*source.z + m13,
430+
m20*source.x + m21*source.y + m22*source.z + m23);
432431
// float tw = m30*source.x + m31*source.y + m32*source.z + m33;
433432
// if (tw != 0 && tw != 1) {
434433
// target.div(tw);
@@ -656,36 +655,36 @@ public float determinant() {
656655
// These functions should not be used, as they will be removed in the future.
657656

658657

659-
public void invTranslate(float tx, float ty, float tz) {
658+
protected void invTranslate(float tx, float ty, float tz) {
660659
preApply(1, 0, 0, -tx,
661660
0, 1, 0, -ty,
662661
0, 0, 1, -tz,
663662
0, 0, 0, 1);
664663
}
665664

666665

667-
public void invRotateX(float angle) {
666+
protected void invRotateX(float angle) {
668667
float c = cos(-angle);
669668
float s = sin(-angle);
670669
preApply(1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1);
671670
}
672671

673672

674-
public void invRotateY(float angle) {
673+
protected void invRotateY(float angle) {
675674
float c = cos(-angle);
676675
float s = sin(-angle);
677676
preApply(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1);
678677
}
679678

680679

681-
public void invRotateZ(float angle) {
680+
protected void invRotateZ(float angle) {
682681
float c = cos(-angle);
683682
float s = sin(-angle);
684683
preApply(c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
685684
}
686685

687686

688-
public void invRotate(float angle, float v0, float v1, float v2) {
687+
protected void invRotate(float angle, float v0, float v1, float v2) {
689688
//TODO should make sure this vector is normalized
690689

691690
float c = cos(-angle);
@@ -699,15 +698,15 @@ public void invRotate(float angle, float v0, float v1, float v2) {
699698
}
700699

701700

702-
public void invScale(float x, float y, float z) {
701+
protected void invScale(float x, float y, float z) {
703702
preApply(1/x, 0, 0, 0, 0, 1/y, 0, 0, 0, 0, 1/z, 0, 0, 0, 0, 1);
704703
}
705704

706705

707-
public boolean invApply(float n00, float n01, float n02, float n03,
708-
float n10, float n11, float n12, float n13,
709-
float n20, float n21, float n22, float n23,
710-
float n30, float n31, float n32, float n33) {
706+
protected boolean invApply(float n00, float n01, float n02, float n03,
707+
float n10, float n11, float n12, float n13,
708+
float n20, float n21, float n22, float n23,
709+
float n30, float n31, float n32, float n33) {
711710
if (inverseCopy == null) {
712711
inverseCopy = new PMatrix3D();
713712
}

core/todo.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ X add XML.getLong() (also update Android)
3333
X http://code.google.com/p/processing/issues/detail?id=1378
3434
X beginShape(QUAD) not working with Java2D
3535
X http://code.google.com/p/processing/issues/detail?id=1365
36+
X fix for PMatrix3D.mult() when vectors are identical
37+
X http://code.google.com/p/processing/issues/detail?id=921
3638

3739

3840
andres (cleanup)

0 commit comments

Comments
 (0)