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();
Vector3f min = vars.vect1.set(new Vector3f(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY));
Vector3f max = vars.vect2.set(new Vector3f(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY));
Vector3f min = vars.vect1.set(new Vector3f(Float.POSITIVE_INFINITY,
Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY));
Vector3f max = vars.vect2.set(new Vector3f(Float.NEGATIVE_INFINITY,
Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY));
Vector3f point;
for (int i = start; i < end; i++) {
@ -240,8 +242,12 @@ public class BoundingBox extends BoundingVolume {
float[] tmpArray = vars.skinPositions;
float minX = Float.POSITIVE_INFINITY, minY = Float.POSITIVE_INFINITY, minZ = Float.POSITIVE_INFINITY;
float maxX = Float.NEGATIVE_INFINITY, maxY = Float.NEGATIVE_INFINITY, maxZ = Float.NEGATIVE_INFINITY;
float minX = Float.POSITIVE_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));
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) {
vars.vect1.x = tmpArray[j];
vars.vect1.y = tmpArray[j+1];
vars.vect1.z = tmpArray[j+2];
vars.vect1.y = tmpArray[j + 1];
vars.vect1.z = tmpArray[j + 2];
if (vars.vect1.x < minX) {
minX = vars.vect1.x;
@ -317,7 +323,9 @@ public class BoundingBox extends BoundingVolume {
transMatrix.absoluteLocal();
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);
// Assign the biggest rotations after scales.
box.xExtent = FastMath.abs(vars.vect2.getX());
@ -339,7 +347,6 @@ public class BoundingBox extends BoundingVolume {
}
TempVars vars = TempVars.get();
float w = trans.multProj(center, box.center);
box.center.divideLocal(w);
@ -432,13 +439,12 @@ public class BoundingBox extends BoundingVolume {
// case OBB: {
// return mergeOBB((OrientedBoundingBox) volume);
// }
default:
return null;
}
}
/**
/*
* Merges this AABB with the given OBB.
*
* @param volume
@ -481,6 +487,7 @@ public class BoundingBox extends BoundingVolume {
// zExtent = max.z - center.z;
// return this;
// }
/**
* <code>mergeLocal</code> combines this bounding box locally with a second
* 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
* box.
*
@ -783,8 +790,11 @@ public class BoundingBox extends BoundingVolume {
&& clip(-direction.z, +diff.z - zExtent, t);
if (notEntirelyClipped && (t[0] != saveT0 || t[1] != saveT1)) {
if (t[1] > t[0]) return 2;
else return 1;
if (t[1] > t[0]) {
return 2;
} else {
return 1;
}
}
return 0;
} finally {
@ -868,10 +878,10 @@ public class BoundingBox extends BoundingVolume {
@Override
public float distanceToEdge(Vector3f point) {
// compute coordinates of point in box coordinate system
TempVars vars= TempVars.get();
TempVars vars = TempVars.get();
Vector3f closest = vars.vect1;
point.subtract(center,closest);
point.subtract(center, closest);
// project test point onto box
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 $
*/
public abstract class BoundingVolume implements Savable, Cloneable, Collidable {
/**
* The type of bounding volume being used.
*/
@ -58,12 +57,10 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable {
* {@link BoundingSphere}
*/
Sphere,
/**
* {@link BoundingBox}.
*/
AABB,
/**
* Currently unsupported by jME3.
*/
@ -82,7 +79,6 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable {
/**
* Grabs the checkplane we should check first.
*
*/
public int getCheckPlane() {
return checkPlane;
@ -103,7 +99,6 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable {
public abstract Type getType();
/**
*
* <code>transform</code> alters the location of the bounding volume by a
* 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
* 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);
/**
*
* <code>whichSide</code> returns the side on which the bounding volume
* lies on a plane. Possible values are POSITIVE_SIDE, NEGATIVE_SIDE, and
* NO_SIDE.
@ -143,7 +136,6 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable {
public abstract Plane.Side whichSide(Plane plane);
/**
*
* <code>computeFromPoints</code> generates a bounding volume that
* encompasses a collection of points.
*
@ -255,7 +247,6 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable {
*/
public abstract boolean intersects(Ray ray);
/**
* determines if this bounding volume and a given bounding sphere are
* intersecting.
@ -276,7 +267,7 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable {
*/
public abstract boolean intersectsBoundingBox(BoundingBox bb);
/**
/*
* determines if this bounding volume and a given bounding box are
* intersecting.
*
@ -286,7 +277,6 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable {
*/
// public abstract boolean intersectsOrientedBoundingBox(OrientedBoundingBox bb);
/**
*
* 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
* 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.
*
* @param point the point to check
* @return true if the point lies within this bounding volume.
*/
@ -308,11 +299,11 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable {
@Override
public BoundingVolume clone() {
try{
try {
BoundingVolume clone = (BoundingVolume) super.clone();
clone.center = center.clone();
return clone;
}catch (CloneNotSupportedException ex){
} catch (CloneNotSupportedException ex) {
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.
*
* 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.
*
* @author Marcin Roguski (Kealthas)
*/
public class CurveAndSurfaceMath {
private static final float KNOTS_MINIMUM_DELTA = 0.0001f;
/**
* A private constructor is defined to avoid instantiation of this
* class.
* A private constructor is defined to avoid instantiation of this class.
*/
private CurveAndSurfaceMath() {}
private CurveAndSurfaceMath() {
}
/**
* This method interpolates the data for the nurbs curve.
* @param u
* the u value
*
* @param u the u value
* @param nurbSpline
* the nurbs spline definition
* @param store
@ -64,7 +65,6 @@ public class CurveAndSurfaceMath {
float[] weights = nurbSpline.getWeights();
List<Float> knots = nurbSpline.getKnots();
int controlPointAmount = controlPoints.size();
store.set(Vector3f.ZERO);
float delimeter = 0;
for (int i = 0; i < controlPointAmount; ++i) {
@ -79,10 +79,8 @@ public class CurveAndSurfaceMath {
/**
* This method interpolates the data for the nurbs surface.
*
* @param u
* the u value
* @param v
* the v value
* @param u the u value
* @param v the v value
* @param controlPoints
* the nurbs' control points
* @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
* repeated) it leads to NaN results during calculations. This method adds a small number to each of such knots to avoid NaN's.
* This method prepares the knots to be used. If the knots represent
* 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
* the knots to be prepared to use
* @param basisFunctionDegree
@ -126,9 +127,9 @@ public class CurveAndSurfaceMath {
public static void prepareNurbsKnots(List<Float> knots, int basisFunctionDegree) {
float delta = KNOTS_MINIMUM_DELTA;
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();
if(value<=prevValue) {
if (value <= prevValue) {
value += delta;
knots.set(i, Float.valueOf(value));
delta += KNOTS_MINIMUM_DELTA;
@ -142,12 +143,10 @@ public class CurveAndSurfaceMath {
/**
* This method computes the base function value for the NURB curve.
* @param i
* the knot index
* @param k
* the base function degree
* @param t
* the knot value
*
* @param i the knot index
* @param k the base function degree
* @param t the knot value
* @param knots
* the knots' values
* @return the base function value
@ -156,10 +155,10 @@ public class CurveAndSurfaceMath {
if (k == 1) {
return knots.get(i) <= t && t < knots.get(i + 1) ? 1.0f : 0.0f;
} else {
return (t - knots.get(i)) / (knots.get(i + k - 1) - knots.get(i)) *
CurveAndSurfaceMath.computeBaseFunctionValue(i, k - 1, t, knots)
+ (knots.get(i + k) - t) / (knots.get(i + k) - knots.get(i + 1)) *
CurveAndSurfaceMath.computeBaseFunctionValue(i + 1, k - 1, t, knots);
return (t - knots.get(i)) / (knots.get(i + k - 1) - knots.get(i))
* CurveAndSurfaceMath.computeBaseFunctionValue(i, k - 1, t, knots)
+ (knots.get(i + k) - t) / (knots.get(i + k) - knots.get(i + 1))
* 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 $
*/
final public class 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;
/** 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;
/** 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 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;
/** 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;
/** 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;
/** 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;
/** The value 1/PI as a float. */
/**
* The value 1/PI as a float.
*/
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;
/** 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;
/** 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;
/** A precreated random object for random numbers. */
/**
* A precreated random object for random numbers.
*/
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
* @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) {
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 the scale is over 1 the value is linearly extrapolated.
* Note that the end value is the value for a scale of 1.
*
* @param scale the scale for extrapolation
* @param startValue the starting value (scale = 0)
* @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 the scale is over 1 the value is linearly extrapolated.
* Note that the end value is the value for a scale of 1.
*
* @param scale the scale for extrapolation
* @param startValue the starting value (scale = 0)
* @param endValue the end value (scale = 1)
* @param store an initialized vector to store the return value
* @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) {
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 the scale is over 1 the value is linearly extrapolated.
* Note that the end value is the value for a scale of 1.
*
* @param scale the scale for extrapolation
* @param startValue the starting value (scale = 0)
* @param endValue the end value (scale = 1)
@ -227,7 +255,8 @@ final public class FastMath {
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
* m = [ 0.0 1.0 0.0 0.0 ]
* [-T 0.0 T 0.0 ]
@ -253,7 +282,8 @@ final public class FastMath {
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
* m = [ 0.0 1.0 0.0 0.0 ]
* [-T 0.0 T 0.0 ]
@ -270,7 +300,8 @@ final public class FastMath {
* @param store a Vector3f to store the result
* @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) {
store = new Vector3f();
}
@ -297,7 +328,8 @@ final public class FastMath {
* @param p3 control point 3
* @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);
}
@ -326,7 +358,8 @@ final public class FastMath {
+ 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
* m = [ -1.0 3.0 -3.0 1.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
* @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) {
store = new Vector3f();
}
@ -352,7 +386,8 @@ final public class FastMath {
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
* m = [ -1.0 3.0 -3.0 1.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
*
* @param p0 control point 0
* @param p1 control point 1
* @param p2 control point 2
@ -382,7 +418,8 @@ final public class FastMath {
* @param curveTension the curve tension
* @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 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.
*
* @param p0 control point 0
* @param p1 control point 1
* @param p2 control point 2
@ -432,6 +470,7 @@ final public class FastMath {
* Special cases:
* <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>
*
* @param fValue The value to arc cosine.
* @return The angle, in radians.
* @see java.lang.Math#acos(double)
@ -453,6 +492,7 @@ final public class FastMath {
* Special cases:
* <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>
*
* @param fValue The value to arc sine.
* @return the angle in radians.
* @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>
*
* @param fValue The angle, in radians.
* @return fValue's atan
* @see java.lang.Math#atan(double)
@ -481,6 +522,7 @@ final public class FastMath {
/**
* A direct call to Math.atan2.
*
* @param fY
* @param fX
* @return Math.atan2(fY,fX)
@ -492,6 +534,7 @@ final public class FastMath {
/**
* Rounds a fValue up. A call to Math.ceil
*
* @param fValue The value.
* @return The fValue rounded up
* @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
*
* @see Math#cos(double)
* @param v The angle to cosine.
* @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
*
* @see Math#sin(double)
* @param v The angle to sine.
* @return the sine of the angle.
@ -522,6 +567,7 @@ final public class FastMath {
/**
* Returns E^fValue
*
* @param fValue Value to raise to a power.
* @return The value E^fValue
* @see java.lang.Math#exp(double)
@ -532,6 +578,7 @@ final public class FastMath {
/**
* Returns Absolute value of a float.
*
* @param fValue The value to abs.
* @return The abs of the value.
* @see java.lang.Math#abs(float)
@ -545,6 +592,7 @@ final public class FastMath {
/**
* Returns a number rounded down.
*
* @param fValue The value to round
* @return The given number rounded down
* @see java.lang.Math#floor(double)
@ -555,6 +603,7 @@ final public class FastMath {
/**
* Returns 1/sqrt(fValue)
*
* @param fValue The value to process.
* @return 1/sqrt(fValue)
* @see java.lang.Math#sqrt(double)
@ -574,6 +623,7 @@ final public class FastMath {
/**
* Returns the log base E of a value.
*
* @param fValue The value to log.
* @return The log of fValue base E
* @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),
* so that pow(base, return)==value (contributed by vear)
*
* @param value The value to log.
* @param base Base of logarithm.
* @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
*
* @param fBase The base value (IE 2)
* @param fExponent The exponent value (IE 3)
* @return base raised to exponent (IE 8)
@ -606,6 +658,7 @@ final public class FastMath {
/**
* Returns the value squared. fValue ^ 2
*
* @param fValue The value to square.
* @return The square of the given value.
*/
@ -615,6 +668,7 @@ final public class FastMath {
/**
* Returns the square root of a given value.
*
* @param fValue The value to sqrt.
* @return The square root of the given value.
* @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
* is returned. Otherwise, a direct value is used.
*
* @param fValue The value to tangent, in radians.
* @return The tangent of fValue.
* @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
*
* @param iValue The integer to examine.
* @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
*
* @param fValue The float to examine.
* @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
* are moving counter clock wise.
*
* @param p0 Point 0.
* @param p1 Point 1.
* @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,
* -1 if the point is on the cw side, and 0 if it is on neither.
*
* @param t0 First point of the triangle.
* @param t1 Second 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.
*
* @param v1 first vertex
* @param v2 second vertex
* @param v3 third vertex
@ -996,6 +1056,7 @@ final public class FastMath {
/**
* Converts a range of min/max to a 0-1 range.
*
* @param value the value between min-max (inclusive).
* @param min the minimum 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) {
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
* initial values for the matrix is that of the identity matrix.
*
*/
public Matrix3f() {
loadIdentity();
@ -70,24 +69,15 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
/**
* constructs a matrix with the given values.
*
* @param m00
* 0x0 in the matrix.
* @param m01
* 0x1 in the matrix.
* @param m02
* 0x2 in the matrix.
* @param m10
* 1x0 in the matrix.
* @param m11
* 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.
* @param m00 0x0 in the matrix.
* @param m01 0x1 in the matrix.
* @param m02 0x2 in the matrix.
* @param m10 1x0 in the matrix.
* @param m11 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,
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
* thrown.
*
* @param i
* the row index.
* @param j
* the colum index.
* @param i the row index.
* @param j the colum index.
* @return the value at (i, j).
*/
@SuppressWarnings("fallthrough")
@ -303,6 +291,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
/**
* Normalize this matrix
*
* @return this matrix once normalized.
*/
public Matrix3f normalizeLocal() {
@ -448,7 +437,6 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
TempVars vars = TempVars.get();
fillFloatArray(vars.matrixWrite, columnMajor);
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) {
if (columnMajor) {
f[ 0] = m00;
f[ 1] = m10;
f[ 2] = m20;
f[ 3] = m01;
f[ 4] = m11;
f[ 5] = m21;
f[ 6] = m02;
f[ 7] = m12;
f[ 8] = m22;
f[0] = m00;
f[1] = m10;
f[2] = m20;
f[3] = m01;
f[4] = m11;
f[5] = m21;
f[6] = m02;
f[7] = m12;
f[8] = m22;
} else {
f[ 0] = m00;
f[ 1] = m01;
f[ 2] = m02;
f[ 3] = m10;
f[ 4] = m11;
f[ 5] = m12;
f[ 6] = m20;
f[ 7] = m21;
f[ 8] = m22;
f[0] = m00;
f[1] = m01;
f[2] = m02;
f[3] = m10;
f[4] = m11;
f[5] = m12;
f[6] = m20;
f[7] = m21;
f[8] = m22;
}
}
/**
*
* <code>setColumn</code> sets a particular column of this matrix to that
* 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
* 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
* 3x3 two dimenion array.
*
@ -652,12 +637,9 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
/**
* Recreate Matrix using the provided axis.
*
* @param uAxis
* Vector3f
* @param vAxis
* Vector3f
* @param wAxis
* Vector3f
* @param uAxis Vector3f
* @param vAxis Vector3f
* @param wAxis Vector3f
*/
public void fromAxes(Vector3f uAxis, Vector3f vAxis, Vector3f wAxis) {
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>Quaternion</code>. It should be noted that all previous values
* 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.
* Where all values are zero except those along the diagonal which are one.
*
*/
public void loadIdentity() {
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
* supported for the benefit of hashing based collection classes such as
* 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
* identity matrix.
*
*/
public Matrix4f() {
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
* thrown.
*
* @param i
* the row index.
* @param j
* the colum index.
* @param i the row index.
* @param j the colum index.
* @return the value at (i, j).
*/
@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
* parameter. This column is returned as a float array of length 4.
*
* @param i
* the column to retrieve. Must be between 0 and 3.
* @param i the column to retrieve. Must be between 0 and 3.
* @return the column specified by the index.
*/
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
* parameter. This column is returned as a float[4].
*
* @param i
* the column to retrieve. Must be between 0 and 3.
* @param i the column to retrieve. Must be between 0 and 3.
* @param store
* the float array to store the result in. if null, a new one
* 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
* represented by the provided vector.
*
* @param i
* the column to set.
* @param i the column to set.
* @param column
* 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
* thrown.
*
* @param i
* the row index.
* @param j
* the colum index.
* @param i the row index.
* @param j the colum index.
* @param value
* the value for (i, j).
*/
@ -532,7 +523,6 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
m33 = matrix[3][3];
}
/**
* 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
* the matrix data.
*
* @param fb the buffer to fill, must be correct size
* @return matrix data as a FloatBuffer.
*/
@ -753,7 +744,6 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
TempVars vars = TempVars.get();
fillFloatArray(vars.matrixWrite, columnMajor);
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) {
if (columnMajor) {
f[ 0] = m00;
f[ 1] = m10;
f[ 2] = m20;
f[ 3] = m30;
f[ 4] = m01;
f[ 5] = m11;
f[ 6] = m21;
f[ 7] = m31;
f[ 8] = m02;
f[ 9] = m12;
f[0] = m00;
f[1] = m10;
f[2] = m20;
f[3] = m30;
f[4] = m01;
f[5] = m11;
f[6] = m21;
f[7] = m31;
f[8] = m02;
f[9] = m12;
f[10] = m22;
f[11] = m32;
f[12] = m03;
@ -781,16 +771,16 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
f[14] = m23;
f[15] = m33;
} else {
f[ 0] = m00;
f[ 1] = m01;
f[ 2] = m02;
f[ 3] = m03;
f[ 4] = m10;
f[ 5] = m11;
f[ 6] = m12;
f[ 7] = m13;
f[ 8] = m20;
f[ 9] = m21;
f[0] = m00;
f[1] = m01;
f[2] = m02;
f[3] = m03;
f[4] = m10;
f[5] = m11;
f[6] = m12;
f[7] = m13;
f[8] = m20;
f[9] = m21;
f[10] = m22;
f[11] = m23;
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.
*
* @param fb the buffer to read from, must be correct size
* @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.
*
* @param fb the buffer to read from, must be correct size
* @param columnMajor if true, this buffer should be filled with column
* 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,
* namely all zeros with ones along the diagonal.
*
*/
public void loadIdentity() {
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;
}
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();
if (parallel) {
// scale
@ -1095,7 +1087,6 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
+ m32 * in2.m23
+ m33 * in2.m33;
store.m00 = m[0];
store.m01 = m[1];
store.m02 = m[2];
@ -1211,7 +1202,6 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
*
* @param vec
* vec to multiply against.
*
* @return the rotated vector.
*/
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.
*
* @param x
* value of the translation on the x axis
* @param y
* value of the translation on the y axis
* @param z
* value of the translation on the z axis
* @param x value of the translation on the x axis
* @param y 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) {
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
* 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
* 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
* 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
* 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
* supported for the benefit of hashing based collection classes such as
* 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) {
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;
}
public Vector3f getClosestPoint(Vector3f point, Vector3f store){
public Vector3f getClosestPoint(Vector3f point, Vector3f store) {
// float t = constant - normal.dot(point);
// return store.set(normal).multLocal(t).addLocal(point);
float t = (constant - normal.dot(point)) / normal.dot(normal);
return store.set(normal).multLocal(t).addLocal(point);
}
public Vector3f getClosestPoint(Vector3f point){
public Vector3f getClosestPoint(Vector3f point) {
return getClosestPoint(point, new Vector3f());
}
public Vector3f reflect(Vector3f point, Vector3f store){
if (store == null)
public Vector3f reflect(Vector3f point, Vector3f store) {
if (store == null) {
store = new Vector3f();
}
float d = pseudoDistance(point);
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);
if (dist < FastMath.FLT_EPSILON && dist > -FastMath.FLT_EPSILON)
if (dist < FastMath.FLT_EPSILON && dist > -FastMath.FLT_EPSILON) {
return true;
else
} else {
return false;
}
}
/**
* Initialize this plane using the three points of the given triangle.
*
* @param t
* the triangle
* @param t the triangle
*/
public void setPlanePoints(AbstractTriangle t) {
setPlanePoints(t.get1(), t.get2(), t.get3());
@ -232,7 +233,7 @@ public class Plane implements Savable, Cloneable, java.io.Serializable {
* @param origin
* @param normal
*/
public void setOriginNormal(Vector3f origin, Vector3f normal){
public void setOriginNormal(Vector3f origin, Vector3f normal) {
this.normal.set(normal);
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
* continuous rotation.
*
* <code>Quaternion</code> is defined by four floating point numbers: {x y z
* w}.
* <code>Quaternion</code> is defined by four floating point numbers: {x y z w}.
*
* @author Mark Powell
* @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
* given list of parameters.
*
* @param x
* the x value of the quaternion.
* @param y
* the y value of the quaternion.
* @param z
* the z value of the quaternion.
* @param w
* the w value of the quaternion.
* @param x the x value of the quaternion.
* @param y the y 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) {
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
* of parameters.
*
* @param x
* the x value of the quaternion.
* @param y
* the y value of the quaternion.
* @param z
* the z value of the quaternion.
* @param w
* the w value of the quaternion.
* sets the data in a <code>Quaternion</code> object from the given list of
* parameters.
*
* @param x the x value of the quaternion.
* @param y the y value of the quaternion.
* @param z the z value of the quaternion.
* @param w the w value of the quaternion.
* @return this
*/
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
* a new object.
*
* @param q
* The Quaternion to copy values from.
* @param q The Quaternion to copy values from.
* @return this
*/
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
* existing quaternion, creating a copy.
*
* @param q
* the quaternion to copy.
* @param q the quaternion to copy.
*/
public Quaternion(Quaternion q) {
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
* angles (x,y,z) aka (pitch, yaw, roll)). 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.
* angles (x,y,z) aka (pitch, yaw, roll)).
* 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>
*
* @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
* 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.
*
* @param q2
* @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
* parameter quaternion. The result is returned as a new quaternion.
*
* @param q
* the quaternion to add to this.
* @param q the quaternion to add to this.
* @return the new quaternion.
*/
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
* parameter quaternion. The result is stored in this Quaternion.
*
* @param q
* the quaternion to add to this.
* @param q the quaternion to add to this.
* @return This Quaternion after addition.
*/
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
* quaternion.
*
* @param q
* the quaternion to subtract from this.
* @param q the quaternion to subtract from this.
* @return the new quaternion.
*/
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
* from those of this quaternion. The result is stored in this Quaternion.
*
* @param q
* the quaternion to subtract from this.
* @param q the quaternion to subtract from this.
* @return This Quaternion after subtraction.
*/
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 NOT safe for this and res to be the same object.
*
* @param q
* the quaternion to multiply this quaternion by.
* @param q the quaternion to multiply this quaternion by.
* @param res
* the quaternion to store the result in.
* @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
* rotation.
*
* @param axis
* the array of vectors to be filled.
* @param axis the array of vectors to be filled.
*/
public void toAxes(Vector3f axis[]) {
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
* result is returned as a new vector.
*
* @param v
* the vector to multiply this quaternion by.
* @param v the vector to multiply this quaternion by.
* @return the new vector.
*/
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
* result is stored in the supplied vector
*
* @param v
* the vector to multiply this quaternion by.
* @param v the vector to multiply this quaternion by.
* @return 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
* to this *= q.
*
* @param q
* The Quaternion to multiply this one by.
* @param q The Quaternion to multiply this one by.
* @return This Quaternion, after multiplication.
*/
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
* to this *= q.
*
* @param qx -
* quat x value
* @param qy -
* quat y value
* @param qz -
* quat z value
* @param qw -
* quat w value
* @param qx quat x value
* @param qy quat y value
* @param qz quat z value
* @param qw quat w value
*
* @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
* supported for the benefit of hashing based collection classes such as
* Hashtable, HashMap, HashSet etc.

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

@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2018 jMonkeyEngine
* Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved.
*
* 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 scale = new Vector3f(1, 1, 1);
public Transform(Vector3f translation, Quaternion rot){
public Transform(Vector3f translation, Quaternion rot) {
this.translation.set(translation);
this.rot.set(rot);
}
public Transform(Vector3f translation, Quaternion rot, Vector3f scale){
public Transform(Vector3f translation, Quaternion rot, Vector3f scale) {
this(translation, rot);
this.scale.set(scale);
}
public Transform(Vector3f translation){
public Transform(Vector3f translation) {
this(translation, Quaternion.IDENTITY);
}
public Transform(Quaternion rot){
public Transform(Quaternion rot) {
this(Vector3f.ZERO, rot);
}
public Transform(){
public Transform() {
this(Vector3f.ZERO, Quaternion.IDENTITY);
}
/**
* Sets this rotation to the given Quaternion value.
*
* @param rot The new rotation for this matrix.
* @return this
*/
@ -87,6 +88,7 @@ public final class Transform implements Savable, Cloneable, java.io.Serializable
/**
* Sets this translation to the given value.
*
* @param trans The new translation for this matrix.
* @return this
*/
@ -97,6 +99,7 @@ public final class Transform implements Savable, Cloneable, java.io.Serializable
/**
* Return the translation vector in this matrix.
*
* @return translation vector.
*/
public Vector3f getTranslation() {
@ -105,6 +108,7 @@ public final class Transform implements Savable, Cloneable, java.io.Serializable
/**
* Sets this scale to the given value.
*
* @param scale The new scale for this matrix.
* @return this
*/
@ -115,6 +119,7 @@ public final class Transform implements Savable, Cloneable, java.io.Serializable
/**
* Sets this scale to the given value.
*
* @param scale The new scale for this matrix.
* @return this
*/
@ -125,6 +130,7 @@ public final class Transform implements Savable, Cloneable, java.io.Serializable
/**
* Return the scale vector in this matrix.
*
* @return scale vector.
*/
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
* hold the value. The value, once stored, is returned.
* Stores this translation value into the given vector3f. If trans is null,
* 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.
* @return The value of this matrix's translation.
*/
public Vector3f getTranslation(Vector3f trans) {
if (trans==null) trans=new Vector3f();
if (trans == null) {
trans = new Vector3f();
}
trans.set(this.translation);
return trans;
}
/**
* Stores this rotation value into the given Quaternion. If quat is null, a new Quaternion is created to
* hold the value. The value, once stored, is returned.
* Stores this rotation value into the given Quaternion. If quat is null, a
* new Quaternion is created to hold the value. The value, once stored, is
* returned.
*
* @param quat The store location for this matrix's rotation.
* @return The value of this matrix's rotation.
*/
public Quaternion getRotation(Quaternion quat) {
if (quat==null) quat=new Quaternion();
if (quat == null) {
quat = new Quaternion();
}
quat.set(rot);
return quat;
}
/**
* Return the rotation quaternion in this matrix.
*
* @return rotation quaternion.
*/
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
* hold the value. The value, once stored, is returned.
* Stores this scale value into the given vector3f. If scale is null, a new
* vector3f is created to hold the value. The value, once stored, is
* returned.
*
* @param scale The store location for this matrix's scale.
* @return The value of this matrix's scale.
*/
public Vector3f getScale(Vector3f scale) {
if (scale==null) scale=new Vector3f();
if (scale == null) {
scale = new Vector3f();
}
scale.set(this.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 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) {
t1.rot.nlerp(t2.rot, delta);
this.rot.set(t1.rot);
this.translation.interpolateLocal(t1.translation,t2.translation,delta);
this.scale.interpolateLocal(t1.scale,t2.scale,delta);
this.translation.interpolateLocal(t1.translation, t2.translation, 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.
* @return This matrix, after combining.
*/
@ -202,8 +226,7 @@ public final class Transform implements Savable, Cloneable, java.io.Serializable
translation.multLocal(parent.scale);
//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"
parent
.rot
parent.rot
.multLocal(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.
*
* @param x This matrix's new x translation.
* @param y This matrix's new y translation.
* @param z This matrix's new z translation.
* @return this
*/
public Transform setTranslation(float x,float y, float z) {
translation.set(x,y,z);
public Transform setTranslation(float x, float y, float z) {
translation.set(x, y, z);
return this;
}
/**
* Sets this matrix's scale to the given x,y,z values.
*
* @param x This matrix's new x scale.
* @param y This matrix's new y scale.
* @param z This matrix's new z scale.
* @return this
*/
public Transform setScale(float x, float y, float z) {
scale.set(x,y,z);
scale.set(x, y, z);
return this;
}
public Vector3f transformVector(final Vector3f in, Vector3f store){
if (store == null)
public Vector3f transformVector(final Vector3f in, Vector3f store) {
if (store == null) {
store = new Vector3f();
}
// multiply with scale first, then rotate, finally translate (cf.
// Eberly)
return rot.mult(store.set(in).multLocal(scale), store).addLocal(translation);
}
public Vector3f transformInverseVector(final Vector3f in, Vector3f store){
if (store == null)
public Vector3f transformInverseVector(final Vector3f in, Vector3f store) {
if (store == null) {
store = new Vector3f();
}
// The author of this code should look above and take the inverse of that
// But for some reason, they didn't ..
// in.subtract(translation, store).divideLocal(scale);
// rot.inverse().mult(store, store);
in.subtract(translation, store);
rot.inverse().mult(store, store);
store.divideLocal(scale);
@ -331,14 +357,16 @@ public final class Transform implements Savable, Cloneable, java.io.Serializable
}
@Override
public String toString(){
return getClass().getSimpleName() + "[ " + translation.x + ", " + translation.y + ", " + translation.z + "]\n"
public String toString() {
return getClass().getSimpleName()
+ "[ " + translation.x + ", " + translation.y + ", " + translation.z + "]\n"
+ "[ " + rot.x + ", " + rot.y + ", " + rot.z + ", " + rot.w + "]\n"
+ "[ " + scale.x + " , " + scale.y + ", " + scale.z + "]";
}
/**
* Sets this matrix to be equal to the given matrix.
*
* @param matrixQuat The matrix to be equal to.
* @return this
*/
@ -361,9 +389,9 @@ public final class Transform implements Savable, Cloneable, java.io.Serializable
public void read(JmeImporter e) throws IOException {
InputCapsule capsule = e.getCapsule(this);
rot.set((Quaternion)capsule.readSavable("rot", Quaternion.IDENTITY));
translation.set((Vector3f)capsule.readSavable("translation", Vector3f.ZERO));
scale.set((Vector3f)capsule.readSavable("scale", Vector3f.UNIT_XYZ));
rot.set((Quaternion) capsule.readSavable("rot", Quaternion.IDENTITY));
translation.set((Vector3f) capsule.readSavable("translation", Vector3f.ZERO));
scale.set((Vector3f) capsule.readSavable("scale", Vector3f.UNIT_XYZ));
}
@Override

@ -29,7 +29,6 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jme3.math;
import com.jme3.export.*;
@ -52,7 +51,6 @@ import java.util.logging.Logger;
public final class Vector3f implements Savable, Cloneable, java.io.Serializable {
static final long serialVersionUID = 1;
private static final Logger logger = Logger.getLogger(Vector3f.class.getName());
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);
/**
* the x value of the vector.
*/
public float x;
/**
* the y value of the vector.
*/
public float y;
/**
* 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
* resultant vector which is returned. If the provided vector is null, null
* 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
* 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
* 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
* 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
* 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
* 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.
* @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);
}
@ -342,7 +330,9 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
* @return result, after receiving the cross product vector.
*/
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 resY = ((z * otherX) - (x * otherZ));
float resZ = ((x * otherY) - (y * otherX));
@ -375,8 +365,8 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
* @return this.
*/
public Vector3f crossLocal(float otherX, float otherY, float otherZ) {
float tempx = ( y * otherZ ) - ( z * otherY );
float tempy = ( z * otherX ) - ( x * otherZ );
float tempx = (y * otherZ) - (z * otherY);
float tempy = (z * otherX) - (x * otherZ);
z = (x * otherY) - (y * otherX);
x = tempx;
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
* @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 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
* @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 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),
* or false otherwise.
*/
public boolean isUnitVector(){
public boolean isUnitVector() {
float len = length();
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
* 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
* 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.");
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);
}
/**
* <code>divide</code> divides the values of this vector by a scalar and
* 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>.
*/
public Vector3f divide(float scalar) {
scalar = 1f/scalar;
scalar = 1f / 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
*/
public Vector3f divideLocal(float scalar) {
scalar = 1f/scalar;
scalar = 1f / scalar;
x *= scalar;
y *= scalar;
z *= scalar;
return this;
}
/**
* <code>divide</code> divides the values of this vector by a scalar and
* 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
* 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.
*
* @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
* of this vector creating a new vector object. If the provided vector is
* null, null is returned.
@ -704,7 +689,6 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
}
/**
*
* <code>subtract</code>
*
* @param vec
@ -714,7 +698,7 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
* @return result
*/
public Vector3f subtract(Vector3f vec, Vector3f result) {
if(result == null) {
if (result == null) {
result = new Vector3f();
}
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,
* 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);
float length = x * x + y * y + z * z;
if (length != 1f && length != 0f){
if (length != 1f && length != 0f) {
length = 1.0f / FastMath.sqrt(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
// is commonly used.
float length = x * x + y * y + z * z;
if (length != 1f && length != 0f){
if (length != 1f && length != 0f) {
length = 1.0f / FastMath.sqrt(length);
x *= 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
* component in this and <code>other</code> vector. The result is stored
* in this vector.
*
* @param other
*/
public Vector3f maxLocal(Vector3f other){
public Vector3f maxLocal(Vector3f other) {
x = other.x > x ? other.x : x;
y = other.y > y ? other.y : y;
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
* component in this and <code>other</code> vector. The result is stored
* in this vector.
*
* @param other
*/
public Vector3f minLocal(Vector3f other){
public Vector3f minLocal(Vector3f other) {
x = other.x < x ? other.x : x;
y = other.y < y ? other.y : y;
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
* this=(1-changeAmnt)*this + changeAmnt * finalVec
*
* @param finalVec The final vector to interpolate towards
* @param changeAmnt An amount between 0.0 - 1.0 representing a percentage
* change from this towards finalVec
*/
public Vector3f interpolateLocal(Vector3f finalVec, float changeAmnt) {
this.x=(1-changeAmnt)*this.x + changeAmnt*finalVec.x;
this.y=(1-changeAmnt)*this.y + changeAmnt*finalVec.y;
this.z=(1-changeAmnt)*this.z + changeAmnt*finalVec.z;
this.x = (1 - changeAmnt) * this.x + changeAmnt * finalVec.x;
this.y = (1 - changeAmnt) * this.y + changeAmnt * finalVec.y;
this.z = (1 - changeAmnt) * this.z + changeAmnt * finalVec.z;
return this;
}
/**
* Sets this vector to the interpolation by changeAmnt from beginVec to finalVec
* this=(1-changeAmnt)*beginVec + changeAmnt * finalVec
*
* @param beginVec the beginning vector (changeAmnt=0)
* @param finalVec The final vector to interpolate towards
* @param changeAmnt An amount between 0.0 - 1.0 representing a percentage
* change from beginVec towards finalVec
*/
public Vector3f interpolateLocal(Vector3f beginVec,Vector3f finalVec, float changeAmnt) {
this.x=(1-changeAmnt)*beginVec.x + changeAmnt*finalVec.x;
this.y=(1-changeAmnt)*beginVec.y + changeAmnt*finalVec.y;
this.z=(1-changeAmnt)*beginVec.z + changeAmnt*finalVec.z;
public Vector3f interpolateLocal(Vector3f beginVec, Vector3f finalVec, float changeAmnt) {
this.x = (1 - changeAmnt) * beginVec.x + changeAmnt * finalVec.x;
this.y = (1 - changeAmnt) * beginVec.y + changeAmnt * finalVec.y;
this.z = (1 - changeAmnt) * beginVec.z + changeAmnt * finalVec.z;
return this;
}
/**
* Check a vector... if it is null or its floats are NaN or infinite,
* return false. Else return true.
*
* @param vector the vector to check
* @return true or false as stated above.
*/
public static boolean isValidVector(Vector3f vector) {
if (vector == null) return false;
if (Float.isNaN(vector.x) ||
Float.isNaN(vector.y) ||
Float.isNaN(vector.z)) return false;
if (Float.isInfinite(vector.x) ||
Float.isInfinite(vector.y) ||
Float.isInfinite(vector.z)) return false;
if (vector == null) {
return false;
}
if (Float.isNaN(vector.x)
|| Float.isNaN(vector.y)
|| Float.isNaN(vector.z)) {
return false;
}
if (Float.isInfinite(vector.x)
|| Float.isInfinite(vector.y)
|| Float.isInfinite(vector.z)) {
return false;
}
return true;
}
@ -960,14 +954,24 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
*/
@Override
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;
if (Float.compare(x,comp.x) != 0) return false;
if (Float.compare(y,comp.y) != 0) return false;
if (Float.compare(z,comp.z) != 0) return false;
if (Float.compare(x, comp.x) != 0) {
return false;
}
if (Float.compare(y, comp.y) != 0) {
return false;
}
if (Float.compare(z, comp.z) != 0) {
return false;
}
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
* on its values. If two vectors are logically equivalent, they will return
* the same hash code value.
*
* @return the hash code value of this vector.
*/
@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");
}
}

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

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

@ -1269,7 +1269,7 @@ public final class BufferUtils {
* and cleans the direct buffers. However, as this doesn't happen
* immediately after discarding all references to a direct buffer, it's easy
* to OutOfMemoryError yourself using direct buffers.
**/
*/
public static void destroyDirectBuffer(Buffer toBeDestroyed) {
if (!isDirect(toBeDestroyed)) {
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.
*
* Redistribution and use in source and binary forms, with or without

Loading…
Cancel
Save