improve formatting and rm trailing whitespace (16 files in jme3-core)

master
Stephen Gold 5 years ago
parent f46a6fac11
commit e99c8a74a3
  1. 40
      jme3-core/src/main/java/com/jme3/bounding/BoundingBox.java
  2. 18
      jme3-core/src/main/java/com/jme3/bounding/BoundingVolume.java
  3. 49
      jme3-core/src/main/java/com/jme3/math/CurveAndSurfaceMath.java
  4. 108
      jme3-core/src/main/java/com/jme3/math/FastMath.java
  5. 87
      jme3-core/src/main/java/com/jme3/math/Matrix3f.java
  6. 88
      jme3-core/src/main/java/com/jme3/math/Matrix4f.java
  7. 23
      jme3-core/src/main/java/com/jme3/math/Plane.java
  8. 87
      jme3-core/src/main/java/com/jme3/math/Quaternion.java
  9. 57
      jme3-core/src/main/java/com/jme3/math/Spline.java
  10. 98
      jme3-core/src/main/java/com/jme3/math/Transform.java
  11. 120
      jme3-core/src/main/java/com/jme3/math/Vector3f.java
  12. 53
      jme3-core/src/main/java/com/jme3/scene/mesh/VirtualIndexBuffer.java
  13. 6
      jme3-core/src/main/java/com/jme3/scene/shape/Curve.java
  14. 142
      jme3-core/src/main/java/com/jme3/texture/FrameBuffer.java
  15. 3
      jme3-core/src/main/java/com/jme3/util/BufferUtils.java
  16. 2
      jme3-core/src/main/java/com/jme3/util/ReflectionAllocator.java

