* Improved performance of Matrix3/4f.fillFloatBuffer() by writing to an array first

* Initial javadoc for com.jme3.collision

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7672 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
sha..rd 14 years ago
parent 8c69c7d205
commit ba88539817
  1. 17
      engine/src/core/com/jme3/collision/Collidable.java
  2. 14
      engine/src/core/com/jme3/collision/CollisionResults.java
  3. 5
      engine/src/core/com/jme3/collision/UnsupportedCollisionException.java
  4. 50
      engine/src/core/com/jme3/math/Matrix3f.java
  5. 31
      engine/src/core/com/jme3/math/Matrix4f.java
  6. 2
      engine/src/core/com/jme3/util/TempVars.java

@ -33,16 +33,21 @@
package com.jme3.collision;
/**
* Interface for collidable objects.
* @author Kirill
* Interface for Collidable objects.
* Classes that implement this interface are marked as collidable, meaning
* they support collision detection between other objects that are also
* collidable.
*
* @author Kirill Vainer
*/
public interface Collidable {
/**
* Check collision with another collidable
* @param other
* @param results
* @return how many collisions were found
* Check collision with another Collidable.
*
* @param other The object to check collision against
* @param results Will contain the list of {@link CollisionResult}s.
* @return how many collisions were found between this and other
*/
public int collideWith(Collidable other, CollisionResults results) throws UnsupportedCollisionException;
}

@ -36,15 +36,29 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
/**
* <code>CollisionResults</code> is a collection returned as a result of a
* collision detection operation done by {@link Collidable}.
*
* @author Kirill Vainer
*/
public class CollisionResults implements Iterable<CollisionResult> {
private final ArrayList<CollisionResult> results = new ArrayList<CollisionResult>();
private boolean sorted = true;
/**
* Clears all collision results added to this list
*/
public void clear(){
results.clear();
}
/**
* Iterator for iterating over the collision results.
*
* @return the iterator
*/
public Iterator<CollisionResult> iterator() {
if (!sorted){
Collections.sort(results);

@ -33,8 +33,11 @@
package com.jme3.collision;
/**
* Thrown by {@link Collidable} when the requested collision query could not
* be completed because one of the collidables does not support colliding with
* the other.
*
* @author Kirill
* @author Kirill Vainer
*/
public class UnsupportedCollisionException extends UnsupportedOperationException {

@ -38,6 +38,7 @@ import com.jme3.export.JmeImporter;
import com.jme3.export.OutputCapsule;
import com.jme3.export.Savable;
import com.jme3.util.BufferUtils;
import com.jme3.util.TempVars;
import java.io.IOException;
import java.nio.FloatBuffer;
import java.util.logging.Logger;
@ -384,16 +385,49 @@ public final class Matrix3f implements Savable, Cloneable {
* limit set is not changed).
*/
public FloatBuffer fillFloatBuffer(FloatBuffer fb, boolean columnMajor) {
if (columnMajor){
fb.put(m00).put(m10).put(m20);
fb.put(m01).put(m11).put(m21);
fb.put(m02).put(m12).put(m22);
// if (columnMajor){
// fb.put(m00).put(m10).put(m20);
// fb.put(m01).put(m11).put(m21);
// fb.put(m02).put(m12).put(m22);
// }else{
// fb.put(m00).put(m01).put(m02);
// 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();
return fb;
}
public void fillFloatArray(float[] f, boolean columnMajor){
if (columnMajor) {
f[ 0] = m00;
f[ 1] = m10;
f[ 2] = m20;
f[ 3] = m01;
f[ 4] = m11;
f[ 5] = m21;
f[ 6] = m02;
f[ 7] = m12;
f[ 8] = m22;
}else{
fb.put(m00).put(m01).put(m02);
fb.put(m10).put(m11).put(m12);
fb.put(m20).put(m21).put(m22);
f[ 0] = m00;
f[ 1] = m01;
f[ 2] = m02;
f[ 3] = m10;
f[ 4] = m11;
f[ 5] = m12;
f[ 6] = m20;
f[ 7] = m21;
f[ 8] = m22;
}
return fb;
}
/**

@ -733,17 +733,26 @@ public final class Matrix4f implements Savable, Cloneable {
* limit set is not changed).
*/
public FloatBuffer fillFloatBuffer(FloatBuffer fb, boolean columnMajor) {
if (columnMajor) {
fb.put(m00).put(m10).put(m20).put(m30);
fb.put(m01).put(m11).put(m21).put(m31);
fb.put(m02).put(m12).put(m22).put(m32);
fb.put(m03).put(m13).put(m23).put(m33);
} else {
fb.put(m00).put(m01).put(m02).put(m03);
fb.put(m10).put(m11).put(m12).put(m13);
fb.put(m20).put(m21).put(m22).put(m23);
fb.put(m30).put(m31).put(m32).put(m33);
}
// if (columnMajor) {
// fb.put(m00).put(m10).put(m20).put(m30);
// fb.put(m01).put(m11).put(m21).put(m31);
// fb.put(m02).put(m12).put(m22).put(m32);
// fb.put(m03).put(m13).put(m23).put(m33);
// } else {
// fb.put(m00).put(m01).put(m02).put(m03);
// fb.put(m10).put(m11).put(m12).put(m13);
// 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();
return fb;
}

@ -193,6 +193,8 @@ public class TempVars {
*/
public final Spatial[] spatialStack = new Spatial[32];
public final float[] matrixWrite = new float[16];
/**
* BIHTree
*/

Loading…
Cancel
Save