diff --git a/engine/src/bullet/com/jme3/bullet/control/KinematicRagdollControl.java b/engine/src/bullet/com/jme3/bullet/control/KinematicRagdollControl.java
index a7dd9dd19..aff608382 100644
--- a/engine/src/bullet/com/jme3/bullet/control/KinematicRagdollControl.java
+++ b/engine/src/bullet/com/jme3/bullet/control/KinematicRagdollControl.java
@@ -165,7 +165,7 @@ public class KinematicRagdollControl implements PhysicsControl, PhysicsCollision
return;
}
TempVars vars = TempVars.get();
- assert vars.lock();
+
Quaternion tmpRot1 = vars.quat1;
Quaternion tmpRot2 = vars.quat2;
@@ -264,7 +264,7 @@ public class KinematicRagdollControl implements PhysicsControl, PhysicsCollision
}
}
}
- assert vars.unlock();
+ vars.release();
}
@@ -681,8 +681,7 @@ public class KinematicRagdollControl implements PhysicsControl, PhysicsCollision
animControl.setEnabled(mode == Mode.Kinetmatic);
baseRigidBody.setKinematic(mode == Mode.Kinetmatic);
- TempVars vars = TempVars.get();
- assert vars.lock();
+ TempVars vars = TempVars.get();
for (PhysicsBoneLink link : boneLinks.values()) {
link.rigidBody.setKinematic(mode == Mode.Kinetmatic);
if (mode == Mode.Ragdoll) {
@@ -693,7 +692,7 @@ public class KinematicRagdollControl implements PhysicsControl, PhysicsCollision
}
}
- assert vars.unlock();
+ vars.release();
for (Bone bone : skeleton.getRoots()) {
RagdollUtils.setUserControl(bone, mode == Mode.Ragdoll);
@@ -718,7 +717,6 @@ public class KinematicRagdollControl implements PhysicsControl, PhysicsCollision
TempVars vars = TempVars.get();
- assert vars.lock();
for (PhysicsBoneLink link : boneLinks.values()) {
Vector3f p = link.rigidBody.getMotionState().getWorldLocation();
@@ -737,7 +735,7 @@ public class KinematicRagdollControl implements PhysicsControl, PhysicsCollision
link.startBlendingRot.set(q2);
link.rigidBody.setKinematic(true);
}
- assert vars.unlock();
+ vars.release();
for (Bone bone : skeleton.getRoots()) {
RagdollUtils.setUserControl(bone, false);
diff --git a/engine/src/bullet/com/jme3/bullet/util/DebugShapeFactory.java b/engine/src/bullet/com/jme3/bullet/util/DebugShapeFactory.java
index 1dd1c3029..b03e185e3 100644
--- a/engine/src/bullet/com/jme3/bullet/util/DebugShapeFactory.java
+++ b/engine/src/bullet/com/jme3/bullet/util/DebugShapeFactory.java
@@ -79,15 +79,14 @@ public class DebugShapeFactory {
geometry.setLocalTranslation(childCollisionShape.location);
// apply rotation
- TempVars vars = TempVars.get();
- assert vars.lock();
+ TempVars vars = TempVars.get();
Matrix3f tempRot = vars.tempMat3;
tempRot.set(geometry.getLocalRotation());
childCollisionShape.rotation.mult(tempRot, tempRot);
geometry.setLocalRotation(tempRot);
- assert vars.unlock();
+ vars.release();
node.attachChild(geometry);
}
diff --git a/engine/src/core/com/jme3/animation/Bone.java b/engine/src/core/com/jme3/animation/Bone.java
index f7a25104b..889cde433 100644
--- a/engine/src/core/com/jme3/animation/Bone.java
+++ b/engine/src/core/com/jme3/animation/Bone.java
@@ -524,7 +524,7 @@ public final class Bone implements Savable {
}
TempVars vars = TempVars.get();
- assert vars.lock();
+// assert vars.lock();
Vector3f tmpV = vars.vect1;
Vector3f tmpV2 = vars.vect2;
@@ -545,7 +545,7 @@ public final class Bone implements Savable {
}
- assert vars.unlock();
+ vars.release();
}
/**
diff --git a/engine/src/core/com/jme3/animation/Skeleton.java b/engine/src/core/com/jme3/animation/Skeleton.java
index 88dca1329..e29ee90d6 100644
--- a/engine/src/core/com/jme3/animation/Skeleton.java
+++ b/engine/src/core/com/jme3/animation/Skeleton.java
@@ -54,7 +54,6 @@ public final class Skeleton implements Savable {
private Bone[] rootBones;
private Bone[] boneList;
-
/**
* Contains the skinning matrices, multiplying it by a vertex effected by a bone
* will cause it to go to the animated position.
@@ -251,11 +250,10 @@ public final class Skeleton implements Savable {
*/
public Matrix4f[] computeSkinningMatrices() {
TempVars vars = TempVars.get();
- assert vars.lock();
for (int i = 0; i < boneList.length; i++) {
boneList[i].getOffsetTransform(skinningMatrixes[i], vars.quat1, vars.vect1, vars.vect2, vars.tempMat3);
}
- assert vars.unlock();
+ vars.release();
return skinningMatrixes;
}
diff --git a/engine/src/core/com/jme3/animation/SkeletonControl.java b/engine/src/core/com/jme3/animation/SkeletonControl.java
index c0455635b..ef735be6e 100644
--- a/engine/src/core/com/jme3/animation/SkeletonControl.java
+++ b/engine/src/core/com/jme3/animation/SkeletonControl.java
@@ -227,7 +227,7 @@ public class SkeletonControl extends AbstractControl implements Savable, Cloneab
int idxWeights = 0;
TempVars vars = TempVars.get();
- assert vars.lock();
+
float[] posBuf = vars.skinPositions;
float[] normBuf = vars.skinNormals;
@@ -284,7 +284,7 @@ public class SkeletonControl extends AbstractControl implements Savable, Cloneab
fnb.put(normBuf, 0, bufLength);
}
- assert vars.unlock();
+ vars.release();
vb.updateData(fvb);
nb.updateData(fnb);
diff --git a/engine/src/core/com/jme3/bounding/BoundingBox.java b/engine/src/core/com/jme3/bounding/BoundingBox.java
index 1e1440a18..878ba37c2 100644
--- a/engine/src/core/com/jme3/bounding/BoundingBox.java
+++ b/engine/src/core/com/jme3/bounding/BoundingBox.java
@@ -29,7 +29,6 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
package com.jme3.bounding;
import com.jme3.collision.Collidable;
@@ -90,14 +89,14 @@ public class BoundingBox extends BoundingVolume {
this.zExtent = z;
}
- public BoundingBox(BoundingBox source){
+ public BoundingBox(BoundingBox source) {
this.center.set(source.center);
this.xExtent = source.xExtent;
this.yExtent = source.yExtent;
this.zExtent = source.zExtent;
}
- public BoundingBox(Vector3f min, Vector3f max){
+ public BoundingBox(Vector3f min, Vector3f max) {
setMinMax(min, max);
}
@@ -130,10 +129,10 @@ public class BoundingBox extends BoundingVolume {
}
TempVars vars = TempVars.get();
- assert vars.lock();
+
Vector3f min = vars.vect1.set(new Vector3f(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY));
Vector3f max = vars.vect2.set(new Vector3f(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY));
-
+
Vector3f point;
for (int i = start; i < end; i++) {
point = tris[i].get(0);
@@ -143,7 +142,7 @@ public class BoundingBox extends BoundingVolume {
point = tris[i].get(2);
checkMinMax(min, max, point);
}
-
+
center.set(min.addLocal(max));
center.multLocal(0.5f);
@@ -151,27 +150,27 @@ public class BoundingBox extends BoundingVolume {
yExtent = max.y - center.y;
zExtent = max.z - center.z;
- assert vars.unlock();
+ vars.release();
}
-
+
public void computeFromTris(int[] indices, Mesh mesh, int start, int end) {
- if (end - start <= 0) {
+ if (end - start <= 0) {
return;
}
TempVars vars = TempVars.get();
- assert vars.lock();
+
Vector3f vect1 = vars.vect1;
Vector3f vect2 = vars.vect2;
Triangle triangle = vars.triangle;
- Vector3f min = vect1.set(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY);
+ Vector3f min = vect1.set(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY);
Vector3f max = vect2.set(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY);
Vector3f point;
for (int i = start; i < end; i++) {
- mesh.getTriangle(indices[i], triangle);
- point = triangle.get(0);
+ mesh.getTriangle(indices[i], triangle);
+ point = triangle.get(0);
checkMinMax(min, max, point);
point = triangle.get(1);
checkMinMax(min, max, point);
@@ -186,22 +185,28 @@ public class BoundingBox extends BoundingVolume {
yExtent = max.y - center.y;
zExtent = max.z - center.z;
- assert vars.unlock();
+ vars.release();
}
public static final void checkMinMax(Vector3f min, Vector3f max, Vector3f point) {
- if (point.x < min.x)
+ if (point.x < min.x) {
min.x = point.x;
- if (point.x > max.x)
+ }
+ if (point.x > max.x) {
max.x = point.x;
- if (point.y < min.y)
+ }
+ if (point.y < min.y) {
min.y = point.y;
- if (point.y > max.y)
+ }
+ if (point.y > max.y) {
max.y = point.y;
- if (point.z < min.z)
+ }
+ if (point.z < min.z) {
min.z = point.z;
- if (point.z > max.z)
+ }
+ if (point.z > max.z) {
max.z = point.z;
+ }
}
/**
@@ -213,15 +218,18 @@ public class BoundingBox extends BoundingVolume {
* the list of points.
*/
public void containAABB(FloatBuffer points) {
- if (points == null)
+ if (points == null) {
return;
+ }
points.rewind();
if (points.remaining() <= 2) // we need at least a 3 float vector
+ {
return;
+ }
TempVars vars = TempVars.get();
- assert vars.lock();
+
BufferUtils.populateFromBuffer(vars.vect1, points, 0);
float minX = vars.vect1.x, minY = vars.vect1.y, minZ = vars.vect1.z;
float maxX = vars.vect1.x, maxY = vars.vect1.y, maxZ = vars.vect1.z;
@@ -229,23 +237,26 @@ public class BoundingBox extends BoundingVolume {
for (int i = 1, len = points.remaining() / 3; i < len; i++) {
BufferUtils.populateFromBuffer(vars.vect1, points, i);
- if (vars.vect1.x < minX)
+ if (vars.vect1.x < minX) {
minX = vars.vect1.x;
- else if (vars.vect1.x > maxX)
+ } else if (vars.vect1.x > maxX) {
maxX = vars.vect1.x;
+ }
- if (vars.vect1.y < minY)
+ if (vars.vect1.y < minY) {
minY = vars.vect1.y;
- else if (vars.vect1.y > maxY)
+ } else if (vars.vect1.y > maxY) {
maxY = vars.vect1.y;
+ }
- if (vars.vect1.z < minZ)
+ if (vars.vect1.z < minZ) {
minZ = vars.vect1.z;
- else if (vars.vect1.z > maxZ)
+ } else if (vars.vect1.z > maxZ) {
maxZ = vars.vect1.z;
+ }
}
- assert vars.unlock();
+ vars.release();
center.set(minX + maxX, minY + maxY, minZ + maxZ);
center.multLocal(0.5f);
@@ -278,7 +289,7 @@ public class BoundingBox extends BoundingVolume {
box.center.addLocal(trans.getTranslation());
TempVars vars = TempVars.get();
- assert vars.lock();
+
Matrix3f transMatrix = vars.tempMat3;
transMatrix.set(trans.getRotation());
// Make the rotation matrix all positive to get the maximum x/y/z extent
@@ -292,12 +303,12 @@ public class BoundingBox extends BoundingVolume {
box.yExtent = FastMath.abs(vars.vect2.getY());
box.zExtent = FastMath.abs(vars.vect2.getZ());
- assert vars.unlock();
+ vars.release();
return box;
}
- public BoundingVolume transform(Matrix4f trans, BoundingVolume store){
+ public BoundingVolume transform(Matrix4f trans, BoundingVolume store) {
BoundingBox box;
if (store == null || store.getType() != Type.AABB) {
box = new BoundingBox();
@@ -305,7 +316,7 @@ public class BoundingBox extends BoundingVolume {
box = (BoundingBox) store;
}
TempVars vars = TempVars.get();
- assert vars.lock();
+
float w = trans.multProj(center, box.center);
box.center.divideLocal(w);
@@ -318,13 +329,13 @@ public class BoundingBox extends BoundingVolume {
vars.vect1.set(xExtent, yExtent, zExtent);
transMatrix.mult(vars.vect1, vars.vect1);
-
+
// Assign the biggest rotations after scales.
box.xExtent = FastMath.abs(vars.vect1.getX());
box.yExtent = FastMath.abs(vars.vect1.getY());
box.zExtent = FastMath.abs(vars.vect1.getZ());
- assert vars.unlock();
+ vars.release();
return box;
}
@@ -371,14 +382,14 @@ public class BoundingBox extends BoundingVolume {
BoundingBox vBox = (BoundingBox) volume;
return merge(vBox.center, vBox.xExtent, vBox.yExtent,
vBox.zExtent, new BoundingBox(new Vector3f(0, 0, 0), 0,
- 0, 0));
+ 0, 0));
}
case Sphere: {
BoundingSphere vSphere = (BoundingSphere) volume;
return merge(vSphere.center, vSphere.radius, vSphere.radius,
vSphere.radius, new BoundingBox(new Vector3f(0, 0, 0),
- 0, 0, 0));
+ 0, 0, 0));
}
// case OBB: {
@@ -471,7 +482,6 @@ public class BoundingBox extends BoundingVolume {
// zExtent = max.z - center.z;
// return this;
// }
-
/**
* merge
combines this bounding box with another box which is
* defined by the center, x, y, z extents.
@@ -492,26 +502,32 @@ public class BoundingBox extends BoundingVolume {
float boxZ, BoundingBox rVal) {
TempVars vars = TempVars.get();
- assert vars.lock();
+
vars.vect1.x = center.x - xExtent;
- if (vars.vect1.x > boxCenter.x - boxX)
+ if (vars.vect1.x > boxCenter.x - boxX) {
vars.vect1.x = boxCenter.x - boxX;
+ }
vars.vect1.y = center.y - yExtent;
- if (vars.vect1.y > boxCenter.y - boxY)
+ if (vars.vect1.y > boxCenter.y - boxY) {
vars.vect1.y = boxCenter.y - boxY;
+ }
vars.vect1.z = center.z - zExtent;
- if (vars.vect1.z > boxCenter.z - boxZ)
+ if (vars.vect1.z > boxCenter.z - boxZ) {
vars.vect1.z = boxCenter.z - boxZ;
+ }
vars.vect2.x = center.x + xExtent;
- if (vars.vect2.x < boxCenter.x + boxX)
+ if (vars.vect2.x < boxCenter.x + boxX) {
vars.vect2.x = boxCenter.x + boxX;
+ }
vars.vect2.y = center.y + yExtent;
- if (vars.vect2.y < boxCenter.y + boxY)
+ if (vars.vect2.y < boxCenter.y + boxY) {
vars.vect2.y = boxCenter.y + boxY;
+ }
vars.vect2.z = center.z + zExtent;
- if (vars.vect2.z < boxCenter.z + boxZ)
+ if (vars.vect2.z < boxCenter.z + boxZ) {
vars.vect2.z = boxCenter.z + boxZ;
+ }
center.set(vars.vect2).addLocal(vars.vect1).multLocal(0.5f);
@@ -519,7 +535,7 @@ public class BoundingBox extends BoundingVolume {
yExtent = vars.vect2.y - center.y;
zExtent = vars.vect2.z - center.z;
- assert vars.unlock();
+ vars.release();
return rVal;
}
@@ -543,10 +559,10 @@ public class BoundingBox extends BoundingVolume {
rVal.checkPlane = checkPlane;
return rVal;
}
-
+
BoundingBox rVal = new BoundingBox(center.clone(),
xExtent, yExtent, zExtent);
- return rVal;
+ return rVal;
}
/**
@@ -583,10 +599,11 @@ public class BoundingBox extends BoundingVolume {
if (FastMath.abs(center.x - bs.center.x) < bs.getRadius()
+ xExtent
&& FastMath.abs(center.y - bs.center.y) < bs.getRadius()
- + yExtent
+ + yExtent
&& FastMath.abs(center.z - bs.center.z) < bs.getRadius()
- + zExtent)
+ + zExtent) {
return true;
+ }
return false;
}
@@ -602,16 +619,17 @@ public class BoundingBox extends BoundingVolume {
assert Vector3f.isValidVector(center) && Vector3f.isValidVector(bb.center);
if (center.x + xExtent < bb.center.x - bb.xExtent
- || center.x - xExtent > bb.center.x + bb.xExtent)
+ || center.x - xExtent > bb.center.x + bb.xExtent) {
return false;
- else if (center.y + yExtent < bb.center.y - bb.yExtent
- || center.y - yExtent > bb.center.y + bb.yExtent)
+ } else if (center.y + yExtent < bb.center.y - bb.yExtent
+ || center.y - yExtent > bb.center.y + bb.yExtent) {
return false;
- else if (center.z + zExtent < bb.center.z - bb.zExtent
- || center.z - zExtent > bb.center.z + bb.zExtent)
+ } else if (center.z + zExtent < bb.center.z - bb.zExtent
+ || center.z - zExtent > bb.center.z + bb.zExtent) {
return false;
- else
+ } else {
return true;
+ }
}
/**
@@ -623,7 +641,6 @@ public class BoundingBox extends BoundingVolume {
// public boolean intersectsOrientedBoundingBox(OrientedBoundingBox obb) {
// return obb.intersectsBoundingBox(this);
// }
-
/**
* determines if this bounding box intersects with a given ray object. If an
* intersection has occurred, true is returned, otherwise false is returned.
@@ -636,21 +653,21 @@ public class BoundingBox extends BoundingVolume {
float rhs;
TempVars vars = TempVars.get();
- assert vars.lock();
+
Vector3f diff = ray.origin.subtract(getCenter(vars.vect2), vars.vect1);
- final float[] fWdU = vars.fWdU;
- final float[] fAWdU = vars.fAWdU;
- final float[] fDdU = vars.fDdU;
- final float[] fADdU = vars.fADdU;
- final float[] fAWxDdU = vars.fAWxDdU;
-
+ final float[] fWdU = vars.fWdU;
+ final float[] fAWdU = vars.fAWdU;
+ final float[] fDdU = vars.fDdU;
+ final float[] fADdU = vars.fADdU;
+ final float[] fAWxDdU = vars.fAWxDdU;
+
fWdU[0] = ray.getDirection().dot(Vector3f.UNIT_X);
fAWdU[0] = FastMath.abs(fWdU[0]);
fDdU[0] = diff.dot(Vector3f.UNIT_X);
fADdU[0] = FastMath.abs(fDdU[0]);
if (fADdU[0] > xExtent && fDdU[0] * fWdU[0] >= 0.0) {
- assert vars.unlock();
+ vars.release();
return false;
}
@@ -659,7 +676,7 @@ public class BoundingBox extends BoundingVolume {
fDdU[1] = diff.dot(Vector3f.UNIT_Y);
fADdU[1] = FastMath.abs(fDdU[1]);
if (fADdU[1] > yExtent && fDdU[1] * fWdU[1] >= 0.0) {
- assert vars.unlock();
+ vars.release();
return false;
}
@@ -668,7 +685,7 @@ public class BoundingBox extends BoundingVolume {
fDdU[2] = diff.dot(Vector3f.UNIT_Z);
fADdU[2] = FastMath.abs(fDdU[2]);
if (fADdU[2] > zExtent && fDdU[2] * fWdU[2] >= 0.0) {
- assert vars.unlock();
+ vars.release();
return false;
}
@@ -677,25 +694,25 @@ public class BoundingBox extends BoundingVolume {
fAWxDdU[0] = FastMath.abs(wCrossD.dot(Vector3f.UNIT_X));
rhs = yExtent * fAWdU[2] + zExtent * fAWdU[1];
if (fAWxDdU[0] > rhs) {
- assert vars.unlock();
+ vars.release();
return false;
}
fAWxDdU[1] = FastMath.abs(wCrossD.dot(Vector3f.UNIT_Y));
rhs = xExtent * fAWdU[2] + zExtent * fAWdU[0];
if (fAWxDdU[1] > rhs) {
- assert vars.unlock();
+ vars.release();
return false;
}
fAWxDdU[2] = FastMath.abs(wCrossD.dot(Vector3f.UNIT_Z));
rhs = xExtent * fAWdU[1] + yExtent * fAWdU[0];
if (fAWxDdU[2] > rhs) {
- assert vars.unlock();
+ vars.release();
return false;
}
- assert vars.unlock();
+ vars.release();
return true;
}
@@ -704,12 +721,12 @@ public class BoundingBox extends BoundingVolume {
*/
private int collideWithRay(Ray ray, CollisionResults results) {
TempVars vars = TempVars.get();
- assert vars.lock();
+
Vector3f diff = vars.vect1.set(ray.origin).subtractLocal(center);
Vector3f direction = vars.vect2.set(ray.direction);
- float[] t = { 0f, Float.POSITIVE_INFINITY };
-
+ float[] t = {0f, Float.POSITIVE_INFINITY};
+
float saveT0 = t[0], saveT1 = t[1];
boolean notEntirelyClipped = clip(+direction.x, -diff.x - xExtent, t)
&& clip(-direction.x, +diff.x - xExtent, t)
@@ -717,15 +734,15 @@ public class BoundingBox extends BoundingVolume {
&& clip(-direction.y, +diff.y - yExtent, t)
&& clip(+direction.z, -diff.z - zExtent, t)
&& clip(-direction.z, +diff.z - zExtent, t);
- assert vars.unlock();
-
+ vars.release();
+
if (notEntirelyClipped && (t[0] != saveT0 || t[1] != saveT1)) {
if (t[1] > t[0]) {
float[] distances = t;
- Vector3f[] points = new Vector3f[] {
- new Vector3f(ray.direction).multLocal(distances[0]).addLocal(ray.origin),
- new Vector3f(ray.direction).multLocal(distances[1]).addLocal(ray.origin)
- };
+ Vector3f[] points = new Vector3f[]{
+ new Vector3f(ray.direction).multLocal(distances[0]).addLocal(ray.origin),
+ new Vector3f(ray.direction).multLocal(distances[1]).addLocal(ray.origin)
+ };
CollisionResult result = new CollisionResult(points[0], distances[0]);
results.addCollision(result);
@@ -733,8 +750,8 @@ public class BoundingBox extends BoundingVolume {
results.addCollision(result);
return 2;
}
-
- Vector3f point = new Vector3f(ray.direction).multLocal(t[0]).addLocal(ray.origin);
+
+ Vector3f point = new Vector3f(ray.direction).multLocal(t[0]).addLocal(ray.origin);
CollisionResult result = new CollisionResult(point, t[0]);
results.addCollision(result);
return 1;
@@ -742,20 +759,20 @@ public class BoundingBox extends BoundingVolume {
return 0;
}
- public int collideWith(Collidable other, CollisionResults results){
- if (other instanceof Ray){
+ public int collideWith(Collidable other, CollisionResults results) {
+ if (other instanceof Ray) {
Ray ray = (Ray) other;
return collideWithRay(ray, results);
- }else if (other instanceof Triangle){
+ } else if (other instanceof Triangle) {
Triangle t = (Triangle) other;
- if (intersects(t.get1(), t.get2(), t.get3())){
+ if (intersects(t.get1(), t.get2(), t.get3())) {
CollisionResult r = new CollisionResult();
results.addCollision(r);
return 1;
}
return 0;
- }else{
- throw new UnsupportedCollisionException("With: "+other.getClass().getSimpleName());
+ } else {
+ throw new UnsupportedCollisionException("With: " + other.getClass().getSimpleName());
}
}
@@ -768,8 +785,8 @@ public class BoundingBox extends BoundingVolume {
* @return True if the bounding box intersects the triangle, false
* otherwise.
*/
- public boolean intersects(Vector3f v1, Vector3f v2, Vector3f v3){
- return Intersection.intersect(this, v1, v2, v3);
+ public boolean intersects(Vector3f v1, Vector3f v2, Vector3f v3) {
+ return Intersection.intersect(this, v1, v2, v3);
}
@Override
@@ -844,16 +861,20 @@ public class BoundingBox extends BoundingVolume {
// plane. Otherwise 'false' is returned in which case the line segment
// is entirely clipped.
if (denom > 0.0f) {
- if (numer > denom * t[1])
+ if (numer > denom * t[1]) {
return false;
- if (numer > denom * t[0])
+ }
+ if (numer > denom * t[0]) {
t[0] = numer / denom;
+ }
return true;
} else if (denom < 0.0f) {
- if (numer > denom * t[0])
+ if (numer > denom * t[0]) {
return false;
- if (numer > denom * t[1])
+ }
+ if (numer > denom * t[1]) {
t[1] = numer / denom;
+ }
return true;
} else {
return numer <= 0.0;
@@ -875,40 +896,43 @@ public class BoundingBox extends BoundingVolume {
return store;
}
- public float getXExtent(){
+ public float getXExtent() {
return xExtent;
}
- public float getYExtent(){
+ public float getYExtent() {
return yExtent;
}
- public float getZExtent(){
+ public float getZExtent() {
return zExtent;
}
public void setXExtent(float xExtent) {
- if (xExtent < 0)
+ if (xExtent < 0) {
throw new IllegalArgumentException();
+ }
this.xExtent = xExtent;
}
public void setYExtent(float yExtent) {
- if (yExtent < 0)
+ if (yExtent < 0) {
throw new IllegalArgumentException();
+ }
this.yExtent = yExtent;
}
public void setZExtent(float zExtent) {
- if (zExtent < 0)
+ if (zExtent < 0) {
throw new IllegalArgumentException();
+ }
this.zExtent = zExtent;
}
-
- public Vector3f getMin(Vector3f store){
+
+ public Vector3f getMin(Vector3f store) {
if (store == null) {
store = new Vector3f();
}
@@ -916,7 +940,7 @@ public class BoundingBox extends BoundingVolume {
return store;
}
- public Vector3f getMax(Vector3f store){
+ public Vector3f getMax(Vector3f store) {
if (store == null) {
store = new Vector3f();
}
@@ -924,13 +948,13 @@ public class BoundingBox extends BoundingVolume {
return store;
}
- public void setMinMax(Vector3f min, Vector3f max){
+ public void setMinMax(Vector3f min, Vector3f max) {
this.center.set(max).addLocal(min).multLocal(0.5f);
xExtent = FastMath.abs(max.x - center.x);
yExtent = FastMath.abs(max.y - center.y);
zExtent = FastMath.abs(max.z - center.z);
}
-
+
@Override
public void write(JmeExporter e) throws IOException {
super.write(e);
@@ -948,10 +972,9 @@ public class BoundingBox extends BoundingVolume {
yExtent = capsule.readFloat("yExtent", 0);
zExtent = capsule.readFloat("zExtent", 0);
}
-
+
@Override
public float getVolume() {
- return (8*xExtent*yExtent*zExtent);
+ return (8 * xExtent * yExtent * zExtent);
}
}
-
diff --git a/engine/src/core/com/jme3/bounding/BoundingSphere.java b/engine/src/core/com/jme3/bounding/BoundingSphere.java
index 6725a4483..68e9a6b39 100644
--- a/engine/src/core/com/jme3/bounding/BoundingSphere.java
+++ b/engine/src/core/com/jme3/bounding/BoundingSphere.java
@@ -29,7 +29,6 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
package com.jme3.bounding;
import com.jme3.collision.Collidable;
@@ -67,11 +66,9 @@ import com.jme3.util.TempVars;
*/
public class BoundingSphere extends BoundingVolume {
- private static final Logger logger =
+ private static final Logger logger =
Logger.getLogger(BoundingSphere.class.getName());
-
float radius;
-
private static final float RADIUS_EPSILON = 1f + 0.00001f;
/**
@@ -95,7 +92,7 @@ public class BoundingSphere extends BoundingVolume {
}
public Type getType() {
- return Type.Sphere;
+ return Type.Sphere;
}
/**
@@ -146,9 +143,9 @@ public class BoundingSphere extends BoundingVolume {
int count = 0;
for (int i = start; i < end; i++) {
- vertList[count++] = tris[i].get(0);
- vertList[count++] = tris[i].get(1);
- vertList[count++] = tris[i].get(2);
+ vertList[count++] = tris[i].get(0);
+ vertList[count++] = tris[i].get(1);
+ vertList[count++] = tris[i].get(2);
}
averagePoints(vertList);
}
@@ -190,8 +187,9 @@ public class BoundingSphere extends BoundingVolume {
* The points to calculate the minimum bounds from.
*/
public void calcWelzl(FloatBuffer points) {
- if (center == null)
+ if (center == null) {
center = new Vector3f();
+ }
FloatBuffer buf = BufferUtils.createFloatBuffer(points.limit());
points.rewind();
buf.put(points);
@@ -216,43 +214,43 @@ public class BoundingSphere extends BoundingVolume {
*/
private void recurseMini(FloatBuffer points, int p, int b, int ap) {
TempVars vars = TempVars.get();
- assert vars.lock();
+
Vector3f tempA = vars.vect1;
Vector3f tempB = vars.vect2;
Vector3f tempC = vars.vect3;
Vector3f tempD = vars.vect4;
switch (b) {
- case 0:
- this.radius = 0;
- this.center.set(0, 0, 0);
- break;
- case 1:
- this.radius = 1f - RADIUS_EPSILON;
- BufferUtils.populateFromBuffer(center, points, ap-1);
- break;
- case 2:
- BufferUtils.populateFromBuffer(tempA, points, ap-1);
- BufferUtils.populateFromBuffer(tempB, points, ap-2);
- setSphere(tempA, tempB);
- break;
- case 3:
- BufferUtils.populateFromBuffer(tempA, points, ap-1);
- BufferUtils.populateFromBuffer(tempB, points, ap-2);
- BufferUtils.populateFromBuffer(tempC, points, ap-3);
- setSphere(tempA, tempB, tempC);
- break;
- case 4:
- BufferUtils.populateFromBuffer(tempA, points, ap-1);
- BufferUtils.populateFromBuffer(tempB, points, ap-2);
- BufferUtils.populateFromBuffer(tempC, points, ap-3);
- BufferUtils.populateFromBuffer(tempD, points, ap-4);
- setSphere(tempA, tempB, tempC, tempD);
- assert vars.unlock();
- return;
+ case 0:
+ this.radius = 0;
+ this.center.set(0, 0, 0);
+ break;
+ case 1:
+ this.radius = 1f - RADIUS_EPSILON;
+ BufferUtils.populateFromBuffer(center, points, ap - 1);
+ break;
+ case 2:
+ BufferUtils.populateFromBuffer(tempA, points, ap - 1);
+ BufferUtils.populateFromBuffer(tempB, points, ap - 2);
+ setSphere(tempA, tempB);
+ break;
+ case 3:
+ BufferUtils.populateFromBuffer(tempA, points, ap - 1);
+ BufferUtils.populateFromBuffer(tempB, points, ap - 2);
+ BufferUtils.populateFromBuffer(tempC, points, ap - 3);
+ setSphere(tempA, tempB, tempC);
+ break;
+ case 4:
+ BufferUtils.populateFromBuffer(tempA, points, ap - 1);
+ BufferUtils.populateFromBuffer(tempB, points, ap - 2);
+ BufferUtils.populateFromBuffer(tempC, points, ap - 3);
+ BufferUtils.populateFromBuffer(tempD, points, ap - 4);
+ setSphere(tempA, tempB, tempC, tempD);
+ vars.release();
+ return;
}
for (int i = 0; i < p; i++) {
- BufferUtils.populateFromBuffer(tempA, points, i+ap);
+ BufferUtils.populateFromBuffer(tempA, points, i + ap);
if (tempA.distanceSquared(center) - (radius * radius) > RADIUS_EPSILON - 1f) {
for (int j = i; j > 0; j--) {
BufferUtils.populateFromBuffer(tempB, points, j + ap);
@@ -260,12 +258,12 @@ public class BoundingSphere extends BoundingVolume {
BufferUtils.setInBuffer(tempC, points, j + ap);
BufferUtils.setInBuffer(tempB, points, j - 1 + ap);
}
- assert vars.unlock();
+ vars.release();
recurseMini(points, i, b + 1, ap + 1);
- assert vars.lock();
+
}
}
- assert vars.unlock();
+ vars.release();
}
/**
@@ -327,9 +325,7 @@ public class BoundingSphere extends BoundingVolume {
radius = 0;
} else {
- Vector3f o = acrossB.cross(a).multLocal(b.lengthSquared())
- .addLocal(b.cross(acrossB).multLocal(a.lengthSquared()))
- .divideLocal(Denominator);
+ Vector3f o = acrossB.cross(a).multLocal(b.lengthSquared()).addLocal(b.cross(acrossB).multLocal(a.lengthSquared())).divideLocal(Denominator);
radius = o.length() * RADIUS_EPSILON;
O.add(o, center);
}
@@ -366,7 +362,7 @@ public class BoundingSphere extends BoundingVolume {
for (int i = 1; i < points.length; i++) {
center.addLocal(points[i]);
}
-
+
float quantity = 1.0f / points.length;
center.multLocal(quantity);
@@ -418,7 +414,7 @@ public class BoundingSphere extends BoundingVolume {
}
trans.mult(center, sphere.center);
- Vector3f axes = new Vector3f(1,1,1);
+ Vector3f axes = new Vector3f(1, 1, 1);
trans.mult(axes, axes);
float ax = getMaxAxis(axes);
sphere.radius = FastMath.abs(ax * radius) + RADIUS_EPSILON - 1f;
@@ -429,16 +425,18 @@ public class BoundingSphere extends BoundingVolume {
float x = FastMath.abs(scale.x);
float y = FastMath.abs(scale.y);
float z = FastMath.abs(scale.z);
-
+
if (x >= y) {
- if (x >= z)
+ if (x >= z) {
return x;
+ }
return z;
}
-
- if (y >= z)
+
+ if (y >= z) {
return y;
-
+ }
+
return z;
}
@@ -475,24 +473,24 @@ public class BoundingSphere extends BoundingVolume {
return this;
}
- switch(volume.getType()) {
+ switch (volume.getType()) {
- case Sphere: {
- BoundingSphere sphere = (BoundingSphere) volume;
- float temp_radius = sphere.getRadius();
- Vector3f temp_center = sphere.center;
- BoundingSphere rVal = new BoundingSphere();
- return merge(temp_radius, temp_center, rVal);
- }
+ case Sphere: {
+ BoundingSphere sphere = (BoundingSphere) volume;
+ float temp_radius = sphere.getRadius();
+ Vector3f temp_center = sphere.center;
+ BoundingSphere rVal = new BoundingSphere();
+ return merge(temp_radius, temp_center, rVal);
+ }
- case AABB: {
- BoundingBox box = (BoundingBox) volume;
- Vector3f radVect = new Vector3f(box.xExtent, box.yExtent,
- box.zExtent);
- Vector3f temp_center = box.center;
- BoundingSphere rVal = new BoundingSphere();
- return merge(radVect.length(), temp_center, rVal);
- }
+ case AABB: {
+ BoundingBox box = (BoundingBox) volume;
+ Vector3f radVect = new Vector3f(box.xExtent, box.yExtent,
+ box.zExtent);
+ Vector3f temp_center = box.center;
+ BoundingSphere rVal = new BoundingSphere();
+ return merge(radVect.length(), temp_center, rVal);
+ }
// case OBB: {
// OrientedBoundingBox box = (OrientedBoundingBox) volume;
@@ -500,8 +498,8 @@ public class BoundingSphere extends BoundingVolume {
// return rVal.mergeOBB(box);
// }
- default:
- return null;
+ default:
+ return null;
}
}
@@ -522,30 +520,30 @@ public class BoundingSphere extends BoundingVolume {
switch (volume.getType()) {
- case Sphere: {
- BoundingSphere sphere = (BoundingSphere) volume;
- float temp_radius = sphere.getRadius();
- Vector3f temp_center = sphere.center;
- return merge(temp_radius, temp_center, this);
- }
+ case Sphere: {
+ BoundingSphere sphere = (BoundingSphere) volume;
+ float temp_radius = sphere.getRadius();
+ Vector3f temp_center = sphere.center;
+ return merge(temp_radius, temp_center, this);
+ }
- case AABB: {
- BoundingBox box = (BoundingBox) volume;
- assert TempVars.get().lock();
- Vector3f radVect = TempVars.get().vect1;
- radVect.set(box.xExtent, box.yExtent, box.zExtent);
- Vector3f temp_center = box.center;
- float len = radVect.length();
- assert TempVars.get().unlock();
- return merge(len, temp_center, this);
- }
+ case AABB: {
+ BoundingBox box = (BoundingBox) volume;
+ TempVars vars = TempVars.get();
+ Vector3f radVect = vars.vect1;
+ radVect.set(box.xExtent, box.yExtent, box.zExtent);
+ Vector3f temp_center = box.center;
+ float len = radVect.length();
+ vars.release();
+ return merge(len, temp_center, this);
+ }
// case OBB: {
// return mergeOBB((OrientedBoundingBox) volume);
// }
- default:
- return null;
+ default:
+ return null;
}
}
@@ -585,11 +583,10 @@ public class BoundingSphere extends BoundingVolume {
//
// return this;
// }
-
private BoundingVolume merge(float temp_radius, Vector3f temp_center,
BoundingSphere rVal) {
TempVars vars = TempVars.get();
- assert vars.lock();
+
Vector3f diff = temp_center.subtract(center, vars.vect1);
float lengthSquared = diff.lengthSquared();
float radiusDiff = temp_radius - radius;
@@ -598,25 +595,25 @@ public class BoundingSphere extends BoundingVolume {
if (fRDiffSqr >= lengthSquared) {
if (radiusDiff <= 0.0f) {
- assert vars.unlock();
+ vars.release();
return this;
- }
-
+ }
+
Vector3f rCenter = rVal.center;
- if ( rCenter == null ) {
- rVal.setCenter( rCenter = new Vector3f() );
+ if (rCenter == null) {
+ rVal.setCenter(rCenter = new Vector3f());
}
rCenter.set(temp_center);
rVal.setRadius(temp_radius);
- assert vars.unlock();
+ vars.release();
return rVal;
}
float length = (float) Math.sqrt(lengthSquared);
Vector3f rCenter = rVal.center;
- if ( rCenter == null ) {
- rVal.setCenter( rCenter = new Vector3f() );
+ if (rCenter == null) {
+ rVal.setCenter(rCenter = new Vector3f());
}
if (length > RADIUS_EPSILON) {
float coeff = (length + radiusDiff) / (2.0f * length);
@@ -626,7 +623,7 @@ public class BoundingSphere extends BoundingVolume {
}
rVal.setRadius(0.5f * (length + radius + temp_radius));
- assert vars.unlock();
+ vars.release();
return rVal;
}
@@ -649,10 +646,10 @@ public class BoundingSphere extends BoundingVolume {
rVal.radius = radius;
rVal.checkPlane = checkPlane;
return rVal;
- }
-
+ }
+
return new BoundingSphere(radius,
- (center != null ? (Vector3f) center.clone() : null));
+ (center != null ? (Vector3f) center.clone() : null));
}
/**
@@ -685,11 +682,11 @@ public class BoundingSphere extends BoundingVolume {
assert Vector3f.isValidVector(center) && Vector3f.isValidVector(bs.center);
TempVars vars = TempVars.get();
- assert vars.lock();
+
Vector3f diff = center.subtract(bs.center, vars.vect1);
float rsum = getRadius() + bs.getRadius();
boolean eq = (diff.dot(diff) <= rsum * rsum);
- assert vars.unlock();
+ vars.release();
return eq;
}
@@ -704,10 +701,11 @@ public class BoundingSphere extends BoundingVolume {
if (FastMath.abs(bb.center.x - center.x) < getRadius()
+ bb.xExtent
&& FastMath.abs(bb.center.y - center.y) < getRadius()
- + bb.yExtent
+ + bb.yExtent
&& FastMath.abs(bb.center.z - center.z) < getRadius()
- + bb.zExtent)
+ + bb.zExtent) {
return true;
+ }
return false;
}
@@ -730,9 +728,8 @@ public class BoundingSphere extends BoundingVolume {
assert Vector3f.isValidVector(center);
TempVars vars = TempVars.get();
- assert vars.lock();
- Vector3f diff = vars.vect1.set(ray.getOrigin())
- .subtractLocal(center);
+
+ Vector3f diff = vars.vect1.set(ray.getOrigin()).subtractLocal(center);
float radiusSquared = getRadius() * getRadius();
float a = diff.dot(diff) - radiusSquared;
if (a <= 0.0) {
@@ -742,11 +739,11 @@ public class BoundingSphere extends BoundingVolume {
// outside sphere
float b = ray.getDirection().dot(diff);
- assert vars.unlock();
+ vars.release();
if (b >= 0.0) {
return false;
}
- return b*b >= a;
+ return b * b >= a;
}
/*
@@ -756,10 +753,10 @@ public class BoundingSphere extends BoundingVolume {
*/
public int collideWithRay(Ray ray, CollisionResults results) {
TempVars vars = TempVars.get();
- assert vars.lock();
+
Vector3f diff = vars.vect1.set(ray.getOrigin()).subtractLocal(
center);
- float a = diff.dot(diff) - (getRadius()*getRadius());
+ float a = diff.dot(diff) - (getRadius() * getRadius());
float a1, discr, root;
if (a <= 0.0) {
// inside sphere
@@ -774,18 +771,17 @@ public class BoundingSphere extends BoundingVolume {
results.addCollision(result);
return 1;
}
-
+
a1 = ray.direction.dot(diff);
- assert vars.unlock();
+ vars.release();
if (a1 >= 0.0) {
return 0;
}
-
- discr = a1*a1 - a;
- if (discr < 0.0)
- return 0;
- else if (discr >= FastMath.ZERO_TOLERANCE) {
+ discr = a1 * a1 - a;
+ if (discr < 0.0) {
+ return 0;
+ } else if (discr >= FastMath.ZERO_TOLERANCE) {
root = FastMath.sqrt(discr);
float dist = -a1 - root;
Vector3f point = new Vector3f(ray.direction).multLocal(dist).addLocal(ray.origin);
@@ -803,11 +799,11 @@ public class BoundingSphere extends BoundingVolume {
}
}
- public int collideWith(Collidable other, CollisionResults results){
- if (other instanceof Ray){
+ public int collideWith(Collidable other, CollisionResults results) {
+ if (other instanceof Ray) {
Ray ray = (Ray) other;
return collideWithRay(ray, results);
- }else{
+ } else {
throw new UnsupportedCollisionException();
}
}
@@ -825,7 +821,7 @@ public class BoundingSphere extends BoundingVolume {
public float distanceToEdge(Vector3f point) {
return center.distance(point) - radius;
}
-
+
@Override
public void write(JmeExporter e) throws IOException {
super.write(e);
diff --git a/engine/src/core/com/jme3/bounding/Intersection.java b/engine/src/core/com/jme3/bounding/Intersection.java
index 6048fc0e6..c4e641ddc 100644
--- a/engine/src/core/com/jme3/bounding/Intersection.java
+++ b/engine/src/core/com/jme3/bounding/Intersection.java
@@ -29,7 +29,6 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
package com.jme3.bounding;
import com.jme3.util.TempVars;
@@ -47,16 +46,23 @@ import static java.lang.Math.max;
*/
public class Intersection {
- private static final void findMinMax(float x0, float x1, float x2, Vector3f minMax){
+ private static final void findMinMax(float x0, float x1, float x2, Vector3f minMax) {
minMax.set(x0, x0, 0);
- if (x1 < minMax.x) minMax.setX(x1);
- if (x1 > minMax.y) minMax.setY(x1);
- if (x2 < minMax.x) minMax.setX(x2);
- if (x2 > minMax.y) minMax.setY(x2);
+ if (x1 < minMax.x) {
+ minMax.setX(x1);
+ }
+ if (x1 > minMax.y) {
+ minMax.setY(x1);
+ }
+ if (x2 < minMax.x) {
+ minMax.setX(x2);
+ }
+ if (x2 > minMax.y) {
+ minMax.setY(x2);
+ }
}
// private boolean axisTest(float a, float b, float fa, float fb, Vector3f v0, Vector3f v1, )
-
// private boolean axisTestX01(float a, float b, float fa, float fb,
// Vector3f center, Vector3f ext,
// Vector3f v1, Vector3f v2, Vector3f v3){
@@ -73,188 +79,187 @@ public class Intersection {
// if(min > rad || max < -rad)
// return false;
// }
-
- public static boolean intersect(BoundingBox bbox, Vector3f v1, Vector3f v2, Vector3f v3){
+ public static boolean intersect(BoundingBox bbox, Vector3f v1, Vector3f v2, Vector3f v3) {
// use separating axis theorem to test overlap between triangle and box
- // need to test for overlap in these directions:
- // 1) the {x,y,z}-directions (actually, since we use the AABB of the triangle
- // we do not even need to test these)
- // 2) normal of the triangle
- // 3) crossproduct(edge from tri, {x,y,z}-directin)
- // this gives 3x3=9 more tests
+ // need to test for overlap in these directions:
+ // 1) the {x,y,z}-directions (actually, since we use the AABB of the triangle
+ // we do not even need to test these)
+ // 2) normal of the triangle
+ // 3) crossproduct(edge from tri, {x,y,z}-directin)
+ // this gives 3x3=9 more tests
+
+ TempVars vars = TempVars.get();
- TempVars vars = TempVars.get();
- assert vars.lock();
- Vector3f tmp0 = vars.vect1,
+ Vector3f tmp0 = vars.vect1,
tmp1 = vars.vect2,
tmp2 = vars.vect3;
- Vector3f e0 = vars.vect4,
+ Vector3f e0 = vars.vect4,
e1 = vars.vect5,
e2 = vars.vect6;
- Vector3f center = bbox.getCenter();
- Vector3f extent = bbox.getExtent(null);
+ Vector3f center = bbox.getCenter();
+ Vector3f extent = bbox.getExtent(null);
// float min,max,p0,p1,p2,rad,fex,fey,fez;
// float normal[3]
- // This is the fastest branch on Sun
- // move everything so that the boxcenter is in (0,0,0)
- v1.subtract(center, tmp0);
- v2.subtract(center, tmp1);
- v3.subtract(center, tmp2);
+ // This is the fastest branch on Sun
+ // move everything so that the boxcenter is in (0,0,0)
+ v1.subtract(center, tmp0);
+ v2.subtract(center, tmp1);
+ v3.subtract(center, tmp2);
- // compute triangle edges
- tmp1.subtract(tmp0, e0); // tri edge 0
- tmp2.subtract(tmp1, e1); // tri edge 1
- tmp0.subtract(tmp2, e2); // tri edge 2
+ // compute triangle edges
+ tmp1.subtract(tmp0, e0); // tri edge 0
+ tmp2.subtract(tmp1, e1); // tri edge 1
+ tmp0.subtract(tmp2, e2); // tri edge 2
- // Bullet 3:
- // test the 9 tests first (this was faster)
- float min, max;
- float p0, p1, p2, rad;
- float fex = FastMath.abs(e0.x);
- float fey = FastMath.abs(e0.y);
- float fez = FastMath.abs(e0.z);
+ // Bullet 3:
+ // test the 9 tests first (this was faster)
+ float min, max;
+ float p0, p1, p2, rad;
+ float fex = FastMath.abs(e0.x);
+ float fey = FastMath.abs(e0.y);
+ float fez = FastMath.abs(e0.z);
- //AXISTEST_X01(e0[Z], e0[Y], fez, fey);
+ //AXISTEST_X01(e0[Z], e0[Y], fez, fey);
p0 = e0.z * tmp0.y - e0.y * tmp0.z;
p2 = e0.z * tmp2.y - e0.y * tmp2.z;
- min = min(p0,p2);
- max = max(p0,p2);
+ min = min(p0, p2);
+ max = max(p0, p2);
rad = fez * extent.y + fey * extent.z;
- if (min > rad || max < -rad){
- assert vars.unlock();
+ if (min > rad || max < -rad) {
+ vars.release();
return false;
}
// AXISTEST_Y02(e0[Z], e0[X], fez, fex);
p0 = -e0.z * tmp0.x + e0.x * tmp0.z;
p2 = -e0.z * tmp2.x + e0.x * tmp2.z;
- min = min(p0,p2);
- max = max(p0,p2);
+ min = min(p0, p2);
+ max = max(p0, p2);
rad = fez * extent.x + fex * extent.z;
- if (min > rad || max < -rad){
- assert vars.unlock();
+ if (min > rad || max < -rad) {
+ vars.release();
return false;
}
// AXISTEST_Z12(e0[Y], e0[X], fey, fex);
p1 = e0.y * tmp1.x - e0.x * tmp1.y;
p2 = e0.y * tmp2.x - e0.x * tmp2.y;
- min = min(p1,p2);
- max = max(p1,p2);
+ min = min(p1, p2);
+ max = max(p1, p2);
rad = fey * extent.x + fex * extent.y;
- if (min > rad || max < -rad){
- assert vars.unlock();
+ if (min > rad || max < -rad) {
+ vars.release();
return false;
}
- fex = FastMath.abs(e1.x);
- fey = FastMath.abs(e1.y);
- fez = FastMath.abs(e1.z);
+ fex = FastMath.abs(e1.x);
+ fey = FastMath.abs(e1.y);
+ fez = FastMath.abs(e1.z);
// AXISTEST_X01(e1[Z], e1[Y], fez, fey);
p0 = e1.z * tmp0.y - e1.y * tmp0.z;
p2 = e1.z * tmp2.y - e1.y * tmp2.z;
- min = min(p0,p2);
- max = max(p0,p2);
+ min = min(p0, p2);
+ max = max(p0, p2);
rad = fez * extent.y + fey * extent.z;
- if (min > rad || max < -rad){
- assert vars.unlock();
+ if (min > rad || max < -rad) {
+ vars.release();
return false;
}
// AXISTEST_Y02(e1[Z], e1[X], fez, fex);
p0 = -e1.z * tmp0.x + e1.x * tmp0.z;
p2 = -e1.z * tmp2.x + e1.x * tmp2.z;
- min = min(p0,p2);
- max = max(p0,p2);
+ min = min(p0, p2);
+ max = max(p0, p2);
rad = fez * extent.x + fex * extent.z;
- if (min > rad || max < -rad){
- assert vars.unlock();
+ if (min > rad || max < -rad) {
+ vars.release();
return false;
}
// AXISTEST_Z0(e1[Y], e1[X], fey, fex);
p0 = e1.y * tmp0.x - e1.x * tmp0.y;
p1 = e1.y * tmp1.x - e1.x * tmp1.y;
- min = min(p0,p1);
- max = max(p0,p1);
+ min = min(p0, p1);
+ max = max(p0, p1);
rad = fey * extent.x + fex * extent.y;
- if (min > rad || max < -rad){
- assert vars.unlock();
+ if (min > rad || max < -rad) {
+ vars.release();
return false;
}
//
- fex = FastMath.abs(e2.x);
- fey = FastMath.abs(e2.y);
- fez = FastMath.abs(e2.z);
+ fex = FastMath.abs(e2.x);
+ fey = FastMath.abs(e2.y);
+ fez = FastMath.abs(e2.z);
// AXISTEST_X2(e2[Z], e2[Y], fez, fey);
p0 = e2.z * tmp0.y - e2.y * tmp0.z;
p1 = e2.z * tmp1.y - e2.y * tmp1.z;
- min = min(p0,p1);
- max = max(p0,p1);
+ min = min(p0, p1);
+ max = max(p0, p1);
rad = fez * extent.y + fey * extent.z;
- if (min > rad || max < -rad){
- assert vars.unlock();
+ if (min > rad || max < -rad) {
+ vars.release();
return false;
}
// AXISTEST_Y1(e2[Z], e2[X], fez, fex);
p0 = -e2.z * tmp0.x + e2.x * tmp0.z;
p1 = -e2.z * tmp1.x + e2.x * tmp1.z;
- min = min(p0,p1);
- max = max(p0,p1);
+ min = min(p0, p1);
+ max = max(p0, p1);
rad = fez * extent.x + fex * extent.y;
- if (min > rad || max < -rad){
- assert vars.unlock();
+ if (min > rad || max < -rad) {
+ vars.release();
return false;
}
// AXISTEST_Z12(e2[Y], e2[X], fey, fex);
p1 = e2.y * tmp1.x - e2.x * tmp1.y;
p2 = e2.y * tmp2.x - e2.x * tmp2.y;
- min = min(p1,p2);
- max = max(p1,p2);
+ min = min(p1, p2);
+ max = max(p1, p2);
rad = fey * extent.x + fex * extent.y;
- if (min > rad || max < -rad){
- assert vars.unlock();
+ if (min > rad || max < -rad) {
+ vars.release();
return false;
}
- // Bullet 1:
- // first test overlap in the {x,y,z}-directions
- // find min, max of the triangle each direction, and test for overlap in
- // that direction -- this is equivalent to testing a minimal AABB around
- // the triangle against the AABB
+ // Bullet 1:
+ // first test overlap in the {x,y,z}-directions
+ // find min, max of the triangle each direction, and test for overlap in
+ // that direction -- this is equivalent to testing a minimal AABB around
+ // the triangle against the AABB
+
-
- Vector3f minMax = vars.vect7;
+ Vector3f minMax = vars.vect7;
- // test in X-direction
- findMinMax(tmp0.x, tmp1.x, tmp2.x, minMax);
- if(minMax.x > extent.x || minMax.y < -extent.x){
- assert vars.unlock();
+ // test in X-direction
+ findMinMax(tmp0.x, tmp1.x, tmp2.x, minMax);
+ if (minMax.x > extent.x || minMax.y < -extent.x) {
+ vars.release();
return false;
}
- // test in Y-direction
- findMinMax(tmp0.y, tmp1.y, tmp2.y, minMax);
- if(minMax.x > extent.y || minMax.y < -extent.y){
- assert vars.unlock();
+ // test in Y-direction
+ findMinMax(tmp0.y, tmp1.y, tmp2.y, minMax);
+ if (minMax.x > extent.y || minMax.y < -extent.y) {
+ vars.release();
return false;
}
- // test in Z-direction
- findMinMax(tmp0.z, tmp1.z, tmp2.z, minMax);
- if(minMax.x > extent.z || minMax.y < -extent.z){
- assert vars.unlock();
+ // test in Z-direction
+ findMinMax(tmp0.z, tmp1.z, tmp2.z, minMax);
+ if (minMax.x > extent.z || minMax.y < -extent.z) {
+ vars.release();
return false;
}
@@ -263,19 +268,18 @@ public class Intersection {
// // compute plane equation of triangle: normal * x + d = 0
// Vector3f normal = new Vector3f();
// e0.cross(e1, normal);
- Plane p = vars.plane;
+ Plane p = vars.plane;
- p.setPlanePoints(v1,v2,v3);
- if (bbox.whichSide(p) == Plane.Side.Negative){
- assert vars.unlock();
+ p.setPlanePoints(v1, v2, v3);
+ if (bbox.whichSide(p) == Plane.Side.Negative) {
+ vars.release();
return false;
}
//
// if(!planeBoxOverlap(normal,v0,boxhalfsize)) return false;
- assert vars.unlock();
-
+ vars.release();
+
return true; /* box and triangle overlaps */
}
-
}
diff --git a/engine/src/core/com/jme3/collision/bih/BIHNode.java b/engine/src/core/com/jme3/collision/bih/BIHNode.java
index d425a7b35..0f9cd814a 100644
--- a/engine/src/core/com/jme3/collision/bih/BIHNode.java
+++ b/engine/src/core/com/jme3/collision/bih/BIHNode.java
@@ -29,7 +29,6 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
package com.jme3.collision.bih;
import com.jme3.bounding.BoundingBox;
@@ -62,24 +61,23 @@ import static java.lang.Math.max;
public final class BIHNode implements Savable {
private int leftIndex, rightIndex;
-
private BIHNode left;
private BIHNode right;
private float leftPlane;
private float rightPlane;
private int axis;
- public BIHNode(int l, int r){
+ public BIHNode(int l, int r) {
leftIndex = l;
rightIndex = r;
axis = 3; // indicates leaf
}
- public BIHNode(int axis){
+ public BIHNode(int axis) {
this.axis = axis;
}
- public BIHNode(){
+ public BIHNode() {
}
public BIHNode getLeftChild() {
@@ -116,7 +114,7 @@ public final class BIHNode implements Savable {
public void write(JmeExporter ex) throws IOException {
OutputCapsule oc = ex.getCapsule(this);
- oc.write(leftIndex, "left_index", 0);
+ oc.write(leftIndex, "left_index", 0);
oc.write(rightIndex, "right_index", 0);
oc.write(leftPlane, "left_plane", 0);
oc.write(rightPlane, "right_plane", 0);
@@ -146,53 +144,55 @@ public final class BIHNode implements Savable {
this.min = min;
this.max = max;
}
-
}
public final int intersectWhere(Collidable col,
- BoundingBox box,
- Matrix4f worldMatrix,
- BIHTree tree,
- CollisionResults results){
+ BoundingBox box,
+ Matrix4f worldMatrix,
+ BIHTree tree,
+ CollisionResults results) {
- ArrayList stack = TempVars.get().bihStack;
+ TempVars vars = TempVars.get();
+ ArrayList stack = vars.bihStack;
stack.clear();
- float[] minExts = { box.getCenter().x - box.getXExtent(),
- box.getCenter().y - box.getYExtent(),
- box.getCenter().z - box.getZExtent() };
+ float[] minExts = {box.getCenter().x - box.getXExtent(),
+ box.getCenter().y - box.getYExtent(),
+ box.getCenter().z - box.getZExtent()};
- float[] maxExts = { box.getCenter().x + box.getXExtent(),
- box.getCenter().y + box.getYExtent(),
- box.getCenter().z + box.getZExtent() };
+ float[] maxExts = {box.getCenter().x + box.getXExtent(),
+ box.getCenter().y + box.getYExtent(),
+ box.getCenter().z + box.getZExtent()};
- stack.add(new BIHStackData(this, 0,0));
+ stack.add(new BIHStackData(this, 0, 0));
Triangle t = new Triangle();
int cols = 0;
- stackloop: while (stack.size() > 0){
- BIHNode node = stack.remove(stack.size()-1).node;
+ stackloop:
+ while (stack.size() > 0) {
+ BIHNode node = stack.remove(stack.size() - 1).node;
- while (node.axis != 3){
+ while (node.axis != 3) {
int a = node.axis;
float maxExt = maxExts[a];
float minExt = minExts[a];
- if (node.leftPlane < node.rightPlane){
+ if (node.leftPlane < node.rightPlane) {
// means there's a gap in the middle
// if the box is in that gap, we stop there
if (minExt > node.leftPlane
- && maxExt < node.rightPlane)
+ && maxExt < node.rightPlane) {
continue stackloop;
+ }
}
- if (maxExt < node.rightPlane){
+ if (maxExt < node.rightPlane) {
node = node.left;
- }else if (minExt > node.leftPlane){
+ } else if (minExt > node.leftPlane) {
node = node.right;
- }else{
+ } else {
stack.add(new BIHStackData(node.right, 0, 0));
node = node.left;
}
@@ -203,13 +203,13 @@ public final class BIHNode implements Savable {
// && minExt > node.rightPlane){
// node = node.right;
// }else{
-
+
// }
}
- for (int i = node.leftIndex; i <= node.rightIndex; i++){
+ for (int i = node.leftIndex; i <= node.rightIndex; i++) {
tree.getTriangle(i, t.get1(), t.get2(), t.get3());
- if (worldMatrix != null){
+ if (worldMatrix != null) {
worldMatrix.mult(t.get1(), t.get1());
worldMatrix.mult(t.get2(), t.get2());
worldMatrix.mult(t.get3(), t.get3());
@@ -217,11 +217,11 @@ public final class BIHNode implements Savable {
int added = col.collideWith(t, results);
- if (added > 0){
+ if (added > 0) {
int index = tree.getTriangleIndex(i);
int start = results.size() - added;
- for (int j = start; j < results.size(); j++){
+ for (int j = start; j < results.size(); j++) {
CollisionResult cr = results.getCollisionDirect(j);
cr.setTriangleIndex(index);
}
@@ -230,76 +230,78 @@ public final class BIHNode implements Savable {
}
}
}
-
+ vars.release();
return cols;
}
public final int intersectBrute(Ray r,
- Matrix4f worldMatrix,
- BIHTree tree,
- float sceneMin,
- float sceneMax,
- CollisionResults results){
+ Matrix4f worldMatrix,
+ BIHTree tree,
+ float sceneMin,
+ float sceneMax,
+ CollisionResults results) {
float tHit = Float.POSITIVE_INFINITY;
Vector3f v1 = new Vector3f(),
- v2 = new Vector3f(),
- v3 = new Vector3f();
-
+ v2 = new Vector3f(),
+ v3 = new Vector3f();
+
int cols = 0;
- ArrayList stack = TempVars.get().bihStack;
+ TempVars vars = TempVars.get();
+ ArrayList stack = vars.bihStack;
stack.clear();
stack.add(new BIHStackData(this, 0, 0));
- stackloop: while (stack.size() > 0){
+ stackloop:
+ while (stack.size() > 0) {
- BIHStackData data = stack.remove(stack.size()-1);
+ BIHStackData data = stack.remove(stack.size() - 1);
BIHNode node = data.node;
- leafloop: while (node.axis != 3){ // while node is not a leaf
+ leafloop:
+ while (node.axis != 3) { // while node is not a leaf
BIHNode nearNode, farNode;
nearNode = node.left;
- farNode = node.right;
+ farNode = node.right;
- stack.add(new BIHStackData(farNode, 0, 0));
+ stack.add(new BIHStackData(farNode, 0, 0));
node = nearNode;
}
// a leaf
- for (int i = node.leftIndex; i <= node.rightIndex; i++){
- tree.getTriangle(i, v1,v2,v3);
+ for (int i = node.leftIndex; i <= node.rightIndex; i++) {
+ tree.getTriangle(i, v1, v2, v3);
- if (worldMatrix != null){
+ if (worldMatrix != null) {
worldMatrix.mult(v1, v1);
worldMatrix.mult(v2, v2);
worldMatrix.mult(v3, v3);
}
- float t = r.intersects(v1,v2,v3);
- if (t < tHit){
+ float t = r.intersects(v1, v2, v3);
+ if (t < tHit) {
tHit = t;
- Vector3f contactPoint = new Vector3f(r.direction)
- .multLocal(tHit)
- .addLocal(r.origin);
+ Vector3f contactPoint = new Vector3f(r.direction).multLocal(tHit).addLocal(r.origin);
CollisionResult cr = new CollisionResult(contactPoint, tHit);
cr.setTriangleIndex(tree.getTriangleIndex(i));
results.addCollision(cr);
- cols ++;
+ cols++;
}
}
}
-
+ vars.release();
return cols;
}
public final int intersectWhere(Ray r,
- Matrix4f worldMatrix,
- BIHTree tree,
- float sceneMin,
- float sceneMax,
- CollisionResults results){
-
- ArrayList stack = TempVars.get().bihStack;
+ Matrix4f worldMatrix,
+ BIHTree tree,
+ float sceneMin,
+ float sceneMax,
+ CollisionResults results) {
+
+ TempVars vars = TempVars.get();
+ ArrayList stack = vars.bihStack;
stack.clear();
// float tHit = Float.POSITIVE_INFINITY;
@@ -308,42 +310,45 @@ public final class BIHNode implements Savable {
Vector3f d = r.getDirection().clone();
Matrix4f inv = worldMatrix.invert();
-
+
inv.mult(r.getOrigin(), r.getOrigin());
// Fixes rotation collision bug
- inv.multNormal(r.getDirection(), r.getDirection());
+ inv.multNormal(r.getDirection(), r.getDirection());
// inv.multNormalAcross(r.getDirection(), r.getDirection());
- float[] origins = { r.getOrigin().x,
- r.getOrigin().y,
- r.getOrigin().z };
-
- float[] invDirections = { 1f / r.getDirection().x,
- 1f / r.getDirection().y,
- 1f / r.getDirection().z };
+ float[] origins = {r.getOrigin().x,
+ r.getOrigin().y,
+ r.getOrigin().z};
+
+ float[] invDirections = {1f / r.getDirection().x,
+ 1f / r.getDirection().y,
+ 1f / r.getDirection().z};
r.getDirection().normalizeLocal();
Vector3f v1 = new Vector3f(),
- v2 = new Vector3f(),
- v3 = new Vector3f();
+ v2 = new Vector3f(),
+ v3 = new Vector3f();
int cols = 0;
stack.add(new BIHStackData(this, sceneMin, sceneMax));
- stackloop: while (stack.size() > 0){
+ stackloop:
+ while (stack.size() > 0) {
- BIHStackData data = stack.remove(stack.size()-1);
+ BIHStackData data = stack.remove(stack.size() - 1);
BIHNode node = data.node;
- float tMin = data.min,
- tMax = data.max;
+ float tMin = data.min,
+ tMax = data.max;
- if (tMax < tMin)
+ if (tMax < tMin) {
continue;
-
- leafloop: while (node.axis != 3){ // while node is not a leaf
+ }
+
+ leafloop:
+ while (node.axis != 3) { // while node is not a leaf
int a = node.axis;
-
+
// find the origin and direction value for the given axis
float origin = origins[a];
float invDirection = invDirections[a];
@@ -351,12 +356,12 @@ public final class BIHNode implements Savable {
float tNearSplit, tFarSplit;
BIHNode nearNode, farNode;
- tNearSplit = (node.leftPlane - origin) * invDirection;
- tFarSplit = (node.rightPlane - origin) * invDirection;
+ tNearSplit = (node.leftPlane - origin) * invDirection;
+ tFarSplit = (node.rightPlane - origin) * invDirection;
nearNode = node.left;
- farNode = node.right;
+ farNode = node.right;
- if (invDirection < 0){
+ if (invDirection < 0) {
float tmpSplit = tNearSplit;
tNearSplit = tFarSplit;
tFarSplit = tmpSplit;
@@ -366,18 +371,18 @@ public final class BIHNode implements Savable {
farNode = tmpNode;
}
- if (tMin > tNearSplit && tMax < tFarSplit){
+ if (tMin > tNearSplit && tMax < tFarSplit) {
continue stackloop;
}
- if (tMin > tNearSplit){
+ if (tMin > tNearSplit) {
tMin = max(tMin, tFarSplit);
node = farNode;
- }else if (tMax < tFarSplit){
+ } else if (tMax < tFarSplit) {
tMax = min(tMax, tNearSplit);
node = nearNode;
- }else{
- stack.add(new BIHStackData(farNode, max(tMin, tFarSplit), tMax));
+ } else {
+ stack.add(new BIHStackData(farNode, max(tMin, tFarSplit), tMax));
tMax = min(tMax, tNearSplit);
node = nearNode;
}
@@ -391,38 +396,35 @@ public final class BIHNode implements Savable {
// }
// a leaf
- for (int i = node.leftIndex; i <= node.rightIndex; i++){
- tree.getTriangle(i, v1,v2,v3);
+ for (int i = node.leftIndex; i <= node.rightIndex; i++) {
+ tree.getTriangle(i, v1, v2, v3);
- float t = r.intersects(v1,v2,v3);
- if (!Float.isInfinite(t)){
+ float t = r.intersects(v1, v2, v3);
+ if (!Float.isInfinite(t)) {
if (worldMatrix != null) {
worldMatrix.mult(v1, v1);
worldMatrix.mult(v2, v2);
worldMatrix.mult(v3, v3);
- float t_world = new Ray(o,d).intersects(v1,v2,v3);
+ float t_world = new Ray(o, d).intersects(v1, v2, v3);
t = t_world;
}
Vector3f contactNormal = Triangle.computeTriangleNormal(v1, v2, v3, null);
- Vector3f contactPoint = new Vector3f(d)
- .multLocal(t)
- .addLocal(o);
- float worldSpaceDist = o.distance(contactPoint);
+ Vector3f contactPoint = new Vector3f(d).multLocal(t).addLocal(o);
+ float worldSpaceDist = o.distance(contactPoint);
CollisionResult cr = new CollisionResult(contactPoint, worldSpaceDist);
cr.setContactNormal(contactNormal);
cr.setTriangleIndex(tree.getTriangleIndex(i));
results.addCollision(cr);
- cols ++;
+ cols++;
}
}
}
-
+ vars.release();
r.setOrigin(o);
r.setDirection(d);
return cols;
}
-
}
diff --git a/engine/src/core/com/jme3/collision/bih/BIHTree.java b/engine/src/core/com/jme3/collision/bih/BIHTree.java
index e2ac1efe7..223bb5cbf 100644
--- a/engine/src/core/com/jme3/collision/bih/BIHTree.java
+++ b/engine/src/core/com/jme3/collision/bih/BIHTree.java
@@ -29,7 +29,6 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
package com.jme3.collision.bih;
import com.jme3.scene.mesh.VirtualIndexBuffer;
@@ -62,20 +61,16 @@ import static java.lang.Math.max;
public class BIHTree implements CollisionData {
- public static final int MAX_TREE_DEPTH = 100;
- public static final int MAX_TRIS_PER_NODE = 21;
-
+ public static final int MAX_TREE_DEPTH = 100;
+ public static final int MAX_TRIS_PER_NODE = 21;
private Mesh mesh;
-
private BIHNode root;
private int maxTrisPerNode;
private int numTris;
private float[] pointData;
private int[] triIndices;
-
private transient CollisionResults boundResults = new CollisionResults();
private transient float[] bihSwapTmp;
-
private static final TriangleAxisComparator[] comparators = new TriangleAxisComparator[3];
static {
@@ -84,45 +79,47 @@ public class BIHTree implements CollisionData {
comparators[2] = new TriangleAxisComparator(2);
}
- private void initTriList(FloatBuffer vb, IndexBuffer ib){
+ private void initTriList(FloatBuffer vb, IndexBuffer ib) {
pointData = new float[numTris * 3 * 3];
int p = 0;
- for (int i = 0; i < numTris*3; i+=3){
- int vert = ib.get(i)*3;
+ for (int i = 0; i < numTris * 3; i += 3) {
+ int vert = ib.get(i) * 3;
pointData[p++] = vb.get(vert++);
pointData[p++] = vb.get(vert++);
pointData[p++] = vb.get(vert);
- vert = ib.get(i+1)*3;
+ vert = ib.get(i + 1) * 3;
pointData[p++] = vb.get(vert++);
pointData[p++] = vb.get(vert++);
pointData[p++] = vb.get(vert);
- vert = ib.get(i+2)*3;
+ vert = ib.get(i + 2) * 3;
pointData[p++] = vb.get(vert++);
pointData[p++] = vb.get(vert++);
pointData[p++] = vb.get(vert);
}
triIndices = new int[numTris];
- for (int i = 0; i < numTris; i++)
+ for (int i = 0; i < numTris; i++) {
triIndices[i] = i;
+ }
}
- public BIHTree(Mesh mesh, int maxTrisPerNode){
+ public BIHTree(Mesh mesh, int maxTrisPerNode) {
this.mesh = mesh;
this.maxTrisPerNode = maxTrisPerNode;
- if (maxTrisPerNode < 1 || mesh == null)
+ if (maxTrisPerNode < 1 || mesh == null) {
throw new IllegalArgumentException();
+ }
bihSwapTmp = new float[9];
FloatBuffer vb = (FloatBuffer) mesh.getBuffer(Type.Position).getData();
IndexBuffer ib = mesh.getIndexBuffer();
- if (ib == null){
+ if (ib == null) {
ib = new VirtualIndexBuffer(mesh.getVertexCount(), mesh.getMode());
- }else if (mesh.getMode() != Mode.Triangles){
+ } else if (mesh.getMode() != Mode.Triangles) {
ib = new WrappedIndexBuffer(mesh);
}
@@ -130,87 +127,89 @@ public class BIHTree implements CollisionData {
initTriList(vb, ib);
}
- public BIHTree(Mesh mesh){
+ public BIHTree(Mesh mesh) {
this(mesh, MAX_TRIS_PER_NODE);
}
- public BIHTree(){
+ public BIHTree() {
}
- public void construct(){
- BoundingBox sceneBbox = createBox(0, numTris-1);
- root = createNode(0, numTris-1, sceneBbox, 0);
+ public void construct() {
+ BoundingBox sceneBbox = createBox(0, numTris - 1);
+ root = createNode(0, numTris - 1, sceneBbox, 0);
}
private BoundingBox createBox(int l, int r) {
TempVars vars = TempVars.get();
- assert vars.lock();
+
Vector3f min = vars.vect1.set(new Vector3f(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY));
Vector3f max = vars.vect2.set(new Vector3f(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY));
Vector3f v1 = vars.vect3,
- v2 = vars.vect4,
- v3 = vars.vect5;
+ v2 = vars.vect4,
+ v3 = vars.vect5;
for (int i = l; i <= r; i++) {
- getTriangle(i, v1,v2,v3);
+ getTriangle(i, v1, v2, v3);
BoundingBox.checkMinMax(min, max, v1);
BoundingBox.checkMinMax(min, max, v2);
BoundingBox.checkMinMax(min, max, v3);
}
- BoundingBox bbox = new BoundingBox(min,max);
- assert vars.unlock();
+ BoundingBox bbox = new BoundingBox(min, max);
+ vars.release();
return bbox;
}
- int getTriangleIndex(int triIndex){
+ int getTriangleIndex(int triIndex) {
return triIndices[triIndex];
}
- private int sortTriangles(int l, int r, float split, int axis){
+ private int sortTriangles(int l, int r, float split, int axis) {
int pivot = l;
int j = r;
TempVars vars = TempVars.get();
- assert vars.lock();
+
Vector3f v1 = vars.vect1,
- v2 = vars.vect2,
- v3 = vars.vect3;
+ v2 = vars.vect2,
+ v3 = vars.vect3;
- while (pivot <= j){
+ while (pivot <= j) {
getTriangle(pivot, v1, v2, v3);
v1.addLocal(v2).addLocal(v3).multLocal(FastMath.ONE_THIRD);
- if (v1.get(axis) > split){
+ if (v1.get(axis) > split) {
swapTriangles(pivot, j);
--j;
- }else{
+ } else {
++pivot;
}
}
- assert vars.unlock();
+ vars.release();
pivot = (pivot == l && j < pivot) ? j : pivot;
return pivot;
}
- private void setMinMax(BoundingBox bbox, boolean doMin, int axis, float value){
+ private void setMinMax(BoundingBox bbox, boolean doMin, int axis, float value) {
Vector3f min = bbox.getMin(null);
Vector3f max = bbox.getMax(null);
- if (doMin)
+ if (doMin) {
min.set(axis, value);
- else
+ } else {
max.set(axis, value);
+ }
bbox.setMinMax(min, max);
}
- private float getMinMax(BoundingBox bbox, boolean doMin, int axis){
- if (doMin)
+ private float getMinMax(BoundingBox bbox, boolean doMin, int axis) {
+ if (doMin) {
return bbox.getMin(null).get(axis);
- else
+ } else {
return bbox.getMax(null).get(axis);
+ }
}
// private BIHNode createNode2(int l, int r, BoundingBox nodeBbox, int depth){
@@ -290,12 +289,11 @@ public class BIHTree implements CollisionData {
//
// return node;
// }
-
private BIHNode createNode(int l, int r, BoundingBox nodeBbox, int depth) {
- if ((r - l) < maxTrisPerNode || depth > MAX_TREE_DEPTH){
+ if ((r - l) < maxTrisPerNode || depth > MAX_TREE_DEPTH) {
return new BIHNode(l, r);
}
-
+
BoundingBox currentBox = createBox(l, r);
Vector3f exteriorExt = nodeBbox.getExtent(null);
@@ -303,38 +301,42 @@ public class BIHTree implements CollisionData {
exteriorExt.subtractLocal(interiorExt);
int axis = 0;
- if (exteriorExt.x > exteriorExt.y){
- if (exteriorExt.x > exteriorExt.z)
+ if (exteriorExt.x > exteriorExt.y) {
+ if (exteriorExt.x > exteriorExt.z) {
axis = 0;
- else
+ } else {
axis = 2;
- }else{
- if (exteriorExt.y > exteriorExt.z)
+ }
+ } else {
+ if (exteriorExt.y > exteriorExt.z) {
axis = 1;
- else
+ } else {
axis = 2;
+ }
}
- if (exteriorExt.equals(Vector3f.ZERO))
+ if (exteriorExt.equals(Vector3f.ZERO)) {
axis = 0;
+ }
// Arrays.sort(tris, l, r, comparators[axis]);
float split = currentBox.getCenter().get(axis);
int pivot = sortTriangles(l, r, split, axis);
- if (pivot == l || pivot == r)
+ if (pivot == l || pivot == r) {
pivot = (r + l) / 2;
+ }
//If one of the partitions is empty, continue with recursion: same level but different bbox
- if (pivot < l){
+ if (pivot < l) {
//Only right
BoundingBox rbbox = new BoundingBox(currentBox);
setMinMax(rbbox, true, axis, split);
- return createNode(l, r, rbbox, depth+1);
- }else if (pivot > r){
+ return createNode(l, r, rbbox, depth + 1);
+ } else if (pivot > r) {
//Only left
BoundingBox lbbox = new BoundingBox(currentBox);
setMinMax(lbbox, false, axis, split);
- return createNode(l, r, lbbox, depth+1);
- }else{
+ return createNode(l, r, lbbox, depth + 1);
+ } else {
//Build the node
BIHNode node = new BIHNode(axis);
@@ -343,21 +345,21 @@ public class BIHTree implements CollisionData {
setMinMax(lbbox, false, axis, split);
//The left node right border is the plane most right
- node.setLeftPlane( getMinMax(createBox(l, max(l, pivot - 1)), false, axis) );
- node.setLeftChild( createNode(l, max(l, pivot - 1), lbbox, depth+1) ); //Recursive call
+ node.setLeftPlane(getMinMax(createBox(l, max(l, pivot - 1)), false, axis));
+ node.setLeftChild(createNode(l, max(l, pivot - 1), lbbox, depth + 1)); //Recursive call
//Right Child
BoundingBox rbbox = new BoundingBox(currentBox);
setMinMax(rbbox, true, axis, split);
//The right node left border is the plane most left
- node.setRightPlane( getMinMax(createBox(pivot, r), true, axis) );
- node.setRightChild( createNode(pivot, r, rbbox, depth+1) ); //Recursive call
+ node.setRightPlane(getMinMax(createBox(pivot, r), true, axis));
+ node.setRightChild(createNode(pivot, r, rbbox, depth + 1)); //Recursive call
return node;
}
}
- public void getTriangle(int index, Vector3f v1, Vector3f v2, Vector3f v3){
+ public void getTriangle(int index, Vector3f v1, Vector3f v2, Vector3f v3) {
int pointIndex = index * 9;
v1.x = pointData[pointIndex++];
@@ -373,7 +375,7 @@ public class BIHTree implements CollisionData {
v3.z = pointData[pointIndex++];
}
- public void swapTriangles(int index1, int index2){
+ public void swapTriangles(int index1, int index2) {
int p1 = index1 * 9;
int p2 = index2 * 9;
@@ -392,26 +394,28 @@ public class BIHTree implements CollisionData {
triIndices[index2] = tmp2;
}
- private int collideWithRay(Ray r,
- Matrix4f worldMatrix,
- BoundingVolume worldBound,
- CollisionResults results){
+ private int collideWithRay(Ray r,
+ Matrix4f worldMatrix,
+ BoundingVolume worldBound,
+ CollisionResults results) {
boundResults.clear();
worldBound.collideWith(r, boundResults);
- if (boundResults.size() > 0){
+ if (boundResults.size() > 0) {
float tMin = boundResults.getClosestCollision().getDistance();
float tMax = boundResults.getFarthestCollision().getDistance();
-
- if (tMax <= 0)
+
+ if (tMax <= 0) {
tMax = Float.POSITIVE_INFINITY;
- else if (tMin == tMax)
+ } else if (tMin == tMax) {
tMin = 0;
+ }
- if (tMin <= 0)
+ if (tMin <= 0) {
tMin = 0;
+ }
- if (r.getLimit() < Float.POSITIVE_INFINITY){
+ if (r.getLimit() < Float.POSITIVE_INFINITY) {
tMax = Math.min(tMax, r.getLimit());
}
@@ -422,17 +426,17 @@ public class BIHTree implements CollisionData {
}
private int collideWithBoundingVolume(BoundingVolume bv,
- Matrix4f worldMatrix,
- CollisionResults results){
+ Matrix4f worldMatrix,
+ CollisionResults results) {
BoundingBox bbox;
- if (bv instanceof BoundingSphere){
+ if (bv instanceof BoundingSphere) {
BoundingSphere sphere = (BoundingSphere) bv;
bbox = new BoundingBox(bv.getCenter().clone(), sphere.getRadius(),
- sphere.getRadius(),
- sphere.getRadius());
- }else if (bv instanceof BoundingBox){
- bbox = new BoundingBox( (BoundingBox) bv );
- }else{
+ sphere.getRadius(),
+ sphere.getRadius());
+ } else if (bv instanceof BoundingBox) {
+ bbox = new BoundingBox((BoundingBox) bv);
+ } else {
throw new UnsupportedCollisionException();
}
@@ -440,18 +444,18 @@ public class BIHTree implements CollisionData {
return root.intersectWhere(bv, bbox, worldMatrix, this, results);
}
- public int collideWith(Collidable other,
- Matrix4f worldMatrix,
- BoundingVolume worldBound,
- CollisionResults results){
-
- if (other instanceof Ray){
+ public int collideWith(Collidable other,
+ Matrix4f worldMatrix,
+ BoundingVolume worldBound,
+ CollisionResults results) {
+
+ if (other instanceof Ray) {
Ray ray = (Ray) other;
return collideWithRay(ray, worldMatrix, worldBound, results);
- }else if (other instanceof BoundingVolume){
+ } else if (other instanceof BoundingVolume) {
BoundingVolume bv = (BoundingVolume) other;
return collideWithBoundingVolume(bv, worldMatrix, results);
- }else{
+ } else {
throw new UnsupportedCollisionException();
}
}
@@ -464,7 +468,7 @@ public class BIHTree implements CollisionData {
oc.write(pointData, "points", null);
oc.write(triIndices, "indices", null);
}
-
+
public void read(JmeImporter im) throws IOException {
InputCapsule ic = im.getCapsule(this);
mesh = (Mesh) ic.readSavable("mesh", null);
@@ -473,5 +477,4 @@ public class BIHTree implements CollisionData {
pointData = ic.readFloatArray("points", null);
triIndices = ic.readIntArray("indices", null);
}
-
}
diff --git a/engine/src/core/com/jme3/effect/ParticleEmitter.java b/engine/src/core/com/jme3/effect/ParticleEmitter.java
index 1166fffde..d418f50ed 100644
--- a/engine/src/core/com/jme3/effect/ParticleEmitter.java
+++ b/engine/src/core/com/jme3/effect/ParticleEmitter.java
@@ -72,10 +72,9 @@ import java.io.IOException;
* @author Kirill Vainer
*/
public class ParticleEmitter extends Geometry {
-
+
private static final EmitterShape DEFAULT_SHAPE = new EmitterPointShape(Vector3f.ZERO);
private static final ParticleInfluencer DEFAULT_INFLUENCER = new DefaultParticleInfluencer();
-
private ParticleEmitterControl control = new ParticleEmitterControl();
private EmitterShape shape = DEFAULT_SHAPE;
private ParticleMesh particleMesh;
@@ -110,7 +109,7 @@ public class ParticleEmitter extends Geometry {
private class ParticleEmitterControl implements Control {
public Control cloneForSpatial(Spatial spatial) {
- return ((ParticleEmitter)spatial).control;
+ return ((ParticleEmitter) spatial).control;
}
public void setSpatial(Spatial spatial) {
@@ -139,9 +138,8 @@ public class ParticleEmitter extends Geometry {
public void read(JmeImporter im) throws IOException {
// the data is not written here
}
-
}
-
+
@Override
public ParticleEmitter clone() {
ParticleEmitter clone = (ParticleEmitter) super.clone();
@@ -199,7 +197,6 @@ public class ParticleEmitter extends Geometry {
this.shape = shape;
}
-
public EmitterShape getShape() {
return shape;
}
@@ -838,7 +835,7 @@ public class ParticleEmitter extends Geometry {
this.getWorldTransform();
TempVars vars = TempVars.get();
- assert vars.lock();
+
BoundingBox bbox = (BoundingBox) this.getMesh().getBound();
@@ -862,7 +859,7 @@ public class ParticleEmitter extends Geometry {
bbox.setMinMax(min, max);
this.setBoundRefresh();
- assert vars.unlock();
+ vars.release();
}
/**
@@ -909,7 +906,7 @@ public class ParticleEmitter extends Geometry {
this.getWorldTransform();
TempVars vars = TempVars.get();
- assert vars.lock();
+
Vector3f min = vars.vect1.set(Vector3f.POSITIVE_INFINITY);
Vector3f max = vars.vect2.set(Vector3f.NEGATIVE_INFINITY);
@@ -979,7 +976,7 @@ public class ParticleEmitter extends Geometry {
bbox.setMinMax(min, max);
this.setBoundRefresh();
- assert vars.unlock();
+ vars.release();
}
/**
@@ -1033,14 +1030,15 @@ public class ParticleEmitter extends Geometry {
}
Matrix3f inverseRotation = Matrix3f.IDENTITY;
+ TempVars vars = null;
if (!worldSpace) {
- TempVars vars = TempVars.get();
- assert vars.lock();
+ vars = TempVars.get();
+
inverseRotation = this.getWorldRotation().toRotationMatrix(vars.tempMat3).invertLocal();
}
particleMesh.updateParticleData(particles, cam, inverseRotation);
if (!worldSpace) {
- assert TempVars.get().unlock();
+ vars.release();
}
}
@@ -1119,22 +1117,22 @@ public class ParticleEmitter extends Geometry {
particleMesh.initParticleData(this, particles.length);
particleInfluencer = (ParticleInfluencer) ic.readSavable("influencer", DEFAULT_INFLUENCER);
-
+
// compatibility before the control inside particle emitter
// was changed:
// find it in the controls and take it out, then add the proper one in
- for (int i = 0; i < controls.size(); i++){
+ for (int i = 0; i < controls.size(); i++) {
Object obj = controls.get(i);
- if (obj instanceof ParticleEmitter){
+ if (obj instanceof ParticleEmitter) {
controls.remove(i);
// now add the proper one in
controls.add(control);
break;
}
}
-
+
// compatability before gravity was not a vector but a float
- if (gravity == null){
+ if (gravity == null) {
gravity = new Vector3f();
gravity.y = ic.readFloat("gravity", 0);
}
diff --git a/engine/src/core/com/jme3/math/Line.java b/engine/src/core/com/jme3/math/Line.java
index 1168a2b3d..67511d74e 100644
--- a/engine/src/core/com/jme3/math/Line.java
+++ b/engine/src/core/com/jme3/math/Line.java
@@ -29,7 +29,6 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
package com.jme3.math;
import com.jme3.export.InputCapsule;
@@ -110,10 +109,10 @@ public class Line implements Savable, Cloneable {
public void setDirection(Vector3f direction) {
this.direction = direction;
}
-
+
public float distanceSquared(Vector3f point) {
TempVars vars = TempVars.get();
- assert vars.lock();
+
Vector3f compVec1 = vars.vect1;
Vector3f compVec2 = vars.vect2;
@@ -122,71 +121,71 @@ public class Line implements Savable, Cloneable {
origin.add(direction.mult(lineParameter, compVec2), compVec2);
compVec2.subtract(point, compVec1);
float len = compVec1.lengthSquared();
- assert vars.unlock();
+ vars.release();
return len;
}
-
+
public float distance(Vector3f point) {
- return FastMath.sqrt(distanceSquared(point));
+ return FastMath.sqrt(distanceSquared(point));
}
-
+
public void orthogonalLineFit(FloatBuffer points) {
- if (points == null) {
- return;
- }
+ if (points == null) {
+ return;
+ }
TempVars vars = TempVars.get();
- assert vars.lock();
+
Vector3f compVec1 = vars.vect1;
Vector3f compVec2 = vars.vect2;
Matrix3f compMat1 = vars.tempMat3;
Eigen3f compEigen1 = vars.eigen;
- points.rewind();
-
- // compute average of points
- int length = points.remaining() / 3;
-
- BufferUtils.populateFromBuffer(origin, points, 0);
- for (int i = 1; i < length; i++) {
- BufferUtils.populateFromBuffer(compVec1, points, i);
- origin.addLocal(compVec1);
- }
-
- origin.multLocal(1f / (float) length);
-
- // compute sums of products
- float sumXX = 0.0f, sumXY = 0.0f, sumXZ = 0.0f;
- float sumYY = 0.0f, sumYZ = 0.0f, sumZZ = 0.0f;
-
- points.rewind();
- for (int i = 0; i < length; i++) {
- BufferUtils.populateFromBuffer(compVec1, points, i);
- compVec1.subtract(origin, compVec2);
- sumXX += compVec2.x * compVec2.x;
- sumXY += compVec2.x * compVec2.y;
- sumXZ += compVec2.x * compVec2.z;
- sumYY += compVec2.y * compVec2.y;
- sumYZ += compVec2.y * compVec2.z;
- sumZZ += compVec2.z * compVec2.z;
- }
-
- //find the smallest eigen vector for the direction vector
- compMat1.m00 = sumYY + sumZZ;
- compMat1.m01 = -sumXY;
- compMat1.m02 = -sumXZ;
- compMat1.m10 = -sumXY;
- compMat1.m11 = sumXX + sumZZ;
- compMat1.m12 = -sumYZ;
- compMat1.m20 = -sumXZ;
- compMat1.m21 = -sumYZ;
- compMat1.m22 = sumXX + sumYY;
-
- compEigen1.calculateEigen(compMat1);
- direction = compEigen1.getEigenVector(0);
-
- assert vars.unlock();
- }
+ points.rewind();
+
+ // compute average of points
+ int length = points.remaining() / 3;
+
+ BufferUtils.populateFromBuffer(origin, points, 0);
+ for (int i = 1; i < length; i++) {
+ BufferUtils.populateFromBuffer(compVec1, points, i);
+ origin.addLocal(compVec1);
+ }
+
+ origin.multLocal(1f / (float) length);
+
+ // compute sums of products
+ float sumXX = 0.0f, sumXY = 0.0f, sumXZ = 0.0f;
+ float sumYY = 0.0f, sumYZ = 0.0f, sumZZ = 0.0f;
+
+ points.rewind();
+ for (int i = 0; i < length; i++) {
+ BufferUtils.populateFromBuffer(compVec1, points, i);
+ compVec1.subtract(origin, compVec2);
+ sumXX += compVec2.x * compVec2.x;
+ sumXY += compVec2.x * compVec2.y;
+ sumXZ += compVec2.x * compVec2.z;
+ sumYY += compVec2.y * compVec2.y;
+ sumYZ += compVec2.y * compVec2.z;
+ sumZZ += compVec2.z * compVec2.z;
+ }
+
+ //find the smallest eigen vector for the direction vector
+ compMat1.m00 = sumYY + sumZZ;
+ compMat1.m01 = -sumXY;
+ compMat1.m02 = -sumXZ;
+ compMat1.m10 = -sumXY;
+ compMat1.m11 = sumXX + sumZZ;
+ compMat1.m12 = -sumYZ;
+ compMat1.m20 = -sumXZ;
+ compMat1.m21 = -sumYZ;
+ compMat1.m22 = sumXX + sumYY;
+
+ compEigen1.calculateEigen(compMat1);
+ direction = compEigen1.getEigenVector(0);
+
+ vars.release();
+ }
/**
*
@@ -224,10 +223,10 @@ public class Line implements Savable, Cloneable {
public void read(JmeImporter e) throws IOException {
InputCapsule capsule = e.getCapsule(this);
- origin = (Vector3f)capsule.readSavable("origin", Vector3f.ZERO.clone());
- direction = (Vector3f)capsule.readSavable("direction", Vector3f.ZERO.clone());
+ origin = (Vector3f) capsule.readSavable("origin", Vector3f.ZERO.clone());
+ direction = (Vector3f) capsule.readSavable("direction", Vector3f.ZERO.clone());
}
-
+
@Override
public Line clone() {
try {
diff --git a/engine/src/core/com/jme3/math/LineSegment.java b/engine/src/core/com/jme3/math/LineSegment.java
index a70067740..42fe06797 100644
--- a/engine/src/core/com/jme3/math/LineSegment.java
+++ b/engine/src/core/com/jme3/math/LineSegment.java
@@ -110,8 +110,8 @@ public class LineSegment implements Cloneable, Savable {
}
public float distanceSquared(Vector3f point) {
- assert TempVars.get().lock();
- Vector3f compVec1 = TempVars.get().vect1;
+ TempVars vars = TempVars.get();
+ Vector3f compVec1 = vars.vect1;
point.subtract(origin, compVec1);
float segmentParameter = direction.dot(compVec1);
@@ -129,20 +129,20 @@ public class LineSegment implements Cloneable, Savable {
compVec1.subtractLocal(point);
float len = compVec1.lengthSquared();
- assert TempVars.get().unlock();
+ vars.release();
return len;
}
public float distanceSquared(LineSegment test) {
- assert TempVars.get().lock();
- Vector3f compVec1 = TempVars.get().vect1;
+ TempVars vars = TempVars.get();
+ Vector3f compVec1 = vars.vect1;
origin.subtract(test.getOrigin(), compVec1);
float negativeDirectionDot = -(direction.dot(test.getDirection()));
float diffThisDot = compVec1.dot(direction);
float diffTestDot = -(compVec1.dot(test.getDirection()));
float lengthOfDiff = compVec1.lengthSquared();
- assert TempVars.get().unlock();
+ vars.release();
float determinant = FastMath.abs(1.0f - negativeDirectionDot
* negativeDirectionDot);
float s0, s1, squareDistance, extentDeterminant0, extentDeterminant1, tempS0, tempS1;
diff --git a/engine/src/core/com/jme3/math/Matrix3f.java b/engine/src/core/com/jme3/math/Matrix3f.java
index 073b9f0a1..8ea03e20a 100644
--- a/engine/src/core/com/jme3/math/Matrix3f.java
+++ b/engine/src/core/com/jme3/math/Matrix3f.java
@@ -29,7 +29,6 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
package com.jme3.math;
import com.jme3.export.InputCapsule;
@@ -55,12 +54,10 @@ import java.util.logging.Logger;
public final class Matrix3f implements Savable, Cloneable {
private static final Logger logger = Logger.getLogger(Matrix3f.class.getName());
-
protected float m00, m01, m02;
protected float m10, m11, m12;
protected float m20, m21, m22;
-
- public static final Matrix3f ZERO = new Matrix3f(0,0,0,0,0,0,0,0,0);
+ public static final Matrix3f ZERO = new Matrix3f(0, 0, 0, 0, 0, 0, 0, 0, 0);
public static final Matrix3f IDENTITY = new Matrix3f();
/**
@@ -174,24 +171,33 @@ public final class Matrix3f implements Savable, Cloneable {
@SuppressWarnings("fallthrough")
public float get(int i, int j) {
switch (i) {
- case 0:
- switch (j) {
- case 0: return m00;
- case 1: return m01;
- case 2: return m02;
- }
- case 1:
- switch (j) {
- case 0: return m10;
- case 1: return m11;
- case 2: return m12;
- }
- case 2:
- switch (j) {
- case 0: return m20;
- case 1: return m21;
- case 2: return m22;
- }
+ case 0:
+ switch (j) {
+ case 0:
+ return m00;
+ case 1:
+ return m01;
+ case 2:
+ return m02;
+ }
+ case 1:
+ switch (j) {
+ case 0:
+ return m10;
+ case 1:
+ return m11;
+ case 2:
+ return m12;
+ }
+ case 2:
+ switch (j) {
+ case 0:
+ return m20;
+ case 1:
+ return m21;
+ case 2:
+ return m22;
+ }
}
logger.warning("Invalid matrix index.");
@@ -220,8 +226,7 @@ public final class Matrix3f implements Savable, Cloneable {
data[6] = m20;
data[7] = m21;
data[8] = m22;
- }
- else {
+ } else {
data[0] = m00;
data[1] = m10;
data[2] = m20;
@@ -232,8 +237,7 @@ public final class Matrix3f implements Savable, Cloneable {
data[7] = m12;
data[8] = m22;
}
- }
- else if (data.length == 16) {
+ } else if (data.length == 16) {
if (rowMajor) {
data[0] = m00;
data[1] = m01;
@@ -244,8 +248,7 @@ public final class Matrix3f implements Savable, Cloneable {
data[8] = m20;
data[9] = m21;
data[10] = m22;
- }
- else {
+ } else {
data[0] = m00;
data[1] = m10;
data[2] = m20;
@@ -256,8 +259,7 @@ public final class Matrix3f implements Savable, Cloneable {
data[9] = m12;
data[10] = m22;
}
- }
- else {
+ } else {
throw new IndexOutOfBoundsException("Array size must be 9 or 16 in Matrix3f.get().");
}
}
@@ -286,26 +288,28 @@ public final class Matrix3f implements Savable, Cloneable {
* @return the column specified by the index.
*/
public Vector3f getColumn(int i, Vector3f store) {
- if (store == null) store = new Vector3f();
+ if (store == null) {
+ store = new Vector3f();
+ }
switch (i) {
- case 0:
- store.x = m00;
- store.y = m10;
- store.z = m20;
- break;
- case 1:
- store.x = m01;
- store.y = m11;
- store.z = m21;
- break;
- case 2:
- store.x = m02;
- store.y = m12;
- store.z = m22;
- break;
- default:
- logger.warning("Invalid column index.");
- throw new IllegalArgumentException("Invalid column index. " + i);
+ case 0:
+ store.x = m00;
+ store.y = m10;
+ store.z = m20;
+ break;
+ case 1:
+ store.x = m01;
+ store.y = m11;
+ store.z = m21;
+ break;
+ case 2:
+ store.x = m02;
+ store.y = m12;
+ store.z = m22;
+ break;
+ default:
+ logger.warning("Invalid column index.");
+ throw new IllegalArgumentException("Invalid column index. " + i);
}
return store;
}
@@ -334,26 +338,28 @@ public final class Matrix3f implements Savable, Cloneable {
* @return the row specified by the index.
*/
public Vector3f getRow(int i, Vector3f store) {
- if (store == null) store = new Vector3f();
+ if (store == null) {
+ store = new Vector3f();
+ }
switch (i) {
- case 0:
- store.x = m00;
- store.y = m01;
- store.z = m02;
- break;
- case 1:
- store.x = m10;
- store.y = m11;
- store.z = m12;
- break;
- case 2:
- store.x = m20;
- store.y = m21;
- store.z = m22;
- break;
- default:
- logger.warning("Invalid row index.");
- throw new IllegalArgumentException("Invalid row index. " + i);
+ case 0:
+ store.x = m00;
+ store.y = m01;
+ store.z = m02;
+ break;
+ case 1:
+ store.x = m10;
+ store.y = m11;
+ store.z = m12;
+ break;
+ case 2:
+ store.x = m20;
+ store.y = m21;
+ store.z = m22;
+ break;
+ default:
+ logger.warning("Invalid row index.");
+ throw new IllegalArgumentException("Invalid row index. " + i);
}
return store;
}
@@ -394,19 +400,19 @@ public final class Matrix3f implements Savable, Cloneable {
// fb.put(m10).put(m11).put(m12);
// fb.put(m20).put(m21).put(m22);
// }
-
+
TempVars vars = TempVars.get();
- assert vars.lock();
-
+
+
fillFloatArray(vars.matrixWrite, columnMajor);
fb.put(vars.matrixWrite, 0, 9);
-
- assert vars.unlock();
-
+
+ vars.release();
+
return fb;
}
-
- public void fillFloatArray(float[] f, boolean columnMajor){
+
+ public void fillFloatArray(float[] f, boolean columnMajor) {
if (columnMajor) {
f[ 0] = m00;
f[ 1] = m10;
@@ -417,7 +423,7 @@ public final class Matrix3f implements Savable, Cloneable {
f[ 6] = m02;
f[ 7] = m12;
f[ 8] = m22;
- }else{
+ } else {
f[ 0] = m00;
f[ 1] = m01;
f[ 2] = m02;
@@ -448,29 +454,28 @@ public final class Matrix3f implements Savable, Cloneable {
return this;
}
switch (i) {
- case 0:
- m00 = column.x;
- m10 = column.y;
- m20 = column.z;
- break;
- case 1:
- m01 = column.x;
- m11 = column.y;
- m21 = column.z;
- break;
- case 2:
- m02 = column.x;
- m12 = column.y;
- m22 = column.z;
- break;
- default:
- logger.warning("Invalid column index.");
- throw new IllegalArgumentException("Invalid column index. " + i);
+ case 0:
+ m00 = column.x;
+ m10 = column.y;
+ m20 = column.z;
+ break;
+ case 1:
+ m01 = column.x;
+ m11 = column.y;
+ m21 = column.z;
+ break;
+ case 2:
+ m02 = column.x;
+ m12 = column.y;
+ m22 = column.z;
+ break;
+ default:
+ logger.warning("Invalid column index.");
+ throw new IllegalArgumentException("Invalid column index. " + i);
}
return this;
}
-
/**
*
* setRow
sets a particular row of this matrix to that
@@ -489,24 +494,24 @@ public final class Matrix3f implements Savable, Cloneable {
return this;
}
switch (i) {
- case 0:
- m00 = row.x;
- m01 = row.y;
- m02 = row.z;
- break;
- case 1:
- m10 = row.x;
- m11 = row.y;
- m12 = row.z;
- break;
- case 2:
- m20 = row.x;
- m21 = row.y;
- m22 = row.z;
- break;
- default:
- logger.warning("Invalid row index.");
- throw new IllegalArgumentException("Invalid row index. " + i);
+ case 0:
+ m00 = row.x;
+ m01 = row.y;
+ m02 = row.z;
+ break;
+ case 1:
+ m10 = row.x;
+ m11 = row.y;
+ m12 = row.z;
+ break;
+ case 2:
+ m20 = row.x;
+ m21 = row.y;
+ m22 = row.z;
+ break;
+ default:
+ logger.warning("Invalid row index.");
+ throw new IllegalArgumentException("Invalid row index. " + i);
}
return this;
}
@@ -527,24 +532,42 @@ public final class Matrix3f implements Savable, Cloneable {
@SuppressWarnings("fallthrough")
public Matrix3f set(int i, int j, float value) {
switch (i) {
- case 0:
- switch (j) {
- case 0: m00 = value; return this;
- case 1: m01 = value; return this;
- case 2: m02 = value; return this;
- }
- case 1:
- switch (j) {
- case 0: m10 = value; return this;
- case 1: m11 = value; return this;
- case 2: m12 = value; return this;
- }
- case 2:
- switch (j) {
- case 0: m20 = value; return this;
- case 1: m21 = value; return this;
- case 2: m22 = value; return this;
- }
+ case 0:
+ switch (j) {
+ case 0:
+ m00 = value;
+ return this;
+ case 1:
+ m01 = value;
+ return this;
+ case 2:
+ m02 = value;
+ return this;
+ }
+ case 1:
+ switch (j) {
+ case 0:
+ m10 = value;
+ return this;
+ case 1:
+ m11 = value;
+ return this;
+ case 2:
+ m12 = value;
+ return this;
+ }
+ case 2:
+ switch (j) {
+ case 0:
+ m20 = value;
+ return this;
+ case 1:
+ m21 = value;
+ return this;
+ case 2:
+ m22 = value;
+ return this;
+ }
}
logger.warning("Invalid matrix index.");
@@ -563,8 +586,10 @@ public final class Matrix3f implements Savable, Cloneable {
* @return this
*/
public Matrix3f set(float[][] matrix) {
- if (matrix.length != 3 || matrix[0].length != 3) { throw new IllegalArgumentException(
- "Array must be of size 9."); }
+ if (matrix.length != 3 || matrix[0].length != 3) {
+ throw new IllegalArgumentException(
+ "Array must be of size 9.");
+ }
m00 = matrix[0][0];
m01 = matrix[0][1];
@@ -626,29 +651,31 @@ public final class Matrix3f implements Savable, Cloneable {
* @return this
*/
public Matrix3f set(float[] matrix, boolean rowMajor) {
- if (matrix.length != 9) throw new IllegalArgumentException(
- "Array must be of size 9.");
+ if (matrix.length != 9) {
+ throw new IllegalArgumentException(
+ "Array must be of size 9.");
+ }
if (rowMajor) {
- m00 = matrix[0];
- m01 = matrix[1];
- m02 = matrix[2];
- m10 = matrix[3];
- m11 = matrix[4];
- m12 = matrix[5];
- m20 = matrix[6];
- m21 = matrix[7];
- m22 = matrix[8];
+ m00 = matrix[0];
+ m01 = matrix[1];
+ m02 = matrix[2];
+ m10 = matrix[3];
+ m11 = matrix[4];
+ m12 = matrix[5];
+ m20 = matrix[6];
+ m21 = matrix[7];
+ m22 = matrix[8];
} else {
- m00 = matrix[0];
- m01 = matrix[3];
- m02 = matrix[6];
- m10 = matrix[1];
- m11 = matrix[4];
- m12 = matrix[7];
- m20 = matrix[2];
- m21 = matrix[5];
- m22 = matrix[8];
+ m00 = matrix[0];
+ m01 = matrix[3];
+ m02 = matrix[6];
+ m10 = matrix[1];
+ m11 = matrix[4];
+ m12 = matrix[7];
+ m20 = matrix[2];
+ m21 = matrix[5];
+ m22 = matrix[8];
}
return this;
}
@@ -681,10 +708,9 @@ public final class Matrix3f implements Savable, Cloneable {
* @return true if this matrix is identity
*/
public boolean isIdentity() {
- return
- (m00 == 1 && m01 == 0 && m02 == 0) &&
- (m10 == 0 && m11 == 1 && m12 == 0) &&
- (m20 == 0 && m21 == 0 && m22 == 1);
+ return (m00 == 1 && m01 == 0 && m02 == 0)
+ && (m10 == 0 && m11 == 1 && m12 == 0)
+ && (m20 == 0 && m21 == 0 && m22 == 1);
}
/**
@@ -714,26 +740,26 @@ public final class Matrix3f implements Savable, Cloneable {
public void fromAngleNormalAxis(float angle, Vector3f axis) {
float fCos = FastMath.cos(angle);
float fSin = FastMath.sin(angle);
- float fOneMinusCos = ((float)1.0)-fCos;
- float fX2 = axis.x*axis.x;
- float fY2 = axis.y*axis.y;
- float fZ2 = axis.z*axis.z;
- float fXYM = axis.x*axis.y*fOneMinusCos;
- float fXZM = axis.x*axis.z*fOneMinusCos;
- float fYZM = axis.y*axis.z*fOneMinusCos;
- float fXSin = axis.x*fSin;
- float fYSin = axis.y*fSin;
- float fZSin = axis.z*fSin;
-
- m00 = fX2*fOneMinusCos+fCos;
- m01 = fXYM-fZSin;
- m02 = fXZM+fYSin;
- m10 = fXYM+fZSin;
- m11 = fY2*fOneMinusCos+fCos;
- m12 = fYZM-fXSin;
- m20 = fXZM-fYSin;
- m21 = fYZM+fXSin;
- m22 = fZ2*fOneMinusCos+fCos;
+ float fOneMinusCos = ((float) 1.0) - fCos;
+ float fX2 = axis.x * axis.x;
+ float fY2 = axis.y * axis.y;
+ float fZ2 = axis.z * axis.z;
+ float fXYM = axis.x * axis.y * fOneMinusCos;
+ float fXZM = axis.x * axis.z * fOneMinusCos;
+ float fYZM = axis.y * axis.z * fOneMinusCos;
+ float fXSin = axis.x * fSin;
+ float fYSin = axis.y * fSin;
+ float fZSin = axis.z * fSin;
+
+ m00 = fX2 * fOneMinusCos + fCos;
+ m01 = fXYM - fZSin;
+ m02 = fXZM + fYSin;
+ m10 = fXYM + fZSin;
+ m11 = fY2 * fOneMinusCos + fCos;
+ m12 = fYZM - fXSin;
+ m20 = fXZM - fYSin;
+ m21 = fYZM + fXSin;
+ m22 = fZ2 * fOneMinusCos + fCos;
}
/**
@@ -761,12 +787,14 @@ public final class Matrix3f implements Savable, Cloneable {
* @return a matrix3f object containing the result of this operation
*/
public Matrix3f mult(Matrix3f mat, Matrix3f product) {
-
+
float temp00, temp01, temp02;
float temp10, temp11, temp12;
float temp20, temp21, temp22;
-
- if (product == null) product = new Matrix3f();
+
+ if (product == null) {
+ product = new Matrix3f();
+ }
temp00 = m00 * mat.m00 + m01 * mat.m10 + m02 * mat.m20;
temp01 = m00 * mat.m01 + m01 * mat.m11 + m02 * mat.m21;
temp02 = m00 * mat.m02 + m01 * mat.m12 + m02 * mat.m22;
@@ -776,7 +804,7 @@ public final class Matrix3f implements Savable, Cloneable {
temp20 = m20 * mat.m00 + m21 * mat.m10 + m22 * mat.m20;
temp21 = m20 * mat.m01 + m21 * mat.m11 + m22 * mat.m21;
temp22 = m20 * mat.m02 + m21 * mat.m12 + m22 * mat.m22;
-
+
product.m00 = temp00;
product.m01 = temp01;
product.m02 = temp02;
@@ -786,7 +814,7 @@ public final class Matrix3f implements Savable, Cloneable {
product.m20 = temp20;
product.m21 = temp21;
product.m22 = temp22;
-
+
return product;
}
@@ -815,7 +843,7 @@ public final class Matrix3f implements Savable, Cloneable {
* @return The given product vector.
*/
public Vector3f mult(Vector3f vec, Vector3f product) {
-
+
if (null == product) {
product = new Vector3f();
}
@@ -862,7 +890,9 @@ public final class Matrix3f implements Savable, Cloneable {
* @return The passed vector after multiplication
*/
public Vector3f multLocal(Vector3f vec) {
- if (vec == null) return null;
+ if (vec == null) {
+ return null;
+ }
float x = vec.x;
float y = vec.y;
vec.x = m00 * x + m01 * y + m02 * vec.z;
@@ -925,23 +955,26 @@ public final class Matrix3f implements Savable, Cloneable {
* @return The store
*/
public Matrix3f invert(Matrix3f store) {
- if (store == null) store = new Matrix3f();
+ if (store == null) {
+ store = new Matrix3f();
+ }
float det = determinant();
- if ( FastMath.abs(det) <= FastMath.FLT_EPSILON )
+ if (FastMath.abs(det) <= FastMath.FLT_EPSILON) {
return store.zero();
+ }
- store.m00 = m11*m22 - m12*m21;
- store.m01 = m02*m21 - m01*m22;
- store.m02 = m01*m12 - m02*m11;
- store.m10 = m12*m20 - m10*m22;
- store.m11 = m00*m22 - m02*m20;
- store.m12 = m02*m10 - m00*m12;
- store.m20 = m10*m21 - m11*m20;
- store.m21 = m01*m20 - m00*m21;
- store.m22 = m00*m11 - m01*m10;
-
- store.multLocal(1f/det);
+ store.m00 = m11 * m22 - m12 * m21;
+ store.m01 = m02 * m21 - m01 * m22;
+ store.m02 = m01 * m12 - m02 * m11;
+ store.m10 = m12 * m20 - m10 * m22;
+ store.m11 = m00 * m22 - m02 * m20;
+ store.m12 = m02 * m10 - m00 * m12;
+ store.m20 = m10 * m21 - m11 * m20;
+ store.m21 = m01 * m20 - m00 * m21;
+ store.m22 = m00 * m11 - m01 * m10;
+
+ store.multLocal(1f / det);
return store;
}
@@ -952,19 +985,20 @@ public final class Matrix3f implements Savable, Cloneable {
*/
public Matrix3f invertLocal() {
float det = determinant();
- if ( FastMath.abs(det) <= FastMath.FLT_EPSILON )
+ if (FastMath.abs(det) <= FastMath.FLT_EPSILON) {
return zero();
+ }
+
+ float f00 = m11 * m22 - m12 * m21;
+ float f01 = m02 * m21 - m01 * m22;
+ float f02 = m01 * m12 - m02 * m11;
+ float f10 = m12 * m20 - m10 * m22;
+ float f11 = m00 * m22 - m02 * m20;
+ float f12 = m02 * m10 - m00 * m12;
+ float f20 = m10 * m21 - m11 * m20;
+ float f21 = m01 * m20 - m00 * m21;
+ float f22 = m00 * m11 - m01 * m10;
- float f00 = m11*m22 - m12*m21;
- float f01 = m02*m21 - m01*m22;
- float f02 = m01*m12 - m02*m11;
- float f10 = m12*m20 - m10*m22;
- float f11 = m00*m22 - m02*m20;
- float f12 = m02*m10 - m00*m12;
- float f20 = m10*m21 - m11*m20;
- float f21 = m01*m20 - m00*m21;
- float f22 = m00*m11 - m01*m10;
-
m00 = f00;
m01 = f01;
m02 = f02;
@@ -975,10 +1009,10 @@ public final class Matrix3f implements Savable, Cloneable {
m21 = f21;
m22 = f22;
- multLocal(1f/det);
+ multLocal(1f / det);
return this;
}
-
+
/**
* Returns a new matrix representing the adjoint of this matrix.
*
@@ -987,7 +1021,7 @@ public final class Matrix3f implements Savable, Cloneable {
public Matrix3f adjoint() {
return adjoint(null);
}
-
+
/**
* Places the adjoint of this matrix in store (creates store if null.)
*
@@ -996,17 +1030,19 @@ public final class Matrix3f implements Savable, Cloneable {
* @return store
*/
public Matrix3f adjoint(Matrix3f store) {
- if (store == null) store = new Matrix3f();
-
- store.m00 = m11*m22 - m12*m21;
- store.m01 = m02*m21 - m01*m22;
- store.m02 = m01*m12 - m02*m11;
- store.m10 = m12*m20 - m10*m22;
- store.m11 = m00*m22 - m02*m20;
- store.m12 = m02*m10 - m00*m12;
- store.m20 = m10*m21 - m11*m20;
- store.m21 = m01*m20 - m00*m21;
- store.m22 = m00*m11 - m01*m10;
+ if (store == null) {
+ store = new Matrix3f();
+ }
+
+ store.m00 = m11 * m22 - m12 * m21;
+ store.m01 = m02 * m21 - m01 * m22;
+ store.m02 = m01 * m12 - m02 * m11;
+ store.m10 = m12 * m20 - m10 * m22;
+ store.m11 = m00 * m22 - m02 * m20;
+ store.m12 = m02 * m10 - m00 * m12;
+ store.m20 = m10 * m21 - m11 * m20;
+ store.m21 = m01 * m20 - m00 * m21;
+ store.m22 = m00 * m11 - m01 * m10;
return store;
}
@@ -1017,10 +1053,10 @@ public final class Matrix3f implements Savable, Cloneable {
* @return the determinate
*/
public float determinant() {
- float fCo00 = m11*m22 - m12*m21;
- float fCo10 = m12*m20 - m10*m22;
- float fCo20 = m10*m21 - m11*m20;
- float fDet = m00*fCo00 + m01*fCo10 + m02*fCo20;
+ float fCo00 = m11 * m22 - m12 * m21;
+ float fCo10 = m12 * m20 - m10 * m22;
+ float fCo20 = m10 * m21 - m11 * m20;
+ float fDet = m00 * fCo00 + m01 * fCo10 + m02 * fCo20;
return fDet;
}
@@ -1045,7 +1081,7 @@ public final class Matrix3f implements Savable, Cloneable {
public Matrix3f transpose() {
return transposeLocal();
}
-
+
/**
* transposeNew
returns a transposed version of this matrix.
*
@@ -1055,7 +1091,7 @@ public final class Matrix3f implements Savable, Cloneable {
Matrix3f ret = new Matrix3f(m00, m10, m20, m01, m11, m21, m02, m12, m22);
return ret;
}
-
+
/**
* toString
returns the string representation of this object.
* It is in a format of a 3x3 matrix. For example, an identity matrix would
@@ -1119,7 +1155,7 @@ public final class Matrix3f implements Savable, Cloneable {
return hash;
}
-
+
/**
* are these two matrices the same? they are is they both have the same mXX values.
*
@@ -1138,17 +1174,35 @@ public final class Matrix3f implements Savable, Cloneable {
}
Matrix3f comp = (Matrix3f) o;
- if (Float.compare(m00,comp.m00) != 0) return false;
- if (Float.compare(m01,comp.m01) != 0) return false;
- if (Float.compare(m02,comp.m02) != 0) return false;
+ if (Float.compare(m00, comp.m00) != 0) {
+ return false;
+ }
+ if (Float.compare(m01, comp.m01) != 0) {
+ return false;
+ }
+ if (Float.compare(m02, comp.m02) != 0) {
+ return false;
+ }
- if (Float.compare(m10,comp.m10) != 0) return false;
- if (Float.compare(m11,comp.m11) != 0) return false;
- if (Float.compare(m12,comp.m12) != 0) return false;
+ if (Float.compare(m10, comp.m10) != 0) {
+ return false;
+ }
+ if (Float.compare(m11, comp.m11) != 0) {
+ return false;
+ }
+ if (Float.compare(m12, comp.m12) != 0) {
+ return false;
+ }
- if (Float.compare(m20,comp.m20) != 0) return false;
- if (Float.compare(m21,comp.m21) != 0) return false;
- if (Float.compare(m22,comp.m22) != 0) return false;
+ if (Float.compare(m20, comp.m20) != 0) {
+ return false;
+ }
+ if (Float.compare(m21, comp.m21) != 0) {
+ return false;
+ }
+ if (Float.compare(m22, comp.m22) != 0) {
+ return false;
+ }
return true;
}
@@ -1178,7 +1232,7 @@ public final class Matrix3f implements Savable, Cloneable {
m21 = cap.readFloat("m21", 0);
m22 = cap.readFloat("m22", 1);
}
-
+
/**
* A function for creating a rotation matrix that rotates a vector called
* "start" into another vector called "end".
@@ -1278,34 +1332,52 @@ public final class Matrix3f implements Savable, Cloneable {
* The scale applied to each of the X, Y and Z output values.
*/
public void scale(Vector3f scale) {
- m00 *= scale.x;
- m10 *= scale.x;
- m20 *= scale.x;
- m01 *= scale.y;
- m11 *= scale.y;
- m21 *= scale.y;
- m02 *= scale.z;
- m12 *= scale.z;
- m22 *= scale.z;
+ m00 *= scale.x;
+ m10 *= scale.x;
+ m20 *= scale.x;
+ m01 *= scale.y;
+ m11 *= scale.y;
+ m21 *= scale.y;
+ m02 *= scale.z;
+ m12 *= scale.z;
+ m22 *= scale.z;
}
static boolean equalIdentity(Matrix3f mat) {
- if (Math.abs(mat.m00 - 1) > 1e-4) return false;
- if (Math.abs(mat.m11 - 1) > 1e-4) return false;
- if (Math.abs(mat.m22 - 1) > 1e-4) return false;
+ if (Math.abs(mat.m00 - 1) > 1e-4) {
+ return false;
+ }
+ if (Math.abs(mat.m11 - 1) > 1e-4) {
+ return false;
+ }
+ if (Math.abs(mat.m22 - 1) > 1e-4) {
+ return false;
+ }
- if (Math.abs(mat.m01) > 1e-4) return false;
- if (Math.abs(mat.m02) > 1e-4) return false;
+ if (Math.abs(mat.m01) > 1e-4) {
+ return false;
+ }
+ if (Math.abs(mat.m02) > 1e-4) {
+ return false;
+ }
- if (Math.abs(mat.m10) > 1e-4) return false;
- if (Math.abs(mat.m12) > 1e-4) return false;
+ if (Math.abs(mat.m10) > 1e-4) {
+ return false;
+ }
+ if (Math.abs(mat.m12) > 1e-4) {
+ return false;
+ }
- if (Math.abs(mat.m20) > 1e-4) return false;
- if (Math.abs(mat.m21) > 1e-4) return false;
+ if (Math.abs(mat.m20) > 1e-4) {
+ return false;
+ }
+ if (Math.abs(mat.m21) > 1e-4) {
+ return false;
+ }
- return true;
+ return true;
}
-
+
@Override
public Matrix3f clone() {
try {
diff --git a/engine/src/core/com/jme3/math/Matrix4f.java b/engine/src/core/com/jme3/math/Matrix4f.java
index fdd5ae468..dc0d4c8ac 100644
--- a/engine/src/core/com/jme3/math/Matrix4f.java
+++ b/engine/src/core/com/jme3/math/Matrix4f.java
@@ -159,7 +159,6 @@ public final class Matrix4f implements Savable, Cloneable {
loadIdentity();
TempVars vars = TempVars.get();
- assert vars.lock();
Vector3f f = vars.vect1.set(direction);
Vector3f s = vars.vect2.set(f).crossLocal(up);
@@ -192,14 +191,14 @@ public final class Matrix4f implements Savable, Cloneable {
// m22 = -direction.z;
//
- Matrix4f transMatrix = TempVars.get().tempMat4;
+ Matrix4f transMatrix = vars.tempMat4;
transMatrix.loadIdentity();
transMatrix.m03 = -location.x;
transMatrix.m13 = -location.y;
transMatrix.m23 = -location.z;
this.multLocal(transMatrix);
- assert TempVars.get().unlock();
+ vars.release();
// transMatrix.multLocal(this);
@@ -744,15 +743,15 @@ public final class Matrix4f implements Savable, Cloneable {
// fb.put(m20).put(m21).put(m22).put(m23);
// fb.put(m30).put(m31).put(m32).put(m33);
// }
-
+
TempVars vars = TempVars.get();
- assert vars.lock();
-
+
+
fillFloatArray(vars.matrixWrite, columnMajor);
fb.put(vars.matrixWrite, 0, 16);
-
- assert vars.unlock();
-
+
+ vars.release();
+
return fb;
}
diff --git a/engine/src/core/com/jme3/math/Quaternion.java b/engine/src/core/com/jme3/math/Quaternion.java
index 5793d21ca..32c44629a 100644
--- a/engine/src/core/com/jme3/math/Quaternion.java
+++ b/engine/src/core/com/jme3/math/Quaternion.java
@@ -1276,12 +1276,11 @@ public final class Quaternion implements Savable, Cloneable {
*/
public void lookAt(Vector3f direction, Vector3f up) {
TempVars vars = TempVars.get();
- assert vars.lock();
vars.vect3.set(direction).normalizeLocal();
vars.vect1.set(up).crossLocal(direction).normalizeLocal();
vars.vect2.set(direction).crossLocal(vars.vect1).normalizeLocal();
fromAxes(vars.vect1, vars.vect2, vars.vect3);
- assert vars.unlock();
+ vars.release();
}
public void write(JmeExporter e) throws IOException {
diff --git a/engine/src/core/com/jme3/math/Ray.java b/engine/src/core/com/jme3/math/Ray.java
index 9adfc70d5..c37c53fb8 100644
--- a/engine/src/core/com/jme3/math/Ray.java
+++ b/engine/src/core/com/jme3/math/Ray.java
@@ -29,7 +29,6 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
package com.jme3.math;
import com.jme3.bounding.BoundingVolume;
@@ -45,7 +44,6 @@ import com.jme3.export.Savable;
import com.jme3.util.TempVars;
import java.io.IOException;
-
/**
* Ray
defines a line segment which has an origin and a direction.
* That is, a point and an infinite ray is cast from this point. The ray is
@@ -57,19 +55,16 @@ import java.io.IOException;
public final class Ray implements Savable, Cloneable, Collidable {
//todo: merge with Line?
-
/** The ray's begining point. */
public Vector3f origin;
/** The direction of the ray. */
public Vector3f direction;
-
public float limit = Float.POSITIVE_INFINITY;
-
+
// protected static final Vector3f tempVa=new Vector3f();
// protected static final Vector3f tempVb=new Vector3f();
// protected static final Vector3f tempVc=new Vector3f();
// protected static final Vector3f tempVd=new Vector3f();
-
/**
* Constructor instantiates a new Ray
object. As default, the
* origin is (0,0,0) and the direction is (0,0,0).
@@ -99,7 +94,6 @@ public final class Ray implements Savable, Cloneable, Collidable {
// public boolean intersect(Triangle t) {
// return intersect(t.get(0), t.get(1), t.get(2));
// }
-
/**
* intersect
determines if the Ray intersects a triangle
* defined by the specified points.
@@ -115,7 +109,6 @@ public final class Ray implements Savable, Cloneable, Collidable {
// public boolean intersect(Vector3f v0,Vector3f v1,Vector3f v2){
// return intersectWhere(v0, v1, v2, null);
// }
-
/**
* intersectWhere
determines if the Ray intersects a triangle. It then
* stores the point of intersection in the given loc vector
@@ -146,8 +139,8 @@ public final class Ray implements Savable, Cloneable, Collidable {
* @return true if the ray collides.
*/
public boolean intersectWhere(Vector3f v0, Vector3f v1, Vector3f v2,
- Vector3f loc) {
- return intersects(v0, v1, v2, loc, false, false );
+ Vector3f loc) {
+ return intersects(v0, v1, v2, loc, false, false);
}
/**
@@ -186,8 +179,8 @@ public final class Ray implements Savable, Cloneable, Collidable {
* @return true if the ray collides.
*/
public boolean intersectWherePlanar(Vector3f v0, Vector3f v1, Vector3f v2,
- Vector3f loc) {
- return intersects(v0, v1, v2, loc, true, false );
+ Vector3f loc) {
+ return intersects(v0, v1, v2, loc, true, false);
}
/**
@@ -206,15 +199,14 @@ public final class Ray implements Savable, Cloneable, Collidable {
* @param quad
* @return true if ray intersects triangle
*/
- private boolean intersects( Vector3f v0, Vector3f v1, Vector3f v2,
- Vector3f store, boolean doPlanar, boolean quad ) {
+ private boolean intersects(Vector3f v0, Vector3f v1, Vector3f v2,
+ Vector3f store, boolean doPlanar, boolean quad) {
TempVars vars = TempVars.get();
- assert vars.lock();
Vector3f tempVa = vars.vect1,
- tempVb = vars.vect2,
- tempVc = vars.vect3,
- tempVd = vars.vect4;
+ tempVb = vars.vect2,
+ tempVc = vars.vect3,
+ tempVd = vars.vect4;
Vector3f diff = origin.subtract(v0, tempVa);
Vector3f edge1 = v1.subtract(v0, tempVb);
@@ -230,7 +222,7 @@ public final class Ray implements Savable, Cloneable, Collidable {
dirDotNorm = -dirDotNorm;
} else {
// ray and triangle/quad are parallel
- assert vars.unlock();
+ vars.release();
return false;
}
@@ -240,16 +232,17 @@ public final class Ray implements Savable, Cloneable, Collidable {
* direction.dot(edge1.crossLocal(diff));
if (dirDotEdge1xDiff >= 0.0f) {
- if ( !quad ? dirDotDiffxEdge2 + dirDotEdge1xDiff <= dirDotNorm : dirDotEdge1xDiff <= dirDotNorm ) {
+ if (!quad ? dirDotDiffxEdge2 + dirDotEdge1xDiff <= dirDotNorm : dirDotEdge1xDiff <= dirDotNorm) {
float diffDotNorm = -sign * diff.dot(norm);
if (diffDotNorm >= 0.0f) {
// this method always returns
- assert vars.unlock();
-
+ vars.release();
+
// ray intersects triangle
// if storage vector is null, just return true,
- if (store == null)
+ if (store == null) {
return true;
+ }
// else fill in.
float inv = 1f / dirDotNorm;
@@ -273,11 +266,11 @@ public final class Ray implements Savable, Cloneable, Collidable {
}
}
}
- assert vars.unlock();
+ vars.release();
return false;
}
- public float intersects(Vector3f v0, Vector3f v1, Vector3f v2){
+ public float intersects(Vector3f v0, Vector3f v1, Vector3f v2) {
float edge1X = v1.x - v0.x;
float edge1Y = v1.y - v0.y;
float edge1Z = v1.z - v0.z;
@@ -312,8 +305,8 @@ public final class Ray implements Savable, Cloneable, Collidable {
float diffEdge2Z = ((diffX * edge2Y) - (diffY * edge2X));
float dirDotDiffxEdge2 = sign * (direction.x * diffEdge2X
- + direction.y * diffEdge2Y
- + direction.z * diffEdge2Z);
+ + direction.y * diffEdge2Y
+ + direction.z * diffEdge2Z);
if (dirDotDiffxEdge2 >= 0.0f) {
diffEdge2X = ((edge1Y * diffZ) - (edge1Z * diffY));
@@ -321,8 +314,8 @@ public final class Ray implements Savable, Cloneable, Collidable {
diffEdge2Z = ((edge1X * diffY) - (edge1Y * diffX));
float dirDotEdge1xDiff = sign * (direction.x * diffEdge2X
- + direction.y * diffEdge2Y
- + direction.z * diffEdge2Z);
+ + direction.y * diffEdge2Y
+ + direction.z * diffEdge2Z);
if (dirDotEdge1xDiff >= 0.0f) {
if (dirDotDiffxEdge2 + dirDotEdge1xDiff <= dirDotNorm) {
@@ -364,10 +357,10 @@ public final class Ray implements Savable, Cloneable, Collidable {
* @return true if the ray collides with the quad.
*/
public boolean intersectWherePlanarQuad(Vector3f v0, Vector3f v1, Vector3f v2,
- Vector3f loc) {
- return intersects( v0, v1, v2, loc, true, true );
+ Vector3f loc) {
+ return intersects(v0, v1, v2, loc, true, true);
}
-
+
/**
*
* @param p
@@ -377,57 +370,57 @@ public final class Ray implements Savable, Cloneable, Collidable {
public boolean intersectsWherePlane(Plane p, Vector3f loc) {
float denominator = p.getNormal().dot(direction);
- if (denominator > -FastMath.FLT_EPSILON && denominator < FastMath.FLT_EPSILON)
+ if (denominator > -FastMath.FLT_EPSILON && denominator < FastMath.FLT_EPSILON) {
return false; // coplanar
-
+ }
float numerator = -(p.getNormal().dot(origin) - p.getConstant());
float ratio = numerator / denominator;
- if (ratio < FastMath.FLT_EPSILON)
+ if (ratio < FastMath.FLT_EPSILON) {
return false; // intersects behind origin
-
+ }
loc.set(direction).multLocal(ratio).addLocal(origin);
return true;
}
- public int collideWith(Collidable other, CollisionResults results){
- if (other instanceof BoundingVolume){
+ public int collideWith(Collidable other, CollisionResults results) {
+ if (other instanceof BoundingVolume) {
BoundingVolume bv = (BoundingVolume) other;
return bv.collideWith(this, results);
- }else if (other instanceof AbstractTriangle){
+ } else if (other instanceof AbstractTriangle) {
AbstractTriangle tri = (AbstractTriangle) other;
float d = intersects(tri.get1(), tri.get2(), tri.get3());
- if (Float.isInfinite(d) || Float.isNaN(d))
+ if (Float.isInfinite(d) || Float.isNaN(d)) {
return 0;
+ }
Vector3f point = new Vector3f(direction).multLocal(d).addLocal(origin);
results.addCollision(new CollisionResult(point, d));
return 1;
- }else{
+ } else {
throw new UnsupportedCollisionException();
}
}
public float distanceSquared(Vector3f point) {
TempVars vars = TempVars.get();
- assert vars.lock();
Vector3f tempVa = vars.vect1,
- tempVb = vars.vect2;
+ tempVb = vars.vect2;
point.subtract(origin, tempVa);
float rayParam = direction.dot(tempVa);
- if (rayParam > 0){
+ if (rayParam > 0) {
origin.add(direction.mult(rayParam, tempVb), tempVb);
- }else{
+ } else {
tempVb.set(origin);
rayParam = 0.0f;
}
tempVb.subtract(point, tempVa);
float len = tempVa.lengthSquared();
- assert vars.unlock();
+ vars.release();
return len;
}
@@ -457,7 +450,7 @@ public final class Ray implements Savable, Cloneable, Collidable {
*
* @return the limit or the ray, aka the length.
*/
- public float getLimit(){
+ public float getLimit() {
return limit;
}
@@ -466,7 +459,7 @@ public final class Ray implements Savable, Cloneable, Collidable {
* @param limit the limit of the ray.
* @see Ray#getLimit()
*/
- public void setLimit(float limit){
+ public void setLimit(float limit) {
this.limit = limit;
}
@@ -499,8 +492,8 @@ public final class Ray implements Savable, Cloneable, Collidable {
direction.set(source.getDirection());
}
- public String toString(){
- return getClass().getSimpleName()+" [Origin: "+origin+", Direction: "+direction+"]";
+ public String toString() {
+ return getClass().getSimpleName() + " [Origin: " + origin + ", Direction: " + direction + "]";
}
public void write(JmeExporter e) throws IOException {
@@ -511,10 +504,10 @@ public final class Ray implements Savable, Cloneable, Collidable {
public void read(JmeImporter e) throws IOException {
InputCapsule capsule = e.getCapsule(this);
- origin = (Vector3f)capsule.readSavable("origin", Vector3f.ZERO.clone());
- direction = (Vector3f)capsule.readSavable("direction", Vector3f.ZERO.clone());
+ origin = (Vector3f) capsule.readSavable("origin", Vector3f.ZERO.clone());
+ direction = (Vector3f) capsule.readSavable("direction", Vector3f.ZERO.clone());
}
-
+
@Override
public Ray clone() {
try {
@@ -527,4 +520,3 @@ public final class Ray implements Savable, Cloneable, Collidable {
}
}
}
-
diff --git a/engine/src/core/com/jme3/renderer/Camera.java b/engine/src/core/com/jme3/renderer/Camera.java
index 6c0cee002..5c787c7c6 100644
--- a/engine/src/core/com/jme3/renderer/Camera.java
+++ b/engine/src/core/com/jme3/renderer/Camera.java
@@ -98,7 +98,6 @@ public class Camera implements Savable, Cloneable {
*/
Intersects;
}
-
/**
* LEFT_PLANE represents the left plane of the camera frustum.
*/
@@ -131,7 +130,6 @@ public class Camera implements Savable, Cloneable {
* MAX_WORLD_PLANES holds the maximum planes allowed by the system.
*/
private static final int MAX_WORLD_PLANES = 6;
-
/**
* Camera's location
*/
@@ -164,14 +162,12 @@ public class Camera implements Savable, Cloneable {
* Distance from camera to bottom frustum plane.
*/
protected float frustumBottom;
-
//Temporary values computed in onFrustumChange that are needed if a
//call is made to onFrameChange.
protected float[] coeffLeft;
protected float[] coeffRight;
protected float[] coeffBottom;
protected float[] coeffTop;
-
//view port coordinates
/**
* Percent value on display where horizontal viewing starts for this camera.
@@ -197,13 +193,11 @@ public class Camera implements Savable, Cloneable {
* Array holding the planes that this camera will check for culling.
*/
protected Plane[] worldPlane;
-
/**
* A mask value set during contains() that allows fast culling of a Node's
* children.
*/
private int planeState;
-
protected int width;
protected int height;
protected boolean viewportChanged = true;
@@ -758,10 +752,9 @@ public class Camera implements Savable, Cloneable {
*/
public void lookAt(Vector3f pos, Vector3f worldUpVector) {
TempVars vars = TempVars.get();
- assert vars.lock();
- Vector3f newDirection = TempVars.get().vect1;
- Vector3f newUp = TempVars.get().vect2;
- Vector3f newLeft = TempVars.get().vect3;
+ Vector3f newDirection = vars.vect1;
+ Vector3f newUp = vars.vect2;
+ Vector3f newLeft = vars.vect3;
newDirection.set(pos).subtractLocal(location).normalizeLocal();
@@ -783,7 +776,7 @@ public class Camera implements Savable, Cloneable {
this.rotation.fromAxes(newLeft, newUp, newDirection);
this.rotation.normalizeLocal();
- assert vars.unlock();
+ vars.release();
onFrameChange();
}
@@ -1285,15 +1278,15 @@ public class Camera implements Savable, Cloneable {
store = new Vector3f();
}
-// assert TempVars.get().lock();
-// Quaternion tmp_quat = TempVars.get().quat1;
+// TempVars vars = vars.lock();
+// Quaternion tmp_quat = vars.quat1;
// tmp_quat.set( worldPosition.x, worldPosition.y, worldPosition.z, 1 );
// viewProjectionMatrix.mult(tmp_quat, tmp_quat);
// tmp_quat.multLocal( 1.0f / tmp_quat.getW() );
// store.x = ( ( tmp_quat.getX() + 1 ) * ( viewPortRight - viewPortLeft ) / 2 + viewPortLeft ) * getWidth();
// store.y = ( ( tmp_quat.getY() + 1 ) * ( viewPortTop - viewPortBottom ) / 2 + viewPortBottom ) * getHeight();
// store.z = ( tmp_quat.getZ() + 1 ) / 2;
-// assert TempVars.get().unlock();
+// vars.release();
float w = viewProjectionMatrix.multProj(worldPosition, store);
store.divideLocal(w);
diff --git a/engine/src/core/com/jme3/renderer/RenderManager.java b/engine/src/core/com/jme3/renderer/RenderManager.java
index f3647db66..692cef024 100644
--- a/engine/src/core/com/jme3/renderer/RenderManager.java
+++ b/engine/src/core/com/jme3/renderer/RenderManager.java
@@ -75,7 +75,6 @@ import java.util.logging.Logger;
public class RenderManager {
private static final Logger logger = Logger.getLogger(RenderManager.class.getName());
-
private Renderer renderer;
private Timer timer;
private ArrayList preViewPorts = new ArrayList();
@@ -344,7 +343,6 @@ public class RenderManager {
public void updateUniformBindings(List params) {
// assums worldMatrix is properly set.
TempVars vars = TempVars.get();
- assert vars.lock();
Matrix4f tempMat4 = vars.tempMat4;
Matrix3f tempMat3 = vars.tempMat3;
@@ -465,7 +463,7 @@ public class RenderManager {
}
}
- assert vars.unlock();
+ vars.release();
}
/**
@@ -579,7 +577,7 @@ public class RenderManager {
public void setHandleTranslucentBucket(boolean handleTranslucentBucket) {
this.handleTranlucentBucket = handleTranslucentBucket;
}
-
+
/**
* Internal use only. Sets the world matrix to use for future
* rendering. This has no effect unless objects are rendered manually
@@ -1167,5 +1165,4 @@ public class RenderManager {
renderViewPort(postViewPorts.get(i), tpf);
}
}
-
}
diff --git a/engine/src/core/com/jme3/scene/Geometry.java b/engine/src/core/com/jme3/scene/Geometry.java
index c7fb669b5..c459c97b8 100644
--- a/engine/src/core/com/jme3/scene/Geometry.java
+++ b/engine/src/core/com/jme3/scene/Geometry.java
@@ -29,7 +29,6 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
package com.jme3.scene;
import com.jme3.asset.AssetNotFoundException;
@@ -60,24 +59,19 @@ import java.util.logging.Logger;
public class Geometry extends Spatial {
private static final Logger logger = Logger.getLogger(Geometry.class.getName());
-
protected Mesh mesh;
-
protected transient int lodLevel = 0;
-
protected Material material;
-
/**
* When true, the geometry's transform will not be applied.
*/
protected boolean ignoreTransform = false;
-
protected transient Matrix4f cachedWorldMat = new Matrix4f();
/**
* Serialization only. Do not use.
*/
- public Geometry(){
+ public Geometry() {
}
/**
@@ -87,7 +81,7 @@ public class Geometry extends Spatial {
*
* @param name The name of this geometry
*/
- public Geometry(String name){
+ public Geometry(String name) {
super(name);
}
@@ -99,10 +93,11 @@ public class Geometry extends Spatial {
* @param name The name of this geometry
* @param mesh The mesh data for this geometry
*/
- public Geometry(String name, Mesh mesh){
+ public Geometry(String name, Mesh mesh) {
this(name);
- if (mesh == null)
+ if (mesh == null) {
throw new NullPointerException();
+ }
this.mesh = mesh;
}
@@ -132,12 +127,14 @@ public class Geometry extends Spatial {
* @param lod The lod level to set
*/
@Override
- public void setLodLevel(int lod){
- if (mesh.getNumLodLevels() == 0)
+ public void setLodLevel(int lod) {
+ if (mesh.getNumLodLevels() == 0) {
throw new IllegalStateException("LOD levels are not set on this mesh");
+ }
- if (lod < 0 || lod >= mesh.getNumLodLevels())
- throw new IllegalArgumentException("LOD level is out of range: "+lod);
+ if (lod < 0 || lod >= mesh.getNumLodLevels()) {
+ throw new IllegalArgumentException("LOD level is out of range: " + lod);
+ }
lodLevel = lod;
}
@@ -147,7 +144,7 @@ public class Geometry extends Spatial {
*
* @return the LOD level set
*/
- public int getLodLevel(){
+ public int getLodLevel() {
return lodLevel;
}
@@ -158,7 +155,7 @@ public class Geometry extends Spatial {
*
* @see Mesh#getVertexCount()
*/
- public int getVertexCount(){
+ public int getVertexCount() {
return mesh.getVertexCount();
}
@@ -169,7 +166,7 @@ public class Geometry extends Spatial {
*
* @see Mesh#getTriangleCount()
*/
- public int getTriangleCount(){
+ public int getTriangleCount() {
return mesh.getTriangleCount();
}
@@ -180,9 +177,10 @@ public class Geometry extends Spatial {
*
* @throws IllegalArgumentException If mesh is null
*/
- public void setMesh(Mesh mesh){
- if (mesh == null)
+ public void setMesh(Mesh mesh) {
+ if (mesh == null) {
throw new IllegalArgumentException();
+ }
this.mesh = mesh;
setBoundRefresh();
@@ -195,7 +193,7 @@ public class Geometry extends Spatial {
*
* @see #setMesh(com.jme3.scene.Mesh)
*/
- public Mesh getMesh(){
+ public Mesh getMesh() {
return mesh;
}
@@ -205,7 +203,7 @@ public class Geometry extends Spatial {
* @param material the material to use for this geometry
*/
@Override
- public void setMaterial(Material material){
+ public void setMaterial(Material material) {
this.material = material;
}
@@ -216,14 +214,14 @@ public class Geometry extends Spatial {
*
* @see #setMaterial(com.jme3.material.Material)
*/
- public Material getMaterial(){
+ public Material getMaterial() {
return material;
}
/**
* @return The bounding volume of the mesh, in model space.
*/
- public BoundingVolume getModelBound(){
+ public BoundingVolume getModelBound() {
return mesh.getBound();
}
@@ -246,22 +244,23 @@ public class Geometry extends Spatial {
@Override
protected void updateWorldBound() {
super.updateWorldBound();
- if (mesh == null)
- throw new NullPointerException("Geometry: "+getName()+" has null mesh");
+ if (mesh == null) {
+ throw new NullPointerException("Geometry: " + getName() + " has null mesh");
+ }
if (mesh.getBound() != null) {
- if (ignoreTransform){
+ if (ignoreTransform) {
// we do not transform the model bound by the world transform,
// just use the model bound as-is
worldBound = mesh.getBound().clone(worldBound);
- }else{
+ } else {
worldBound = mesh.getBound().transform(worldTransform, worldBound);
}
}
}
@Override
- protected void updateWorldTransforms(){
+ protected void updateWorldTransforms() {
super.updateWorldTransforms();
computeWorldMatrix();
@@ -274,7 +273,7 @@ public class Geometry extends Spatial {
* Recomputes the matrix returned by {@link Geometry#getWorldMatrix() }.
* This will require a localized transform update for this geometry.
*/
- public void computeWorldMatrix(){
+ public void computeWorldMatrix() {
// Force a local update of the geometry's transform
checkDoTransformUpdate();
@@ -283,12 +282,12 @@ public class Geometry extends Spatial {
cachedWorldMat.setRotationQuaternion(worldTransform.getRotation());
cachedWorldMat.setTranslation(worldTransform.getTranslation());
- assert TempVars.get().lock();
- Matrix4f scaleMat = TempVars.get().tempMat4;
+ TempVars vars = TempVars.get();
+ Matrix4f scaleMat = vars.tempMat4;
scaleMat.loadIdentity();
scaleMat.scale(worldTransform.getScale());
cachedWorldMat.multLocal(scaleMat);
- assert TempVars.get().unlock();
+ vars.release();
}
/**
@@ -300,7 +299,7 @@ public class Geometry extends Spatial {
*
* @return Matrix to transform from local space to world space
*/
- public Matrix4f getWorldMatrix(){
+ public Matrix4f getWorldMatrix() {
return cachedWorldMat;
}
@@ -319,33 +318,33 @@ public class Geometry extends Spatial {
updateModelBound();
}
- public int collideWith(Collidable other, CollisionResults results){
+ public int collideWith(Collidable other, CollisionResults results) {
// Force bound to update
checkDoBoundUpdate();
// Update transform, and compute cached world matrix
computeWorldMatrix();
-
+
assert (refreshFlags & (RF_BOUND | RF_TRANSFORM)) == 0;
- if (mesh != null){
+ if (mesh != null) {
// NOTE: BIHTree in mesh already checks collision with the
// mesh's bound
int prevSize = results.size();
int added = mesh.collideWith(other, cachedWorldMat, worldBound, results);
int newSize = results.size();
- for (int i = prevSize; i < newSize; i++){
+ for (int i = prevSize; i < newSize; i++) {
results.getCollisionDirect(i).setGeometry(this);
}
return added;
}
return 0;
}
-
+
@Override
public void depthFirstTraversal(SceneGraphVisitor visitor) {
visitor.visit(this);
}
-
+
@Override
protected void breadthFirstTraversal(SceneGraphVisitor visitor, Queue queue) {
}
@@ -358,20 +357,21 @@ public class Geometry extends Spatial {
* and normals are deep copied.
*/
@Override
- public Geometry clone(boolean cloneMaterial){
+ public Geometry clone(boolean cloneMaterial) {
Geometry geomClone = (Geometry) super.clone(cloneMaterial);
geomClone.cachedWorldMat = cachedWorldMat.clone();
- if (material != null){
- if (cloneMaterial)
+ if (material != null) {
+ if (cloneMaterial) {
geomClone.material = material.clone();
- else
+ } else {
geomClone.material = material;
+ }
}
-
- if (mesh != null && mesh.getBuffer(Type.BindPosePosition) != null){
+
+ if (mesh != null && mesh.getBuffer(Type.BindPosePosition) != null) {
geomClone.mesh = mesh.cloneForAnim();
}
-
+
return geomClone;
}
@@ -383,7 +383,7 @@ public class Geometry extends Spatial {
* and normals are deep copied.
*/
@Override
- public Geometry clone(){
+ public Geometry clone() {
return clone(true);
}
@@ -393,7 +393,7 @@ public class Geometry extends Spatial {
* with the vertexbuffer data duplicated.
*/
@Override
- public Spatial deepClone(){
+ public Spatial deepClone() {
Geometry geomClone = clone(true);
geomClone.mesh = mesh.deepClone();
return geomClone;
@@ -404,7 +404,7 @@ public class Geometry extends Spatial {
super.write(ex);
OutputCapsule oc = ex.getCapsule(this);
oc.write(mesh, "mesh", null);
- if (material != null){
+ if (material != null) {
oc.write(material.getAssetName(), "materialName", null);
}
oc.write(material, "material", null);
@@ -419,22 +419,21 @@ public class Geometry extends Spatial {
material = null;
String matName = ic.readString("materialName", null);
- if (matName != null){
+ if (matName != null) {
// Material name is set,
// Attempt to load material via J3M
try {
material = im.getAssetManager().loadMaterial(matName);
- } catch (AssetNotFoundException ex){
+ } catch (AssetNotFoundException ex) {
// Cannot find J3M file.
logger.log(Level.FINE, "Could not load J3M file {0} for Geometry.",
matName);
}
}
// If material is NULL, try to load it from the geometry
- if (material == null){
+ if (material == null) {
material = (Material) ic.readSavable("material", null);
}
ignoreTransform = ic.readBoolean("ignoreTransform", false);
}
-
}
diff --git a/engine/src/core/com/jme3/scene/Spatial.java b/engine/src/core/com/jme3/scene/Spatial.java
index 217dc27c5..f67984bb5 100644
--- a/engine/src/core/com/jme3/scene/Spatial.java
+++ b/engine/src/core/com/jme3/scene/Spatial.java
@@ -82,7 +82,7 @@ public abstract class Spatial implements Savable, Cloneable, Collidable {
* this spatial.
*/
public enum CullHint {
-
+
/**
* Do whatever our parent does. If no parent, default to {@link #Dynamic}.
*/
@@ -340,7 +340,6 @@ public abstract class Spatial implements Savable, Cloneable, Collidable {
*/
public void rotateUpTo(Vector3f newUp) {
TempVars vars = TempVars.get();
- assert vars.lock();
Vector3f compVecA = vars.vect1;
Quaternion q = vars.quat1;
@@ -360,7 +359,7 @@ public abstract class Spatial implements Savable, Cloneable, Collidable {
q.fromAngleNormalAxis(angle, rotAxis);
q.mult(rot, rot);
- assert vars.unlock();
+ vars.release();
setTransformRefresh();
}
@@ -382,9 +381,9 @@ public abstract class Spatial implements Savable, Cloneable, Collidable {
Vector3f worldTranslation = getWorldTranslation();
TempVars vars = TempVars.get();
- assert vars.lock();
+
Vector3f compVecA = vars.vect4;
- assert vars.unlock();
+ vars.release();
compVecA.set(position).subtractLocal(worldTranslation);
getLocalRotation().lookAt(compVecA, upVector);
@@ -448,7 +447,6 @@ public abstract class Spatial implements Savable, Cloneable, Collidable {
refreshFlags &= ~RF_TRANSFORM;
} else {
TempVars vars = TempVars.get();
- assert vars.lock();
Spatial[] stack = vars.spatialStack;
Spatial rootNode = this;
@@ -472,7 +470,7 @@ public abstract class Spatial implements Savable, Cloneable, Collidable {
i++;
}
- assert vars.unlock();
+ vars.release();
for (int j = i; j >= 0; j--) {
rootNode = stack[j];
@@ -978,11 +976,11 @@ public abstract class Spatial implements Savable, Cloneable, Collidable {
* @return The spatial on which this method is called, e.g this
.
*/
public Spatial rotate(float yaw, float roll, float pitch) {
- assert TempVars.get().lock();
- Quaternion q = TempVars.get().quat1;
+ TempVars vars = TempVars.get();
+ Quaternion q = vars.quat1;
q.fromAngles(yaw, roll, pitch);
rotate(q);
- assert TempVars.get().unlock();
+ vars.release();
return this;
}
@@ -1268,7 +1266,7 @@ public abstract class Spatial implements Savable, Cloneable, Collidable {
//When backward compatibility won't be needed anymore this can be replaced by :
//controls = ic.readSavableArrayList("controlsList", null));
controls.addAll(0, ic.readSavableArrayList("controlsList", null));
-
+
userData = (HashMap) ic.readStringSavableMap("user_data", null);
}
diff --git a/engine/src/core/com/jme3/scene/control/CameraControl.java b/engine/src/core/com/jme3/scene/control/CameraControl.java
index 602323f5c..5dd559c27 100644
--- a/engine/src/core/com/jme3/scene/control/CameraControl.java
+++ b/engine/src/core/com/jme3/scene/control/CameraControl.java
@@ -116,7 +116,6 @@ public class CameraControl extends AbstractControl {
// set the localtransform, so that the worldtransform would be equal to the camera's transform.
// Location:
TempVars vars = TempVars.get();
- assert vars.lock();
Vector3f vecDiff = vars.vect1.set(camera.getLocation()).subtractLocal(spatial.getWorldTranslation());
spatial.setLocalTranslation(vecDiff.addLocal(spatial.getLocalTranslation()));
@@ -124,7 +123,7 @@ public class CameraControl extends AbstractControl {
// Rotation:
Quaternion worldDiff = vars.quat1.set(camera.getRotation()).subtractLocal(spatial.getWorldRotation());
spatial.setLocalRotation(worldDiff.addLocal(spatial.getLocalRotation()));
- assert vars.unlock();
+ vars.release();
break;
}
}
diff --git a/engine/src/core/com/jme3/scene/control/LightControl.java b/engine/src/core/com/jme3/scene/control/LightControl.java
index 226515974..a51539534 100644
--- a/engine/src/core/com/jme3/scene/control/LightControl.java
+++ b/engine/src/core/com/jme3/scene/control/LightControl.java
@@ -126,12 +126,11 @@ public class LightControl extends AbstractControl {
((PointLight) light).setPosition(spatial.getWorldTranslation());
}
TempVars vars = TempVars.get();
- assert vars.lock();
if (light instanceof DirectionalLight) {
((DirectionalLight) light).setDirection(vars.vect1.set(spatial.getWorldTranslation()).multLocal(-1.0f));
}
- assert vars.unlock();
+ vars.release();
//TODO add code for Spot light here when it's done
// if( light instanceof SpotLight){
// ((SpotLight)light).setPosition(spatial.getWorldTranslation());
@@ -142,15 +141,12 @@ public class LightControl extends AbstractControl {
private void lightToSpatial(Light light) {
TempVars vars = TempVars.get();
- assert vars.lock();
if (light instanceof PointLight) {
PointLight pLight = (PointLight) light;
Vector3f vecDiff = vars.vect1.set(pLight.getPosition()).subtractLocal(spatial.getWorldTranslation());
spatial.setLocalTranslation(vecDiff.addLocal(spatial.getLocalTranslation()));
- assert vars.unlock();
-
}
if (light instanceof DirectionalLight) {
@@ -159,7 +155,7 @@ public class LightControl extends AbstractControl {
Vector3f vecDiff = vars.vect1.subtractLocal(spatial.getWorldTranslation());
spatial.setLocalTranslation(vecDiff.addLocal(spatial.getLocalTranslation()));
}
- assert vars.unlock();
+ vars.release();
//TODO add code for Spot light here when it's done
diff --git a/engine/src/core/com/jme3/scene/debug/SkeletonDebugger.java b/engine/src/core/com/jme3/scene/debug/SkeletonDebugger.java
index 5b6592d10..07efdc99c 100644
--- a/engine/src/core/com/jme3/scene/debug/SkeletonDebugger.java
+++ b/engine/src/core/com/jme3/scene/debug/SkeletonDebugger.java
@@ -67,4 +67,14 @@ public class SkeletonDebugger extends Node {
wires.updateGeometry();
points.updateGeometry();
}
+
+ public SkeletonPoints getPoints() {
+ return points;
+ }
+
+ public SkeletonWire getWires() {
+ return wires;
+ }
+
+
}
diff --git a/engine/src/core/com/jme3/scene/shape/Dome.java b/engine/src/core/com/jme3/scene/shape/Dome.java
index 96bc9aac0..b3fa3433c 100644
--- a/engine/src/core/com/jme3/scene/shape/Dome.java
+++ b/engine/src/core/com/jme3/scene/shape/Dome.java
@@ -29,11 +29,9 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
// $Id: Dome.java 4131 2009-03-19 20:15:28Z blaine.dev $
package com.jme3.scene.shape;
-
import com.jme3.scene.*;
import com.jme3.export.JmeImporter;
import com.jme3.export.InputCapsule;
@@ -58,15 +56,11 @@ import java.nio.ShortBuffer;
public class Dome extends Mesh {
private int planes;
-
private int radialSamples;
-
/** The radius of the dome */
private float radius;
-
/** The center of the dome */
private Vector3f center;
-
private boolean outsideView = true;
/**
@@ -202,7 +196,7 @@ public class Dome extends Mesh {
FloatBuffer nb = BufferUtils.createVector3Buffer(vertCount);
FloatBuffer tb = BufferUtils.createVector2Buffer(vertCount);
setBuffer(Type.Position, 3, vb);
- setBuffer(Type.Normal, 3, nb);
+ setBuffer(Type.Normal, 3, nb);
setBuffer(Type.TexCoord, 2, tb);
// generate geometry
@@ -220,7 +214,6 @@ public class Dome extends Mesh {
}
TempVars vars = TempVars.get();
- assert vars.lock();
Vector3f tempVc = vars.vect3;
Vector3f tempVb = vars.vect2;
Vector3f tempVa = vars.vect1;
@@ -251,10 +244,11 @@ public class Dome extends Mesh {
BufferUtils.populateFromBuffer(tempVa, vb, i);
kNormal = tempVa.subtractLocal(center);
kNormal.normalizeLocal();
- if (outsideView)
+ if (outsideView) {
nb.put(kNormal.x).put(kNormal.y).put(kNormal.z);
- else
+ } else {
nb.put(-kNormal.x).put(-kNormal.y).put(-kNormal.z);
+ }
tb.put(fRadialFraction).put(fYFraction);
}
@@ -263,7 +257,7 @@ public class Dome extends Mesh {
tb.put(1.0f).put(fYFraction);
}
- assert vars.unlock();
+ vars.release();
// pole
vb.put(center.x).put(center.y + radius).put(center.z);
@@ -274,7 +268,7 @@ public class Dome extends Mesh {
int triCount = (planes - 2) * radialSamples * 2 + radialSamples;
ShortBuffer ib = BufferUtils.createShortBuffer(3 * triCount);
setBuffer(Type.Index, 3, ib);
-
+
// generate connectivity
int index = 0;
// Generate only for middle planes
@@ -282,21 +276,21 @@ public class Dome extends Mesh {
int bottomPlaneStart = ((plane - 1) * (radialSamples + 1));
int topPlaneStart = (plane * (radialSamples + 1));
for (int sample = 0; sample < radialSamples; sample++, index += 6) {
- ib.put((short)(bottomPlaneStart + sample));
- ib.put((short)(topPlaneStart + sample));
- ib.put((short)(bottomPlaneStart + sample + 1));
- ib.put((short)(bottomPlaneStart + sample + 1));
- ib.put((short)(topPlaneStart + sample));
- ib.put((short)(topPlaneStart + sample + 1));
+ ib.put((short) (bottomPlaneStart + sample));
+ ib.put((short) (topPlaneStart + sample));
+ ib.put((short) (bottomPlaneStart + sample + 1));
+ ib.put((short) (bottomPlaneStart + sample + 1));
+ ib.put((short) (topPlaneStart + sample));
+ ib.put((short) (topPlaneStart + sample + 1));
}
}
// pole triangles
int bottomPlaneStart = (planes - 2) * (radialSamples + 1);
for (int samples = 0; samples < radialSamples; samples++, index += 3) {
- ib.put((short)(bottomPlaneStart + samples));
- ib.put((short)(vertCount - 1));
- ib.put((short)(bottomPlaneStart + samples + 1));
+ ib.put((short) (bottomPlaneStart + samples));
+ ib.put((short) (vertCount - 1));
+ ib.put((short) (bottomPlaneStart + samples + 1));
}
updateBound();
@@ -321,5 +315,4 @@ public class Dome extends Mesh {
capsule.write(radius, "radius", 0);
capsule.write(center, "center", Vector3f.ZERO);
}
-
}
\ No newline at end of file
diff --git a/engine/src/core/com/jme3/scene/shape/Sphere.java b/engine/src/core/com/jme3/scene/shape/Sphere.java
index 8f0ace85a..caea209ac 100644
--- a/engine/src/core/com/jme3/scene/shape/Sphere.java
+++ b/engine/src/core/com/jme3/scene/shape/Sphere.java
@@ -29,7 +29,6 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
// $Id: Sphere.java 4163 2009-03-25 01:14:55Z matt.yellen $
package com.jme3.scene.shape;
@@ -47,7 +46,6 @@ import java.io.IOException;
import java.nio.FloatBuffer;
import java.nio.ShortBuffer;
-
/**
* Sphere
represents a 3D object with all points equidistance
* from a center point.
@@ -58,6 +56,7 @@ import java.nio.ShortBuffer;
public class Sphere extends Mesh {
public enum TextureMode {
+
/**
* Wrap texture radially and along z-axis
*/
@@ -72,28 +71,20 @@ public class Sphere extends Mesh {
*/
Polar
}
-
protected int vertCount;
-
protected int triCount;
-
protected int zSamples;
-
protected int radialSamples;
-
protected boolean useEvenSlices;
-
protected boolean interior;
-
/** the distance from the center point each point falls on */
public float radius;
-
protected TextureMode textureMode = TextureMode.Original;
/**
* Serialization only. Do not use.
*/
- public Sphere(){
+ public Sphere() {
}
/**
@@ -165,7 +156,7 @@ public class Sphere extends Mesh {
FloatBuffer texBuf = BufferUtils.createVector2Buffer(vertCount);
setBuffer(Type.Position, 3, posBuf);
- setBuffer(Type.Normal, 3, normBuf);
+ setBuffer(Type.Normal, 3, normBuf);
setBuffer(Type.TexCoord, 2, texBuf);
// generate geometry
@@ -185,7 +176,6 @@ public class Sphere extends Mesh {
afCos[radialSamples] = afCos[0];
TempVars vars = TempVars.get();
- assert vars.lock();
Vector3f tempVa = vars.vect1;
Vector3f tempVb = vars.vect2;
Vector3f tempVc = vars.vect3;
@@ -195,11 +185,11 @@ public class Sphere extends Mesh {
for (int iZ = 1; iZ < (zSamples - 1); iZ++) {
float fAFraction = FastMath.HALF_PI * (-1.0f + fZFactor * iZ); // in (-pi/2, pi/2)
float fZFraction;
- if (useEvenSlices)
+ if (useEvenSlices) {
fZFraction = -1.0f + fZFactor * iZ; // in (-1, 1)
- else
+ } else {
fZFraction = FastMath.sin(fAFraction); // in (-1,1)
-
+ }
float fZ = radius * fZFraction;
// compute center of slice
@@ -218,28 +208,29 @@ public class Sphere extends Mesh {
Vector3f kRadial = tempVc.set(afCos[iR], afSin[iR], 0);
kRadial.mult(fSliceRadius, tempVa);
posBuf.put(kSliceCenter.x + tempVa.x).put(
- kSliceCenter.y + tempVa.y).put(
- kSliceCenter.z + tempVa.z);
+ kSliceCenter.y + tempVa.y).put(
+ kSliceCenter.z + tempVa.z);
BufferUtils.populateFromBuffer(tempVa, posBuf, i);
kNormal = tempVa;
kNormal.normalizeLocal();
if (!interior) // allow interior texture vs. exterior
+ {
normBuf.put(kNormal.x).put(kNormal.y).put(
kNormal.z);
- else
+ } else {
normBuf.put(-kNormal.x).put(-kNormal.y).put(
-kNormal.z);
+ }
- if (textureMode == TextureMode.Original)
+ if (textureMode == TextureMode.Original) {
texBuf.put(fRadialFraction).put(
0.5f * (fZFraction + 1.0f));
- else if (textureMode == TextureMode.Projected)
+ } else if (textureMode == TextureMode.Projected) {
texBuf.put(fRadialFraction).put(
FastMath.INV_PI
- * (FastMath.HALF_PI + FastMath
- .asin(fZFraction)));
- else if (textureMode == TextureMode.Polar) {
+ * (FastMath.HALF_PI + FastMath.asin(fZFraction)));
+ } else if (textureMode == TextureMode.Polar) {
float r = (FastMath.HALF_PI - FastMath.abs(fAFraction)) / FastMath.PI;
float u = r * afCos[iR] + 0.5f;
float v = r * afSin[iR] + 0.5f;
@@ -252,43 +243,41 @@ public class Sphere extends Mesh {
BufferUtils.copyInternalVector3(posBuf, iSave, i);
BufferUtils.copyInternalVector3(normBuf, iSave, i);
- if (textureMode == TextureMode.Original)
+ if (textureMode == TextureMode.Original) {
texBuf.put(1.0f).put(
0.5f * (fZFraction + 1.0f));
- else if (textureMode == TextureMode.Projected)
- texBuf.put(1.0f)
- .put(
- FastMath.INV_PI
- * (FastMath.HALF_PI + FastMath
- .asin(fZFraction)));
- else if (textureMode == TextureMode.Polar) {
+ } else if (textureMode == TextureMode.Projected) {
+ texBuf.put(1.0f).put(
+ FastMath.INV_PI
+ * (FastMath.HALF_PI + FastMath.asin(fZFraction)));
+ } else if (textureMode == TextureMode.Polar) {
float r = (FastMath.HALF_PI - FastMath.abs(fAFraction)) / FastMath.PI;
- texBuf.put(r+0.5f).put(0.5f);
+ texBuf.put(r + 0.5f).put(0.5f);
}
i++;
}
- assert vars.unlock();
+ vars.release();
// south pole
posBuf.position(i * 3);
posBuf.put(0f).put(0f).put(-radius);
normBuf.position(i * 3);
- if (!interior)
+ if (!interior) {
normBuf.put(0).put(0).put(-1); // allow for inner
- // texture orientation
- // later.
- else
+ } // texture orientation
+ // later.
+ else {
normBuf.put(0).put(0).put(1);
+ }
texBuf.position(i * 2);
if (textureMode == TextureMode.Polar) {
texBuf.put(0.5f).put(0.5f);
- }
- else {
+ } else {
texBuf.put(0.5f).put(0.0f);
}
@@ -297,10 +286,11 @@ public class Sphere extends Mesh {
// north pole
posBuf.put(0).put(0).put(radius);
- if (!interior)
+ if (!interior) {
normBuf.put(0).put(0).put(1);
- else
+ } else {
normBuf.put(0).put(0).put(-1);
+ }
if (textureMode == TextureMode.Polar) {
texBuf.put(0.5f).put(0.5f);
@@ -331,19 +321,19 @@ public class Sphere extends Mesh {
int i3 = i2 + 1;
for (int i = 0; i < radialSamples; i++, index += 6) {
if (!interior) {
- idxBuf.put((short)i0++);
- idxBuf.put((short)i1);
- idxBuf.put((short)i2);
- idxBuf.put((short)i1++);
- idxBuf.put((short)i3++);
- idxBuf.put((short)i2++);
+ idxBuf.put((short) i0++);
+ idxBuf.put((short) i1);
+ idxBuf.put((short) i2);
+ idxBuf.put((short) i1++);
+ idxBuf.put((short) i3++);
+ idxBuf.put((short) i2++);
} else { // inside view
- idxBuf.put((short)i0++);
- idxBuf.put((short)i2);
- idxBuf.put((short)i1);
- idxBuf.put((short)i1++);
- idxBuf.put((short)i2++);
- idxBuf.put((short)i3++);
+ idxBuf.put((short) i0++);
+ idxBuf.put((short) i2);
+ idxBuf.put((short) i1);
+ idxBuf.put((short) i1++);
+ idxBuf.put((short) i2++);
+ idxBuf.put((short) i3++);
}
}
}
@@ -351,13 +341,13 @@ public class Sphere extends Mesh {
// south pole triangles
for (int i = 0; i < radialSamples; i++, index += 3) {
if (!interior) {
- idxBuf.put((short)i);
- idxBuf.put((short)(vertCount - 2));
- idxBuf.put((short)(i + 1));
+ idxBuf.put((short) i);
+ idxBuf.put((short) (vertCount - 2));
+ idxBuf.put((short) (i + 1));
} else { // inside view
- idxBuf.put((short)i);
- idxBuf.put((short)(i + 1));
- idxBuf.put((short)(vertCount - 2));
+ idxBuf.put((short) i);
+ idxBuf.put((short) (i + 1));
+ idxBuf.put((short) (vertCount - 2));
}
}
@@ -365,13 +355,13 @@ public class Sphere extends Mesh {
int iOffset = (zSamples - 3) * (radialSamples + 1);
for (int i = 0; i < radialSamples; i++, index += 3) {
if (!interior) {
- idxBuf.put((short)(i + iOffset));
- idxBuf.put((short)(i + 1 + iOffset));
- idxBuf.put((short)(vertCount - 1));
+ idxBuf.put((short) (i + iOffset));
+ idxBuf.put((short) (i + 1 + iOffset));
+ idxBuf.put((short) (vertCount - 1));
} else { // inside view
- idxBuf.put((short)(i + iOffset));
- idxBuf.put((short)(vertCount - 1));
- idxBuf.put((short)(i + 1 + iOffset));
+ idxBuf.put((short) (i + iOffset));
+ idxBuf.put((short) (vertCount - 1));
+ idxBuf.put((short) (i + 1 + iOffset));
}
}
}
@@ -427,5 +417,4 @@ public class Sphere extends Mesh {
capsule.write(textureMode, "textureMode", TextureMode.Original);
capsule.write(interior, "interior", false);
}
-
}
diff --git a/engine/src/core/com/jme3/util/BufferUtils.java b/engine/src/core/com/jme3/util/BufferUtils.java
index d8f3e52f2..a9cea5eca 100644
--- a/engine/src/core/com/jme3/util/BufferUtils.java
+++ b/engine/src/core/com/jme3/util/BufferUtils.java
@@ -29,7 +29,6 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
package com.jme3.util;
import com.jme3.math.ColorRGBA;
@@ -48,7 +47,6 @@ import java.util.Collections;
import java.util.Map;
import java.util.WeakHashMap;
-
/**
* BufferUtils
is a helper class for generating nio buffers from
* jME data classes such as Vectors and ColorRGBA.
@@ -62,14 +60,12 @@ public final class BufferUtils {
// private static final Vector2f _tempVec2 = new Vector2f();
// private static final Vector3f _tempVec3 = new Vector3f();
// private static final ColorRGBA _tempColor = new ColorRGBA();
-
//// -- TRACKER HASH -- ////
private static final Map trackingHash = Collections.synchronizedMap(new WeakHashMap());
private static final Object ref = new Object();
private static final boolean trackDirectMemory = false;
//// -- GENERIC CLONE -- ////
-
/**
* Creates a clone of the given buffer. The clone's capacity is
* equal to the given buffer's limit.
@@ -77,25 +73,23 @@ public final class BufferUtils {
* @param buf The buffer to clone
* @return The cloned buffer
*/
- public static Buffer clone(Buffer buf){
- if (buf instanceof FloatBuffer){
- return clone( (FloatBuffer) buf );
- }else if (buf instanceof ShortBuffer){
- return clone( (ShortBuffer) buf );
- }else if (buf instanceof ByteBuffer){
- return clone( (ByteBuffer) buf );
- }else if (buf instanceof IntBuffer){
- return clone( (IntBuffer) buf );
- }else if (buf instanceof DoubleBuffer){
- return clone( (DoubleBuffer) buf );
- }else{
+ public static Buffer clone(Buffer buf) {
+ if (buf instanceof FloatBuffer) {
+ return clone((FloatBuffer) buf);
+ } else if (buf instanceof ShortBuffer) {
+ return clone((ShortBuffer) buf);
+ } else if (buf instanceof ByteBuffer) {
+ return clone((ByteBuffer) buf);
+ } else if (buf instanceof IntBuffer) {
+ return clone((IntBuffer) buf);
+ } else if (buf instanceof DoubleBuffer) {
+ return clone((DoubleBuffer) buf);
+ } else {
throw new UnsupportedOperationException();
}
}
-
//// -- VECTOR3F METHODS -- ////
-
/**
* Generate a new FloatBuffer using the given array of Vector3f objects.
* The FloatBuffer will be 3 * data.length long and contain the vector data
@@ -103,14 +97,17 @@ public final class BufferUtils {
*
* @param data array of Vector3f objects to place into a new FloatBuffer
*/
- public static FloatBuffer createFloatBuffer(Vector3f ... data) {
- if (data == null) return null;
+ public static FloatBuffer createFloatBuffer(Vector3f... data) {
+ if (data == null) {
+ return null;
+ }
FloatBuffer buff = createFloatBuffer(3 * data.length);
for (int x = 0; x < data.length; x++) {
- if (data[x] != null)
+ if (data[x] != null) {
buff.put(data[x].x).put(data[x].y).put(data[x].z);
- else
+ } else {
buff.put(0).put(0).put(0);
+ }
}
buff.flip();
return buff;
@@ -122,15 +119,17 @@ public final class BufferUtils {
*
* @param data array of Quaternion objects to place into a new FloatBuffer
*/
- public static FloatBuffer createFloatBuffer(Quaternion ... data) {
- if (data == null) return null;
+ public static FloatBuffer createFloatBuffer(Quaternion... data) {
+ if (data == null) {
+ return null;
+ }
FloatBuffer buff = createFloatBuffer(4 * data.length);
for (int x = 0; x < data.length; x++) {
- if (data[x] != null)
- buff.put(data[x].getX()).put(data[x].getY())
- .put(data[x].getZ()).put(data[x].getW());
- else
+ if (data[x] != null) {
+ buff.put(data[x].getX()).put(data[x].getY()).put(data[x].getZ()).put(data[x].getW());
+ } else {
buff.put(0).put(0).put(0);
+ }
}
buff.flip();
return buff;
@@ -140,8 +139,10 @@ public final class BufferUtils {
* Generate a new FloatBuffer using the given array of float primitives.
* @param data array of float primitives to place into a new FloatBuffer
*/
- public static FloatBuffer createFloatBuffer(float ... data) {
- if (data == null) return null;
+ public static FloatBuffer createFloatBuffer(float... data) {
+ if (data == null) {
+ return null;
+ }
FloatBuffer buff = createFloatBuffer(data.length);
buff.clear();
buff.put(data);
@@ -197,7 +198,7 @@ public final class BufferUtils {
*/
public static void setInBuffer(ColorRGBA color, FloatBuffer buf,
int index) {
- buf.position(index*4);
+ buf.position(index * 4);
buf.put(color.r);
buf.put(color.g);
buf.put(color.b);
@@ -217,7 +218,7 @@ public final class BufferUtils {
*/
public static void setInBuffer(Quaternion quat, FloatBuffer buf,
int index) {
- buf.position(index*4);
+ buf.position(index * 4);
buf.put(quat.getX());
buf.put(quat.getY());
buf.put(quat.getZ());
@@ -236,17 +237,17 @@ public final class BufferUtils {
* the postion to place the data; in terms of vectors not floats
*/
public static void setInBuffer(Vector3f vector, FloatBuffer buf, int index) {
- if(buf == null) {
- return;
- }
- if(vector == null) {
- buf.put(index * 3, 0);
+ if (buf == null) {
+ return;
+ }
+ if (vector == null) {
+ buf.put(index * 3, 0);
buf.put((index * 3) + 1, 0);
buf.put((index * 3) + 2, 0);
} else {
- buf.put(index * 3, vector.x);
- buf.put((index * 3) + 1, vector.y);
- buf.put((index * 3) + 2, vector.z);
+ buf.put(index * 3, vector.x);
+ buf.put((index * 3) + 1, vector.y);
+ buf.put((index * 3) + 2, vector.z);
}
}
@@ -263,9 +264,9 @@ public final class BufferUtils {
* the buf
*/
public static void populateFromBuffer(Vector3f vector, FloatBuffer buf, int index) {
- vector.x = buf.get(index*3);
- vector.y = buf.get(index*3+1);
- vector.z = buf.get(index*3+2);
+ vector.x = buf.get(index * 3);
+ vector.y = buf.get(index * 3 + 1);
+ vector.z = buf.get(index * 3 + 2);
}
/**
@@ -298,7 +299,7 @@ public final class BufferUtils {
* the index to copy the vector to
*/
public static void copyInternalVector3(FloatBuffer buf, int fromPos, int toPos) {
- copyInternal(buf, fromPos*3, toPos*3, 3);
+ copyInternal(buf, fromPos * 3, toPos * 3, 3);
}
/**
@@ -311,12 +312,12 @@ public final class BufferUtils {
* to normalize
*/
public static void normalizeVector3(FloatBuffer buf, int index) {
- assert TempVars.get().lock();
- Vector3f tempVec3 = TempVars.get().vect1;
+ TempVars vars = TempVars.get();
+ Vector3f tempVec3 = vars.vect1;
populateFromBuffer(tempVec3, buf, index);
tempVec3.normalizeLocal();
setInBuffer(tempVec3, buf, index);
- assert TempVars.get().unlock();
+ vars.release();
}
/**
@@ -331,12 +332,12 @@ public final class BufferUtils {
* to add to
*/
public static void addInBuffer(Vector3f toAdd, FloatBuffer buf, int index) {
- assert TempVars.get().lock();
- Vector3f tempVec3 = TempVars.get().vect1;
+ TempVars vars = TempVars.get();
+ Vector3f tempVec3 = vars.vect1;
populateFromBuffer(tempVec3, buf, index);
tempVec3.addLocal(toAdd);
setInBuffer(tempVec3, buf, index);
- assert TempVars.get().unlock();
+ vars.release();
}
/**
@@ -351,12 +352,12 @@ public final class BufferUtils {
* to multiply
*/
public static void multInBuffer(Vector3f toMult, FloatBuffer buf, int index) {
- assert TempVars.get().lock();
- Vector3f tempVec3 = TempVars.get().vect1;
+ TempVars vars = TempVars.get();
+ Vector3f tempVec3 = vars.vect1;
populateFromBuffer(tempVec3, buf, index);
tempVec3.multLocal(toMult);
setInBuffer(tempVec3, buf, index);
- assert TempVars.get().unlock();
+ vars.release();
}
/**
@@ -373,16 +374,15 @@ public final class BufferUtils {
* @return
*/
public static boolean equals(Vector3f check, FloatBuffer buf, int index) {
- assert TempVars.get().lock();
- Vector3f tempVec3 = TempVars.get().vect1;
+ TempVars vars = TempVars.get();
+ Vector3f tempVec3 = vars.vect1;
populateFromBuffer(tempVec3, buf, index);
boolean eq = tempVec3.equals(check);
- assert TempVars.get().unlock();
+ vars.release();
return eq;
}
// // -- VECTOR2F METHODS -- ////
-
/**
* Generate a new FloatBuffer using the given array of Vector2f objects.
* The FloatBuffer will be 2 * data.length long and contain the vector data
@@ -390,14 +390,17 @@ public final class BufferUtils {
*
* @param data array of Vector2f objects to place into a new FloatBuffer
*/
- public static FloatBuffer createFloatBuffer(Vector2f ... data) {
- if (data == null) return null;
+ public static FloatBuffer createFloatBuffer(Vector2f... data) {
+ if (data == null) {
+ return null;
+ }
FloatBuffer buff = createFloatBuffer(2 * data.length);
for (int x = 0; x < data.length; x++) {
- if (data[x] != null)
+ if (data[x] != null) {
buff.put(data[x].x).put(data[x].y);
- else
+ } else {
buff.put(0).put(0);
+ }
}
buff.flip();
return buff;
@@ -467,8 +470,8 @@ public final class BufferUtils {
* the buf
*/
public static void populateFromBuffer(Vector2f vector, FloatBuffer buf, int index) {
- vector.x = buf.get(index*2);
- vector.y = buf.get(index*2+1);
+ vector.x = buf.get(index * 2);
+ vector.y = buf.get(index * 2 + 1);
}
/**
@@ -501,7 +504,7 @@ public final class BufferUtils {
* the index to copy the vector to
*/
public static void copyInternalVector2(FloatBuffer buf, int fromPos, int toPos) {
- copyInternal(buf, fromPos*2, toPos*2, 2);
+ copyInternal(buf, fromPos * 2, toPos * 2, 2);
}
/**
@@ -514,12 +517,12 @@ public final class BufferUtils {
* to normalize
*/
public static void normalizeVector2(FloatBuffer buf, int index) {
- assert TempVars.get().lock();
- Vector2f tempVec2 = TempVars.get().vect2d;
+ TempVars vars = TempVars.get();
+ Vector2f tempVec2 = vars.vect2d;
populateFromBuffer(tempVec2, buf, index);
tempVec2.normalizeLocal();
setInBuffer(tempVec2, buf, index);
- assert TempVars.get().unlock();
+ vars.release();
}
/**
@@ -534,12 +537,12 @@ public final class BufferUtils {
* to add to
*/
public static void addInBuffer(Vector2f toAdd, FloatBuffer buf, int index) {
- assert TempVars.get().lock();
- Vector2f tempVec2 = TempVars.get().vect2d;
+ TempVars vars = TempVars.get();
+ Vector2f tempVec2 = vars.vect2d;
populateFromBuffer(tempVec2, buf, index);
tempVec2.addLocal(toAdd);
setInBuffer(tempVec2, buf, index);
- assert TempVars.get().unlock();
+ vars.release();
}
/**
@@ -554,12 +557,12 @@ public final class BufferUtils {
* to multiply
*/
public static void multInBuffer(Vector2f toMult, FloatBuffer buf, int index) {
- assert TempVars.get().lock();
- Vector2f tempVec2 = TempVars.get().vect2d;
+ TempVars vars = TempVars.get();
+ Vector2f tempVec2 = vars.vect2d;
populateFromBuffer(tempVec2, buf, index);
tempVec2.multLocal(toMult);
setInBuffer(tempVec2, buf, index);
- assert TempVars.get().unlock();
+ vars.release();
}
/**
@@ -576,17 +579,15 @@ public final class BufferUtils {
* @return
*/
public static boolean equals(Vector2f check, FloatBuffer buf, int index) {
- assert TempVars.get().lock();
- Vector2f tempVec2 = TempVars.get().vect2d;
+ TempVars vars = TempVars.get();
+ Vector2f tempVec2 = vars.vect2d;
populateFromBuffer(tempVec2, buf, index);
boolean eq = tempVec2.equals(check);
- assert TempVars.get().unlock();
+ vars.release();
return eq;
}
-
//// -- INT METHODS -- ////
-
/**
* Generate a new IntBuffer using the given array of ints. The IntBuffer
* will be data.length long and contain the int data as data[0], data[1]...
@@ -596,7 +597,9 @@ public final class BufferUtils {
* array of ints to place into a new IntBuffer
*/
public static IntBuffer createIntBuffer(int... data) {
- if (data == null) return null;
+ if (data == null) {
+ return null;
+ }
IntBuffer buff = createIntBuffer(data.length);
buff.clear();
buff.put(data);
@@ -613,7 +616,9 @@ public final class BufferUtils {
* @return a new int array populated from the IntBuffer
*/
public static int[] getIntArray(IntBuffer buff) {
- if (buff == null) return null;
+ if (buff == null) {
+ return null;
+ }
buff.clear();
int[] inds = new int[buff.limit()];
for (int x = 0; x < inds.length; x++) {
@@ -621,7 +626,7 @@ public final class BufferUtils {
}
return inds;
}
-
+
/**
* Create a new float[] array and populate it with the given FloatBuffer's
* contents.
@@ -631,7 +636,9 @@ public final class BufferUtils {
* @return a new float array populated from the FloatBuffer
*/
public static float[] getFloatArray(FloatBuffer buff) {
- if (buff == null) return null;
+ if (buff == null) {
+ return null;
+ }
buff.clear();
float[] inds = new float[buff.limit()];
for (int x = 0; x < inds.length; x++) {
@@ -640,9 +647,7 @@ public final class BufferUtils {
return inds;
}
-
//// -- GENERAL DOUBLE ROUTINES -- ////
-
/**
* Create a new DoubleBuffer of the specified size.
*
@@ -691,13 +696,15 @@ public final class BufferUtils {
* @return the copy
*/
public static DoubleBuffer clone(DoubleBuffer buf) {
- if (buf == null) return null;
+ if (buf == null) {
+ return null;
+ }
buf.rewind();
DoubleBuffer copy;
- if (buf.isDirect()){
+ if (buf.isDirect()) {
copy = createDoubleBuffer(buf.limit());
- }else{
+ } else {
copy = DoubleBuffer.allocate(buf.limit());
}
copy.put(buf);
@@ -705,10 +712,7 @@ public final class BufferUtils {
return copy;
}
-
-
//// -- GENERAL FLOAT ROUTINES -- ////
-
/**
* Create a new FloatBuffer of the specified size.
*
@@ -756,13 +760,15 @@ public final class BufferUtils {
* @return the copy
*/
public static FloatBuffer clone(FloatBuffer buf) {
- if (buf == null) return null;
+ if (buf == null) {
+ return null;
+ }
buf.rewind();
FloatBuffer copy;
- if (buf.isDirect()){
+ if (buf.isDirect()) {
copy = createFloatBuffer(buf.limit());
- }else{
+ } else {
copy = FloatBuffer.allocate(buf.limit());
}
copy.put(buf);
@@ -770,9 +776,7 @@ public final class BufferUtils {
return copy;
}
-
//// -- GENERAL INT ROUTINES -- ////
-
/**
* Create a new IntBuffer of the specified size.
*
@@ -821,13 +825,15 @@ public final class BufferUtils {
* @return the copy
*/
public static IntBuffer clone(IntBuffer buf) {
- if (buf == null) return null;
+ if (buf == null) {
+ return null;
+ }
buf.rewind();
IntBuffer copy;
- if (buf.isDirect()){
+ if (buf.isDirect()) {
copy = createIntBuffer(buf.limit());
- }else{
+ } else {
copy = IntBuffer.allocate(buf.limit());
}
copy.put(buf);
@@ -835,9 +841,7 @@ public final class BufferUtils {
return copy;
}
-
//// -- GENERAL BYTE ROUTINES -- ////
-
/**
* Create a new ByteBuffer of the specified size.
*
@@ -875,14 +879,14 @@ public final class BufferUtils {
return buf;
}
- public static ByteBuffer createByteBuffer(byte ... data){
+ public static ByteBuffer createByteBuffer(byte... data) {
ByteBuffer bb = createByteBuffer(data.length);
bb.put(data);
bb.flip();
return bb;
}
- public static ByteBuffer createByteBuffer(String data){
+ public static ByteBuffer createByteBuffer(String data) {
byte[] bytes = data.getBytes();
ByteBuffer bb = createByteBuffer(bytes.length);
bb.put(bytes);
@@ -901,13 +905,15 @@ public final class BufferUtils {
* @return the copy
*/
public static ByteBuffer clone(ByteBuffer buf) {
- if (buf == null) return null;
+ if (buf == null) {
+ return null;
+ }
buf.rewind();
ByteBuffer copy;
- if (buf.isDirect()){
+ if (buf.isDirect()) {
copy = createByteBuffer(buf.limit());
- }else{
+ } else {
copy = ByteBuffer.allocate(buf.limit());
}
copy.put(buf);
@@ -915,9 +921,7 @@ public final class BufferUtils {
return copy;
}
-
//// -- GENERAL SHORT ROUTINES -- ////
-
/**
* Create a new ShortBuffer of the specified size.
*
@@ -956,7 +960,9 @@ public final class BufferUtils {
}
public static ShortBuffer createShortBuffer(short... data) {
- if (data == null) return null;
+ if (data == null) {
+ return null;
+ }
ShortBuffer buff = createShortBuffer(data.length);
buff.clear();
buff.put(data);
@@ -975,13 +981,15 @@ public final class BufferUtils {
* @return the copy
*/
public static ShortBuffer clone(ShortBuffer buf) {
- if (buf == null) return null;
+ if (buf == null) {
+ return null;
+ }
buf.rewind();
ShortBuffer copy;
- if (buf.isDirect()){
+ if (buf.isDirect()) {
copy = createShortBuffer(buf.limit());
- }else{
+ } else {
copy = ShortBuffer.allocate(buf.limit());
}
copy.put(buf);
@@ -997,42 +1005,42 @@ public final class BufferUtils {
* @return a buffer large enough to receive at least the required
number of entries, same position as
* the input buffer, not null
*/
- public static FloatBuffer ensureLargeEnough( FloatBuffer buffer, int required ) {
- if ( buffer == null || ( buffer.remaining() < required ) ) {
- int position = ( buffer != null ? buffer.position() : 0 );
- FloatBuffer newVerts = createFloatBuffer( position + required );
- if ( buffer != null ) {
+ public static FloatBuffer ensureLargeEnough(FloatBuffer buffer, int required) {
+ if (buffer == null || (buffer.remaining() < required)) {
+ int position = (buffer != null ? buffer.position() : 0);
+ FloatBuffer newVerts = createFloatBuffer(position + required);
+ if (buffer != null) {
buffer.rewind();
- newVerts.put( buffer );
- newVerts.position( position );
+ newVerts.put(buffer);
+ newVerts.position(position);
}
buffer = newVerts;
}
return buffer;
}
- public static ShortBuffer ensureLargeEnough( ShortBuffer buffer, int required ) {
- if ( buffer == null || ( buffer.remaining() < required ) ) {
- int position = ( buffer != null ? buffer.position() : 0 );
- ShortBuffer newVerts = createShortBuffer( position + required );
- if ( buffer != null ) {
+ public static ShortBuffer ensureLargeEnough(ShortBuffer buffer, int required) {
+ if (buffer == null || (buffer.remaining() < required)) {
+ int position = (buffer != null ? buffer.position() : 0);
+ ShortBuffer newVerts = createShortBuffer(position + required);
+ if (buffer != null) {
buffer.rewind();
- newVerts.put( buffer );
- newVerts.position( position );
+ newVerts.put(buffer);
+ newVerts.position(position);
}
buffer = newVerts;
}
return buffer;
}
- public static ByteBuffer ensureLargeEnough( ByteBuffer buffer, int required ) {
- if ( buffer == null || ( buffer.remaining() < required ) ) {
- int position = ( buffer != null ? buffer.position() : 0 );
- ByteBuffer newVerts = createByteBuffer( position + required );
- if ( buffer != null ) {
+ public static ByteBuffer ensureLargeEnough(ByteBuffer buffer, int required) {
+ if (buffer == null || (buffer.remaining() < required)) {
+ int position = (buffer != null ? buffer.position() : 0);
+ ByteBuffer newVerts = createByteBuffer(position + required);
+ if (buffer != null) {
buffer.rewind();
- newVerts.put( buffer );
- newVerts.position( position );
+ newVerts.put(buffer);
+ newVerts.position(position);
}
buffer = newVerts;
}
@@ -1068,25 +1076,20 @@ public final class BufferUtils {
dBufs++;
}
}
- long heapMem = Runtime.getRuntime().totalMemory() -
- Runtime.getRuntime().freeMemory();
+ long heapMem = Runtime.getRuntime().totalMemory()
+ - Runtime.getRuntime().freeMemory();
boolean printStout = store == null;
if (store == null) {
store = new StringBuilder();
}
store.append("Existing buffers: ").append(bufs.size()).append("\n");
- store.append("(b: ").append(bBufs).append(" f: ").append(fBufs)
- .append(" i: ").append(iBufs).append(" s: ").append(sBufs)
- .append(" d: ").append(dBufs).append(")").append("\n");
- store.append("Total heap memory held: ").append(heapMem/1024).append("kb\n");
- store.append("Total direct memory held: ").append(totalHeld/1024).append("kb\n");
- store.append("(b: ").append(bBufsM/1024).append("kb f: ").append(fBufsM/1024)
- .append("kb i: ").append(iBufsM/1024).append("kb s: ").append(sBufsM/1024)
- .append("kb d: ").append(dBufsM/1024).append("kb)").append("\n");
+ store.append("(b: ").append(bBufs).append(" f: ").append(fBufs).append(" i: ").append(iBufs).append(" s: ").append(sBufs).append(" d: ").append(dBufs).append(")").append("\n");
+ store.append("Total heap memory held: ").append(heapMem / 1024).append("kb\n");
+ store.append("Total direct memory held: ").append(totalHeld / 1024).append("kb\n");
+ store.append("(b: ").append(bBufsM / 1024).append("kb f: ").append(fBufsM / 1024).append("kb i: ").append(iBufsM / 1024).append("kb s: ").append(sBufsM / 1024).append("kb d: ").append(dBufsM / 1024).append("kb)").append("\n");
if (printStout) {
System.out.println(store.toString());
}
}
-
}
diff --git a/engine/src/core/com/jme3/util/TempVars.java b/engine/src/core/com/jme3/util/TempVars.java
index c96508c80..e7370b95e 100644
--- a/engine/src/core/com/jme3/util/TempVars.java
+++ b/engine/src/core/com/jme3/util/TempVars.java
@@ -29,7 +29,6 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
package com.jme3.util;
import com.jme3.collision.bih.BIHNode.BIHStackData;
@@ -45,94 +44,148 @@ import com.jme3.scene.Spatial;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.util.ArrayList;
+import java.util.logging.Level;
+import java.util.logging.Logger;
/**
* Temporary variables assigned to each thread. Engine classes may access
- * these temp variables with TempVars.get(). A method using temp vars with this
- * class is not allowed to make calls to other methods using the class otherwise
- * memory corruption will occur. A locking mechanism may be implemented
- * in the future to prevent the occurance of such situation.
+ * these temp variables with TempVars.get().
+ * This returns an available instance of the TempVar class ensuring this particular instance is never used elsewhere in the mean time.
*/
-public class TempVars {
+public class TempVars {
+
+ private static final Logger log = Logger.getLogger(TempVars.class.getName());
+ //default array size
+ private static final int arraySize = 30;
+ //one array per thread
+ private static final ThreadLocal varsLocal = new ThreadLocal() {
- private static final ThreadLocal varsLocal
- = new ThreadLocal(){
@Override
- public TempVars initialValue(){
- return new TempVars();
+ public TempVars[] initialValue() {
+ TempVars[] l = new TempVars[arraySize];
+ //the array is initialized with one instance (should be enough in most cases)
+ l[0] = new TempVars();
+ return l;
}
};
+ //the current index in the stack
+ private static int stackLevel = 0;
+ //number of instanced TempVar, just to raise a warning if too much are instanced
+ private static int instanceCount = 1;
- public static TempVars get(){
- return varsLocal.get();
- }
-
- private TempVars(){
- }
-
- private boolean locked = false;
- private StackTraceElement[] lockerStack;
-
- public final boolean lock(){
- if (locked){
- System.err.println("INTERNAL ERROR");
- System.err.println("Offending trace: ");
-
- StackTraceElement[] stack = new Throwable().getStackTrace();
- for (int i = 1; i < stack.length; i++){
- System.err.println("\tat "+stack[i].toString());
- }
-
- System.err.println("Attempted to aquire TempVars lock owned by");
- for (int i = 1; i < lockerStack.length; i++){
- System.err.println("\tat "+lockerStack[i].toString());
- }
- System.exit(1);
- return false;
+ /**
+ * Returns an available instance of the TempVar class
+ * Warning, you have to release the instance once used by calling the release() method
+ * @return a TempVar instance
+ */
+ public static TempVars get() {
+
+ TempVars vars = null;
+ TempVars[] array = varsLocal.get();
+ //if the stack level is > 0 it means we have some instances in the array, we can return one of them
+ if (stackLevel >= 0) {
+ //getting the lastTempVar instance
+ vars = array[stackLevel];
+ //removing the reference to it in the array so if it's never released it will be garbage collected.
+ array[stackLevel] = null;
+ //decreasing the stack level since we have one less instance
+ stackLevel--;
+
+ //In some cases (when lauching jme threads from another thread), the instance at 0 can be null
+ //so we check that to avoid NPE
+ if (vars==null){
+ vars = new TempVars();
+ //increasing the count to keep track
+ instanceCount++;
+ }
+ } else {
+ //if the stack level is <0 it means the stack is empty, we have to create a new instance
+ //there
+ vars = new TempVars();
+ //increasing the count to keep track
+ instanceCount++;
+ //raising a warning if the instance count is to high, because it might be due to bad usage
+ if (instanceCount == array.length) {
+ log.log(Level.WARNING, "TempVars has been requested {0} times, maybe you forgot to call release()?", instanceCount);
+ }
}
-
- lockerStack = new Throwable().getStackTrace();
- locked = true;
- return true;
+ return vars;
}
- public final boolean unlock(){
- if (!locked){
- System.err.println("INTERNAL ERROR");
- System.err.println("Attempted to release non-existent lock: ");
-
- StackTraceElement[] stack = new Throwable().getStackTrace();
- for (int i = 1; i < stack.length; i++){
- System.err.println("\tat "+stack[i].toString());
- }
-
- System.exit(1);
- return false;
+ private TempVars() {
+ }
+// private boolean locked = false;
+// private StackTraceElement[] lockerStack;
+
+// public final boolean lock() {
+// if (locked) {
+// System.err.println("INTERNAL ERROR");
+// System.err.println("Offending trace: ");
+//
+// StackTraceElement[] stack = new Throwable().getStackTrace();
+// for (int i = 1; i < stack.length; i++) {
+// System.err.println("\tat " + stack[i].toString());
+// }
+//
+// System.err.println("Attempted to aquire TempVars lock owned by");
+// for (int i = 1; i < lockerStack.length; i++) {
+// System.err.println("\tat " + lockerStack[i].toString());
+// }
+// System.exit(1);
+// return false;
+// }
+//
+// lockerStack = new Throwable().getStackTrace();
+// locked = true;
+// return true;
+// }
+//
+// public final boolean unlock() {
+// if (!locked) {
+// System.err.println("INTERNAL ERROR");
+// System.err.println("Attempted to release non-existent lock: ");
+//
+// StackTraceElement[] stack = new Throwable().getStackTrace();
+// for (int i = 1; i < stack.length; i++) {
+// System.err.println("\tat " + stack[i].toString());
+// }
+//
+// System.exit(1);
+// return false;
+// }
+//
+// lockerStack = null;
+// locked = false;
+// return true;
+// }
+ /**
+ * Release this instance of TempVar, allowing it to be reused later.
+ */
+ public final void release() {
+
+ //we only keep as much instances as we can,
+ //but if too much are instanced, we just don't readd them, they'll be garbage collected
+ //This can happen only in case of recursive calls that are instancing the TempVar
+ if (stackLevel < arraySize - 1) {
+ stackLevel++;
+ varsLocal.get()[stackLevel] = this;
}
-
- lockerStack = null;
- locked = false;
- return true;
}
-
/**
* For interfacing with OpenGL in Renderer.
*/
public final IntBuffer intBuffer1 = BufferUtils.createIntBuffer(1);
public final IntBuffer intBuffer16 = BufferUtils.createIntBuffer(16);
public final FloatBuffer floatBuffer16 = BufferUtils.createFloatBuffer(16);
-
/**
* Skinning buffers
*/
public final float[] skinPositions = new float[512 * 3];
public final float[] skinNormals = new float[512 * 3];
-
/**
* Fetching triangle from mesh
*/
public final Triangle triangle = new Triangle();
-
/**
* General vectors.
*/
@@ -143,42 +196,36 @@ public class TempVars {
public final Vector3f vect5 = new Vector3f();
public final Vector3f vect6 = new Vector3f();
public final Vector3f vect7 = new Vector3f();
+ //seems the maximum number of vector used is 7 in com.jme3.bounding.java
public final Vector3f vect8 = new Vector3f();
public final Vector3f vect9 = new Vector3f();
public final Vector3f vect10 = new Vector3f();
-
- public final Vector3f[] tri = { new Vector3f(),
- new Vector3f(),
- new Vector3f() };
-
+ public final Vector3f[] tri = {new Vector3f(),
+ new Vector3f(),
+ new Vector3f()};
/**
* 2D vector
*/
- public final Vector2f vect2d = new Vector2f();
+ public final Vector2f vect2d = new Vector2f();
public final Vector2f vect2d2 = new Vector2f();
-
/**
* General matrices.
*/
public final Matrix3f tempMat3 = new Matrix3f();
public final Matrix4f tempMat4 = new Matrix4f();
-
/**
* General quaternions.
*/
public final Quaternion quat1 = new Quaternion();
public final Quaternion quat2 = new Quaternion();
-
/**
* Eigen
*/
public final Eigen3f eigen = new Eigen3f();
-
/**
* Plane
*/
- public final Plane plane = new Plane();
-
+ public final Plane plane = new Plane();
/**
* BoundingBox ray collision
*/
@@ -187,18 +234,14 @@ public class TempVars {
public final float[] fDdU = new float[3];
public final float[] fADdU = new float[3];
public final float[] fAWxDdU = new float[3];
-
/**
* Maximum tree depth .. 32 levels??
*/
public final Spatial[] spatialStack = new Spatial[32];
-
public final float[] matrixWrite = new float[16];
-
/**
* BIHTree
*/
public final float[] bihSwapTmp = new float[9];
public final ArrayList bihStack = new ArrayList();
-
}
diff --git a/engine/src/desktop-fx/com/jme3/water/WaterFilter.java b/engine/src/desktop-fx/com/jme3/water/WaterFilter.java
index 9ecaf05e2..c6ad3bf30 100644
--- a/engine/src/desktop-fx/com/jme3/water/WaterFilter.java
+++ b/engine/src/desktop-fx/com/jme3/water/WaterFilter.java
@@ -109,7 +109,6 @@ public class WaterFilter extends Filter {
private boolean useCaustics = true;
private boolean useRefraction = true;
private float time = 0;
- private float savedTpf = 0;
private float reflectionDisplace = 30;
private float foamIntensity = 0.5f;
private boolean underWater;
@@ -168,7 +167,7 @@ public class WaterFilter extends Filter {
sceneCam.getFrustumTop(),
sceneCam.getFrustumBottom());
TempVars vars = TempVars.get();
- assert vars.lock();
+
vars.vect1.set(sceneCam.getLocation()).addLocal(sceneCam.getUp());
float planeDistance = plane.pseudoDistance(vars.vect1);
@@ -176,8 +175,8 @@ public class WaterFilter extends Filter {
vars.vect3.set(vars.vect1.subtractLocal(vars.vect2)).subtractLocal(loc).normalizeLocal().negateLocal();
reflectionCam.lookAt(targetLocation, vars.vect3);
+ vars.release();
- assert vars.unlock();
if (inv) {
reflectionCam.setAxes(reflectionCam.getLeft().negateLocal(), reflectionCam.getUp(), reflectionCam.getDirection().negateLocal());
}
diff --git a/engine/src/jbullet/com/jme3/bullet/control/KinematicRagdollControl.java b/engine/src/jbullet/com/jme3/bullet/control/KinematicRagdollControl.java
index a7dd9dd19..c34b0a85b 100644
--- a/engine/src/jbullet/com/jme3/bullet/control/KinematicRagdollControl.java
+++ b/engine/src/jbullet/com/jme3/bullet/control/KinematicRagdollControl.java
@@ -165,7 +165,7 @@ public class KinematicRagdollControl implements PhysicsControl, PhysicsCollision
return;
}
TempVars vars = TempVars.get();
- assert vars.lock();
+
Quaternion tmpRot1 = vars.quat1;
Quaternion tmpRot2 = vars.quat2;
@@ -264,7 +264,7 @@ public class KinematicRagdollControl implements PhysicsControl, PhysicsCollision
}
}
}
- assert vars.unlock();
+ vars.release();
}
@@ -682,7 +682,7 @@ public class KinematicRagdollControl implements PhysicsControl, PhysicsCollision
baseRigidBody.setKinematic(mode == Mode.Kinetmatic);
TempVars vars = TempVars.get();
- assert vars.lock();
+
for (PhysicsBoneLink link : boneLinks.values()) {
link.rigidBody.setKinematic(mode == Mode.Kinetmatic);
if (mode == Mode.Ragdoll) {
@@ -693,7 +693,7 @@ public class KinematicRagdollControl implements PhysicsControl, PhysicsCollision
}
}
- assert vars.unlock();
+ vars.release();
for (Bone bone : skeleton.getRoots()) {
RagdollUtils.setUserControl(bone, mode == Mode.Ragdoll);
@@ -716,9 +716,7 @@ public class KinematicRagdollControl implements PhysicsControl, PhysicsCollision
animControl.setEnabled(true);
-
- TempVars vars = TempVars.get();
- assert vars.lock();
+ TempVars vars = TempVars.get();
for (PhysicsBoneLink link : boneLinks.values()) {
Vector3f p = link.rigidBody.getMotionState().getWorldLocation();
@@ -737,7 +735,7 @@ public class KinematicRagdollControl implements PhysicsControl, PhysicsCollision
link.startBlendingRot.set(q2);
link.rigidBody.setKinematic(true);
}
- assert vars.unlock();
+ vars.release();
for (Bone bone : skeleton.getRoots()) {
RagdollUtils.setUserControl(bone, false);
diff --git a/engine/src/jbullet/com/jme3/bullet/util/DebugShapeFactory.java b/engine/src/jbullet/com/jme3/bullet/util/DebugShapeFactory.java
index bd04a0229..c9a89eeb6 100644
--- a/engine/src/jbullet/com/jme3/bullet/util/DebugShapeFactory.java
+++ b/engine/src/jbullet/com/jme3/bullet/util/DebugShapeFactory.java
@@ -90,14 +90,14 @@ public class DebugShapeFactory {
// apply rotation
TempVars vars = TempVars.get();
- assert vars.lock();
+
Matrix3f tempRot = vars.tempMat3;
tempRot.set(geometry.getLocalRotation());
childCollisionShape.rotation.mult(tempRot, tempRot);
geometry.setLocalRotation(tempRot);
- assert vars.unlock();
+ vars.release();
node.attachChild(geometry);
}
@@ -120,17 +120,15 @@ public class DebugShapeFactory {
return geom;
}
- public static Mesh getDebugMesh(CollisionShape shape){
- Mesh mesh=null;
- if(shape.getCShape() instanceof ConvexShape){
- mesh=new Mesh();
- mesh.setBuffer(Type.Position, 3, getVertices((ConvexShape)shape.getCShape()));
+ public static Mesh getDebugMesh(CollisionShape shape) {
+ Mesh mesh = null;
+ if (shape.getCShape() instanceof ConvexShape) {
+ mesh = new Mesh();
+ mesh.setBuffer(Type.Position, 3, getVertices((ConvexShape) shape.getCShape()));
mesh.getFloatBuffer(Type.Position).clear();
- }
- else if(shape.getCShape() instanceof ConcaveShape)
- {
- mesh=new Mesh();
- mesh.setBuffer(Type.Position, 3, getVertices((ConcaveShape)shape.getCShape()));
+ } else if (shape.getCShape() instanceof ConcaveShape) {
+ mesh = new Mesh();
+ mesh.setBuffer(Type.Position, 3, getVertices((ConcaveShape) shape.getCShape()));
mesh.getFloatBuffer(Type.Position).clear();
}
return mesh;
diff --git a/engine/src/test/jme3test/app/TestTempVars.java b/engine/src/test/jme3test/app/TestTempVars.java
index cd175931c..24a09c45b 100644
--- a/engine/src/test/jme3test/app/TestTempVars.java
+++ b/engine/src/test/jme3test/app/TestTempVars.java
@@ -29,51 +29,82 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
package jme3test.app;
import com.jme3.util.TempVars;
+import java.util.Date;
+import java.util.Iterator;
public class TestTempVars {
- public static void methodThatUsesTempVars(){
- TempVars vars = TempVars.get();
- assert vars.lock();
- {
- vars.vect1.set(123,999,-55);
- }
- assert vars.unlock();
- }
- public static void main(String[] args){
- System.err.println("NOTE: This test simulates a data corruption attempt\n" +
- " in the engine. If assertions are enabled (-ea VM flag), the \n" +
- "data corruption will be detected and displayed below.");
+ public static void main(String[] args) {
+
+ Date d,d2;
+ System.err.println("NOTE: This test simulates a data corruption attempt\n"
+ + " in the engine. If assertions are enabled (-ea VM flag), the \n"
+ + "data corruption will be detected and displayed below.");
+ //get the vars
TempVars vars = TempVars.get();
+
+ // do something with temporary vars
+ vars.vect1.addLocal(vars.vect2);
+
+ //release the vars
+ vars.release();
- assert vars.lock();
+ //Perf tests
+
+ //100 million calls
+ d = new Date();
+ for (int i = 0; i < 100000000; i++) {
+ methodThatUsesTempVars();
+ }
+ d2 = new Date();
+ System.out.println("100 million calls : " +(d2.getTime() - d.getTime())+" ms");
+
+
+ //recursive Method
+ d = new Date();
+ recursiveMethod();
+ d2 = new Date();
+ System.out.println("100 recursive calls : " +(d2.getTime() - d.getTime())+" ms");
+
+ d = new Date();
+ for (int i = 0; i < 1000000; i++) {
+ methodThatUsesTempVarsWithNoRelease();
+ }
+ d2 = new Date();
+ System.out.println("1 million calls with no release : " +(d2.getTime() - d.getTime())+" ms");
+
+ }
+ static int recurse = 0;
+ public static void recursiveMethod(){
+ TempVars vars = TempVars.get();
+ vars.vect1.set(123, 999, -55);
+ recurse++;
+ if(recurse<100){
+ recursiveMethod();
+ }
+
+ vars.release();
+ }
+
+ public static void methodThatUsesTempVars() {
+ TempVars vars = TempVars.get();
{
- // do something with temporary vars
- vars.vect1.addLocal(vars.vect2);
+ vars.vect1.set(123, 999, -55);
}
- assert vars.unlock();
-
-
+ vars.release();
+ }
- assert vars.lock();
+ public static void methodThatUsesTempVarsWithNoRelease() {
+ TempVars vars = TempVars.get();
{
- // set a value
- vars.vect1.set(1,1,1);
-
- // method that currupts the value
- methodThatUsesTempVars();
-
- // read the value
- System.out.println(vars.vect1);
+ vars.vect1.set(123, 999, -55);
}
- assert vars.unlock();
+
}
-
}