@ -138,8 +138,10 @@ public class BoundingBox extends BoundingVolume {
TempVars vars = TempVars.get(); TempVars vars = TempVars.get();
Vector3f min = vars.vect1.set(new Vector3f(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY)); Vector3f min = vars.vect1.set(new Vector3f(Float.POSITIVE_INFINITY,
Vector3f max = vars.vect2.set(new Vector3f(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NEGATIVE_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; Vector3f point;
for (int i = start; i < end; i++) { for (int i = start; i < end; i++) {
@ -240,8 +242,12 @@ public class BoundingBox extends BoundingVolume {
float[] tmpArray = vars.skinPositions; float[] tmpArray = vars.skinPositions;
float minX = Float.POSITIVE_INFINITY, minY = Float.POSITIVE_INFINITY, minZ = Float.POSITIVE_INFINITY; float minX = Float.POSITIVE_INFINITY,
float maxX = Float.NEGATIVE_INFINITY, maxY = Float.NEGATIVE_INFINITY, maxZ = Float.NEGATIVE_INFINITY; minY = Float.POSITIVE_INFINITY,
minZ = Float.POSITIVE_INFINITY;
float maxX = Float.NEGATIVE_INFINITY,
maxY = Float.NEGATIVE_INFINITY,
maxZ = Float.NEGATIVE_INFINITY;
int iterations = (int) FastMath.ceil(points.limit() / ((float) tmpArray.length)); int iterations = (int) FastMath.ceil(points.limit() / ((float) tmpArray.length));
for (int i = iterations - 1; i >= 0; i--) { for (int i = iterations - 1; i >= 0; i--) {
@ -250,8 +256,8 @@ public class BoundingBox extends BoundingVolume {
for (int j = 0; j < bufLength; j += 3) { for (int j = 0; j < bufLength; j += 3) {
vars.vect1.x = tmpArray[j]; vars.vect1.x = tmpArray[j];
vars.vect1.y = tmpArray[j+1]; vars.vect1.y = tmpArray[j + 1];
vars.vect1.z = tmpArray[j+2]; vars.vect1.z = tmpArray[j + 2];
if (vars.vect1.x < minX) { if (vars.vect1.x < minX) {
minX = vars.vect1.x; minX = vars.vect1.x;
@ -317,7 +323,9 @@ public class BoundingBox extends BoundingVolume {
transMatrix.absoluteLocal(); transMatrix.absoluteLocal();
Vector3f scale = trans.getScale(); Vector3f scale = trans.getScale();
vars.vect1.set(xExtent * FastMath.abs(scale.x), yExtent * FastMath.abs(scale.y), zExtent * FastMath.abs(scale.z)); vars.vect1.set(xExtent * FastMath.abs(scale.x),
yExtent * FastMath.abs(scale.y),
zExtent * FastMath.abs(scale.z));
transMatrix.mult(vars.vect1, vars.vect2); transMatrix.mult(vars.vect1, vars.vect2);
// Assign the biggest rotations after scales. // Assign the biggest rotations after scales.
box.xExtent = FastMath.abs(vars.vect2.getX()); box.xExtent = FastMath.abs(vars.vect2.getX());
@ -339,7 +347,6 @@ public class BoundingBox extends BoundingVolume {
} }
TempVars vars = TempVars.get(); TempVars vars = TempVars.get();
float w = trans.multProj(center, box.center); float w = trans.multProj(center, box.center);
box.center.divideLocal(w); box.center.divideLocal(w);
@ -432,13 +439,12 @@ public class BoundingBox extends BoundingVolume {
// case OBB: { // case OBB: {
// return mergeOBB((OrientedBoundingBox) volume); // return mergeOBB((OrientedBoundingBox) volume);
// } // }
default: default:
return null; return null;
} }
} }
/** /*
* Merges this AABB with the given OBB. * Merges this AABB with the given OBB.
* *
* @param volume * @param volume
@ -481,6 +487,7 @@ public class BoundingBox extends BoundingVolume {
// zExtent = max.z - center.z; // zExtent = max.z - center.z;
// return this; // return this;
// } // }
/** /**
* <code>mergeLocal</code> combines this bounding box locally with a second * <code>mergeLocal</code> combines this bounding box locally with a second
* bounding box described by its center and extents. * bounding box described by its center and extents.
@ -632,7 +639,7 @@ public class BoundingBox extends BoundingVolume {
} }
} }
/** /*
* determines if this bounding box intersects with a given oriented bounding * determines if this bounding box intersects with a given oriented bounding
* box. * box.
* *
@ -783,8 +790,11 @@ public class BoundingBox extends BoundingVolume {
&& clip(-direction.z, +diff.z - zExtent, t); && clip(-direction.z, +diff.z - zExtent, t);
if (notEntirelyClipped && (t[0] != saveT0 || t[1] != saveT1)) { if (notEntirelyClipped && (t[0] != saveT0 || t[1] != saveT1)) {
if (t[1] > t[0]) return 2; if (t[1] > t[0]) {
else return 1; return 2;
} else {
return 1;
}
} }
return 0; return 0;
} finally { } finally {
@ -868,10 +878,10 @@ public class BoundingBox extends BoundingVolume {
@Override @Override
public float distanceToEdge(Vector3f point) { public float distanceToEdge(Vector3f point) {
// compute coordinates of point in box coordinate system // compute coordinates of point in box coordinate system
TempVars vars= TempVars.get(); TempVars vars = TempVars.get();
Vector3f closest = vars.vect1; Vector3f closest = vars.vect1;
point.subtract(center,closest); point.subtract(center, closest);
// project test point onto box // project test point onto box
float sqrDistance = 0.0f; float sqrDistance = 0.0f;

@ -49,7 +49,6 @@ import java.nio.FloatBuffer;
* @version $Id: BoundingVolume.java,v 1.24 2007/09/21 15:45:32 nca Exp $ * @version $Id: BoundingVolume.java,v 1.24 2007/09/21 15:45:32 nca Exp $
*/ */
public abstract class BoundingVolume implements Savable, Cloneable, Collidable { public abstract class BoundingVolume implements Savable, Cloneable, Collidable {
/** /**
* The type of bounding volume being used. * The type of bounding volume being used.
*/ */
@ -58,12 +57,10 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable {
* {@link BoundingSphere} * {@link BoundingSphere}
*/ */
Sphere, Sphere,
/** /**
* {@link BoundingBox}. * {@link BoundingBox}.
*/ */
AABB, AABB,
/** /**
* Currently unsupported by jME3. * Currently unsupported by jME3.
*/ */
@ -82,7 +79,6 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable {
/** /**
* Grabs the checkplane we should check first. * Grabs the checkplane we should check first.
*
*/ */
public int getCheckPlane() { public int getCheckPlane() {
return checkPlane; return checkPlane;
@ -103,7 +99,6 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable {
public abstract Type getType(); public abstract Type getType();
/** /**
*
* <code>transform</code> alters the location of the bounding volume by a * <code>transform</code> alters the location of the bounding volume by a
* rotation, translation and a scalar. * rotation, translation and a scalar.
* *
@ -116,7 +111,6 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable {
} }
/** /**
*
* <code>transform</code> alters the location of the bounding volume by a * <code>transform</code> alters the location of the bounding volume by a
* rotation, translation and a scalar. * rotation, translation and a scalar.
* *
@ -131,7 +125,6 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable {
public abstract BoundingVolume transform(Matrix4f trans, BoundingVolume store); public abstract BoundingVolume transform(Matrix4f trans, BoundingVolume store);
/** /**
*
* <code>whichSide</code> returns the side on which the bounding volume * <code>whichSide</code> returns the side on which the bounding volume
* lies on a plane. Possible values are POSITIVE_SIDE, NEGATIVE_SIDE, and * lies on a plane. Possible values are POSITIVE_SIDE, NEGATIVE_SIDE, and
* NO_SIDE. * NO_SIDE.
@ -143,7 +136,6 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable {
public abstract Plane.Side whichSide(Plane plane); public abstract Plane.Side whichSide(Plane plane);
/** /**
*
* <code>computeFromPoints</code> generates a bounding volume that * <code>computeFromPoints</code> generates a bounding volume that
* encompasses a collection of points. * encompasses a collection of points.
* *
@ -255,7 +247,6 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable {
*/ */
public abstract boolean intersects(Ray ray); public abstract boolean intersects(Ray ray);
/** /**
* determines if this bounding volume and a given bounding sphere are * determines if this bounding volume and a given bounding sphere are
* intersecting. * intersecting.
@ -276,7 +267,7 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable {
*/ */
public abstract boolean intersectsBoundingBox(BoundingBox bb); public abstract boolean intersectsBoundingBox(BoundingBox bb);
/** /*
* determines if this bounding volume and a given bounding box are * determines if this bounding volume and a given bounding box are
* intersecting. * intersecting.
* *
@ -286,7 +277,6 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable {
*/ */
// public abstract boolean intersectsOrientedBoundingBox(OrientedBoundingBox bb); // public abstract boolean intersectsOrientedBoundingBox(OrientedBoundingBox bb);
/** /**
*
* determines if a given point is contained within this bounding volume. * determines if a given point is contained within this bounding volume.
* If the point is on the edge of the bounding volume, this method will * If the point is on the edge of the bounding volume, this method will
* return false. Use intersects(Vector3f) to check for edge intersection. * return false. Use intersects(Vector3f) to check for edge intersection.
@ -299,6 +289,7 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable {
/** /**
* Determines if a given point intersects (touches or is inside) this bounding volume. * Determines if a given point intersects (touches or is inside) this bounding volume.
*
* @param point the point to check * @param point the point to check
* @return true if the point lies within this bounding volume. * @return true if the point lies within this bounding volume.
*/ */
@ -308,11 +299,11 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable {
@Override @Override
public BoundingVolume clone() { public BoundingVolume clone() {
try{ try {
BoundingVolume clone = (BoundingVolume) super.clone(); BoundingVolume clone = (BoundingVolume) super.clone();
clone.center = center.clone(); clone.center = center.clone();
return clone; return clone;
}catch (CloneNotSupportedException ex){ } catch (CloneNotSupportedException ex) {
throw new AssertionError(); throw new AssertionError();
} }
} }
@ -338,4 +329,3 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable {
} }
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2009-2012 jMonkeyEngine * Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -36,21 +36,22 @@ import java.util.List;
/** /**
* This class offers methods to help with curves and surfaces calculations. * This class offers methods to help with curves and surfaces calculations.
*
* @author Marcin Roguski (Kealthas) * @author Marcin Roguski (Kealthas)
*/ */
public class CurveAndSurfaceMath { public class CurveAndSurfaceMath {
private static final float KNOTS_MINIMUM_DELTA = 0.0001f; private static final float KNOTS_MINIMUM_DELTA = 0.0001f;
/** /**
* A private constructor is defined to avoid instantiation of this * A private constructor is defined to avoid instantiation of this class.
* class.
*/ */
private CurveAndSurfaceMath() {} private CurveAndSurfaceMath() {
}
/** /**
* This method interpolates the data for the nurbs curve. * This method interpolates the data for the nurbs curve.
* @param u *
* the u value * @param u the u value
* @param nurbSpline * @param nurbSpline
* the nurbs spline definition * the nurbs spline definition
* @param store * @param store
@ -64,7 +65,6 @@ public class CurveAndSurfaceMath {
float[] weights = nurbSpline.getWeights(); float[] weights = nurbSpline.getWeights();
List<Float> knots = nurbSpline.getKnots(); List<Float> knots = nurbSpline.getKnots();
int controlPointAmount = controlPoints.size(); int controlPointAmount = controlPoints.size();
store.set(Vector3f.ZERO); store.set(Vector3f.ZERO);
float delimeter = 0; float delimeter = 0;
for (int i = 0; i < controlPointAmount; ++i) { for (int i = 0; i < controlPointAmount; ++i) {
@ -79,10 +79,8 @@ public class CurveAndSurfaceMath {
/** /**
* This method interpolates the data for the nurbs surface. * This method interpolates the data for the nurbs surface.
* *
* @param u * @param u the u value
* the u value * @param v the v value
* @param v
* the v value
* @param controlPoints * @param controlPoints
* the nurbs' control points * the nurbs' control points
* @param knots * @param knots
@ -114,8 +112,11 @@ public class CurveAndSurfaceMath {
} }
/** /**
* This method prepares the knots to be used. If the knots represent non-uniform B-splines (first and last knot values are being * This method prepares the knots to be used. If the knots represent
* repeated) it leads to NaN results during calculations. This method adds a small number to each of such knots to avoid NaN's. * non-uniform B-splines (first and last knot values are being repeated) it
* leads to NaN results during calculations. This method adds a small number
* to each of such knots to avoid NaN's.
*
* @param knots * @param knots
* the knots to be prepared to use * the knots to be prepared to use
* @param basisFunctionDegree * @param basisFunctionDegree
@ -126,9 +127,9 @@ public class CurveAndSurfaceMath {
public static void prepareNurbsKnots(List<Float> knots, int basisFunctionDegree) { public static void prepareNurbsKnots(List<Float> knots, int basisFunctionDegree) {
float delta = KNOTS_MINIMUM_DELTA; float delta = KNOTS_MINIMUM_DELTA;
float prevValue = knots.get(0).floatValue(); float prevValue = knots.get(0).floatValue();
for(int i=1;i<knots.size();++i) { for (int i = 1; i < knots.size(); ++i) {
float value = knots.get(i).floatValue(); float value = knots.get(i).floatValue();
if(value<=prevValue) { if (value <= prevValue) {
value += delta; value += delta;
knots.set(i, Float.valueOf(value)); knots.set(i, Float.valueOf(value));
delta += KNOTS_MINIMUM_DELTA; delta += KNOTS_MINIMUM_DELTA;
@ -142,12 +143,10 @@ public class CurveAndSurfaceMath {
/** /**
* This method computes the base function value for the NURB curve. * This method computes the base function value for the NURB curve.
* @param i *
* the knot index * @param i the knot index
* @param k * @param k the base function degree
* the base function degree * @param t the knot value
* @param t
* the knot value
* @param knots * @param knots
* the knots' values * the knots' values
* @return the base function value * @return the base function value
@ -156,10 +155,10 @@ public class CurveAndSurfaceMath {
if (k == 1) { if (k == 1) {
return knots.get(i) <= t && t < knots.get(i + 1) ? 1.0f : 0.0f; return knots.get(i) <= t && t < knots.get(i + 1) ? 1.0f : 0.0f;
} else { } else {
return (t - knots.get(i)) / (knots.get(i + k - 1) - knots.get(i)) * return (t - knots.get(i)) / (knots.get(i + k - 1) - knots.get(i))
CurveAndSurfaceMath.computeBaseFunctionValue(i, k - 1, t, knots) * CurveAndSurfaceMath.computeBaseFunctionValue(i, k - 1, t, knots)
+ (knots.get(i + k) - t) / (knots.get(i + k) - knots.get(i + 1)) * + (knots.get(i + k) - t) / (knots.get(i + k) - knots.get(i + 1))
CurveAndSurfaceMath.computeBaseFunctionValue(i + 1, k - 1, t, knots); * CurveAndSurfaceMath.computeBaseFunctionValue(i + 1, k - 1, t, knots);
} }
} }
} }

@ -41,33 +41,56 @@ import java.util.Random;
* @version $Id: FastMath.java,v 1.45 2007/08/26 08:44:20 irrisor Exp $ * @version $Id: FastMath.java,v 1.45 2007/08/26 08:44:20 irrisor Exp $
*/ */
final public class FastMath { final public class FastMath {
private FastMath() { private FastMath() {
} }
/** A "close to zero" double epsilon value for use*/ /**
* A "close to zero" double epsilon value for use
*/
public static final double DBL_EPSILON = 2.220446049250313E-16d; public static final double DBL_EPSILON = 2.220446049250313E-16d;
/** A "close to zero" float epsilon value for use*/ /**
* A "close to zero" float epsilon value for use
*/
public static final float FLT_EPSILON = 1.1920928955078125E-7f; public static final float FLT_EPSILON = 1.1920928955078125E-7f;
/** A "close to zero" float epsilon value for use*/ /**
* A "close to zero" float epsilon value for use
*/
public static final float ZERO_TOLERANCE = 0.0001f; public static final float ZERO_TOLERANCE = 0.0001f;
public static final float ONE_THIRD = 1f / 3f; public static final float ONE_THIRD = 1f / 3f;
/** The value PI as a float. (180 degrees) */ /**
* The value PI as a float. (180 degrees)
*/
public static final float PI = (float) Math.PI; public static final float PI = (float) Math.PI;
/** The value 2PI as a float. (360 degrees) */ /**
* The value 2PI as a float. (360 degrees)
*/
public static final float TWO_PI = 2.0f * PI; public static final float TWO_PI = 2.0f * PI;
/** The value PI/2 as a float. (90 degrees) */ /**
* The value PI/2 as a float. (90 degrees)
*/
public static final float HALF_PI = 0.5f * PI; public static final float HALF_PI = 0.5f * PI;
/** The value PI/4 as a float. (45 degrees) */ /**
* The value PI/4 as a float. (45 degrees)
*/
public static final float QUARTER_PI = 0.25f * PI; public static final float QUARTER_PI = 0.25f * PI;
/** The value 1/PI as a float. */ /**
* The value 1/PI as a float.
*/
public static final float INV_PI = 1.0f / PI; public static final float INV_PI = 1.0f / PI;
/** The value 1/(2PI) as a float. */ /**
* The value 1/(2PI) as a float.
*/
public static final float INV_TWO_PI = 1.0f / TWO_PI; public static final float INV_TWO_PI = 1.0f / TWO_PI;
/** A value to multiply a degree value by, to convert it to radians. */ /**
* A value to multiply a degree value by, to convert it to radians.
*/
public static final float DEG_TO_RAD = PI / 180.0f; public static final float DEG_TO_RAD = PI / 180.0f;
/** A value to multiply a radian value by, to convert it to degrees. */ /**
* A value to multiply a radian value by, to convert it to degrees.
*/
public static final float RAD_TO_DEG = 180.0f / PI; public static final float RAD_TO_DEG = 180.0f / PI;
/** A precreated random object for random numbers. */ /**
* A precreated random object for random numbers.
*/
public static final Random rand = new Random(System.currentTimeMillis()); public static final Random rand = new Random(System.currentTimeMillis());
/** /**
@ -146,7 +169,8 @@ final public class FastMath {
* @param store a vector3f to store the result * @param store a vector3f to store the result
* @return The interpolated value between startValue and endValue. * @return The interpolated value between startValue and endValue.
*/ */
public static Vector3f interpolateLinear(float scale, Vector3f startValue, Vector3f endValue, Vector3f store) { public static Vector3f interpolateLinear(float scale, Vector3f startValue,
Vector3f endValue, Vector3f store) {
if (store == null) { if (store == null) {
store = new Vector3f(); store = new Vector3f();
} }
@ -177,6 +201,7 @@ final public class FastMath {
* if scale is between 0 and 1 this method returns the same result as interpolateLinear * if scale is between 0 and 1 this method returns the same result as interpolateLinear
* if the scale is over 1 the value is linearly extrapolated. * if the scale is over 1 the value is linearly extrapolated.
* Note that the end value is the value for a scale of 1. * Note that the end value is the value for a scale of 1.
*
* @param scale the scale for extrapolation * @param scale the scale for extrapolation
* @param startValue the starting value (scale = 0) * @param startValue the starting value (scale = 0)
* @param endValue the end value (scale = 1) * @param endValue the end value (scale = 1)
@ -194,13 +219,15 @@ final public class FastMath {
* if scale is between 0 and 1 this method returns the same result as interpolateLinear * if scale is between 0 and 1 this method returns the same result as interpolateLinear
* if the scale is over 1 the value is linearly extrapolated. * if the scale is over 1 the value is linearly extrapolated.
* Note that the end value is the value for a scale of 1. * Note that the end value is the value for a scale of 1.
*
* @param scale the scale for extrapolation * @param scale the scale for extrapolation
* @param startValue the starting value (scale = 0) * @param startValue the starting value (scale = 0)
* @param endValue the end value (scale = 1) * @param endValue the end value (scale = 1)
* @param store an initialized vector to store the return value * @param store an initialized vector to store the return value
* @return an extrapolation for the given parameters * @return an extrapolation for the given parameters
*/ */
public static Vector3f extrapolateLinear(float scale, Vector3f startValue, Vector3f endValue, Vector3f store) { public static Vector3f extrapolateLinear(float scale, Vector3f startValue,
Vector3f endValue, Vector3f store) {
if (store == null) { if (store == null) {
store = new Vector3f(); store = new Vector3f();
} }
@ -218,6 +245,7 @@ final public class FastMath {
* if scale is between 0 and 1 this method returns the same result as interpolateLinear * if scale is between 0 and 1 this method returns the same result as interpolateLinear
* if the scale is over 1 the value is linearly extrapolated. * if the scale is over 1 the value is linearly extrapolated.
* Note that the end value is the value for a scale of 1. * Note that the end value is the value for a scale of 1.
*
* @param scale the scale for extrapolation * @param scale the scale for extrapolation
* @param startValue the starting value (scale = 0) * @param startValue the starting value (scale = 0)
* @param endValue the end value (scale = 1) * @param endValue the end value (scale = 1)
@ -227,7 +255,8 @@ final public class FastMath {
return extrapolateLinear(scale, startValue, endValue, null); return extrapolateLinear(scale, startValue, endValue, null);
} }
/**Interpolate a spline between at least 4 control points following the Catmull-Rom equation. /**
* Interpolate a spline between at least 4 control points following the Catmull-Rom equation.
* here is the interpolation matrix * here is the interpolation matrix
* m = [ 0.0 1.0 0.0 0.0 ] * m = [ 0.0 1.0 0.0 0.0 ]
* [-T 0.0 T 0.0 ] * [-T 0.0 T 0.0 ]
@ -253,7 +282,8 @@ final public class FastMath {
return ((c4 * u + c3) * u + c2) * u + c1; return ((c4 * u + c3) * u + c2) * u + c1;
} }
/**Interpolate a spline between at least 4 control points following the Catmull-Rom equation. /**
* Interpolate a spline between at least 4 control points following the Catmull-Rom equation.
* here is the interpolation matrix * here is the interpolation matrix
* m = [ 0.0 1.0 0.0 0.0 ] * m = [ 0.0 1.0 0.0 0.0 ]
* [-T 0.0 T 0.0 ] * [-T 0.0 T 0.0 ]
@ -270,7 +300,8 @@ final public class FastMath {
* @param store a Vector3f to store the result * @param store a Vector3f to store the result
* @return CatmullRom interpolation * @return CatmullRom interpolation
*/ */
public static Vector3f interpolateCatmullRom(float u, float T, Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3, Vector3f store) { public static Vector3f interpolateCatmullRom(float u, float T, Vector3f p0,
Vector3f p1, Vector3f p2, Vector3f p3, Vector3f store) {
if (store == null) { if (store == null) {
store = new Vector3f(); store = new Vector3f();
} }
@ -297,7 +328,8 @@ final public class FastMath {
* @param p3 control point 3 * @param p3 control point 3
* @return CatmullRom interpolation * @return CatmullRom interpolation
*/ */
public static Vector3f interpolateCatmullRom(float u, float T, Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3) { public static Vector3f interpolateCatmullRom(float u, float T, Vector3f p0,
Vector3f p1, Vector3f p2, Vector3f p3) {
return interpolateCatmullRom(u, T, p0, p1, p2, p3, null); return interpolateCatmullRom(u, T, p0, p1, p2, p3, null);
} }
@ -326,7 +358,8 @@ final public class FastMath {
+ p3 * u2 * u; + p3 * u2 * u;
} }
/**Interpolate a spline between at least 4 control points following the Bezier equation. /**
* Interpolate a spline between at least 4 control points following the Bezier equation.
* here is the interpolation matrix * here is the interpolation matrix
* m = [ -1.0 3.0 -3.0 1.0 ] * m = [ -1.0 3.0 -3.0 1.0 ]
* [ 3.0 -6.0 3.0 0.0 ] * [ 3.0 -6.0 3.0 0.0 ]
@ -342,7 +375,8 @@ final public class FastMath {
* @param store a Vector3f to store the result * @param store a Vector3f to store the result
* @return Bezier interpolation * @return Bezier interpolation
*/ */
public static Vector3f interpolateBezier(float u, Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3, Vector3f store) { public static Vector3f interpolateBezier(float u, Vector3f p0, Vector3f p1,
Vector3f p2, Vector3f p3, Vector3f store) {
if (store == null) { if (store == null) {
store = new Vector3f(); store = new Vector3f();
} }
@ -352,7 +386,8 @@ final public class FastMath {
return store; return store;
} }
/**Interpolate a spline between at least 4 control points following the Bezier equation. /**
* Interpolate a spline between at least 4 control points following the Bezier equation.
* here is the interpolation matrix * here is the interpolation matrix
* m = [ -1.0 3.0 -3.0 1.0 ] * m = [ -1.0 3.0 -3.0 1.0 ]
* [ 3.0 -6.0 3.0 0.0 ] * [ 3.0 -6.0 3.0 0.0 ]
@ -373,6 +408,7 @@ final public class FastMath {
/** /**
* Compute the length of a CatmullRom spline between control points 1 and 2 * Compute the length of a CatmullRom spline between control points 1 and 2
*
* @param p0 control point 0 * @param p0 control point 0
* @param p1 control point 1 * @param p1 control point 1
* @param p2 control point 2 * @param p2 control point 2
@ -382,7 +418,8 @@ final public class FastMath {
* @param curveTension the curve tension * @param curveTension the curve tension
* @return the length of the segment * @return the length of the segment
*/ */
public static float getCatmullRomP1toP2Length(Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3, float startRange, float endRange, float curveTension) { public static float getCatmullRomP1toP2Length(Vector3f p0, Vector3f p1,
Vector3f p2, Vector3f p3, float startRange, float endRange, float curveTension) {
float epsilon = 0.001f; float epsilon = 0.001f;
float middleValue = (startRange + endRange) * 0.5f; float middleValue = (startRange + endRange) * 0.5f;
@ -409,6 +446,7 @@ final public class FastMath {
/** /**
* Compute the length on a Bezier spline between control points 1 and 2. * Compute the length on a Bezier spline between control points 1 and 2.
*
* @param p0 control point 0 * @param p0 control point 0
* @param p1 control point 1 * @param p1 control point 1
* @param p2 control point 2 * @param p2 control point 2
@ -432,6 +470,7 @@ final public class FastMath {
* Special cases: * Special cases:
* <ul><li>If fValue is smaller than -1, then the result is PI. * <ul><li>If fValue is smaller than -1, then the result is PI.
* <li>If the argument is greater than 1, then the result is 0.</ul> * <li>If the argument is greater than 1, then the result is 0.</ul>
*
* @param fValue The value to arc cosine. * @param fValue The value to arc cosine.
* @return The angle, in radians. * @return The angle, in radians.
* @see java.lang.Math#acos(double) * @see java.lang.Math#acos(double)
@ -453,6 +492,7 @@ final public class FastMath {
* Special cases: * Special cases:
* <ul><li>If fValue is smaller than -1, then the result is -HALF_PI. * <ul><li>If fValue is smaller than -1, then the result is -HALF_PI.
* <li>If the argument is greater than 1, then the result is HALF_PI.</ul> * <li>If the argument is greater than 1, then the result is HALF_PI.</ul>
*
* @param fValue The value to arc sine. * @param fValue The value to arc sine.
* @return the angle in radians. * @return the angle in radians.
* @see java.lang.Math#asin(double) * @see java.lang.Math#asin(double)
@ -471,6 +511,7 @@ final public class FastMath {
/** /**
* Returns the arc tangent of an angle given in radians.<br> * Returns the arc tangent of an angle given in radians.<br>
*
* @param fValue The angle, in radians. * @param fValue The angle, in radians.
* @return fValue's atan * @return fValue's atan
* @see java.lang.Math#atan(double) * @see java.lang.Math#atan(double)
@ -481,6 +522,7 @@ final public class FastMath {
/** /**
* A direct call to Math.atan2. * A direct call to Math.atan2.
*
* @param fY * @param fY
* @param fX * @param fX
* @return Math.atan2(fY,fX) * @return Math.atan2(fY,fX)
@ -492,6 +534,7 @@ final public class FastMath {
/** /**
* Rounds a fValue up. A call to Math.ceil * Rounds a fValue up. A call to Math.ceil
*
* @param fValue The value. * @param fValue The value.
* @return The fValue rounded up * @return The fValue rounded up
* @see java.lang.Math#ceil(double) * @see java.lang.Math#ceil(double)
@ -502,6 +545,7 @@ final public class FastMath {
/** /**
* Returns cosine of an angle. Direct call to java.lang.Math * Returns cosine of an angle. Direct call to java.lang.Math
*
* @see Math#cos(double) * @see Math#cos(double)
* @param v The angle to cosine. * @param v The angle to cosine.
* @return the cosine of the angle. * @return the cosine of the angle.
@ -512,6 +556,7 @@ final public class FastMath {
/** /**
* Returns the sine of an angle. Direct call to java.lang.Math * Returns the sine of an angle. Direct call to java.lang.Math
*
* @see Math#sin(double) * @see Math#sin(double)
* @param v The angle to sine. * @param v The angle to sine.
* @return the sine of the angle. * @return the sine of the angle.
@ -522,6 +567,7 @@ final public class FastMath {
/** /**
* Returns E^fValue * Returns E^fValue
*
* @param fValue Value to raise to a power. * @param fValue Value to raise to a power.
* @return The value E^fValue * @return The value E^fValue
* @see java.lang.Math#exp(double) * @see java.lang.Math#exp(double)
@ -532,6 +578,7 @@ final public class FastMath {
/** /**
* Returns Absolute value of a float. * Returns Absolute value of a float.
*
* @param fValue The value to abs. * @param fValue The value to abs.
* @return The abs of the value. * @return The abs of the value.
* @see java.lang.Math#abs(float) * @see java.lang.Math#abs(float)
@ -545,6 +592,7 @@ final public class FastMath {
/** /**
* Returns a number rounded down. * Returns a number rounded down.
*
* @param fValue The value to round * @param fValue The value to round
* @return The given number rounded down * @return The given number rounded down
* @see java.lang.Math#floor(double) * @see java.lang.Math#floor(double)
@ -555,6 +603,7 @@ final public class FastMath {
/** /**
* Returns 1/sqrt(fValue) * Returns 1/sqrt(fValue)
*
* @param fValue The value to process. * @param fValue The value to process.
* @return 1/sqrt(fValue) * @return 1/sqrt(fValue)
* @see java.lang.Math#sqrt(double) * @see java.lang.Math#sqrt(double)
@ -574,6 +623,7 @@ final public class FastMath {
/** /**
* Returns the log base E of a value. * Returns the log base E of a value.
*
* @param fValue The value to log. * @param fValue The value to log.
* @return The log of fValue base E * @return The log of fValue base E
* @see java.lang.Math#log(double) * @see java.lang.Math#log(double)
@ -585,6 +635,7 @@ final public class FastMath {
/** /**
* Returns the logarithm of value with given base, calculated as log(value)/log(base), * Returns the logarithm of value with given base, calculated as log(value)/log(base),
* so that pow(base, return)==value (contributed by vear) * so that pow(base, return)==value (contributed by vear)
*
* @param value The value to log. * @param value The value to log.
* @param base Base of logarithm. * @param base Base of logarithm.
* @return The logarithm of value with given base * @return The logarithm of value with given base
@ -595,6 +646,7 @@ final public class FastMath {
/** /**
* Returns a number raised to an exponent power. fBase^fExponent * Returns a number raised to an exponent power. fBase^fExponent
*
* @param fBase The base value (IE 2) * @param fBase The base value (IE 2)
* @param fExponent The exponent value (IE 3) * @param fExponent The exponent value (IE 3)
* @return base raised to exponent (IE 8) * @return base raised to exponent (IE 8)
@ -606,6 +658,7 @@ final public class FastMath {
/** /**
* Returns the value squared. fValue ^ 2 * Returns the value squared. fValue ^ 2
*
* @param fValue The value to square. * @param fValue The value to square.
* @return The square of the given value. * @return The square of the given value.
*/ */
@ -615,6 +668,7 @@ final public class FastMath {
/** /**
* Returns the square root of a given value. * Returns the square root of a given value.
*
* @param fValue The value to sqrt. * @param fValue The value to sqrt.
* @return The square root of the given value. * @return The square root of the given value.
* @see java.lang.Math#sqrt(double) * @see java.lang.Math#sqrt(double)
@ -626,6 +680,7 @@ final public class FastMath {
/** /**
* Returns the tangent of a value. If USE_FAST_TRIG is enabled, an approximate value * Returns the tangent of a value. If USE_FAST_TRIG is enabled, an approximate value
* is returned. Otherwise, a direct value is used. * is returned. Otherwise, a direct value is used.
*
* @param fValue The value to tangent, in radians. * @param fValue The value to tangent, in radians.
* @return The tangent of fValue. * @return The tangent of fValue.
* @see java.lang.Math#tan(double) * @see java.lang.Math#tan(double)
@ -636,6 +691,7 @@ final public class FastMath {
/** /**
* Returns 1 if the number is positive, -1 if the number is negative, and 0 otherwise * Returns 1 if the number is positive, -1 if the number is negative, and 0 otherwise
*
* @param iValue The integer to examine. * @param iValue The integer to examine.
* @return The integer's sign. * @return The integer's sign.
*/ */
@ -651,6 +707,7 @@ final public class FastMath {
/** /**
* Returns 1 if the number is positive, -1 if the number is negative, and 0 otherwise * Returns 1 if the number is positive, -1 if the number is negative, and 0 otherwise
*
* @param fValue The float to examine. * @param fValue The float to examine.
* @return The float's sign. * @return The float's sign.
*/ */
@ -661,6 +718,7 @@ final public class FastMath {
/** /**
* Given 3 points in a 2d plane, this function computes if the points going from A-B-C * Given 3 points in a 2d plane, this function computes if the points going from A-B-C
* are moving counter clock wise. * are moving counter clock wise.
*
* @param p0 Point 0. * @param p0 Point 0.
* @param p1 Point 1. * @param p1 Point 1.
* @param p2 Point 2. * @param p2 Point 2.
@ -690,6 +748,7 @@ final public class FastMath {
/** /**
* Test if a point is inside a triangle. 1 if the point is on the ccw side, * Test if a point is inside a triangle. 1 if the point is on the ccw side,
* -1 if the point is on the cw side, and 0 if it is on neither. * -1 if the point is on the cw side, and 0 if it is on neither.
*
* @param t0 First point of the triangle. * @param t0 First point of the triangle.
* @param t1 Second point of the triangle. * @param t1 Second point of the triangle.
* @param t2 Third point of the triangle. * @param t2 Third point of the triangle.
@ -720,6 +779,7 @@ final public class FastMath {
/** /**
* A method that computes normal for a triangle defined by three vertices. * A method that computes normal for a triangle defined by three vertices.
*
* @param v1 first vertex * @param v1 first vertex
* @param v2 second vertex * @param v2 second vertex
* @param v3 third vertex * @param v3 third vertex
@ -996,6 +1056,7 @@ final public class FastMath {
/** /**
* Converts a range of min/max to a 0-1 range. * Converts a range of min/max to a 0-1 range.
*
* @param value the value between min-max (inclusive). * @param value the value between min-max (inclusive).
* @param min the minimum of the range. * @param min the minimum of the range.
* @param max the maximum of the range. * @param max the maximum of the range.
@ -1004,5 +1065,4 @@ final public class FastMath {
public static float unInterpolateLinear(float value, float min, float max) { public static float unInterpolateLinear(float value, float min, float max) {
return (value - min) / (max - min); return (value - min) / (max - min);
} }
} }

@ -61,7 +61,6 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
/** /**
* Constructor instantiates a new <code>Matrix3f</code> object. The * Constructor instantiates a new <code>Matrix3f</code> object. The
* initial values for the matrix is that of the identity matrix. * initial values for the matrix is that of the identity matrix.
*
*/ */
public Matrix3f() { public Matrix3f() {
loadIdentity(); loadIdentity();
@ -70,24 +69,15 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
/** /**
* constructs a matrix with the given values. * constructs a matrix with the given values.
* *
* @param m00 * @param m00 0x0 in the matrix.
* 0x0 in the matrix. * @param m01 0x1 in the matrix.
* @param m01 * @param m02 0x2 in the matrix.
* 0x1 in the matrix. * @param m10 1x0 in the matrix.
* @param m02 * @param m11 1x1 in the matrix.
* 0x2 in the matrix. * @param m12 1x2 in the matrix.
* @param m10 * @param m20 2x0 in the matrix.
* 1x0 in the matrix. * @param m21 2x1 in the matrix.
* @param m11 * @param m22 2x2 in the matrix.
* 1x1 in the matrix.
* @param m12
* 1x2 in the matrix.
* @param m20
* 2x0 in the matrix.
* @param m21
* 2x1 in the matrix.
* @param m22
* 2x2 in the matrix.
*/ */
public Matrix3f(float m00, float m01, float m02, float m10, float m11, public Matrix3f(float m00, float m01, float m02, float m10, float m11,
float m12, float m20, float m21, float m22) { float m12, float m20, float m21, float m22) {
@ -160,10 +150,8 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
* position. If the position is invalid a <code>JmeException</code> is * position. If the position is invalid a <code>JmeException</code> is
* thrown. * thrown.
* *
* @param i * @param i the row index.
* the row index. * @param j the colum index.
* @param j
* the colum index.
* @return the value at (i, j). * @return the value at (i, j).
*/ */
@SuppressWarnings("fallthrough") @SuppressWarnings("fallthrough")
@ -303,6 +291,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
/** /**
* Normalize this matrix * Normalize this matrix
*
* @return this matrix once normalized. * @return this matrix once normalized.
*/ */
public Matrix3f normalizeLocal() { public Matrix3f normalizeLocal() {
@ -448,7 +437,6 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
TempVars vars = TempVars.get(); TempVars vars = TempVars.get();
fillFloatArray(vars.matrixWrite, columnMajor); fillFloatArray(vars.matrixWrite, columnMajor);
fb.put(vars.matrixWrite, 0, 9); fb.put(vars.matrixWrite, 0, 9);
@ -459,30 +447,29 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
public void fillFloatArray(float[] f, boolean columnMajor) { public void fillFloatArray(float[] f, boolean columnMajor) {
if (columnMajor) { if (columnMajor) {
f[ 0] = m00; f[0] = m00;
f[ 1] = m10; f[1] = m10;
f[ 2] = m20; f[2] = m20;
f[ 3] = m01; f[3] = m01;
f[ 4] = m11; f[4] = m11;
f[ 5] = m21; f[5] = m21;
f[ 6] = m02; f[6] = m02;
f[ 7] = m12; f[7] = m12;
f[ 8] = m22; f[8] = m22;
} else { } else {
f[ 0] = m00; f[0] = m00;
f[ 1] = m01; f[1] = m01;
f[ 2] = m02; f[2] = m02;
f[ 3] = m10; f[3] = m10;
f[ 4] = m11; f[4] = m11;
f[ 5] = m12; f[5] = m12;
f[ 6] = m20; f[6] = m20;
f[ 7] = m21; f[7] = m21;
f[ 8] = m22; f[8] = m22;
} }
} }
/** /**
*
* <code>setColumn</code> sets a particular column of this matrix to that * <code>setColumn</code> sets a particular column of this matrix to that
* represented by the provided vector. * represented by the provided vector.
* *
@ -522,7 +509,6 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
} }
/** /**
*
* <code>setRow</code> sets a particular row of this matrix to that * <code>setRow</code> sets a particular row of this matrix to that
* represented by the provided vector. * represented by the provided vector.
* *
@ -620,7 +606,6 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
} }
/** /**
*
* <code>set</code> sets the values of the matrix to those supplied by the * <code>set</code> sets the values of the matrix to those supplied by the
* 3x3 two dimenion array. * 3x3 two dimenion array.
* *
@ -652,12 +637,9 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
/** /**
* Recreate Matrix using the provided axis. * Recreate Matrix using the provided axis.
* *
* @param uAxis * @param uAxis Vector3f
* Vector3f * @param vAxis Vector3f
* @param vAxis * @param wAxis Vector3f
* Vector3f
* @param wAxis
* Vector3f
*/ */
public void fromAxes(Vector3f uAxis, Vector3f vAxis, Vector3f wAxis) { public void fromAxes(Vector3f uAxis, Vector3f vAxis, Vector3f wAxis) {
m00 = uAxis.x; m00 = uAxis.x;
@ -726,7 +708,6 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
} }
/** /**
*
* <code>set</code> defines the values of the matrix based on a supplied * <code>set</code> defines the values of the matrix based on a supplied
* <code>Quaternion</code>. It should be noted that all previous values * <code>Quaternion</code>. It should be noted that all previous values
* will be overridden. * will be overridden.
@ -742,7 +723,6 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
/** /**
* <code>loadIdentity</code> sets this matrix to the identity matrix. * <code>loadIdentity</code> sets this matrix to the identity matrix.
* Where all values are zero except those along the diagonal which are one. * Where all values are zero except those along the diagonal which are one.
*
*/ */
public void loadIdentity() { public void loadIdentity() {
m01 = m02 = m10 = m12 = m20 = m21 = 0; m01 = m02 = m10 = m12 = m20 = m21 = 0;
@ -1175,7 +1155,6 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
} }
/** /**
*
* <code>hashCode</code> returns the hash code value as an integer and is * <code>hashCode</code> returns the hash code value as an integer and is
* supported for the benefit of hashing based collection classes such as * supported for the benefit of hashing based collection classes such as
* Hashtable, HashMap, HashSet etc. * Hashtable, HashMap, HashSet etc.

@ -69,7 +69,6 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
/** /**
* Constructor instantiates a new <code>Matrix</code> that is set to the * Constructor instantiates a new <code>Matrix</code> that is set to the
* identity matrix. * identity matrix.
*
*/ */
public Matrix4f() { public Matrix4f() {
loadIdentity(); loadIdentity();
@ -253,10 +252,8 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
* position. If the position is invalid a <code>JmeException</code> is * position. If the position is invalid a <code>JmeException</code> is
* thrown. * thrown.
* *
* @param i * @param i the row index.
* the row index. * @param j the colum index.
* @param j
* the colum index.
* @return the value at (i, j). * @return the value at (i, j).
*/ */
@SuppressWarnings("fallthrough") @SuppressWarnings("fallthrough")
@ -316,8 +313,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
* <code>getColumn</code> returns one of three columns specified by the * <code>getColumn</code> returns one of three columns specified by the
* parameter. This column is returned as a float array of length 4. * parameter. This column is returned as a float array of length 4.
* *
* @param i * @param i the column to retrieve. Must be between 0 and 3.
* the column to retrieve. Must be between 0 and 3.
* @return the column specified by the index. * @return the column specified by the index.
*/ */
public float[] getColumn(int i) { public float[] getColumn(int i) {
@ -328,8 +324,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
* <code>getColumn</code> returns one of three columns specified by the * <code>getColumn</code> returns one of three columns specified by the
* parameter. This column is returned as a float[4]. * parameter. This column is returned as a float[4].
* *
* @param i * @param i the column to retrieve. Must be between 0 and 3.
* the column to retrieve. Must be between 0 and 3.
* @param store * @param store
* the float array to store the result in. if null, a new one * the float array to store the result in. if null, a new one
* is created. * is created.
@ -372,12 +367,10 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
} }
/** /**
*
* <code>setColumn</code> sets a particular column of this matrix to that * <code>setColumn</code> sets a particular column of this matrix to that
* represented by the provided vector. * represented by the provided vector.
* *
* @param i * @param i the column to set.
* the column to set.
* @param column * @param column
* the data to set. * the data to set.
*/ */
@ -423,10 +416,8 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
* position. If the position is invalid a <code>JmeException</code> is * position. If the position is invalid a <code>JmeException</code> is
* thrown. * thrown.
* *
* @param i * @param i the row index.
* the row index. * @param j the colum index.
* @param j
* the colum index.
* @param value * @param value
* the value for (i, j). * the value for (i, j).
*/ */
@ -532,7 +523,6 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
m33 = matrix[3][3]; m33 = matrix[3][3];
} }
/** /**
* Sets the values of this matrix * Sets the values of this matrix
*/ */
@ -718,6 +708,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
/** /**
* <code>fillFloatBuffer</code> fills a FloatBuffer object with * <code>fillFloatBuffer</code> fills a FloatBuffer object with
* the matrix data. * the matrix data.
*
* @param fb the buffer to fill, must be correct size * @param fb the buffer to fill, must be correct size
* @return matrix data as a FloatBuffer. * @return matrix data as a FloatBuffer.
*/ */
@ -753,7 +744,6 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
TempVars vars = TempVars.get(); TempVars vars = TempVars.get();
fillFloatArray(vars.matrixWrite, columnMajor); fillFloatArray(vars.matrixWrite, columnMajor);
fb.put(vars.matrixWrite, 0, 16); fb.put(vars.matrixWrite, 0, 16);
@ -764,16 +754,16 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
public void fillFloatArray(float[] f, boolean columnMajor) { public void fillFloatArray(float[] f, boolean columnMajor) {
if (columnMajor) { if (columnMajor) {
f[ 0] = m00; f[0] = m00;
f[ 1] = m10; f[1] = m10;
f[ 2] = m20; f[2] = m20;
f[ 3] = m30; f[3] = m30;
f[ 4] = m01; f[4] = m01;
f[ 5] = m11; f[5] = m11;
f[ 6] = m21; f[6] = m21;
f[ 7] = m31; f[7] = m31;
f[ 8] = m02; f[8] = m02;
f[ 9] = m12; f[9] = m12;
f[10] = m22; f[10] = m22;
f[11] = m32; f[11] = m32;
f[12] = m03; f[12] = m03;
@ -781,16 +771,16 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
f[14] = m23; f[14] = m23;
f[15] = m33; f[15] = m33;
} else { } else {
f[ 0] = m00; f[0] = m00;
f[ 1] = m01; f[1] = m01;
f[ 2] = m02; f[2] = m02;
f[ 3] = m03; f[3] = m03;
f[ 4] = m10; f[4] = m10;
f[ 5] = m11; f[5] = m11;
f[ 6] = m12; f[6] = m12;
f[ 7] = m13; f[7] = m13;
f[ 8] = m20; f[8] = m20;
f[ 9] = m21; f[9] = m21;
f[10] = m22; f[10] = m22;
f[11] = m23; f[11] = m23;
f[12] = m30; f[12] = m30;
@ -802,6 +792,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
/** /**
* <code>readFloatBuffer</code> reads value for this matrix from a FloatBuffer. * <code>readFloatBuffer</code> reads value for this matrix from a FloatBuffer.
*
* @param fb the buffer to read from, must be correct size * @param fb the buffer to read from, must be correct size
* @return this data as a FloatBuffer. * @return this data as a FloatBuffer.
*/ */
@ -811,6 +802,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
/** /**
* <code>readFloatBuffer</code> reads value for this matrix from a FloatBuffer. * <code>readFloatBuffer</code> reads value for this matrix from a FloatBuffer.
*
* @param fb the buffer to read from, must be correct size * @param fb the buffer to read from, must be correct size
* @param columnMajor if true, this buffer should be filled with column * @param columnMajor if true, this buffer should be filled with column
* major data, otherwise it will be filled row major. * major data, otherwise it will be filled row major.
@ -859,7 +851,6 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
/** /**
* <code>loadIdentity</code> sets this matrix to the identity matrix, * <code>loadIdentity</code> sets this matrix to the identity matrix,
* namely all zeros with ones along the diagonal. * namely all zeros with ones along the diagonal.
*
*/ */
public void loadIdentity() { public void loadIdentity() {
m01 = m02 = m03 = 0.0f; m01 = m02 = m03 = 0.0f;
@ -869,7 +860,8 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
m00 = m11 = m22 = m33 = 1.0f; m00 = m11 = m22 = m33 = 1.0f;
} }
public void fromFrustum(float near, float far, float left, float right, float top, float bottom, boolean parallel) { public void fromFrustum(float near, float far, float left, float right,
float top, float bottom, boolean parallel) {
loadIdentity(); loadIdentity();
if (parallel) { if (parallel) {
// scale // scale
@ -1095,7 +1087,6 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
+ m32 * in2.m23 + m32 * in2.m23
+ m33 * in2.m33; + m33 * in2.m33;
store.m00 = m[0]; store.m00 = m[0];
store.m01 = m[1]; store.m01 = m[1];
store.m02 = m[2]; store.m02 = m[2];
@ -1211,7 +1202,6 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
* *
* @param vec * @param vec
* vec to multiply against. * vec to multiply against.
*
* @return the rotated vector. * @return the rotated vector.
*/ */
public Vector4f multAcross(Vector4f vec) { public Vector4f multAcross(Vector4f vec) {
@ -1834,12 +1824,9 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
/** /**
* <code>setTranslation</code> will set the matrix's translation values. * <code>setTranslation</code> will set the matrix's translation values.
* *
* @param x * @param x value of the translation on the x axis
* value of the translation on the x axis * @param y value of the translation on the y axis
* @param y * @param z value of the translation on the z axis
* value of the translation on the y axis
* @param z
* value of the translation on the z axis
*/ */
public void setTranslation(float x, float y, float z) { public void setTranslation(float x, float y, float z) {
m03 = x; m03 = x;
@ -1988,7 +1975,6 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
} }
/** /**
*
* <code>inverseTranslateVect</code> translates a given Vector3f by the * <code>inverseTranslateVect</code> translates a given Vector3f by the
* translation part of this matrix. * translation part of this matrix.
* *
@ -2009,7 +1995,6 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
} }
/** /**
*
* <code>inverseTranslateVect</code> translates a given Vector3f by the * <code>inverseTranslateVect</code> translates a given Vector3f by the
* translation part of this matrix. * translation part of this matrix.
* *
@ -2025,7 +2010,6 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
} }
/** /**
*
* <code>inverseTranslateVect</code> translates a given Vector3f by the * <code>inverseTranslateVect</code> translates a given Vector3f by the
* translation part of this matrix. * translation part of this matrix.
* *
@ -2041,7 +2025,6 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
} }
/** /**
*
* <code>inverseRotateVect</code> rotates a given Vector3f by the rotation * <code>inverseRotateVect</code> rotates a given Vector3f by the rotation
* part of this matrix. * part of this matrix.
* *
@ -2118,7 +2101,6 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
} }
/** /**
*
* <code>hashCode</code> returns the hash code value as an integer and is * <code>hashCode</code> returns the hash code value as an integer and is
* supported for the benefit of hashing based collection classes such as * supported for the benefit of hashing based collection classes such as
* Hashtable, HashMap, HashSet etc. * Hashtable, HashMap, HashSet etc.

@ -121,7 +121,7 @@ public class Plane implements Savable, Cloneable, java.io.Serializable {
* *
*/ */
public void setNormal(float x, float y, float z) { public void setNormal(float x, float y, float z) {
this.normal.set(x,y,z); this.normal.set(x, y, z);
} }
/** /**
@ -153,20 +153,21 @@ public class Plane implements Savable, Cloneable, java.io.Serializable {
return constant; return constant;
} }
public Vector3f getClosestPoint(Vector3f point, Vector3f store){ public Vector3f getClosestPoint(Vector3f point, Vector3f store) {
// float t = constant - normal.dot(point); // float t = constant - normal.dot(point);
// return store.set(normal).multLocal(t).addLocal(point); // return store.set(normal).multLocal(t).addLocal(point);
float t = (constant - normal.dot(point)) / normal.dot(normal); float t = (constant - normal.dot(point)) / normal.dot(normal);
return store.set(normal).multLocal(t).addLocal(point); return store.set(normal).multLocal(t).addLocal(point);
} }
public Vector3f getClosestPoint(Vector3f point){ public Vector3f getClosestPoint(Vector3f point) {
return getClosestPoint(point, new Vector3f()); return getClosestPoint(point, new Vector3f());
} }
public Vector3f reflect(Vector3f point, Vector3f store){ public Vector3f reflect(Vector3f point, Vector3f store) {
if (store == null) if (store == null) {
store = new Vector3f(); store = new Vector3f();
}
float d = pseudoDistance(point); float d = pseudoDistance(point);
store.set(normal).negateLocal().multLocal(d * 2f); store.set(normal).negateLocal().multLocal(d * 2f);
@ -208,19 +209,19 @@ public class Plane implements Savable, Cloneable, java.io.Serializable {
} }
} }
public boolean isOnPlane(Vector3f point){ public boolean isOnPlane(Vector3f point) {
float dist = pseudoDistance(point); float dist = pseudoDistance(point);
if (dist < FastMath.FLT_EPSILON && dist > -FastMath.FLT_EPSILON) if (dist < FastMath.FLT_EPSILON && dist > -FastMath.FLT_EPSILON) {
return true; return true;
else } else {
return false; return false;
} }
}
/** /**
* Initialize this plane using the three points of the given triangle. * Initialize this plane using the three points of the given triangle.
* *
* @param t * @param t the triangle
* the triangle
*/ */
public void setPlanePoints(AbstractTriangle t) { public void setPlanePoints(AbstractTriangle t) {
setPlanePoints(t.get1(), t.get2(), t.get3()); setPlanePoints(t.get1(), t.get2(), t.get3());
@ -232,7 +233,7 @@ public class Plane implements Savable, Cloneable, java.io.Serializable {
* @param origin * @param origin
* @param normal * @param normal
*/ */
public void setOriginNormal(Vector3f origin, Vector3f normal){ public void setOriginNormal(Vector3f origin, Vector3f normal) {
this.normal.set(normal); this.normal.set(normal);
this.constant = normal.x * origin.x + normal.y * origin.y + normal.z * origin.z; this.constant = normal.x * origin.x + normal.y * origin.y + normal.z * origin.z;
} }

@ -43,8 +43,7 @@ import java.util.logging.Logger;
* rotation in four dimensions. This avoids "gimbal lock" and allows for smooth * rotation in four dimensions. This avoids "gimbal lock" and allows for smooth
* continuous rotation. * continuous rotation.
* *
* <code>Quaternion</code> is defined by four floating point numbers: {x y z * <code>Quaternion</code> is defined by four floating point numbers: {x y z w}.
* w}.
* *
* @author Mark Powell * @author Mark Powell
* @author Joshua Slack * @author Joshua Slack
@ -82,14 +81,10 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
* Constructor instantiates a new <code>Quaternion</code> object from the * Constructor instantiates a new <code>Quaternion</code> object from the
* given list of parameters. * given list of parameters.
* *
* @param x * @param x the x value of the quaternion.
* the x value of the quaternion. * @param y the y value of the quaternion.
* @param y * @param z the z value of the quaternion.
* the y value of the quaternion. * @param w the w value of the quaternion.
* @param z
* the z value of the quaternion.
* @param w
* the w value of the quaternion.
*/ */
public Quaternion(float x, float y, float z, float w) { public Quaternion(float x, float y, float z, float w) {
this.x = x; this.x = x;
@ -115,17 +110,13 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
} }
/** /**
* sets the data in a <code>Quaternion</code> object from the given list * sets the data in a <code>Quaternion</code> object from the given list of
* of parameters. * parameters.
* *
* @param x * @param x the x value of the quaternion.
* the x value of the quaternion. * @param y the y value of the quaternion.
* @param y * @param z the z value of the quaternion.
* the y value of the quaternion. * @param w the w value of the quaternion.
* @param z
* the z value of the quaternion.
* @param w
* the w value of the quaternion.
* @return this * @return this
*/ */
public Quaternion set(float x, float y, float z, float w) { public Quaternion set(float x, float y, float z, float w) {
@ -141,8 +132,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
* passed <code>Quaternion</code> object. The values are copied producing * passed <code>Quaternion</code> object. The values are copied producing
* a new object. * a new object.
* *
* @param q * @param q The Quaternion to copy values from.
* The Quaternion to copy values from.
* @return this * @return this
*/ */
public Quaternion set(Quaternion q) { public Quaternion set(Quaternion q) {
@ -184,8 +174,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
* Constructor instantiates a new <code>Quaternion</code> object from an * Constructor instantiates a new <code>Quaternion</code> object from an
* existing quaternion, creating a copy. * existing quaternion, creating a copy.
* *
* @param q * @param q the quaternion to copy.
* the quaternion to copy.
*/ */
public Quaternion(Quaternion q) { public Quaternion(Quaternion q) {
this.x = q.x; this.x = q.x;
@ -231,8 +220,10 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
/** /**
* <code>fromAngles</code> builds a Quaternion from the Euler rotation * <code>fromAngles</code> builds a Quaternion from the Euler rotation
* angles (x,y,z) aka (pitch, yaw, roll)). Note that we are applying in order: (y, z, x) aka (yaw, roll, pitch) but * angles (x,y,z) aka (pitch, yaw, roll)).
* we've ordered them in x, y, and z for convenience. * Note that we are applying in order: (y, z, x) aka (yaw, roll, pitch)
* but we've ordered them in x, y, and z for convenience.
*
* @see <a href="http://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToQuaternion/index.htm">http://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToQuaternion/index.htm</a> * @see <a href="http://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToQuaternion/index.htm">http://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToQuaternion/index.htm</a>
* *
* @param xAngle * @param xAngle
@ -315,7 +306,6 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
} }
/** /**
*
* <code>fromRotationMatrix</code> generates a quaternion from a supplied * <code>fromRotationMatrix</code> generates a quaternion from a supplied
* matrix. This matrix is assumed to be a rotational matrix. * matrix. This matrix is assumed to be a rotational matrix.
* *
@ -805,6 +795,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
/** /**
* Sets the values of this quaternion to the nlerp from itself to q2 by blend. * Sets the values of this quaternion to the nlerp from itself to q2 by blend.
*
* @param q2 * @param q2
* @param blend * @param blend
*/ */
@ -829,8 +820,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
* <code>add</code> adds the values of this quaternion to those of the * <code>add</code> adds the values of this quaternion to those of the
* parameter quaternion. The result is returned as a new quaternion. * parameter quaternion. The result is returned as a new quaternion.
* *
* @param q * @param q the quaternion to add to this.
* the quaternion to add to this.
* @return the new quaternion. * @return the new quaternion.
*/ */
public Quaternion add(Quaternion q) { public Quaternion add(Quaternion q) {
@ -841,8 +831,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
* <code>add</code> adds the values of this quaternion to those of the * <code>add</code> adds the values of this quaternion to those of the
* parameter quaternion. The result is stored in this Quaternion. * parameter quaternion. The result is stored in this Quaternion.
* *
* @param q * @param q the quaternion to add to this.
* the quaternion to add to this.
* @return This Quaternion after addition. * @return This Quaternion after addition.
*/ */
public Quaternion addLocal(Quaternion q) { public Quaternion addLocal(Quaternion q) {
@ -858,8 +847,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
* from those of this quaternion. The result is returned as a new * from those of this quaternion. The result is returned as a new
* quaternion. * quaternion.
* *
* @param q * @param q the quaternion to subtract from this.
* the quaternion to subtract from this.
* @return the new quaternion. * @return the new quaternion.
*/ */
public Quaternion subtract(Quaternion q) { public Quaternion subtract(Quaternion q) {
@ -870,8 +858,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
* <code>subtract</code> subtracts the values of the parameter quaternion * <code>subtract</code> subtracts the values of the parameter quaternion
* from those of this quaternion. The result is stored in this Quaternion. * from those of this quaternion. The result is stored in this Quaternion.
* *
* @param q * @param q the quaternion to subtract from this.
* the quaternion to subtract from this.
* @return This Quaternion after subtraction. * @return This Quaternion after subtraction.
*/ */
public Quaternion subtractLocal(Quaternion q) { public Quaternion subtractLocal(Quaternion q) {
@ -903,8 +890,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
* It IS safe for q and res to be the same object. * It IS safe for q and res to be the same object.
* It IS NOT safe for this and res to be the same object. * It IS NOT safe for this and res to be the same object.
* *
* @param q * @param q the quaternion to multiply this quaternion by.
* the quaternion to multiply this quaternion by.
* @param res * @param res
* the quaternion to store the result in. * the quaternion to store the result in.
* @return the new quaternion. * @return the new quaternion.
@ -982,8 +968,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
* corresponds to an axis of the coordinate system defined by the quaternion * corresponds to an axis of the coordinate system defined by the quaternion
* rotation. * rotation.
* *
* @param axis * @param axis the array of vectors to be filled.
* the array of vectors to be filled.
*/ */
public void toAxes(Vector3f axis[]) { public void toAxes(Vector3f axis[]) {
Matrix3f tempMat = toRotationMatrix(); Matrix3f tempMat = toRotationMatrix();
@ -996,8 +981,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
* <code>mult</code> multiplies this quaternion by a parameter vector. The * <code>mult</code> multiplies this quaternion by a parameter vector. The
* result is returned as a new vector. * result is returned as a new vector.
* *
* @param v * @param v the vector to multiply this quaternion by.
* the vector to multiply this quaternion by.
* @return the new vector. * @return the new vector.
*/ */
public Vector3f mult(Vector3f v) { public Vector3f mult(Vector3f v) {
@ -1008,8 +992,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
* <code>mult</code> multiplies this quaternion by a parameter vector. The * <code>mult</code> multiplies this quaternion by a parameter vector. The
* result is stored in the supplied vector * result is stored in the supplied vector
* *
* @param v * @param v the vector to multiply this quaternion by.
* the vector to multiply this quaternion by.
* @return v * @return v
*/ */
public Vector3f multLocal(Vector3f v) { public Vector3f multLocal(Vector3f v) {
@ -1031,8 +1014,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
* stored in this Quaternion, which is also returned for chaining. Similar * stored in this Quaternion, which is also returned for chaining. Similar
* to this *= q. * to this *= q.
* *
* @param q * @param q The Quaternion to multiply this one by.
* The Quaternion to multiply this one by.
* @return This Quaternion, after multiplication. * @return This Quaternion, after multiplication.
*/ */
public Quaternion multLocal(Quaternion q) { public Quaternion multLocal(Quaternion q) {
@ -1051,14 +1033,10 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
* stored in this Quaternion, which is also returned for chaining. Similar * stored in this Quaternion, which is also returned for chaining. Similar
* to this *= q. * to this *= q.
* *
* @param qx - * @param qx quat x value
* quat x value * @param qy quat y value
* @param qy - * @param qz quat z value
* quat y value * @param qw quat w value
* @param qz -
* quat z value
* @param qw -
* quat w value
* *
* @return This Quaternion, after multiplication. * @return This Quaternion, after multiplication.
*/ */
@ -1304,7 +1282,6 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
} }
/** /**
*
* <code>hashCode</code> returns the hash code value as an integer and is * <code>hashCode</code> returns the hash code value as an integer and is
* supported for the benefit of hashing based collection classes such as * supported for the benefit of hashing based collection classes such as
* Hashtable, HashMap, HashSet etc. * Hashtable, HashMap, HashSet etc.

@ -66,6 +66,7 @@ public class Spline implements Savable {
/** /**
* Create a spline * Create a spline
*
* @param splineType the type of the spline @see {SplineType} * @param splineType the type of the spline @see {SplineType}
* @param controlPoints an array of vector to use as control points of the spline * @param controlPoints an array of vector to use as control points of the spline
* If the type of the curve is Bezier curve the control points should be provided * If the type of the curve is Bezier curve the control points should be provided
@ -80,7 +81,7 @@ public class Spline implements Savable {
* @param cycle true if the spline cycle. * @param cycle true if the spline cycle.
*/ */
public Spline(SplineType splineType, Vector3f[] controlPoints, float curveTension, boolean cycle) { public Spline(SplineType splineType, Vector3f[] controlPoints, float curveTension, boolean cycle) {
if(splineType==SplineType.Nurb) { if (splineType == SplineType.Nurb) {
throw new IllegalArgumentException("To create NURBS spline use: 'public Spline(Vector3f[] controlPoints, float[] weights, float[] nurbKnots)' constructor!"); throw new IllegalArgumentException("To create NURBS spline use: 'public Spline(Vector3f[] controlPoints, float[] weights, float[] nurbKnots)' constructor!");
} }
for (int i = 0; i < controlPoints.length; i++) { for (int i = 0; i < controlPoints.length; i++) {
@ -95,6 +96,7 @@ public class Spline implements Savable {
/** /**
* Create a spline * Create a spline
*
* @param splineType the type of the spline @see {SplineType} * @param splineType the type of the spline @see {SplineType}
* @param controlPoints a list of vector to use as control points of the spline * @param controlPoints a list of vector to use as control points of the spline
* If the type of the curve is Bezier curve the control points should be provided * If the type of the curve is Bezier curve the control points should be provided
@ -109,7 +111,7 @@ public class Spline implements Savable {
* @param cycle true if the spline cycle. * @param cycle true if the spline cycle.
*/ */
public Spline(SplineType splineType, List<Vector3f> controlPoints, float curveTension, boolean cycle) { public Spline(SplineType splineType, List<Vector3f> controlPoints, float curveTension, boolean cycle) {
if(splineType==SplineType.Nurb) { if (splineType == SplineType.Nurb) {
throw new IllegalArgumentException("To create NURBS spline use: 'public Spline(Vector3f[] controlPoints, float[] weights, float[] nurbKnots)' constructor!"); throw new IllegalArgumentException("To create NURBS spline use: 'public Spline(Vector3f[] controlPoints, float[] weights, float[] nurbKnots)' constructor!");
} }
type = splineType; type = splineType;
@ -122,13 +124,14 @@ public class Spline implements Savable {
/** /**
* Create a NURBS spline. A spline type is automatically set to SplineType.Nurb. * Create a NURBS spline. A spline type is automatically set to SplineType.Nurb.
* The cycle is set to <b>false</b> by default. * The cycle is set to <b>false</b> by default.
*
* @param controlPoints a list of vector to use as control points of the spline * @param controlPoints a list of vector to use as control points of the spline
* @param nurbKnots the nurb's spline knots * @param nurbKnots the nurb's spline knots
*/ */
public Spline(List<Vector4f> controlPoints, List<Float> nurbKnots) { public Spline(List<Vector4f> controlPoints, List<Float> nurbKnots) {
//input data control //input data control
for(int i=0;i<nurbKnots.size()-1;++i) { for (int i = 0; i < nurbKnots.size() - 1; ++i) {
if(nurbKnots.get(i)>nurbKnots.get(i+1)) { if (nurbKnots.get(i) > nurbKnots.get(i + 1)) {
throw new IllegalArgumentException("The knots values cannot decrease!"); throw new IllegalArgumentException("The knots values cannot decrease!");
} }
} }
@ -138,7 +141,7 @@ public class Spline implements Savable {
this.weights = new float[controlPoints.size()]; this.weights = new float[controlPoints.size()];
this.knots = nurbKnots; this.knots = nurbKnots;
this.basisFunctionDegree = nurbKnots.size() - weights.length; this.basisFunctionDegree = nurbKnots.size() - weights.length;
for(int i=0;i<controlPoints.size();++i) { for (int i = 0; i < controlPoints.size(); ++i) {
Vector4f controlPoint = controlPoints.get(i); Vector4f controlPoint = controlPoints.get(i);
this.controlPoints.add(new Vector3f(controlPoint.x, controlPoint.y, controlPoint.z)); this.controlPoints.add(new Vector3f(controlPoint.x, controlPoint.y, controlPoint.z));
this.weights[i] = controlPoint.w; this.weights[i] = controlPoint.w;
@ -175,6 +178,7 @@ public class Spline implements Savable {
/** /**
* Adds a controlPoint to the spline * Adds a controlPoint to the spline
*
* @param controlPoint a position in world space * @param controlPoint a position in world space
*/ */
public void addControlPoint(Vector3f controlPoint) { public void addControlPoint(Vector3f controlPoint) {
@ -192,6 +196,7 @@ public class Spline implements Savable {
/** /**
* remove the controlPoint from the spline * remove the controlPoint from the spline
*
* @param controlPoint the controlPoint to remove * @param controlPoint the controlPoint to remove
*/ */
public void removeControlPoint(Vector3f controlPoint) { public void removeControlPoint(Vector3f controlPoint) {
@ -201,7 +206,7 @@ public class Spline implements Savable {
} }
} }
public void clearControlPoints(){ public void clearControlPoints() {
controlPoints.clear(); controlPoints.clear();
totalLength = 0; totalLength = 0;
} }
@ -225,9 +230,9 @@ public class Spline implements Savable {
totalLength += l; totalLength += l;
} }
} }
} else if(type == SplineType.Bezier) { } else if (type == SplineType.Bezier) {
this.computeBezierLength(); this.computeBezierLength();
} else if(type == SplineType.Nurb) { } else if (type == SplineType.Nurb) {
this.computeNurbLength(); this.computeNurbLength();
} else { } else {
this.initCatmullRomWayPoints(controlPoints); this.initCatmullRomWayPoints(controlPoints);
@ -256,7 +261,7 @@ public class Spline implements Savable {
private void computeBezierLength() { private void computeBezierLength() {
float l = 0; float l = 0;
if (controlPoints.size() > 1) { if (controlPoints.size() > 1) {
for (int i = 0; i < controlPoints.size() - 1; i+=3) { for (int i = 0; i < controlPoints.size() - 1; i += 3) {
l = FastMath.getBezierP1toP2Length(controlPoints.get(i), l = FastMath.getBezierP1toP2Length(controlPoints.get(i),
controlPoints.get(i + 1), controlPoints.get(i + 2), controlPoints.get(i + 3)); controlPoints.get(i + 1), controlPoints.get(i + 2), controlPoints.get(i + 3));
segmentsLength.add(l); segmentsLength.add(l);
@ -274,9 +279,12 @@ public class Spline implements Savable {
/** /**
* Interpolate a position on the spline * Interpolate a position on the spline
* @param value a value from 0 to 1 that represent the position between the current control point and the next one *
* @param value a value from 0 to 1 that represent the position between the
* current control point and the next one
* @param currentControlPoint the current control point * @param currentControlPoint the current control point
* @param store a vector to store the result (use null to create a new one that will be returned by the method) * @param store a vector to store the result (use null to create a new one
* that will be returned by the method)
* @return the position * @return the position
*/ */
public Vector3f interpolate(float value, int currentControlPoint, Vector3f store) { public Vector3f interpolate(float value, int currentControlPoint, Vector3f store) {
@ -316,7 +324,7 @@ public class Spline implements Savable {
*/ */
public void setCurveTension(float curveTension) { public void setCurveTension(float curveTension) {
this.curveTension = curveTension; this.curveTension = curveTension;
if(type==SplineType.CatmullRom && !getControlPoints().isEmpty()) { if (type == SplineType.CatmullRom && !getControlPoints().isEmpty()) {
this.computeTotalLength(); this.computeTotalLength();
} }
} }
@ -330,10 +338,11 @@ public class Spline implements Savable {
/** /**
* set to true to make the spline cycle * set to true to make the spline cycle
*
* @param cycle * @param cycle
*/ */
public void setCycle(boolean cycle) { public void setCycle(boolean cycle) {
if(type!=SplineType.Nurb) { if (type != SplineType.Nurb) {
if (controlPoints.size() >= 2) { if (controlPoints.size() >= 2) {
if (this.cycle && !cycle) { if (this.cycle && !cycle) {
controlPoints.remove(controlPoints.size() - 1); controlPoints.remove(controlPoints.size() - 1);
@ -365,6 +374,7 @@ public class Spline implements Savable {
/** /**
* Sets the type of the spline * Sets the type of the spline
*
* @param type * @param type
*/ */
public void setType(SplineType type) { public void setType(SplineType type) {
@ -387,10 +397,11 @@ public class Spline implements Savable {
} }
//////////// NURBS getters ///////////////////// //////////// NURBS getters /////////////////////
/** /**
* This method returns the minimum nurb curve knot value. Check the nurb type before calling this method. It the curve is not of a Nurb * This method returns the minimum nurb curve knot value. Check the nurb
* type - NPE will be thrown. * type before calling this method. It the curve is not of a Nurb type - NPE
* will be thrown.
*
* @return the minimum nurb curve knot value * @return the minimum nurb curve knot value
*/ */
public float getMinNurbKnot() { public float getMinNurbKnot() {
@ -398,8 +409,10 @@ public class Spline implements Savable {
} }
/** /**
* This method returns the maximum nurb curve knot value. Check the nurb type before calling this method. It the curve is not of a Nurb * This method returns the maximum nurb curve knot value. Check the nurb
* type - NPE will be thrown. * type before calling this method. It the curve is not of a Nurb type - NPE
* will be thrown.
*
* @return the maximum nurb curve knot value * @return the maximum nurb curve knot value
*/ */
public float getMaxNurbKnot() { public float getMaxNurbKnot() {
@ -408,6 +421,7 @@ public class Spline implements Savable {
/** /**
* This method returns NURBS' spline knots. * This method returns NURBS' spline knots.
*
* @return NURBS' spline knots * @return NURBS' spline knots
*/ */
public List<Float> getKnots() { public List<Float> getKnots() {
@ -416,6 +430,7 @@ public class Spline implements Savable {
/** /**
* This method returns NURBS' spline weights. * This method returns NURBS' spline weights.
*
* @return NURBS' spline weights * @return NURBS' spline weights
*/ */
public float[] getWeights() { public float[] getWeights() {
@ -424,6 +439,7 @@ public class Spline implements Savable {
/** /**
* This method returns NURBS' spline basis function degree. * This method returns NURBS' spline basis function degree.
*
* @return NURBS' spline basis function degree * @return NURBS' spline basis function degree
*/ */
public int getBasisFunctionDegree() { public int getBasisFunctionDegree() {
@ -449,7 +465,7 @@ public class Spline implements Savable {
oc.writeSavableArrayList((ArrayList) CRcontrolPoints, "CRControlPoints", null); oc.writeSavableArrayList((ArrayList) CRcontrolPoints, "CRControlPoints", null);
oc.write(curveTension, "curveTension", 0.5f); oc.write(curveTension, "curveTension", 0.5f);
oc.write(cycle, "cycle", false); oc.write(cycle, "cycle", false);
oc.writeSavableArrayList((ArrayList<Float>)knots, "knots", null); oc.writeSavableArrayList((ArrayList<Float>) knots, "knots", null);
oc.write(weights, "weights", null); oc.write(weights, "weights", null);
oc.write(basisFunctionDegree, "basisFunctionDegree", 0); oc.write(basisFunctionDegree, "basisFunctionDegree", 0);
} }
@ -459,7 +475,8 @@ public class Spline implements Savable {
public void read(JmeImporter im) throws IOException { public void read(JmeImporter im) throws IOException {
InputCapsule in = im.getCapsule(this); InputCapsule in = im.getCapsule(this);
controlPoints = in.readSavableArrayList("controlPoints", new ArrayList<>()); /* Empty List as default, prevents null pointers */ controlPoints = in.readSavableArrayList("controlPoints", new ArrayList<>());
/* Empty List as default, prevents null pointers */
float list[] = in.readFloatArray("segmentsLength", null); float list[] = in.readFloatArray("segmentsLength", null);
if (list != null) { if (list != null) {
segmentsLength = new ArrayList<Float>(); segmentsLength = new ArrayList<Float>();

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2009-2018 jMonkeyEngine * Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -53,30 +53,31 @@ public final class Transform implements Savable, Cloneable, java.io.Serializable
private Vector3f translation = new Vector3f(); private Vector3f translation = new Vector3f();
private Vector3f scale = new Vector3f(1, 1, 1); private Vector3f scale = new Vector3f(1, 1, 1);
public Transform(Vector3f translation, Quaternion rot){ public Transform(Vector3f translation, Quaternion rot) {
this.translation.set(translation); this.translation.set(translation);
this.rot.set(rot); this.rot.set(rot);
} }
public Transform(Vector3f translation, Quaternion rot, Vector3f scale){ public Transform(Vector3f translation, Quaternion rot, Vector3f scale) {
this(translation, rot); this(translation, rot);
this.scale.set(scale); this.scale.set(scale);
} }
public Transform(Vector3f translation){ public Transform(Vector3f translation) {
this(translation, Quaternion.IDENTITY); this(translation, Quaternion.IDENTITY);
} }
public Transform(Quaternion rot){ public Transform(Quaternion rot) {
this(Vector3f.ZERO, rot); this(Vector3f.ZERO, rot);
} }
public Transform(){ public Transform() {
this(Vector3f.ZERO, Quaternion.IDENTITY); this(Vector3f.ZERO, Quaternion.IDENTITY);
} }
/** /**
* Sets this rotation to the given Quaternion value. * Sets this rotation to the given Quaternion value.
*
* @param rot The new rotation for this matrix. * @param rot The new rotation for this matrix.
* @return this * @return this
*/ */
@ -87,6 +88,7 @@ public final class Transform implements Savable, Cloneable, java.io.Serializable
/** /**
* Sets this translation to the given value. * Sets this translation to the given value.
*
* @param trans The new translation for this matrix. * @param trans The new translation for this matrix.
* @return this * @return this
*/ */
@ -97,6 +99,7 @@ public final class Transform implements Savable, Cloneable, java.io.Serializable
/** /**
* Return the translation vector in this matrix. * Return the translation vector in this matrix.
*
* @return translation vector. * @return translation vector.
*/ */
public Vector3f getTranslation() { public Vector3f getTranslation() {
@ -105,6 +108,7 @@ public final class Transform implements Savable, Cloneable, java.io.Serializable
/** /**
* Sets this scale to the given value. * Sets this scale to the given value.
*
* @param scale The new scale for this matrix. * @param scale The new scale for this matrix.
* @return this * @return this
*/ */
@ -115,6 +119,7 @@ public final class Transform implements Savable, Cloneable, java.io.Serializable
/** /**
* Sets this scale to the given value. * Sets this scale to the given value.
*
* @param scale The new scale for this matrix. * @param scale The new scale for this matrix.
* @return this * @return this
*/ */
@ -125,6 +130,7 @@ public final class Transform implements Savable, Cloneable, java.io.Serializable
/** /**
* Return the scale vector in this matrix. * Return the scale vector in this matrix.
*
* @return scale vector. * @return scale vector.
*/ */
public Vector3f getScale() { public Vector3f getScale() {
@ -132,31 +138,40 @@ public final class Transform implements Savable, Cloneable, java.io.Serializable
} }
/** /**
* Stores this translation value into the given vector3f. If trans is null, a new vector3f is created to * Stores this translation value into the given vector3f. If trans is null,
* hold the value. The value, once stored, is returned. * a new vector3f is created to hold the value. The value, once stored, is
* returned.
*
* @param trans The store location for this matrix's translation. * @param trans The store location for this matrix's translation.
* @return The value of this matrix's translation. * @return The value of this matrix's translation.
*/ */
public Vector3f getTranslation(Vector3f trans) { public Vector3f getTranslation(Vector3f trans) {
if (trans==null) trans=new Vector3f(); if (trans == null) {
trans = new Vector3f();
}
trans.set(this.translation); trans.set(this.translation);
return trans; return trans;
} }
/** /**
* Stores this rotation value into the given Quaternion. If quat is null, a new Quaternion is created to * Stores this rotation value into the given Quaternion. If quat is null, a
* hold the value. The value, once stored, is returned. * new Quaternion is created to hold the value. The value, once stored, is
* returned.
*
* @param quat The store location for this matrix's rotation. * @param quat The store location for this matrix's rotation.
* @return The value of this matrix's rotation. * @return The value of this matrix's rotation.
*/ */
public Quaternion getRotation(Quaternion quat) { public Quaternion getRotation(Quaternion quat) {
if (quat==null) quat=new Quaternion(); if (quat == null) {
quat = new Quaternion();
}
quat.set(rot); quat.set(rot);
return quat; return quat;
} }
/** /**
* Return the rotation quaternion in this matrix. * Return the rotation quaternion in this matrix.
*
* @return rotation quaternion. * @return rotation quaternion.
*/ */
public Quaternion getRotation() { public Quaternion getRotation() {
@ -164,32 +179,41 @@ public final class Transform implements Savable, Cloneable, java.io.Serializable
} }
/** /**
* Stores this scale value into the given vector3f. If scale is null, a new vector3f is created to * Stores this scale value into the given vector3f. If scale is null, a new
* hold the value. The value, once stored, is returned. * vector3f is created to hold the value. The value, once stored, is
* returned.
*
* @param scale The store location for this matrix's scale. * @param scale The store location for this matrix's scale.
* @return The value of this matrix's scale. * @return The value of this matrix's scale.
*/ */
public Vector3f getScale(Vector3f scale) { public Vector3f getScale(Vector3f scale) {
if (scale==null) scale=new Vector3f(); if (scale == null) {
scale = new Vector3f();
}
scale.set(this.scale); scale.set(this.scale);
return scale; return scale;
} }
/** /**
* Sets this transform to the interpolation between the first transform and the second by delta amount. * Sets this transform to the interpolation between the first transform and
* the second by delta amount.
*
* @param t1 The beginning transform. * @param t1 The beginning transform.
* @param t2 The ending transform. * @param t2 The ending transform.
* @param delta An amount between 0 and 1 representing how far to interpolate from t1 to t2. * @param delta An amount between 0 and 1 representing how far to
* interpolate from t1 to t2.
*/ */
public void interpolateTransforms(Transform t1, Transform t2, float delta) { public void interpolateTransforms(Transform t1, Transform t2, float delta) {
t1.rot.nlerp(t2.rot, delta); t1.rot.nlerp(t2.rot, delta);
this.rot.set(t1.rot); this.rot.set(t1.rot);
this.translation.interpolateLocal(t1.translation,t2.translation,delta); this.translation.interpolateLocal(t1.translation, t2.translation, delta);
this.scale.interpolateLocal(t1.scale,t2.scale,delta); this.scale.interpolateLocal(t1.scale, t2.scale, delta);
} }
/** /**
* Changes the values of this matrix according to its parent. Very similar to the concept of Node/Spatial transforms. * Changes the values of this matrix according to its parent. Very similar
* to the concept of Node/Spatial transforms.
*
* @param parent The parent matrix. * @param parent The parent matrix.
* @return This matrix, after combining. * @return This matrix, after combining.
*/ */
@ -202,8 +226,7 @@ public final class Transform implements Savable, Cloneable, java.io.Serializable
translation.multLocal(parent.scale); translation.multLocal(parent.scale);
//applying parent rotation to local translation, then applying parent translation to local translation. //applying parent rotation to local translation, then applying parent translation to local translation.
//Note that parent.rot.multLocal(translation) doesn't modify "parent.rot" but "translation" //Note that parent.rot.multLocal(translation) doesn't modify "parent.rot" but "translation"
parent parent.rot
.rot
.multLocal(translation) .multLocal(translation)
.addLocal(parent.translation); .addLocal(parent.translation);
@ -212,46 +235,49 @@ public final class Transform implements Savable, Cloneable, java.io.Serializable
/** /**
* Sets this matrix's translation to the given x,y,z values. * Sets this matrix's translation to the given x,y,z values.
*
* @param x This matrix's new x translation. * @param x This matrix's new x translation.
* @param y This matrix's new y translation. * @param y This matrix's new y translation.
* @param z This matrix's new z translation. * @param z This matrix's new z translation.
* @return this * @return this
*/ */
public Transform setTranslation(float x,float y, float z) { public Transform setTranslation(float x, float y, float z) {
translation.set(x,y,z); translation.set(x, y, z);
return this; return this;
} }
/** /**
* Sets this matrix's scale to the given x,y,z values. * Sets this matrix's scale to the given x,y,z values.
*
* @param x This matrix's new x scale. * @param x This matrix's new x scale.
* @param y This matrix's new y scale. * @param y This matrix's new y scale.
* @param z This matrix's new z scale. * @param z This matrix's new z scale.
* @return this * @return this
*/ */
public Transform setScale(float x, float y, float z) { public Transform setScale(float x, float y, float z) {
scale.set(x,y,z); scale.set(x, y, z);
return this; return this;
} }
public Vector3f transformVector(final Vector3f in, Vector3f store){ public Vector3f transformVector(final Vector3f in, Vector3f store) {
if (store == null) if (store == null) {
store = new Vector3f(); store = new Vector3f();
}
// multiply with scale first, then rotate, finally translate (cf. // multiply with scale first, then rotate, finally translate (cf.
// Eberly) // Eberly)
return rot.mult(store.set(in).multLocal(scale), store).addLocal(translation); return rot.mult(store.set(in).multLocal(scale), store).addLocal(translation);
} }
public Vector3f transformInverseVector(final Vector3f in, Vector3f store){ public Vector3f transformInverseVector(final Vector3f in, Vector3f store) {
if (store == null) if (store == null) {
store = new Vector3f(); store = new Vector3f();
}
// The author of this code should look above and take the inverse of that // The author of this code should look above and take the inverse of that
// But for some reason, they didn't .. // But for some reason, they didn't ..
// in.subtract(translation, store).divideLocal(scale); // in.subtract(translation, store).divideLocal(scale);
// rot.inverse().mult(store, store); // rot.inverse().mult(store, store);
in.subtract(translation, store); in.subtract(translation, store);
rot.inverse().mult(store, store); rot.inverse().mult(store, store);
store.divideLocal(scale); store.divideLocal(scale);
@ -331,14 +357,16 @@ public final class Transform implements Savable, Cloneable, java.io.Serializable
} }
@Override @Override
public String toString(){ public String toString() {
return getClass().getSimpleName() + "[ " + translation.x + ", " + translation.y + ", " + translation.z + "]\n" return getClass().getSimpleName()
+ "[ " + translation.x + ", " + translation.y + ", " + translation.z + "]\n"
+ "[ " + rot.x + ", " + rot.y + ", " + rot.z + ", " + rot.w + "]\n" + "[ " + rot.x + ", " + rot.y + ", " + rot.z + ", " + rot.w + "]\n"
+ "[ " + scale.x + " , " + scale.y + ", " + scale.z + "]"; + "[ " + scale.x + " , " + scale.y + ", " + scale.z + "]";
} }
/** /**
* Sets this matrix to be equal to the given matrix. * Sets this matrix to be equal to the given matrix.
*
* @param matrixQuat The matrix to be equal to. * @param matrixQuat The matrix to be equal to.
* @return this * @return this
*/ */
@ -361,9 +389,9 @@ public final class Transform implements Savable, Cloneable, java.io.Serializable
public void read(JmeImporter e) throws IOException { public void read(JmeImporter e) throws IOException {
InputCapsule capsule = e.getCapsule(this); InputCapsule capsule = e.getCapsule(this);
rot.set((Quaternion)capsule.readSavable("rot", Quaternion.IDENTITY)); rot.set((Quaternion) capsule.readSavable("rot", Quaternion.IDENTITY));
translation.set((Vector3f)capsule.readSavable("translation", Vector3f.ZERO)); translation.set((Vector3f) capsule.readSavable("translation", Vector3f.ZERO));
scale.set((Vector3f)capsule.readSavable("scale", Vector3f.UNIT_XYZ)); scale.set((Vector3f) capsule.readSavable("scale", Vector3f.UNIT_XYZ));
} }
@Override @Override

@ -29,7 +29,6 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package com.jme3.math; package com.jme3.math;
import com.jme3.export.*; import com.jme3.export.*;
@ -52,7 +51,6 @@ import java.util.logging.Logger;
public final class Vector3f implements Savable, Cloneable, java.io.Serializable { public final class Vector3f implements Savable, Cloneable, java.io.Serializable {
static final long serialVersionUID = 1; static final long serialVersionUID = 1;
private static final Logger logger = Logger.getLogger(Vector3f.class.getName()); private static final Logger logger = Logger.getLogger(Vector3f.class.getName());
public final static Vector3f ZERO = new Vector3f(0, 0, 0); public final static Vector3f ZERO = new Vector3f(0, 0, 0);
@ -69,18 +67,14 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY,
Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY,
Float.NEGATIVE_INFINITY); Float.NEGATIVE_INFINITY);
/** /**
* the x value of the vector. * the x value of the vector.
*/ */
public float x; public float x;
/** /**
* the y value of the vector. * the y value of the vector.
*/ */
public float y; public float y;
/** /**
* the z value of the vector. * the z value of the vector.
*/ */
@ -156,7 +150,6 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
} }
/** /**
*
* <code>add</code> adds a provided vector to this vector creating a * <code>add</code> adds a provided vector to this vector creating a
* resultant vector which is returned. If the provided vector is null, null * resultant vector which is returned. If the provided vector is null, null
* is returned. * is returned.
@ -174,7 +167,6 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
} }
/** /**
*
* <code>add</code> adds the values of a provided vector storing the * <code>add</code> adds the values of a provided vector storing the
* values in the supplied vector. * values in the supplied vector.
* *
@ -212,7 +204,6 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
} }
/** /**
*
* <code>add</code> adds the provided values to this vector, creating a * <code>add</code> adds the provided values to this vector, creating a
* new vector that is then returned. * new vector that is then returned.
* *
@ -249,7 +240,6 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
} }
/** /**
*
* <code>scaleAdd</code> multiplies this vector by a scalar then adds the * <code>scaleAdd</code> multiplies this vector by a scalar then adds the
* given Vector3f. * given Vector3f.
* *
@ -266,7 +256,6 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
} }
/** /**
*
* <code>scaleAdd</code> multiplies the given vector by a scalar then adds * <code>scaleAdd</code> multiplies the given vector by a scalar then adds
* the given vector. * the given vector.
* *
@ -285,7 +274,6 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
} }
/** /**
*
* <code>dot</code> calculates the dot product of this vector with a * <code>dot</code> calculates the dot product of this vector with a
* provided vector. If the provided vector is null, 0 is returned. * provided vector. If the provided vector is null, 0 is returned.
* *
@ -323,7 +311,7 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
* the vector to store the cross product result. * the vector to store the cross product result.
* @return result, after receiving the cross product vector. * @return result, after receiving the cross product vector.
*/ */
public Vector3f cross(Vector3f v,Vector3f result) { public Vector3f cross(Vector3f v, Vector3f result) {
return cross(v.x, v.y, v.z, result); return cross(v.x, v.y, v.z, result);
} }
@ -342,7 +330,9 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
* @return result, after receiving the cross product vector. * @return result, after receiving the cross product vector.
*/ */
public Vector3f cross(float otherX, float otherY, float otherZ, Vector3f result) { public Vector3f cross(float otherX, float otherY, float otherZ, Vector3f result) {
if (result == null) result = new Vector3f(); if (result == null) {
result = new Vector3f();
}
float resX = ((y * otherZ) - (z * otherY)); float resX = ((y * otherZ) - (z * otherY));
float resY = ((z * otherX) - (x * otherZ)); float resY = ((z * otherX) - (x * otherZ));
float resZ = ((x * otherY) - (y * otherX)); float resZ = ((x * otherY) - (y * otherX));
@ -375,8 +365,8 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
* @return this. * @return this.
*/ */
public Vector3f crossLocal(float otherX, float otherY, float otherZ) { public Vector3f crossLocal(float otherX, float otherY, float otherZ) {
float tempx = ( y * otherZ ) - ( z * otherY ); float tempx = (y * otherZ) - (z * otherY);
float tempy = ( z * otherX ) - ( x * otherZ ); float tempy = (z * otherX) - (x * otherZ);
z = (x * otherY) - (y * otherX); z = (x * otherY) - (y * otherX);
x = tempx; x = tempx;
y = tempy; y = tempy;
@ -389,10 +379,10 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
* @param other The vector to project this vector onto * @param other The vector to project this vector onto
* @return A new vector with the projection result * @return A new vector with the projection result
*/ */
public Vector3f project(Vector3f other){ public Vector3f project(Vector3f other) {
float n = this.dot(other); // A . B float n = this.dot(other); // A . B
float d = other.lengthSquared(); // |B|^2 float d = other.lengthSquared(); // |B|^2
return new Vector3f(other).multLocal(n/d); return new Vector3f(other).multLocal(n / d);
} }
/** /**
@ -402,10 +392,10 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
* @param other The vector to project this vector onto * @param other The vector to project this vector onto
* @return This Vector3f, set to the projection result * @return This Vector3f, set to the projection result
*/ */
public Vector3f projectLocal(Vector3f other){ public Vector3f projectLocal(Vector3f other) {
float n = this.dot(other); // A . B float n = this.dot(other); // A . B
float d = other.lengthSquared(); // |B|^2 float d = other.lengthSquared(); // |B|^2
return set(other).multLocal(n/d); return set(other).multLocal(n / d);
} }
/** /**
@ -415,7 +405,7 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
* @return true if this vector is a unit vector (length() ~= 1), * @return true if this vector is a unit vector (length() ~= 1),
* or false otherwise. * or false otherwise.
*/ */
public boolean isUnitVector(){ public boolean isUnitVector() {
float len = length(); float len = length();
return 0.99f < len && len < 1.01f; return 0.99f < len && len < 1.01f;
} }
@ -465,7 +455,6 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
} }
/** /**
*
* <code>mult</code> multiplies this vector by a scalar. The resultant * <code>mult</code> multiplies this vector by a scalar. The resultant
* vector is returned. * vector is returned.
* *
@ -478,7 +467,6 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
} }
/** /**
*
* <code>mult</code> multiplies this vector by a scalar. The resultant * <code>mult</code> multiplies this vector by a scalar. The resultant
* vector is supplied as the second parameter and returned. * vector is supplied as the second parameter and returned.
* *
@ -581,11 +569,12 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
logger.warning("Provided vector is null, null returned."); logger.warning("Provided vector is null, null returned.");
return null; return null;
} }
if (store == null) store = new Vector3f(); if (store == null) {
store = new Vector3f();
}
return store.set(x * vec.x, y * vec.y, z * vec.z); return store.set(x * vec.x, y * vec.y, z * vec.z);
} }
/** /**
* <code>divide</code> divides the values of this vector by a scalar and * <code>divide</code> divides the values of this vector by a scalar and
* returns the result. The values of this vector remain untouched. * returns the result. The values of this vector remain untouched.
@ -595,7 +584,7 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
* @return the result <code>Vector</code>. * @return the result <code>Vector</code>.
*/ */
public Vector3f divide(float scalar) { public Vector3f divide(float scalar) {
scalar = 1f/scalar; scalar = 1f / scalar;
return new Vector3f(x * scalar, y * scalar, z * scalar); return new Vector3f(x * scalar, y * scalar, z * scalar);
} }
@ -609,14 +598,13 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
* @return this * @return this
*/ */
public Vector3f divideLocal(float scalar) { public Vector3f divideLocal(float scalar) {
scalar = 1f/scalar; scalar = 1f / scalar;
x *= scalar; x *= scalar;
y *= scalar; y *= scalar;
z *= scalar; z *= scalar;
return this; return this;
} }
/** /**
* <code>divide</code> divides the values of this vector by a scalar and * <code>divide</code> divides the values of this vector by a scalar and
* returns the result. The values of this vector remain untouched. * returns the result. The values of this vector remain untouched.
@ -646,7 +634,6 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
} }
/** /**
*
* <code>negate</code> returns the negative of this vector. All values are * <code>negate</code> returns the negative of this vector. All values are
* negated and set to a new vector. * negated and set to a new vector.
* *
@ -657,7 +644,6 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
} }
/** /**
*
* <code>negateLocal</code> negates the internal values of this vector. * <code>negateLocal</code> negates the internal values of this vector.
* *
* @return this. * @return this.
@ -670,7 +656,6 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
} }
/** /**
*
* <code>subtract</code> subtracts the values of a given vector from those * <code>subtract</code> subtracts the values of a given vector from those
* of this vector creating a new vector object. If the provided vector is * of this vector creating a new vector object. If the provided vector is
* null, null is returned. * null, null is returned.
@ -704,7 +689,6 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
} }
/** /**
*
* <code>subtract</code> * <code>subtract</code>
* *
* @param vec * @param vec
@ -714,7 +698,7 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
* @return result * @return result
*/ */
public Vector3f subtract(Vector3f vec, Vector3f result) { public Vector3f subtract(Vector3f vec, Vector3f result) {
if(result == null) { if (result == null) {
result = new Vector3f(); result = new Vector3f();
} }
result.x = x - vec.x; result.x = x - vec.x;
@ -724,7 +708,6 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
} }
/** /**
*
* <code>subtract</code> subtracts the provided values from this vector, * <code>subtract</code> subtracts the provided values from this vector,
* creating a new vector that is then returned. * creating a new vector that is then returned.
* *
@ -773,7 +756,7 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
// //
// return divide(1); // return divide(1);
float length = x * x + y * y + z * z; float length = x * x + y * y + z * z;
if (length != 1f && length != 0f){ if (length != 1f && length != 0f) {
length = 1.0f / FastMath.sqrt(length); length = 1.0f / FastMath.sqrt(length);
return new Vector3f(x * length, y * length, z * length); return new Vector3f(x * length, y * length, z * length);
} }
@ -791,7 +774,7 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
// than the old jme normalize as this method // than the old jme normalize as this method
// is commonly used. // is commonly used.
float length = x * x + y * y + z * z; float length = x * x + y * y + z * z;
if (length != 1f && length != 0f){ if (length != 1f && length != 0f) {
length = 1.0f / FastMath.sqrt(length); length = 1.0f / FastMath.sqrt(length);
x *= length; x *= length;
y *= length; y *= length;
@ -804,9 +787,10 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
* <code>maxLocal</code> computes the maximum value for each * <code>maxLocal</code> computes the maximum value for each
* component in this and <code>other</code> vector. The result is stored * component in this and <code>other</code> vector. The result is stored
* in this vector. * in this vector.
*
* @param other * @param other
*/ */
public Vector3f maxLocal(Vector3f other){ public Vector3f maxLocal(Vector3f other) {
x = other.x > x ? other.x : x; x = other.x > x ? other.x : x;
y = other.y > y ? other.y : y; y = other.y > y ? other.y : y;
z = other.z > z ? other.z : z; z = other.z > z ? other.z : z;
@ -817,9 +801,10 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
* <code>minLocal</code> computes the minimum value for each * <code>minLocal</code> computes the minimum value for each
* component in this and <code>other</code> vector. The result is stored * component in this and <code>other</code> vector. The result is stored
* in this vector. * in this vector.
*
* @param other * @param other
*/ */
public Vector3f minLocal(Vector3f other){ public Vector3f minLocal(Vector3f other) {
x = other.x < x ? other.x : x; x = other.x < x ? other.x : x;
y = other.y < y ? other.y : y; y = other.y < y ? other.y : y;
z = other.z < z ? other.z : z; z = other.z < z ? other.z : z;
@ -850,46 +835,55 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
/** /**
* Sets this vector to the interpolation by changeAmnt from this to the finalVec * Sets this vector to the interpolation by changeAmnt from this to the finalVec
* this=(1-changeAmnt)*this + changeAmnt * finalVec * this=(1-changeAmnt)*this + changeAmnt * finalVec
*
* @param finalVec The final vector to interpolate towards * @param finalVec The final vector to interpolate towards
* @param changeAmnt An amount between 0.0 - 1.0 representing a percentage * @param changeAmnt An amount between 0.0 - 1.0 representing a percentage
* change from this towards finalVec * change from this towards finalVec
*/ */
public Vector3f interpolateLocal(Vector3f finalVec, float changeAmnt) { public Vector3f interpolateLocal(Vector3f finalVec, float changeAmnt) {
this.x=(1-changeAmnt)*this.x + changeAmnt*finalVec.x; this.x = (1 - changeAmnt) * this.x + changeAmnt * finalVec.x;
this.y=(1-changeAmnt)*this.y + changeAmnt*finalVec.y; this.y = (1 - changeAmnt) * this.y + changeAmnt * finalVec.y;
this.z=(1-changeAmnt)*this.z + changeAmnt*finalVec.z; this.z = (1 - changeAmnt) * this.z + changeAmnt * finalVec.z;
return this; return this;
} }
/** /**
* Sets this vector to the interpolation by changeAmnt from beginVec to finalVec * Sets this vector to the interpolation by changeAmnt from beginVec to finalVec
* this=(1-changeAmnt)*beginVec + changeAmnt * finalVec * this=(1-changeAmnt)*beginVec + changeAmnt * finalVec
*
* @param beginVec the beginning vector (changeAmnt=0) * @param beginVec the beginning vector (changeAmnt=0)
* @param finalVec The final vector to interpolate towards * @param finalVec The final vector to interpolate towards
* @param changeAmnt An amount between 0.0 - 1.0 representing a percentage * @param changeAmnt An amount between 0.0 - 1.0 representing a percentage
* change from beginVec towards finalVec * change from beginVec towards finalVec
*/ */
public Vector3f interpolateLocal(Vector3f beginVec,Vector3f finalVec, float changeAmnt) { public Vector3f interpolateLocal(Vector3f beginVec, Vector3f finalVec, float changeAmnt) {
this.x=(1-changeAmnt)*beginVec.x + changeAmnt*finalVec.x; this.x = (1 - changeAmnt) * beginVec.x + changeAmnt * finalVec.x;
this.y=(1-changeAmnt)*beginVec.y + changeAmnt*finalVec.y; this.y = (1 - changeAmnt) * beginVec.y + changeAmnt * finalVec.y;
this.z=(1-changeAmnt)*beginVec.z + changeAmnt*finalVec.z; this.z = (1 - changeAmnt) * beginVec.z + changeAmnt * finalVec.z;
return this; return this;
} }
/** /**
* Check a vector... if it is null or its floats are NaN or infinite, * Check a vector... if it is null or its floats are NaN or infinite,
* return false. Else return true. * return false. Else return true.
*
* @param vector the vector to check * @param vector the vector to check
* @return true or false as stated above. * @return true or false as stated above.
*/ */
public static boolean isValidVector(Vector3f vector) { public static boolean isValidVector(Vector3f vector) {
if (vector == null) return false; if (vector == null) {
if (Float.isNaN(vector.x) || return false;
Float.isNaN(vector.y) || }
Float.isNaN(vector.z)) return false; if (Float.isNaN(vector.x)
if (Float.isInfinite(vector.x) || || Float.isNaN(vector.y)
Float.isInfinite(vector.y) || || Float.isNaN(vector.z)) {
Float.isInfinite(vector.z)) return false; return false;
}
if (Float.isInfinite(vector.x)
|| Float.isInfinite(vector.y)
|| Float.isInfinite(vector.z)) {
return false;
}
return true; return true;
} }
@ -960,14 +954,24 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
*/ */
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (!(o instanceof Vector3f)) { return false; } if (!(o instanceof Vector3f)) {
return false;
}
if (this == o) { return true; } if (this == o) {
return true;
}
Vector3f comp = (Vector3f) o; Vector3f comp = (Vector3f) o;
if (Float.compare(x,comp.x) != 0) return false; if (Float.compare(x, comp.x) != 0) {
if (Float.compare(y,comp.y) != 0) return false; return false;
if (Float.compare(z,comp.z) != 0) return false; }
if (Float.compare(y, comp.y) != 0) {
return false;
}
if (Float.compare(z, comp.z) != 0) {
return false;
}
return true; return true;
} }
@ -995,6 +999,7 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
* <code>hashCode</code> returns a unique code for this vector object based * <code>hashCode</code> returns a unique code for this vector object based
* on its values. If two vectors are logically equivalent, they will return * on its values. If two vectors are logically equivalent, they will return
* the same hash code value. * the same hash code value.
*
* @return the hash code value of this vector. * @return the hash code value of this vector.
*/ */
@Override @Override
@ -1103,5 +1108,4 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
} }
throw new IllegalArgumentException("index must be either 0, 1 or 2"); throw new IllegalArgumentException("index must be either 0, 1 or 2");
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2009-2012 jMonkeyEngine * Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -59,7 +59,7 @@ public class VirtualIndexBuffer extends IndexBuffer {
protected Mode meshMode; protected Mode meshMode;
protected int position = 0; protected int position = 0;
public VirtualIndexBuffer(int numVerts, Mode meshMode){ public VirtualIndexBuffer(int numVerts, Mode meshMode) {
this.numVerts = numVerts; this.numVerts = numVerts;
this.meshMode = meshMode; this.meshMode = meshMode;
switch (meshMode) { switch (meshMode) {
@ -108,33 +108,38 @@ public class VirtualIndexBuffer extends IndexBuffer {
@Override @Override
public int get(int i) { public int get(int i) {
if (meshMode == Mode.Triangles || meshMode == Mode.Lines || meshMode == Mode.Points){ if (meshMode == Mode.Triangles || meshMode == Mode.Lines || meshMode == Mode.Points) {
return i; return i;
}else if (meshMode == Mode.LineStrip){ } else if (meshMode == Mode.LineStrip) {
return (i + 1) / 2; return (i + 1) / 2;
}else if (meshMode == Mode.LineLoop){ } else if (meshMode == Mode.LineLoop) {
return (i == (numVerts-1)) ? 0 : ((i + 1) / 2); return (i == (numVerts - 1)) ? 0 : ((i + 1) / 2);
}else if (meshMode == Mode.TriangleStrip){ } else if (meshMode == Mode.TriangleStrip) {
int triIndex = i/3; int triIndex = i / 3;
int vertIndex = i%3; int vertIndex = i % 3;
boolean isBack = (i/3)%2==1; boolean isBack = (i / 3) % 2 == 1;
if (!isBack){ if (!isBack) {
return triIndex + vertIndex; return triIndex + vertIndex;
}else{ } else {
switch (vertIndex){ switch (vertIndex) {
case 0: return triIndex + 1; case 0:
case 1: return triIndex; return triIndex + 1;
case 2: return triIndex + 2; case 1:
default: throw new AssertionError(); return triIndex;
case 2:
return triIndex + 2;
default:
throw new AssertionError();
} }
} }
}else if (meshMode == Mode.TriangleFan){ } else if (meshMode == Mode.TriangleFan) {
int vertIndex = i%3; int vertIndex = i % 3;
if (vertIndex == 0) if (vertIndex == 0) {
return 0; return 0;
else } else {
return (i / 3) + vertIndex; return (i / 3) + vertIndex;
}else{ }
} else {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
} }
@ -155,12 +160,12 @@ public class VirtualIndexBuffer extends IndexBuffer {
} }
@Override @Override
public IndexBuffer put (int value) { public IndexBuffer put(int value) {
throw new UnsupportedOperationException("Does not represent index buffer"); throw new UnsupportedOperationException("Does not represent index buffer");
} }
@Override @Override
public Format getFormat () { public Format getFormat() {
// return largest size // return largest size
return Format.UnsignedInt; return Format.UnsignedInt;
} }

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2009-2019 jMonkeyEngine * Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -198,8 +198,8 @@ public class Curve extends Mesh {
* points * points
*/ */
private void createNurbMesh(int nbSubSegments) { private void createNurbMesh(int nbSubSegments) {
if(spline.getControlPoints() != null && spline.getControlPoints().size() > 0) { if (spline.getControlPoints() != null && spline.getControlPoints().size() > 0) {
if(nbSubSegments == 0) { if (nbSubSegments == 0) {
nbSubSegments = spline.getControlPoints().size() + 1; nbSubSegments = spline.getControlPoints().size() + 1;
} else { } else {
nbSubSegments = spline.getControlPoints().size() * nbSubSegments + 1; nbSubSegments = spline.getControlPoints().size() * nbSubSegments + 1;

@ -110,7 +110,7 @@ public class FrameBuffer extends NativeObject {
* @return The texture to render to for this <code>RenderBuffer</code> * @return The texture to render to for this <code>RenderBuffer</code>
* or null if content should be rendered into a buffer. * or null if content should be rendered into a buffer.
*/ */
public Texture getTexture(){ public Texture getTexture() {
return tex; return tex;
} }
@ -124,7 +124,7 @@ public class FrameBuffer extends NativeObject {
/** /**
* Do not use. * Do not use.
*/ */
public void setId(int id){ public void setId(int id) {
this.id = id; this.id = id;
} }
@ -139,14 +139,14 @@ public class FrameBuffer extends NativeObject {
return face; return face;
} }
public void resetObject(){ public void resetObject() {
id = -1; id = -1;
} }
public RenderBuffer createDestructableClone(){ public RenderBuffer createDestructableClone() {
if (tex != null){ if (tex != null) {
return null; return null;
}else{ } else {
RenderBuffer destructClone = new RenderBuffer(); RenderBuffer destructClone = new RenderBuffer();
destructClone.id = id; destructClone.id = id;
return destructClone; return destructClone;
@ -154,10 +154,10 @@ public class FrameBuffer extends NativeObject {
} }
@Override @Override
public String toString(){ public String toString() {
if (tex != null){ if (tex != null) {
return "TextureTarget[format=" + format + "]"; return "TextureTarget[format=" + format + "]";
}else{ } else {
return "BufferTarget[format=" + format + "]"; return "BufferTarget[format=" + format + "]";
} }
} }
@ -184,17 +184,18 @@ public class FrameBuffer extends NativeObject {
* *
* @throws IllegalArgumentException If width or height are not positive. * @throws IllegalArgumentException If width or height are not positive.
*/ */
public FrameBuffer(int width, int height, int samples){ public FrameBuffer(int width, int height, int samples) {
super(); super();
if (width <= 0 || height <= 0) if (width <= 0 || height <= 0) {
throw new IllegalArgumentException("FrameBuffer must have valid size."); throw new IllegalArgumentException("FrameBuffer must have valid size.");
}
this.width = width; this.width = width;
this.height = height; this.height = height;
this.samples = samples == 0 ? 1 : samples; this.samples = samples == 0 ? 1 : samples;
} }
protected FrameBuffer(FrameBuffer src){ protected FrameBuffer(FrameBuffer src) {
super(src.id); super(src.id);
/* /*
for (RenderBuffer renderBuf : src.colorBufs){ for (RenderBuffer renderBuf : src.colorBufs){
@ -213,12 +214,14 @@ public class FrameBuffer extends NativeObject {
* @param format The format to use for the depth buffer. * @param format The format to use for the depth buffer.
* @throws IllegalArgumentException If <code>format</code> is not a depth format. * @throws IllegalArgumentException If <code>format</code> is not a depth format.
*/ */
public void setDepthBuffer(Image.Format format){ public void setDepthBuffer(Image.Format format) {
if (id != -1) if (id != -1) {
throw new UnsupportedOperationException("FrameBuffer already initialized."); throw new UnsupportedOperationException("FrameBuffer already initialized.");
}
if (!format.isDepthFormat()) if (!format.isDepthFormat()) {
throw new IllegalArgumentException("Depth buffer format must be depth."); throw new IllegalArgumentException("Depth buffer format must be depth.");
}
depthBuf = new RenderBuffer(); depthBuf = new RenderBuffer();
depthBuf.slot = format.isDepthStencilFormat() ? SLOT_DEPTH_STENCIL : SLOT_DEPTH; depthBuf.slot = format.isDepthStencilFormat() ? SLOT_DEPTH_STENCIL : SLOT_DEPTH;
@ -231,12 +234,14 @@ public class FrameBuffer extends NativeObject {
* @param format The format to use for the color buffer. * @param format The format to use for the color buffer.
* @throws IllegalArgumentException If <code>format</code> is not a color format. * @throws IllegalArgumentException If <code>format</code> is not a color format.
*/ */
public void setColorBuffer(Image.Format format){ public void setColorBuffer(Image.Format format) {
if (id != -1) if (id != -1) {
throw new UnsupportedOperationException("FrameBuffer already initialized."); throw new UnsupportedOperationException("FrameBuffer already initialized.");
}
if (format.isDepthFormat()) if (format.isDepthFormat()) {
throw new IllegalArgumentException("Color buffer format must be color/luminance."); throw new IllegalArgumentException("Color buffer format must be color/luminance.");
}
RenderBuffer colorBuf = new RenderBuffer(); RenderBuffer colorBuf = new RenderBuffer();
colorBuf.slot = 0; colorBuf.slot = 0;
@ -246,24 +251,28 @@ public class FrameBuffer extends NativeObject {
colorBufs.add(colorBuf); colorBufs.add(colorBuf);
} }
private void checkSetTexture(Texture tex, boolean depth){ private void checkSetTexture(Texture tex, boolean depth) {
Image img = tex.getImage(); Image img = tex.getImage();
if (img == null) if (img == null) {
throw new IllegalArgumentException("Texture not initialized with RTT."); throw new IllegalArgumentException("Texture not initialized with RTT.");
}
if (depth && !img.getFormat().isDepthFormat()) if (depth && !img.getFormat().isDepthFormat()) {
throw new IllegalArgumentException("Texture image format must be depth."); throw new IllegalArgumentException("Texture image format must be depth.");
else if (!depth && img.getFormat().isDepthFormat()) } else if (!depth && img.getFormat().isDepthFormat()) {
throw new IllegalArgumentException("Texture image format must be color/luminance."); throw new IllegalArgumentException("Texture image format must be color/luminance.");
}
// check that resolution matches texture resolution // check that resolution matches texture resolution
if (width != img.getWidth() || height != img.getHeight()) if (width != img.getWidth() || height != img.getHeight()) {
throw new IllegalArgumentException("Texture image resolution " + throw new IllegalArgumentException("Texture image resolution "
"must match FB resolution"); + "must match FB resolution");
}
if (samples != tex.getImage().getMultiSamples()) if (samples != tex.getImage().getMultiSamples()) {
throw new IllegalStateException("Texture samples must match framebuffer samples"); throw new IllegalStateException("Texture samples must match framebuffer samples");
} }
}
/** /**
* If enabled, any shaders rendering into this <code>FrameBuffer</code> * If enabled, any shaders rendering into this <code>FrameBuffer</code>
@ -273,16 +282,19 @@ public class FrameBuffer extends NativeObject {
* *
* @param enabled True to enable MRT (multiple rendering targets). * @param enabled True to enable MRT (multiple rendering targets).
*/ */
public void setMultiTarget(boolean enabled){ public void setMultiTarget(boolean enabled) {
if (enabled) colorBufIndex = -1; if (enabled) {
else colorBufIndex = 0; colorBufIndex = -1;
} else {
colorBufIndex = 0;
}
} }
/** /**
* @return True if MRT (multiple rendering targets) is enabled. * @return True if MRT (multiple rendering targets) is enabled.
* @see FrameBuffer#setMultiTarget(boolean) * @see FrameBuffer#setMultiTarget(boolean)
*/ */
public boolean isMultiTarget(){ public boolean isMultiTarget() {
return colorBufIndex == -1; return colorBufIndex == -1;
} }
@ -296,12 +308,14 @@ public class FrameBuffer extends NativeObject {
* @throws IllegalArgumentException If index is negative or doesn't map * @throws IllegalArgumentException If index is negative or doesn't map
* to any attachment on this framebuffer. * to any attachment on this framebuffer.
*/ */
public void setTargetIndex(int index){ public void setTargetIndex(int index) {
if (index < 0 || index >= 16) if (index < 0 || index >= 16) {
throw new IllegalArgumentException("Target index must be between 0 and 16"); throw new IllegalArgumentException("Target index must be between 0 and 16");
}
if (colorBufs.size() < index) if (colorBufs.size() < index) {
throw new IllegalArgumentException("The target at " + index + " is not set!"); throw new IllegalArgumentException("The target at " + index + " is not set!");
}
colorBufIndex = index; colorBufIndex = index;
setUpdateNeeded(); setUpdateNeeded();
@ -312,7 +326,7 @@ public class FrameBuffer extends NativeObject {
* *
* @see FrameBuffer#setTargetIndex(int) * @see FrameBuffer#setTargetIndex(int)
*/ */
public int getTargetIndex(){ public int getTargetIndex() {
return colorBufIndex; return colorBufIndex;
} }
@ -324,7 +338,7 @@ public class FrameBuffer extends NativeObject {
* *
* @param tex The color texture to set. * @param tex The color texture to set.
*/ */
public void setColorTexture(Texture2D tex){ public void setColorTexture(Texture2D tex) {
clearColorTargets(); clearColorTargets();
addColorTexture(tex); addColorTexture(tex);
} }
@ -337,7 +351,7 @@ public class FrameBuffer extends NativeObject {
* *
* @param tex The color texture array to set. * @param tex The color texture array to set.
*/ */
public void setColorTexture(TextureArray tex, int layer){ public void setColorTexture(TextureArray tex, int layer) {
clearColorTargets(); clearColorTargets();
addColorTexture(tex, layer); addColorTexture(tex, layer);
} }
@ -359,7 +373,7 @@ public class FrameBuffer extends NativeObject {
/** /**
* Clears all color targets that were set or added previously. * Clears all color targets that were set or added previously.
*/ */
public void clearColorTargets(){ public void clearColorTargets() {
colorBufs.clear(); colorBufs.clear();
} }
@ -373,12 +387,14 @@ public class FrameBuffer extends NativeObject {
* @param format the format of the color buffer * @param format the format of the color buffer
* @see #addColorTexture(com.jme3.texture.Texture2D) * @see #addColorTexture(com.jme3.texture.Texture2D)
*/ */
public void addColorBuffer(Image.Format format){ public void addColorBuffer(Image.Format format) {
if (id != -1) if (id != -1) {
throw new UnsupportedOperationException("FrameBuffer already initialized."); throw new UnsupportedOperationException("FrameBuffer already initialized.");
}
if (format.isDepthFormat()) if (format.isDepthFormat()) {
throw new IllegalArgumentException("Color buffer format must be color/luminance."); throw new IllegalArgumentException("Color buffer format must be color/luminance.");
}
RenderBuffer colorBuf = new RenderBuffer(); RenderBuffer colorBuf = new RenderBuffer();
colorBuf.slot = colorBufs.size(); colorBuf.slot = colorBufs.size();
@ -398,8 +414,9 @@ public class FrameBuffer extends NativeObject {
* @see #addColorBuffer(com.jme3.texture.Image.Format) * @see #addColorBuffer(com.jme3.texture.Image.Format)
*/ */
public void addColorTexture(Texture2D tex) { public void addColorTexture(Texture2D tex) {
if (id != -1) if (id != -1) {
throw new UnsupportedOperationException("FrameBuffer already initialized."); throw new UnsupportedOperationException("FrameBuffer already initialized.");
}
Image img = tex.getImage(); Image img = tex.getImage();
checkSetTexture(tex, false); checkSetTexture(tex, false);
@ -422,8 +439,9 @@ public class FrameBuffer extends NativeObject {
* @param tex The texture array to add. * @param tex The texture array to add.
*/ */
public void addColorTexture(TextureArray tex, int layer) { public void addColorTexture(TextureArray tex, int layer) {
if (id != -1) if (id != -1) {
throw new UnsupportedOperationException("FrameBuffer already initialized."); throw new UnsupportedOperationException("FrameBuffer already initialized.");
}
Image img = tex.getImage(); Image img = tex.getImage();
checkSetTexture(tex, false); checkSetTexture(tex, false);
@ -448,8 +466,9 @@ public class FrameBuffer extends NativeObject {
* @param face The face of the cube-map to render to. * @param face The face of the cube-map to render to.
*/ */
public void addColorTexture(TextureCubeMap tex, TextureCubeMap.Face face) { public void addColorTexture(TextureCubeMap tex, TextureCubeMap.Face face) {
if (id != -1) if (id != -1) {
throw new UnsupportedOperationException("FrameBuffer already initialized."); throw new UnsupportedOperationException("FrameBuffer already initialized.");
}
Image img = tex.getImage(); Image img = tex.getImage();
checkSetTexture(tex, false); checkSetTexture(tex, false);
@ -468,9 +487,10 @@ public class FrameBuffer extends NativeObject {
* *
* @param tex The color texture to set. * @param tex The color texture to set.
*/ */
public void setDepthTexture(Texture2D tex){ public void setDepthTexture(Texture2D tex) {
if (id != -1) if (id != -1) {
throw new UnsupportedOperationException("FrameBuffer already initialized."); throw new UnsupportedOperationException("FrameBuffer already initialized.");
}
Image img = tex.getImage(); Image img = tex.getImage();
checkSetTexture(tex, true); checkSetTexture(tex, true);
@ -480,9 +500,11 @@ public class FrameBuffer extends NativeObject {
depthBuf.tex = tex; depthBuf.tex = tex;
depthBuf.format = img.getFormat(); depthBuf.format = img.getFormat();
} }
public void setDepthTexture(TextureArray tex, int layer){
if (id != -1) public void setDepthTexture(TextureArray tex, int layer) {
if (id != -1) {
throw new UnsupportedOperationException("FrameBuffer already initialized."); throw new UnsupportedOperationException("FrameBuffer already initialized.");
}
Image img = tex.getImage(); Image img = tex.getImage();
checkSetTexture(tex, true); checkSetTexture(tex, true);
@ -497,7 +519,7 @@ public class FrameBuffer extends NativeObject {
/** /**
* @return The number of color buffers attached to this texture. * @return The number of color buffers attached to this texture.
*/ */
public int getNumColorBuffers(){ public int getNumColorBuffers() {
return colorBufs.size(); return colorBufs.size();
} }
@ -505,7 +527,7 @@ public class FrameBuffer extends NativeObject {
* @param index * @param index
* @return The color buffer at the given index. * @return The color buffer at the given index.
*/ */
public RenderBuffer getColorBuffer(int index){ public RenderBuffer getColorBuffer(int index) {
return colorBufs.get(index); return colorBufs.get(index);
} }
@ -515,9 +537,10 @@ public class FrameBuffer extends NativeObject {
* If MRT is disabled, the first color buffer is returned. * If MRT is disabled, the first color buffer is returned.
*/ */
public RenderBuffer getColorBuffer() { public RenderBuffer getColorBuffer() {
if (colorBufs.isEmpty()) if (colorBufs.isEmpty()) {
return null; return null;
if (colorBufIndex<0 || colorBufIndex>=colorBufs.size()) { }
if (colorBufIndex < 0 || colorBufIndex >= colorBufs.size()) {
return colorBufs.get(0); return colorBufs.get(0);
} }
return colorBufs.get(colorBufIndex); return colorBufs.get(colorBufIndex);
@ -554,14 +577,15 @@ public class FrameBuffer extends NativeObject {
} }
@Override @Override
public String toString(){ public String toString() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
String mrtStr = colorBufIndex >= 0 ? "" + colorBufIndex : "mrt"; String mrtStr = colorBufIndex >= 0 ? "" + colorBufIndex : "mrt";
sb.append("FrameBuffer[format=").append(width).append("x").append(height) sb.append("FrameBuffer[format=").append(width).append("x").append(height)
.append("x").append(samples).append(", drawBuf=").append(mrtStr).append("]\n"); .append("x").append(samples).append(", drawBuf=").append(mrtStr).append("]\n");
if (depthBuf != null) if (depthBuf != null) {
sb.append("Depth => ").append(depthBuf).append("\n"); sb.append("Depth => ").append(depthBuf).append("\n");
for (RenderBuffer colorBuf : colorBufs){ }
for (RenderBuffer colorBuf : colorBufs) {
sb.append("Color(").append(colorBuf.slot) sb.append("Color(").append(colorBuf.slot)
.append(") => ").append(colorBuf).append("\n"); .append(") => ").append(colorBuf).append("\n");
} }
@ -576,25 +600,26 @@ public class FrameBuffer extends NativeObject {
colorBufs.get(i).resetObject(); colorBufs.get(i).resetObject();
} }
if (depthBuf != null) if (depthBuf != null) {
depthBuf.resetObject(); depthBuf.resetObject();
}
setUpdateNeeded(); setUpdateNeeded();
} }
@Override @Override
public void deleteObject(Object rendererObject) { public void deleteObject(Object rendererObject) {
((Renderer)rendererObject).deleteFrameBuffer(this); ((Renderer) rendererObject).deleteFrameBuffer(this);
} }
@Override @Override
public NativeObject createDestructableClone(){ public NativeObject createDestructableClone() {
return new FrameBuffer(this); return new FrameBuffer(this);
} }
@Override @Override
public long getUniqueId() { public long getUniqueId() {
return ((long)OBJTYPE_FRAMEBUFFER << 32) | ((long)id); return ((long) OBJTYPE_FRAMEBUFFER << 32) | ((long) id);
} }
/** /**
@ -632,5 +657,4 @@ public class FrameBuffer extends NativeObject {
public boolean isSrgb() { public boolean isSrgb() {
return srgb; return srgb;
} }
} }

@ -1269,7 +1269,7 @@ public final class BufferUtils {
* and cleans the direct buffers. However, as this doesn't happen * and cleans the direct buffers. However, as this doesn't happen
* immediately after discarding all references to a direct buffer, it's easy * immediately after discarding all references to a direct buffer, it's easy
* to OutOfMemoryError yourself using direct buffers. * to OutOfMemoryError yourself using direct buffers.
**/ */
public static void destroyDirectBuffer(Buffer toBeDestroyed) { public static void destroyDirectBuffer(Buffer toBeDestroyed) {
if (!isDirect(toBeDestroyed)) { if (!isDirect(toBeDestroyed)) {
return; return;
@ -1318,5 +1318,4 @@ public final class BufferUtils {
} }
} }
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2009-2012 jMonkeyEngine * Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

Loading…
Cancel
Save