fix for PMatrix3D.mult() when vectors are identical (issue 921)

This commit is contained in:
benfry
2012-11-25 01:26:56 +00:00
parent c06ba067b5
commit c08be82528
3 changed files with 30 additions and 29 deletions
+13 -13
View File
@@ -3,7 +3,7 @@
/*
Part of the Processing project - http://processing.org
Copyright (c) 2005-10 Ben Fry and Casey Reas
Copyright (c) 2005-12 Ben Fry and Casey Reas
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -26,7 +26,7 @@ package processing.core;
/**
* 4x4 matrix implementation.
*/
public class PMatrix3D implements PMatrix /*, PConstants*/ {
public final class PMatrix3D implements PMatrix /*, PConstants*/ {
public float m00, m01, m02, m03;
public float m10, m11, m12, m13;
@@ -232,16 +232,16 @@ public class PMatrix3D implements PMatrix /*, PConstants*/ {
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);
float t = 1.0f - c;
@@ -425,9 +425,9 @@ public class PMatrix3D implements PMatrix /*, PConstants*/ {
if (target == null) {
target = new PVector();
}
target.x = m00*source.x + m01*source.y + m02*source.z + m03;
target.y = m10*source.x + m11*source.y + m12*source.z + m13;
target.z = m20*source.x + m21*source.y + m22*source.z + m23;
target.set(m00*source.x + m01*source.y + m02*source.z + m03,
m10*source.x + m11*source.y + m12*source.z + m13,
m20*source.x + m21*source.y + m22*source.z + m23);
// float tw = m30*source.x + m31*source.y + m32*source.z + m33;
// if (tw != 0 && tw != 1) {
// target.div(tw);
@@ -775,19 +775,19 @@ public class PMatrix3D implements PMatrix /*, PConstants*/ {
//////////////////////////////////////////////////////////////
private final float max(float a, float b) {
static private final float max(float a, float b) {
return (a > b) ? a : b;
}
private final float abs(float a) {
static private final float abs(float a) {
return (a < 0) ? -a : a;
}
private final float sin(float angle) {
static private final float sin(float angle) {
return (float) Math.sin(angle);
}
private final float cos(float angle) {
static private final float cos(float angle) {
return (float) Math.cos(angle);
}
}
+15 -16
View File
@@ -3,12 +3,11 @@
/*
Part of the Processing project - http://processing.org
Copyright (c) 2005-08 Ben Fry and Casey Reas
Copyright (c) 2005-12 Ben Fry and Casey Reas
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
License version 2.1 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -426,9 +425,9 @@ public final class PMatrix3D implements PMatrix /*, PConstants*/ {
if (target == null) {
target = new PVector();
}
target.x = m00*source.x + m01*source.y + m02*source.z + m03;
target.y = m10*source.x + m11*source.y + m12*source.z + m13;
target.z = m20*source.x + m21*source.y + m22*source.z + m23;
target.set(m00*source.x + m01*source.y + m02*source.z + m03,
m10*source.x + m11*source.y + m12*source.z + m13,
m20*source.x + m21*source.y + m22*source.z + m23);
// float tw = m30*source.x + m31*source.y + m32*source.z + m33;
// if (tw != 0 && tw != 1) {
// target.div(tw);
@@ -656,7 +655,7 @@ public final class PMatrix3D implements PMatrix /*, PConstants*/ {
// These functions should not be used, as they will be removed in the future.
public void invTranslate(float tx, float ty, float tz) {
protected void invTranslate(float tx, float ty, float tz) {
preApply(1, 0, 0, -tx,
0, 1, 0, -ty,
0, 0, 1, -tz,
@@ -664,28 +663,28 @@ public final class PMatrix3D implements PMatrix /*, PConstants*/ {
}
public void invRotateX(float angle) {
protected void invRotateX(float angle) {
float c = cos(-angle);
float s = sin(-angle);
preApply(1, 0, 0, 0, 0, c, -s, 0, 0, s, c, 0, 0, 0, 0, 1);
}
public void invRotateY(float angle) {
protected void invRotateY(float angle) {
float c = cos(-angle);
float s = sin(-angle);
preApply(c, 0, s, 0, 0, 1, 0, 0, -s, 0, c, 0, 0, 0, 0, 1);
}
public void invRotateZ(float angle) {
protected void invRotateZ(float angle) {
float c = cos(-angle);
float s = sin(-angle);
preApply(c, -s, 0, 0, s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
}
public void invRotate(float angle, float v0, float v1, float v2) {
protected void invRotate(float angle, float v0, float v1, float v2) {
//TODO should make sure this vector is normalized
float c = cos(-angle);
@@ -699,15 +698,15 @@ public final class PMatrix3D implements PMatrix /*, PConstants*/ {
}
public void invScale(float x, float y, float z) {
protected void invScale(float x, float y, float z) {
preApply(1/x, 0, 0, 0, 0, 1/y, 0, 0, 0, 0, 1/z, 0, 0, 0, 0, 1);
}
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) {
protected 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) {
if (inverseCopy == null) {
inverseCopy = new PMatrix3D();
}
+2
View File
@@ -33,6 +33,8 @@ X add XML.getLong() (also update Android)
X http://code.google.com/p/processing/issues/detail?id=1378
X beginShape(QUAD) not working with Java2D
X http://code.google.com/p/processing/issues/detail?id=1365
X fix for PMatrix3D.mult() when vectors are identical
X http://code.google.com/p/processing/issues/detail?id=921
andres (cleanup)