diff --git a/jme3-core/src/main/java/com/jme3/bounding/BoundingBox.java b/jme3-core/src/main/java/com/jme3/bounding/BoundingBox.java index 37722efb2..f9a2c0049 100644 --- a/jme3-core/src/main/java/com/jme3/bounding/BoundingBox.java +++ b/jme3-core/src/main/java/com/jme3/bounding/BoundingBox.java @@ -68,7 +68,7 @@ public class BoundingBox extends BoundingVolume { * the Z-extent of the box (>=0, may be +Infinity) */ float zExtent; - + /** * Instantiate a BoundingBox without initializing it. */ @@ -114,7 +114,7 @@ public class BoundingBox extends BoundingVolume { /** * computeFromPoints creates a new Bounding Box from a given * set of points. It uses the containAABB method as default. - * + * * @param points * the points to contain. */ @@ -126,7 +126,7 @@ public class BoundingBox extends BoundingVolume { /** * computeFromTris creates a new Bounding Box from a given * set of triangles. It is used in OBBTree calculations. - * + * * @param tris * @param start * @param end @@ -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++) { @@ -221,7 +223,7 @@ public class BoundingBox extends BoundingVolume { * containAABB creates a minimum-volume axis-aligned bounding * box of the points, then selects the smallest enclosing sphere of the box * with the sphere centered at the boxes center. - * + * * @param points * the list of points. */ @@ -237,12 +239,16 @@ public class BoundingBox extends BoundingVolume { } TempVars vars = TempVars.get(); - + 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--) { int bufLength = Math.min(tmpArray.length, points.remaining()); @@ -250,9 +256,9 @@ 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; } @@ -289,8 +295,8 @@ public class BoundingBox extends BoundingVolume { /** * transform modifies the center of the box to reflect the * change made via a rotation, translation and scale. - * - * @param trans + * + * @param trans * the transform to apply * @param store * box to store result in @@ -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); @@ -365,7 +372,7 @@ public class BoundingBox extends BoundingVolume { /** * whichSide takes a plane (typically provided by a view * frustum) to determine which side this bound is on. - * + * * @param plane * the plane to check against. */ @@ -432,15 +439,14 @@ public class BoundingBox extends BoundingVolume { // case OBB: { // return mergeOBB((OrientedBoundingBox) volume); // } - default: return null; } } - /** + /* * Merges this AABB with the given OBB. - * + * * @param volume * the OBB to merge this AABB with. * @return This AABB extended to fit the given OBB. @@ -481,6 +487,7 @@ public class BoundingBox extends BoundingVolume { // zExtent = max.z - center.z; // return this; // } + /** * mergeLocal combines this bounding box locally with a second * bounding box described by its center and extents. @@ -549,7 +556,7 @@ public class BoundingBox extends BoundingVolume { /** * clone creates a new BoundingBox object containing the same * data as this one. - * + * * @param store * where to store the cloned information. if null or wrong class, * a new store is created. @@ -589,8 +596,8 @@ public class BoundingBox extends BoundingVolume { /** * intersects determines if this Bounding Box intersects with another given * bounding volume. If so, true is returned, otherwise, false is returned. - * - * @see BoundingVolume#intersects(com.jme3.bounding.BoundingVolume) + * + * @see BoundingVolume#intersects(com.jme3.bounding.BoundingVolume) */ @Override public boolean intersects(BoundingVolume bv) { @@ -599,7 +606,7 @@ public class BoundingBox extends BoundingVolume { /** * determines if this bounding box intersects a given bounding sphere. - * + * * @see BoundingVolume#intersectsSphere(com.jme3.bounding.BoundingSphere) */ @Override @@ -611,7 +618,7 @@ public class BoundingBox extends BoundingVolume { * determines if this bounding box intersects a given bounding box. If the * two boxes intersect in any way, true is returned. Otherwise, false is * returned. - * + * * @see BoundingVolume#intersectsBoundingBox(com.jme3.bounding.BoundingBox) */ @Override @@ -632,10 +639,10 @@ public class BoundingBox extends BoundingVolume { } } - /** + /* * determines if this bounding box intersects with a given oriented bounding * box. - * + * * @see com.jme.bounding.BoundingVolume#intersectsOrientedBoundingBox(com.jme.bounding.OrientedBoundingBox) */ // public boolean intersectsOrientedBoundingBox(OrientedBoundingBox obb) { @@ -644,8 +651,8 @@ public class BoundingBox extends BoundingVolume { /** * determines if this bounding box intersects with a given ray object. If an * intersection has occurred, true is returned, otherwise false is returned. - * - * @see BoundingVolume#intersects(com.jme3.math.Ray) + * + * @see BoundingVolume#intersects(com.jme3.math.Ray) */ @Override public boolean intersects(Ray ray) { @@ -722,14 +729,14 @@ public class BoundingBox extends BoundingVolume { */ private int collideWithRay(Ray ray, CollisionResults results) { TempVars vars = TempVars.get(); - try { + try { Vector3f diff = vars.vect1.set(ray.origin).subtractLocal(center); Vector3f direction = vars.vect2.set(ray.direction); //float[] t = {0f, Float.POSITIVE_INFINITY}; float[] t = vars.fWdU; // use one of the tempvars arrays t[0] = 0; - t[1] = Float.POSITIVE_INFINITY; + t[1] = Float.POSITIVE_INFINITY; float saveT0 = t[0], saveT1 = t[1]; boolean notEntirelyClipped = clip(+direction.x, -diff.x - xExtent, t) @@ -744,14 +751,14 @@ public class BoundingBox extends BoundingVolume { float[] distances = t; Vector3f point0 = new Vector3f(ray.direction).multLocal(distances[0]).addLocal(ray.origin); Vector3f point1 = new Vector3f(ray.direction).multLocal(distances[1]).addLocal(ray.origin); - + CollisionResult result = new CollisionResult(point0, distances[0]); results.addCollision(result); result = new CollisionResult(point1, distances[1]); results.addCollision(result); return 2; } - + Vector3f point = new Vector3f(ray.direction).multLocal(t[0]).addLocal(ray.origin); CollisionResult result = new CollisionResult(point, t[0]); results.addCollision(result); @@ -765,14 +772,14 @@ public class BoundingBox extends BoundingVolume { private int collideWithRay(Ray ray) { TempVars vars = TempVars.get(); - try { + try { Vector3f diff = vars.vect1.set(ray.origin).subtractLocal(center); Vector3f direction = vars.vect2.set(ray.direction); //float[] t = {0f, Float.POSITIVE_INFINITY}; float[] t = vars.fWdU; // use one of the tempvars arrays t[0] = 0; - t[1] = Float.POSITIVE_INFINITY; + t[1] = Float.POSITIVE_INFINITY; float saveT0 = t[0], saveT1 = t[1]; boolean notEntirelyClipped = clip(+direction.x, -diff.x - xExtent, t) @@ -783,15 +790,18 @@ 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 { vars.release(); } } - + @Override public int collideWith(Collidable other, CollisionResults results) { if (other instanceof Ray) { @@ -818,7 +828,7 @@ public class BoundingBox extends BoundingVolume { throw new UnsupportedCollisionException("With: " + other.getClass().getSimpleName()); } } - + @Override public int collideWith(Collidable other) { if (other instanceof Ray) { @@ -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; @@ -906,7 +916,7 @@ public class BoundingBox extends BoundingVolume { sqrDistance += delta * delta; closest.z = zExtent; } - + vars.release(); return FastMath.sqrt(sqrDistance); } @@ -914,7 +924,7 @@ public class BoundingBox extends BoundingVolume { /** * clip determines if a line segment intersects the current * test plane. - * + * * @param denom * the denominator of the line segment. * @param numer @@ -936,26 +946,26 @@ public class BoundingBox extends BoundingVolume { // work out the same but in floating point there can // be subtle math errors. The multiply will exaggerate // errors that may have been introduced when the value - // was originally divided. + // was originally divided. // // This is especially true when the bounding box has zero // extents in some plane because the error rate is critical. // comparing a to b * c is not the same as comparing a/b to c - // in this case. In fact, I tried converting this method to - // double and the and the error was in the last decimal place. + // in this case. In fact, I tried converting this method to + // double and the and the error was in the last decimal place. // // So, instead, we now compare the divided version to the divided // version. We lose some slight performance here as divide // will be more expensive than the divide. Some microbenchmarks // show divide to be 3x slower than multiple on Java 1.6. - // BUT... we also saved a multiply in the non-clipped case because + // BUT... we also saved a multiply in the non-clipped case because // we can reuse the divided version in both if checks. // I think it's better to be right in this case. // // Bug that I'm fixing: rays going right through quads at certain // angles and distances because they fail the bounding box test. - // Many Bothans died bring you this fix. - // -pspeed + // Many Bothans died bring you this fix. + // -pspeed float newT = numer / denom; if (newT > t[1]) { return false; @@ -972,7 +982,7 @@ public class BoundingBox extends BoundingVolume { // When we move it over to the other side we have to flip // the comparison. Algebra for the win. float newT = numer / denom; - if (newT < t[0]) { + if (newT < t[0]) { return false; } if (newT < t[1]) { @@ -986,7 +996,7 @@ public class BoundingBox extends BoundingVolume { /** * Query extent. - * + * * @param store * where extent gets stored - null to return a new vector * @return store / new vector diff --git a/jme3-core/src/main/java/com/jme3/bounding/BoundingVolume.java b/jme3-core/src/main/java/com/jme3/bounding/BoundingVolume.java index 8ee6788ee..c5dc9b75b 100644 --- a/jme3-core/src/main/java/com/jme3/bounding/BoundingVolume.java +++ b/jme3-core/src/main/java/com/jme3/bounding/BoundingVolume.java @@ -44,12 +44,11 @@ import java.nio.FloatBuffer; /** * BoundingVolume defines an interface for dealing with * containment of a collection of points. - * + * * @author Mark Powell * @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. */ @@ -57,13 +56,11 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable { /** * {@link BoundingSphere} */ - Sphere, - + Sphere, /** * {@link BoundingBox}. */ - AABB, - + 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(); /** - * * transform 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 { } /** - * * transform 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); /** - * * whichSide 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); /** - * * computeFromPoints generates a bounding volume that * encompasses a collection of points. * @@ -204,7 +196,7 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable { /** * Find the distance from the center of this Bounding Volume to the given * point. - * + * * @param point * The point to get the distance to * @return distance @@ -216,7 +208,7 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable { /** * Find the squared distance from the center of this Bounding Volume to the * given point. - * + * * @param point * The point to get the distance to * @return distance @@ -228,7 +220,7 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable { /** * Find the distance from the nearest edge of this Bounding Volume to the given * point. - * + * * @param point * The point to get the distance to * @return distance @@ -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,11 +277,10 @@ 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. - * + * * @param point * the point to check * @return true if the point lies within this bounding volume. @@ -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(); } } @@ -326,7 +317,7 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable { public void read(JmeImporter e) throws IOException { center = (Vector3f) e.getCapsule(this).readSavable("center", Vector3f.ZERO.clone()); } - + public int collideWith(Collidable other) { TempVars tempVars = TempVars.get(); try { @@ -338,4 +329,3 @@ public abstract class BoundingVolume implements Savable, Cloneable, Collidable { } } } - diff --git a/jme3-core/src/main/java/com/jme3/math/CurveAndSurfaceMath.java b/jme3-core/src/main/java/com/jme3/math/CurveAndSurfaceMath.java index 522821e03..79374825f 100644 --- a/jme3-core/src/main/java/com/jme3/math/CurveAndSurfaceMath.java +++ b/jme3-core/src/main/java/com/jme3/math/CurveAndSurfaceMath.java @@ -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,130 +36,129 @@ 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; + private static final float KNOTS_MINIMUM_DELTA = 0.0001f; + + /** + * A private constructor is defined to avoid instantiation of this class. + */ + private CurveAndSurfaceMath() { + } - /** - * A private constructor is defined to avoid instantiation of this - * class. - */ - private CurveAndSurfaceMath() {} - - /** - * This method interpolates the data for the nurbs curve. - * @param u - * the u value - * @param nurbSpline - * the nurbs spline definition - * @param store - * the resulting point in 3D space - */ - public static void interpolateNurbs(float u, Spline nurbSpline, Vector3f store) { - if (nurbSpline.getType() != SplineType.Nurb) { - throw new IllegalArgumentException("Given spline is not of a NURB type!"); - } - List controlPoints = nurbSpline.getControlPoints(); - float[] weights = nurbSpline.getWeights(); - List knots = nurbSpline.getKnots(); - int controlPointAmount = controlPoints.size(); + /** + * This method interpolates the data for the nurbs curve. + * + * @param u the u value + * @param nurbSpline + * the nurbs spline definition + * @param store + * the resulting point in 3D space + */ + public static void interpolateNurbs(float u, Spline nurbSpline, Vector3f store) { + if (nurbSpline.getType() != SplineType.Nurb) { + throw new IllegalArgumentException("Given spline is not of a NURB type!"); + } + List controlPoints = nurbSpline.getControlPoints(); + float[] weights = nurbSpline.getWeights(); + List knots = nurbSpline.getKnots(); + int controlPointAmount = controlPoints.size(); + store.set(Vector3f.ZERO); + float delimeter = 0; + for (int i = 0; i < controlPointAmount; ++i) { + float val = weights[i] * CurveAndSurfaceMath.computeBaseFunctionValue(i, nurbSpline.getBasisFunctionDegree(), u, knots); + store.addLocal(nurbSpline.getControlPoints().get(i) + .mult(val)); + delimeter += val; + } + store.divideLocal(delimeter); + } - store.set(Vector3f.ZERO); - float delimeter = 0; - for (int i = 0; i < controlPointAmount; ++i) { - float val = weights[i] * CurveAndSurfaceMath.computeBaseFunctionValue(i, nurbSpline.getBasisFunctionDegree(), u, knots); - store.addLocal(nurbSpline.getControlPoints().get(i) - .mult(val)); - delimeter += val; - } - store.divideLocal(delimeter); - } + /** + * This method interpolates the data for the nurbs surface. + * + * @param u the u value + * @param v the v value + * @param controlPoints + * the nurbs' control points + * @param knots + * the nurbs' knots + * @param basisUFunctionDegree + * the degree of basis U function + * @param basisVFunctionDegree + * the degree of basis V function + * @param store + * the resulting point in 3D space + */ + public static void interpolate(float u, float v, List> controlPoints, List[] knots, + int basisUFunctionDegree, int basisVFunctionDegree, Vector3f store) { + store.set(Vector3f.ZERO); + float delimeter = 0; + int vControlPointsAmount = controlPoints.size(); + int uControlPointsAmount = controlPoints.get(0).size(); + for (int i = 0; i < vControlPointsAmount; ++i) { + for (int j = 0; j < uControlPointsAmount; ++j) { + Vector4f controlPoint = controlPoints.get(i).get(j); + float val = controlPoint.w + * CurveAndSurfaceMath.computeBaseFunctionValue(i, basisVFunctionDegree, v, knots[1]) + * CurveAndSurfaceMath.computeBaseFunctionValue(j, basisUFunctionDegree, u, knots[0]); + store.addLocal(controlPoint.x * val, controlPoint.y * val, controlPoint.z * val); + delimeter += val; + } + } + store.divideLocal(delimeter); + } - /** - * This method interpolates the data for the nurbs surface. - * - * @param u - * the u value - * @param v - * the v value - * @param controlPoints - * the nurbs' control points - * @param knots - * the nurbs' knots - * @param basisUFunctionDegree - * the degree of basis U function - * @param basisVFunctionDegree - * the degree of basis V function - * @param store - * the resulting point in 3D space - */ - public static void interpolate(float u, float v, List> controlPoints, List[] knots, - int basisUFunctionDegree, int basisVFunctionDegree, Vector3f store) { - store.set(Vector3f.ZERO); - float delimeter = 0; - int vControlPointsAmount = controlPoints.size(); - int uControlPointsAmount = controlPoints.get(0).size(); - for (int i = 0; i < vControlPointsAmount; ++i) { - for (int j = 0; j < uControlPointsAmount; ++j) { - Vector4f controlPoint = controlPoints.get(i).get(j); - float val = controlPoint.w - * CurveAndSurfaceMath.computeBaseFunctionValue(i, basisVFunctionDegree, v, knots[1]) - * CurveAndSurfaceMath.computeBaseFunctionValue(j, basisUFunctionDegree, u, knots[0]); - store.addLocal(controlPoint.x * val, controlPoint.y * val, controlPoint.z * val); - delimeter += val; - } - } - store.divideLocal(delimeter); - } + /** + * 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 + * the degree of basis function + */ + // TODO: improve this; constant delta may lead to errors if the difference between tha last repeated + // point and the following one is lower than it + public static void prepareNurbsKnots(List knots, int basisFunctionDegree) { + float delta = KNOTS_MINIMUM_DELTA; + float prevValue = knots.get(0).floatValue(); + for (int i = 1; i < knots.size(); ++i) { + float value = knots.get(i).floatValue(); + if (value <= prevValue) { + value += delta; + knots.set(i, Float.valueOf(value)); + delta += KNOTS_MINIMUM_DELTA; + } else { + delta = KNOTS_MINIMUM_DELTA;//reset the delta's value + } - /** - * 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 - * the degree of basis function - */ - // TODO: improve this; constant delta may lead to errors if the difference between tha last repeated - // point and the following one is lower than it - public static void prepareNurbsKnots(List knots, int basisFunctionDegree) { - float delta = KNOTS_MINIMUM_DELTA; - float prevValue = knots.get(0).floatValue(); - for(int i=1;i knots) { - 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); - } - } + /** + * 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 knots + * the knots' values + * @return the base function value + */ + private static float computeBaseFunctionValue(int i, int k, float t, List knots) { + 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); + } + } } diff --git a/jme3-core/src/main/java/com/jme3/math/FastMath.java b/jme3-core/src/main/java/com/jme3/math/FastMath.java index 6358a142a..65ae2249a 100644 --- a/jme3-core/src/main/java/com/jme3/math/FastMath.java +++ b/jme3-core/src/main/java/com/jme3/math/FastMath.java @@ -41,44 +41,67 @@ 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()); /** * Returns true if the number is a power of 2 (2,4,8,16...) - * + * * A good implementation found on the Java boards. note: a number is a power * of two if and only if it is the smallest number with that number of * significant bits. Therefore, if you subtract 1, you know that the new * number will have fewer bits, so ANDing the original number with anything * less than it will give 0. - * + * * @param number * The number to test. * @return True if it is a power of two. @@ -89,10 +112,10 @@ final public class FastMath { /** * Get the next power of two of the given number. - * + * * E.g. for an input 100, this returns 128. * Returns 1 for all numbers less than or equal to 1. - * + * * @param number The number to obtain the POT for. * @return The next power of two. */ @@ -111,7 +134,7 @@ final public class FastMath { /** * Linear interpolation from startValue to endValue by the given percent. * Basically: ((1 - percent) * startValue) + (percent * endValue) - * + * * @param scale * scale value to use. if 1, use endValue, if 0, use startValue. * @param startValue @@ -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) @@ -193,14 +218,16 @@ final public class FastMath { * Linear extrapolation from startValue to endValue by the given scale. * 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. + * 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 Catmull–Rom 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(); } @@ -282,7 +313,7 @@ final public class FastMath { /** * Interpolate a spline between at least 4 control points using the - * Catmull-Rom equation. Here is the interpolation matrix: + * Catmull-Rom equation. Here is the interpolation matrix: * m = [ 0.0 1.0 0.0 0.0 ] * [-T 0.0 T 0.0 ] * [ 2T T-3 3-2T -T ] @@ -297,7 +328,8 @@ final public class FastMath { * @param p3 control point 3 * @return Catmull–Rom 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 Catmull–Rom 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: *
  • If fValue is smaller than -1, then the result is PI. *
  • If the argument is greater than 1, then the result is 0.
+ * * @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: *
  • If fValue is smaller than -1, then the result is -HALF_PI. *
  • If the argument is greater than 1, then the result is HALF_PI.
+ * * @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.
+ * * @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) @@ -491,7 +533,8 @@ 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. * @return The fValue rounded up * @see java.lang.Math#ceil(double) @@ -502,9 +545,10 @@ final public class FastMath { /** * 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. - * @return the cosine of the angle. + * @return the cosine of the angle. */ public static float cos(float v) { return (float) Math.cos(v); @@ -512,7 +556,8 @@ final public class FastMath { /** * 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. * @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) @@ -583,8 +633,9 @@ 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) + * * @param value The value to log. * @param base Base of logarithm. * @return The logarithm of value with given base @@ -594,7 +645,8 @@ 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 fExponent The exponent value (IE 3) * @return base raised to exponent (IE 8) @@ -605,7 +657,8 @@ final public class FastMath { } /** - * Returns the value squared. fValue ^ 2 + * 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 @@ -753,9 +813,9 @@ final public class FastMath { /** * Returns a random float between 0 and 1. - * + * * @return A random float between 0.0f (inclusive) to - * 1.0f (exclusive). + * 1.0f (exclusive). */ public static float nextRandomFloat() { return rand.nextFloat(); @@ -763,9 +823,9 @@ final public class FastMath { /** * Returns a random integer between min and max. - * + * * @return A random int between min (inclusive) to - * max (inclusive). + * max (inclusive). */ public static int nextRandomInt(int min, int max) { return (int) (nextRandomFloat() * (max - min + 1)) + min; @@ -861,7 +921,7 @@ final public class FastMath { /** * Takes a value and expresses it in terms of min to max. - * + * * @param val - * the angle to normalize (in radians) * @return the normalized angle (also in radians) @@ -899,7 +959,7 @@ final public class FastMath { /** * Take a float input and clamp it between min and max. - * + * * @param input * @param min * @param max @@ -923,9 +983,9 @@ final public class FastMath { * Determine if two floats are approximately equal. * This takes into account the magnitude of the floats, since * large numbers will have larger differences be close to each other. - * + * * Should return true for a=100000, b=100001, but false for a=10000, b=10001. - * + * * @param a The first float to compare * @param b The second float to compare * @return True if a and b are approximately equal, false otherwise. @@ -937,7 +997,7 @@ final public class FastMath { return (abs(a - b) / Math.max(abs(a), abs(b))) <= 0.00001f; } } - + /** * Converts a single precision (32 bit) floating point value * into half precision (16 bit). @@ -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); } - } diff --git a/jme3-core/src/main/java/com/jme3/math/Matrix3f.java b/jme3-core/src/main/java/com/jme3/math/Matrix3f.java index 757ddbe0e..34ce7748a 100644 --- a/jme3-core/src/main/java/com/jme3/math/Matrix3f.java +++ b/jme3-core/src/main/java/com/jme3/math/Matrix3f.java @@ -43,7 +43,7 @@ import java.util.logging.Logger; * internally and is accessible via the get and set methods. Convenience methods * are used for matrix operations as well as generating a matrix from a given * set of values. - * + * * @author Mark Powell * @author Joshua Slack */ @@ -61,7 +61,6 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable /** * Constructor instantiates a new Matrix3f object. The * initial values for the matrix is that of the identity matrix. - * */ public Matrix3f() { loadIdentity(); @@ -69,25 +68,16 @@ 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) { @@ -106,7 +96,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable /** * Copy constructor that creates a new Matrix3f object that * is the same as the provided matrix. - * + * * @param mat * the matrix to copy. */ @@ -133,7 +123,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable * copy transfers the contents of a given matrix to this * matrix. If a null matrix is supplied, this matrix is set to the identity * matrix. - * + * * @param matrix * the matrix to copy. * @return this @@ -159,11 +149,9 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable * get retrieves a value from the matrix at the given * position. If the position is invalid a JmeException 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") @@ -261,11 +249,11 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable throw new IndexOutOfBoundsException("Array size must be 9 or 16 in Matrix3f.get()."); } } - + /** * Normalize this matrix and store the result in the store parameter that is * returned. - * + * * Note that the original matrix is not altered. * * @param store the matrix to store the result of the normalization. If this @@ -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() { @@ -312,7 +301,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable /** * getColumn returns one of three columns specified by the * parameter. This column is returned as a Vector3f object. - * + * * @param i * the column to retrieve. Must be between 0 and 2. * @return the column specified by the index. @@ -324,7 +313,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable /** * getColumn returns one of three columns specified by the * parameter. This column is returned as a Vector3f object. - * + * * @param i * the column to retrieve. Must be between 0 and 2. * @param store @@ -362,7 +351,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable /** * getColumn returns one of three rows as specified by the * parameter. This row is returned as a Vector3f object. - * + * * @param i * the row to retrieve. Must be between 0 and 2. * @return the row specified by the index. @@ -374,7 +363,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable /** * getRow returns one of three rows as specified by the * parameter. This row is returned as a Vector3f object. - * + * * @param i * the row to retrieve. Must be between 0 and 2. * @param store @@ -412,7 +401,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable /** * toFloatBuffer returns a FloatBuffer object that contains * the matrix data. - * + * * @return matrix data as a FloatBuffer. */ public FloatBuffer toFloatBuffer() { @@ -428,7 +417,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable /** * fillFloatBuffer fills a FloatBuffer object with the matrix * data. - * + * * @param fb * the buffer to fill, starting at current position. Must have * room for 9 more floats. @@ -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,33 +447,32 @@ 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; } } /** - * * setColumn sets a particular column of this matrix to that * represented by the provided vector. - * + * * @param i * the column to set. * @param column @@ -522,10 +509,9 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable } /** - * * setRow sets a particular row of this matrix to that * represented by the provided vector. - * + * * @param i * the row to set. * @param row @@ -565,7 +551,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable * set places a given value into the matrix at the given * position. If the position is invalid a JmeException is * thrown. - * + * * @param i * the row index. * @param j @@ -620,10 +606,9 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable } /** - * * set sets the values of the matrix to those supplied by the * 3x3 two dimenion array. - * + * * @param matrix * the new values of the matrix. * @throws JmeException @@ -651,13 +636,10 @@ 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; @@ -676,7 +658,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable /** * set sets the values of this matrix from an array of * values assuming that the data is rowMajor order; - * + * * @param matrix * the matrix to set the value to. * @return this @@ -688,7 +670,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable /** * set sets the values of this matrix from an array of * values; - * + * * @param matrix * the matrix to set the value to. * @param rowMajor @@ -726,11 +708,10 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable } /** - * * set defines the values of the matrix based on a supplied * Quaternion. It should be noted that all previous values * will be overridden. - * + * * @param quaternion * the quaternion to create a rotational matrix from. * @return this @@ -742,7 +723,6 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable /** * loadIdentity 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; @@ -762,7 +742,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable * fromAngleAxis sets this matrix4f to the values specified * by an angle and an axis of rotation. This method creates an object, so * use fromAngleNormalAxis if your axis is already normalized. - * + * * @param angle * the angle to rotate (in radians). * @param axis @@ -776,7 +756,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable /** * fromAngleNormalAxis sets this matrix4f to the values * specified by an angle and a normalized axis of rotation. - * + * * @param angle * the angle to rotate (in radians). * @param axis @@ -811,7 +791,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable * mult multiplies this matrix by a given matrix. The result * matrix is returned as a new object. If the given matrix is null, a null * matrix is returned. - * + * * @param mat * the matrix to multiply this matrix by. * @return the result matrix. @@ -823,7 +803,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable /** * mult multiplies this matrix by a given matrix. The result * matrix is returned as a new object. - * + * * @param mat * the matrix to multiply this matrix by. * @param product @@ -867,7 +847,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable * mult multiplies this matrix by a given * Vector3f object. The result vector is returned. If the * given vector is null, null will be returned. - * + * * @param vec * the vector to multiply this matrix by. * @return the result vector. @@ -879,7 +859,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable /** * Multiplies this 3x3 matrix by the 1x3 Vector vec and stores the result in * product. - * + * * @param vec * The Vector3f to multiply. * @param product @@ -904,9 +884,9 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable } /** - * multLocal multiplies this matrix internally by + * multLocal multiplies this matrix internally by * a given float scale factor. - * + * * @param scale * the value to scale by. * @return this Matrix3f @@ -929,7 +909,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable * Vector3f object. The result vector is stored inside the * passed vector, then returned . If the given vector is null, null will be * returned. - * + * * @param vec * the vector to multiply this matrix by. * @return The passed vector after multiplication @@ -951,7 +931,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable * matrix is saved in the current matrix. If the given matrix is null, * nothing happens. The current matrix is returned. This is equivalent to * this*=mat - * + * * @param mat * the matrix to multiply this matrix by. * @return This matrix, after the multiplication @@ -962,7 +942,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable /** * Transposes this matrix in place. Returns this matrix for chaining - * + * * @return This matrix after transpose */ public Matrix3f transposeLocal() { @@ -987,7 +967,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable /** * Inverts this matrix as a new Matrix3f. - * + * * @return The new inverse matrix */ public Matrix3f invert() { @@ -996,7 +976,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable /** * Inverts this matrix and stores it in the given store. - * + * * @return The store */ public Matrix3f invert(Matrix3f store) { @@ -1025,7 +1005,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable /** * Inverts this matrix locally. - * + * * @return this */ public Matrix3f invertLocal() { @@ -1060,7 +1040,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable /** * Returns a new matrix representing the adjoint of this matrix. - * + * * @return The adjoint matrix */ public Matrix3f adjoint() { @@ -1069,7 +1049,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable /** * Places the adjoint of this matrix in store (creates store if null.) - * + * * @param store * The matrix to store the result in. If null, a new matrix is created. * @return store @@ -1094,7 +1074,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable /** * determinant generates the determinant of this matrix. - * + * * @return the determinant */ public float determinant() { @@ -1107,7 +1087,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable /** * Sets all of the values in this matrix to zero. - * + * * @return this matrix */ public Matrix3f zero() { @@ -1120,7 +1100,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable * This is inconsistent with general value vs local semantics, but is * preserved for backwards compatibility. Use transposeNew() to transpose * to a new object (value). - * + * * @return this object for chaining. */ public Matrix3f transpose() { @@ -1144,7 +1124,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable * 1.0 0.0 0.0
* 0.0 1.0 0.0
* 0.0 0.0 1.0
]
- * + * * @return the string representation of this object. */ @Override @@ -1175,11 +1155,10 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable } /** - * * hashCode 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. - * + * * @return the hashcode for this instance of Matrix4f. * @see java.lang.Object#hashCode() */ @@ -1283,7 +1262,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable /** * A function for creating a rotation matrix that rotates a vector called * "start" into another vector called "end". - * + * * @param start * normalized non-zero starting vector * @param end diff --git a/jme3-core/src/main/java/com/jme3/math/Matrix4f.java b/jme3-core/src/main/java/com/jme3/math/Matrix4f.java index 6e7064f26..bc8318688 100644 --- a/jme3-core/src/main/java/com/jme3/math/Matrix4f.java +++ b/jme3-core/src/main/java/com/jme3/math/Matrix4f.java @@ -41,10 +41,10 @@ import java.util.logging.Logger; /** * Matrix4f defines and maintains a 4x4 matrix in row major order. - * This matrix is intended for use in a translation and rotational capacity. - * It provides convenience methods for creating the matrix from a multitude + * This matrix is intended for use in a translation and rotational capacity. + * It provides convenience methods for creating the matrix from a multitude * of sources. - * + * * Matrices are stored assuming column vectors on the right, with the translation * in the rightmost column. Element numbering is row,column, so m03 is the zeroth * row, third column, which is the "x" translation part. This means that the implicit @@ -69,7 +69,6 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable /** * Constructor instantiates a new Matrix that is set to the * identity matrix. - * */ public Matrix4f() { loadIdentity(); @@ -105,7 +104,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable * Create a new Matrix4f, given data in column-major format. * * @param array - * An array of 16 floats in column-major format (translation in elements 12, 13 and 14). + * An array of 16 floats in column-major format (translation in elements 12, 13 and 14). */ public Matrix4f(float[] array) { set(array, false); @@ -115,7 +114,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable * Constructor instantiates a new Matrix that is set to the * provided matrix. This constructor copies a given Matrix. If the provided * matrix is null, the constructor sets the matrix to the identity. - * + * * @param mat * the matrix to copy. */ @@ -127,7 +126,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable * copy transfers the contents of a given matrix to this * matrix. If a null matrix is supplied, this matrix is set to the identity * matrix. - * + * * @param matrix * the matrix to copy. */ @@ -188,7 +187,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable /** * get retrieves the values of this object into * a float array in row-major order. - * + * * @param matrix * the matrix to set the values into. */ @@ -199,7 +198,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable /** * set retrieves the values of this object into * a float array. - * + * * @param matrix * the matrix to set the values into. * @param rowMajor @@ -252,11 +251,9 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable * get retrieves a value from the matrix at the given * position. If the position is invalid a JmeException 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") @@ -315,9 +312,8 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable /** * getColumn 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) { @@ -327,9 +323,8 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable /** * getColumn 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 } /** - * * setColumn 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. */ @@ -422,11 +415,9 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable * set places a given value into the matrix at the given * position. If the position is invalid a JmeException 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). */ @@ -502,7 +493,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable /** * set sets the values of this matrix from an array of * values. - * + * * @param matrix * the matrix to set the value to. * @throws JmeException @@ -531,8 +522,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable m32 = matrix[3][2]; m33 = matrix[3][3]; } - - + /** * Sets the values of this matrix */ @@ -588,7 +578,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable /** * set sets the values of this matrix from an array of * values assuming that the data is rowMajor order; - * + * * @param matrix * the matrix to set the value to. */ @@ -599,7 +589,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable /** * set sets the values of this matrix from an array of * values; - * + * * @param matrix * the matrix to set the value to. * @param rowMajor @@ -657,7 +647,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable /** * transpose locally transposes this Matrix. - * + * * @return this object for chaining. */ public Matrix4f transposeLocal() { @@ -691,7 +681,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable /** * toFloatBuffer returns a FloatBuffer object that contains * the matrix data. - * + * * @return matrix data as a FloatBuffer. */ public FloatBuffer toFloatBuffer() { @@ -701,7 +691,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable /** * toFloatBuffer returns a FloatBuffer object that contains the * matrix data. - * + * * @param columnMajor * if true, this buffer should be filled with column major data, * otherwise it will be filled row major. @@ -718,6 +708,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable /** * fillFloatBuffer fills a FloatBuffer object with * the matrix data. + * * @param fb the buffer to fill, must be correct size * @return matrix data as a FloatBuffer. */ @@ -728,7 +719,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable /** * fillFloatBuffer fills a FloatBuffer object with the matrix * data. - * + * * @param fb * the buffer to fill, starting at current position. Must have * room for 16 more floats. @@ -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 /** * readFloatBuffer 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,9 +802,10 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable /** * readFloatBuffer 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. + * major data, otherwise it will be filled row major. * @return this data as a FloatBuffer. */ public Matrix4f readFloatBuffer(FloatBuffer fb, boolean columnMajor) { @@ -859,7 +851,6 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable /** * loadIdentity 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 @@ -893,7 +885,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable // A m02 = (right + left) / (right - left); - // B + // B m12 = (top + bottom) / (top - bottom); // C @@ -908,7 +900,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable * fromAngleAxis sets this matrix4f to the values specified * by an angle and an axis of rotation. This method creates an object, so * use fromAngleNormalAxis if your axis is already normalized. - * + * * @param angle * the angle to rotate (in radians). * @param axis @@ -922,7 +914,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable /** * fromAngleNormalAxis sets this matrix4f to the values * specified by an angle and a normalized axis of rotation. - * + * * @param angle * the angle to rotate (in radians). * @param axis @@ -958,7 +950,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable /** * mult multiplies this matrix by a scalar. - * + * * @param scalar * the scalar to multiply this matrix by. */ @@ -998,7 +990,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable * mult multiplies this matrix with another matrix. The * result matrix will then be returned. This matrix will be on the left hand * side, while the parameter matrix will be on the right. - * + * * @param in2 * the matrix to multiply this matrix by. * @return the resultant matrix @@ -1011,7 +1003,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable * mult multiplies this matrix with another matrix. The * result matrix will then be returned. This matrix will be on the left hand * side, while the parameter matrix will be on the right. - * + * * @param in2 * the matrix to multiply this matrix by. * @param store @@ -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]; @@ -1118,10 +1109,10 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable /** * mult multiplies this matrix with another matrix. The - * results are stored internally and a handle to this matrix will + * results are stored internally and a handle to this matrix will * then be returned. This matrix will be on the left hand * side, while the parameter matrix will be on the right. - * + * * @param in2 * the matrix to multiply this matrix by. * @return the resultant matrix @@ -1133,7 +1124,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable /** * mult multiplies a vector about a rotation matrix. The * resulting vector is returned as a new Vector3f. - * + * * @param vec * vec to multiply against. * @return the rotated vector. @@ -1145,7 +1136,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable /** * mult multiplies a vector about a rotation matrix and adds * translation. The resulting vector is returned. - * + * * @param vec * vec to multiply against. * @param store @@ -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) { @@ -1296,11 +1286,11 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable * mult multiplies a vector about a rotation matrix and adds * translation. The w value is returned as a result of * multiplying the last column of the matrix by 1.0 - * + * * @param vec * vec to multiply against. * @param store - * a vector to store the result in. + * a vector to store the result in. * @return the W value */ public float multProj(Vector3f vec, Vector3f store) { @@ -1314,7 +1304,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable /** * mult multiplies a vector about a rotation matrix. The * resulting vector is returned. - * + * * @param vec * vec to multiply against. * @param store @@ -1371,9 +1361,9 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable } /** - * mult multiplies an array of 4 floats against this rotation + * mult multiplies an array of 4 floats against this rotation * matrix. The results are stored directly in the array. (vec4f x mat4f) - * + * * @param vec4f * float array (size 4) to multiply against the matrix. * @return the vec4f for chaining. @@ -1395,9 +1385,9 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable } /** - * mult multiplies an array of 4 floats against this rotation + * mult multiplies an array of 4 floats against this rotation * matrix. The results are stored directly in the array. (vec4f x mat4f) - * + * * @param vec4f * float array (size 4) to multiply against the matrix. * @return the vec4f for chaining. @@ -1420,7 +1410,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable /** * Inverts this matrix as a new Matrix4f. - * + * * @return The new inverse matrix */ public Matrix4f invert() { @@ -1429,7 +1419,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable /** * Inverts this matrix and stores it in the given store. - * + * * @return The store */ public Matrix4f invert(Matrix4f store) { @@ -1480,7 +1470,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable /** * Inverts this matrix locally. - * + * * @return this */ public Matrix4f invertLocal() { @@ -1545,7 +1535,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable /** * Returns a new matrix representing the adjoint of this matrix. - * + * * @return The adjoint matrix */ public Matrix4f adjoint() { @@ -1581,7 +1571,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable /** * Places the adjoint of this matrix in store (creates store if null.) - * + * * @param store * The matrix to store the result in. If null, a new matrix is created. * @return store @@ -1626,7 +1616,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable /** * determinant generates the determinate of this matrix. - * + * * @return the determinate */ public float determinant() { @@ -1648,7 +1638,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable /** * Sets all of the values in this matrix to zero. - * + * * @return this matrix */ public Matrix4f zero() { @@ -1682,7 +1672,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable /** * add adds the values of a parameter matrix to this matrix. - * + * * @param mat * the matrix to add to this. */ @@ -1738,18 +1728,18 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable mat.m20 = m20; mat.m21 = m21; mat.m22 = m22; - } + } - /** - * Retrieves the scale vector from the matrix. - * - * @return the scale vector - */ - public Vector3f toScaleVector() { - Vector3f result = new Vector3f(); - this.toScaleVector(result); - return result; - } + /** + * Retrieves the scale vector from the matrix. + * + * @return the scale vector + */ + public Vector3f toScaleVector() { + Vector3f result = new Vector3f(); + this.toScaleVector(result); + return result; + } /** * Retrieves the scale vector from the matrix and stores it into a given @@ -1759,16 +1749,16 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable * @return the store vector */ public Vector3f toScaleVector(Vector3f store) { - float scaleX = (float) Math.sqrt(m00 * m00 + m10 * m10 + m20 * m20); - float scaleY = (float) Math.sqrt(m01 * m01 + m11 * m11 + m21 * m21); - float scaleZ = (float) Math.sqrt(m02 * m02 + m12 * m12 + m22 * m22); + float scaleX = (float) Math.sqrt(m00 * m00 + m10 * m10 + m20 * m20); + float scaleY = (float) Math.sqrt(m01 * m01 + m11 * m11 + m21 * m21); + float scaleZ = (float) Math.sqrt(m02 * m02 + m12 * m12 + m22 * m22); store.set(scaleX, scaleY, scaleZ); return store; } /** * Sets the scale. - * + * * @param x * the X scale * @param y @@ -1805,7 +1795,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable /** * Sets the scale. - * + * * @param scale * the scale vector to set */ @@ -1815,7 +1805,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable /** * setTranslation will set the matrix's translation values. - * + * * @param translation * the new values for the translation. * @throws JmeException @@ -1833,13 +1823,10 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable /** * setTranslation 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; @@ -1862,7 +1849,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable /** * setInverseTranslation will set the matrix's inverse * translation values. - * + * * @param translation * the new values for the inverse translation. * @throws JmeException @@ -1883,7 +1870,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable * three axes (x, y, z). Where each axis has a specified rotation in * degrees. These rotations are expressed in a single Vector3f * object. - * + * * @param angles * the angles to rotate. */ @@ -1919,7 +1906,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable /** * setRotationQuaternion builds a rotation from a * Quaternion. - * + * * @param quat * the quaternion to build the rotation from. * @throws NullPointerException @@ -1932,7 +1919,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable /** * setInverseRotationRadians builds an inverted rotation from * Euler angles that are in radians. - * + * * @param angles * the Euler angles in radians. * @throws JmeException @@ -1969,7 +1956,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable /** * setInverseRotationDegrees builds an inverted rotation from * Euler angles that are in degrees. - * + * * @param angles * the Euler angles in degrees. * @throws JmeException @@ -1988,10 +1975,9 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable } /** - * * inverseTranslateVect translates a given Vector3f by the * translation part of this matrix. - * + * * @param vec * the Vector3f data to be translated. * @throws JmeException @@ -2009,10 +1995,9 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable } /** - * * inverseTranslateVect translates a given Vector3f by the * translation part of this matrix. - * + * * @param data * the Vector3f to be translated. * @throws JmeException @@ -2025,10 +2010,9 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable } /** - * * inverseTranslateVect translates a given Vector3f by the * translation part of this matrix. - * + * * @param data * the Vector3f to be translated. * @throws JmeException @@ -2041,10 +2025,9 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable } /** - * * inverseRotateVect rotates a given Vector3f by the rotation * part of this matrix. - * + * * @param vec * the Vector3f to be rotated. */ @@ -2072,7 +2055,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable * 0.0 1.0 0.0 0.0
* 0.0 0.0 1.0 0.0
* 0.0 0.0 0.0 1.0
]
- * + * * @return the string representation of this object. */ @Override @@ -2118,11 +2101,10 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable } /** - * * hashCode 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. - * + * * @return the hashcode for this instance of Matrix4f. * @see java.lang.Object#hashCode() */ @@ -2279,7 +2261,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable /** * Apply a scale to this matrix. - * + * * @param scale * the scale to apply */ diff --git a/jme3-core/src/main/java/com/jme3/math/Plane.java b/jme3-core/src/main/java/com/jme3/math/Plane.java index 078f8a335..0b6e562a1 100644 --- a/jme3-core/src/main/java/com/jme3/math/Plane.java +++ b/jme3-core/src/main/java/com/jme3/math/Plane.java @@ -40,7 +40,7 @@ import java.util.logging.Logger; * This provides methods for calculating a "distance" of a point from this * plane. The distance is pseudo due to the fact that it can be negative if the * point is on the non-normal side of the plane. - * + * * @author Mark Powell * @author Joshua Slack * @author Ian McClean @@ -58,12 +58,12 @@ public class Plane implements Savable, Cloneable, java.io.Serializable { Negative } - /** + /** * Vector normal to the plane. */ protected Vector3f normal = new Vector3f(); - /** + /** * Constant of the plane. See formula in class definition. */ protected float constant; @@ -78,7 +78,7 @@ public class Plane implements Savable, Cloneable, java.io.Serializable { /** * Constructor instantiates a new Plane object. The normal * and constant values are set at creation. - * + * * @param normal * the normal of the plane. * @param constant @@ -105,7 +105,7 @@ public class Plane implements Savable, Cloneable, java.io.Serializable { /** * setNormal sets the normal of the plane. - * + * * @param normal * the new normal of the plane. */ @@ -121,12 +121,12 @@ 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); } /** * getNormal retrieves the normal of the plane. - * + * * @return the normal of the plane. */ public Vector3f getNormal() { @@ -136,7 +136,7 @@ public class Plane implements Savable, Cloneable, java.io.Serializable { /** * setConstant sets the constant value that helps define the * plane. - * + * * @param constant * the new constant value. */ @@ -146,27 +146,28 @@ public class Plane implements Savable, Cloneable, java.io.Serializable { /** * getConstant returns the constant of the plane. - * + * * @return the constant of the plane. */ public float getConstant() { 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); @@ -179,7 +180,7 @@ public class Plane implements Savable, Cloneable, java.io.Serializable { * a provided point. If the point is on the negative side of the plane the * distance returned is negative, otherwise it is positive. If the point is * on the plane, it is zero. - * + * * @param point * the point to check. * @return the signed distance from the plane to a point. @@ -192,7 +193,7 @@ public class Plane implements Savable, Cloneable, java.io.Serializable { * whichSide returns the side at which a point lies on the * plane. The positive values returned are: NEGATIVE_SIDE, POSITIVE_SIDE and * NO_SIDE. - * + * * @param point * the point to check. * @return the side at which the point lies. @@ -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,14 +233,14 @@ 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; } /** * Initialize the Plane using the given 3 points as coplanar. - * + * * @param v1 * the first point * @param v2 @@ -260,7 +261,7 @@ public class Plane implements Savable, Cloneable, java.io.Serializable { * Vector3f object, so the format is the following: * com.jme.math.Plane [Normal: org.jme.math.Vector3f [X=XX.XXXX, Y=YY.YYYY, * Z=ZZ.ZZZZ] - Constant: CC.CCCCC] - * + * * @return the string representation of this plane. */ @Override diff --git a/jme3-core/src/main/java/com/jme3/math/Quaternion.java b/jme3-core/src/main/java/com/jme3/math/Quaternion.java index 84671660d..8093f20d0 100644 --- a/jme3-core/src/main/java/com/jme3/math/Quaternion.java +++ b/jme3-core/src/main/java/com/jme3/math/Quaternion.java @@ -42,10 +42,9 @@ import java.util.logging.Logger; * hypercomplex numbers. Quaternions extends a rotation in three dimensions to a * rotation in four dimensions. This avoids "gimbal lock" and allows for smooth * continuous rotation. - * - * Quaternion is defined by four floating point numbers: {x y z - * w}. - * + * + * Quaternion is defined by four floating point numbers: {x y z w}. + * * @author Mark Powell * @author Joshua Slack */ @@ -60,7 +59,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl public static final Quaternion IDENTITY = new Quaternion(); public static final Quaternion DIRECTION_Z = new Quaternion(); public static final Quaternion ZERO = new Quaternion(0, 0, 0, 0); - + static { DIRECTION_Z.fromAxes(Vector3f.UNIT_X, Vector3f.UNIT_Y, Vector3f.UNIT_Z); } @@ -82,14 +81,10 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl * Constructor instantiates a new Quaternion 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 Quaternion object from the given list - * of parameters. + * sets the data in a Quaternion 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. * @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 Quaternion 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 Quaternion 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; @@ -195,7 +184,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl } /** - * Sets this Quaternion to {0, 0, 0, 1}. Same as calling set(0,0,0,1). + * Sets this Quaternion to {0, 0, 0, 1}. Same as calling set(0,0,0,1). */ public void loadIdentity() { x = y = z = 0; @@ -231,10 +220,12 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl /** * fromAngles 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 http://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToQuaternion/index.htm - * + * * @param xAngle * the Euler pitch of rotation (in radians). (aka Attitude, often rot * around x) @@ -275,10 +266,10 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl /** * toAngles returns this quaternion converted to Euler rotation - * angles (x,y,z) aka (pitch, yaw, roll).
+ * angles (x,y,z) aka (pitch, yaw, roll).
* Note that the result is not always 100% accurate due to the implications of euler angles. * @see http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/index.htm - * + * * @param angles * the float[] in which the angles should be stored, or null if * you want a new float[] to be created @@ -307,7 +298,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl angles[2] = -FastMath.HALF_PI; angles[0] = 0; } else { - angles[1] = FastMath.atan2(2 * y * w - 2 * x * z, sqx - sqy - sqz + sqw); // yaw or heading + angles[1] = FastMath.atan2(2 * y * w - 2 * x * z, sqx - sqy - sqz + sqw); // yaw or heading angles[2] = FastMath.asin(2 * test / unit); // roll or bank angles[0] = FastMath.atan2(2 * x * w - 2 * y * z, -sqx + sqy - sqz + sqw); // pitch or attitude } @@ -315,10 +306,9 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl } /** - * * fromRotationMatrix generates a quaternion from a supplied * matrix. This matrix is assumed to be a rotational matrix. - * + * * @param matrix * the matrix that defines the rotation. */ @@ -353,7 +343,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl m22 *= lengthSquared; } - // Use the Graphics Gems code, from + // Use the Graphics Gems code, from // ftp://ftp.cis.upenn.edu/pub/graphics/shoemake/quatut.ps.Z // *NOT* the "Matrix and Quaternions FAQ", which has errors! @@ -398,7 +388,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl /** * toRotationMatrix converts this quaternion to a rotational * matrix. Note: the result is created from a normalized version of this quat. - * + * * @return the rotation matrix representation of this quaternion. */ public Matrix3f toRotationMatrix() { @@ -409,7 +399,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl /** * toRotationMatrix converts this quaternion to a rotational * matrix. The result is stored in result. - * + * * @param result * The Matrix3f to store the result in. * @return the rotation matrix representation of this quaternion. @@ -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 * add 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 * add 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 * subtract 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 * mult 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 * mult 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. */ @@ -1076,7 +1054,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl /** * mult 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 store @@ -1279,7 +1257,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl } return true; } - + /** * Returns true if this quaternion is similar to the specified quaternion * within some value of epsilon. @@ -1304,11 +1282,10 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl } /** - * * hashCode 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. - * + * * @return the hashcode for this instance of Quaternion. * @see java.lang.Object#hashCode() */ @@ -1327,7 +1304,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl * readExternal builds a quaternion from an * ObjectInput object.
* NOTE: Used with serialization. Not to be called manually. - * + * * @param in * the ObjectInput value to read from. * @throws IOException @@ -1345,7 +1322,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl * writeExternal writes this quaternion out to a * ObjectOutput object. NOTE: Used with serialization. Not to * be called manually. - * + * * @param out * the object to write to. * @throws IOException diff --git a/jme3-core/src/main/java/com/jme3/math/Spline.java b/jme3-core/src/main/java/com/jme3/math/Spline.java index 33c2f2a34..103ce24d9 100644 --- a/jme3-core/src/main/java/com/jme3/math/Spline.java +++ b/jme3-core/src/main/java/com/jme3/math/Spline.java @@ -49,11 +49,11 @@ public class Spline implements Savable { Bezier, Nurb } - + private List controlPoints = new ArrayList(); - private List knots; //knots of NURBS spline - private float[] weights; //weights of NURBS spline - private int basisFunctionDegree; //degree of NURBS spline basis function (computed automatically) + private List knots; //knots of NURBS spline + private float[] weights; //weights of NURBS spline + private int basisFunctionDegree; //degree of NURBS spline basis function (computed automatically) private boolean cycle; private List segmentsLength; private float totalLength; @@ -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 @@ -74,15 +75,15 @@ public class Spline implements Savable { * for the border points of the curve, who should have only one handle point. * The pattern should be as follows: * P0 - H0 : H1 - P1 - H1 : ... : Hn - Pn - * + * * n is the amount of 'P' - points. * @param curveTension the tension of the spline * @param cycle true if the spline cycle. */ public Spline(SplineType splineType, Vector3f[] controlPoints, float curveTension, boolean cycle) { - if(splineType==SplineType.Nurb) { - throw new IllegalArgumentException("To create NURBS spline use: 'public Spline(Vector3f[] controlPoints, float[] weights, float[] nurbKnots)' constructor!"); - } + 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++) { Vector3f vector3f = controlPoints[i]; this.controlPoints.add(vector3f); @@ -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 @@ -103,45 +105,46 @@ public class Spline implements Savable { * for the border points of the curve, who should have only one handle point. * The pattern should be as follows: * P0 - H0 : H1 - P1 - H1 : ... : Hn - Pn - * + * * n is the amount of 'P' - points. * @param curveTension the tension of the spline * @param cycle true if the spline cycle. */ public Spline(SplineType splineType, List controlPoints, float curveTension, boolean cycle) { - if(splineType==SplineType.Nurb) { - throw new IllegalArgumentException("To create NURBS spline use: 'public Spline(Vector3f[] controlPoints, float[] weights, float[] nurbKnots)' constructor!"); - } + if (splineType == SplineType.Nurb) { + throw new IllegalArgumentException("To create NURBS spline use: 'public Spline(Vector3f[] controlPoints, float[] weights, float[] nurbKnots)' constructor!"); + } type = splineType; this.controlPoints.addAll(controlPoints); this.curveTension = curveTension; this.cycle = cycle; this.computeTotalLength(); } - + /** * Create a NURBS spline. A spline type is automatically set to SplineType.Nurb. * The cycle is set to false by default. + * * @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 controlPoints, List nurbKnots) { - //input data control - for(int i=0;inurbKnots.get(i+1)) { - throw new IllegalArgumentException("The knots values cannot decrease!"); - } - } - - //storing the data + //input data control + 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!"); + } + } + + //storing the data type = SplineType.Nurb; this.weights = new float[controlPoints.size()]; this.knots = nurbKnots; this.basisFunctionDegree = nurbKnots.size() - weights.length; - for(int i=0;i 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)); + controlPoints.get(i + 1), controlPoints.get(i + 2), controlPoints.get(i + 3)); segmentsLength.add(l); totalLength += l; } } } - + /** * This method calculates the NURB curve length. */ private void computeNurbLength() { - //TODO: implement + //TODO: implement } /** * 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) { @@ -291,11 +299,11 @@ public class Spline implements Savable { FastMath.interpolateLinear(value, controlPoints.get(currentControlPoint), controlPoints.get(currentControlPoint + 1), store); break; case Bezier: - FastMath.interpolateBezier(value, controlPoints.get(currentControlPoint), controlPoints.get(currentControlPoint + 1), controlPoints.get(currentControlPoint + 2), controlPoints.get(currentControlPoint + 3), store); - break; + FastMath.interpolateBezier(value, controlPoints.get(currentControlPoint), controlPoints.get(currentControlPoint + 1), controlPoints.get(currentControlPoint + 2), controlPoints.get(currentControlPoint + 3), store); + break; case Nurb: - CurveAndSurfaceMath.interpolateNurbs(value, this, store); - break; + CurveAndSurfaceMath.interpolateNurbs(value, this, store); + break; default: break; } @@ -316,8 +324,8 @@ public class Spline implements Savable { */ public void setCurveTension(float curveTension) { this.curveTension = curveTension; - if(type==SplineType.CatmullRom && !getControlPoints().isEmpty()) { - this.computeTotalLength(); + if (type == SplineType.CatmullRom && !getControlPoints().isEmpty()) { + this.computeTotalLength(); } } @@ -330,23 +338,24 @@ 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 (controlPoints.size() >= 2) { - if (this.cycle && !cycle) { - controlPoints.remove(controlPoints.size() - 1); - } - if (!this.cycle && cycle) { - controlPoints.add(controlPoints.get(0)); - } - this.cycle = cycle; - this.computeTotalLength(); - } else { - this.cycle = cycle; - } - } + if (type != SplineType.Nurb) { + if (controlPoints.size() >= 2) { + if (this.cycle && !cycle) { + controlPoints.remove(controlPoints.size() - 1); + } + if (!this.cycle && cycle) { + controlPoints.add(controlPoints.get(0)); + } + this.cycle = cycle; + this.computeTotalLength(); + } else { + this.cycle = cycle; + } + } } /** @@ -365,6 +374,7 @@ public class Spline implements Savable { /** * Sets the type of the spline + * * @param type */ public void setType(SplineType type) { @@ -385,57 +395,63 @@ public class Spline implements Savable { public List getSegmentsLength() { return segmentsLength; } - + //////////// 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. - * @return the minimum nurb curve knot value - */ + /** + * 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() { - return knots.get(basisFunctionDegree - 1); + return knots.get(basisFunctionDegree - 1); } - + /** - * 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 - */ + * 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() { - return knots.get(weights.length); + return knots.get(weights.length); } - + /** * This method returns NURBS' spline knots. + * * @return NURBS' spline knots */ public List getKnots() { - return knots; - } - + return knots; + } + /** * This method returns NURBS' spline weights. + * * @return NURBS' spline weights */ public float[] getWeights() { - return weights; - } - + return weights; + } + /** * This method returns NURBS' spline basis function degree. + * * @return NURBS' spline basis function degree */ public int getBasisFunctionDegree() { - return basisFunctionDegree; - } + return basisFunctionDegree; + } @Override public void write(JmeExporter ex) throws IOException { OutputCapsule oc = ex.getCapsule(this); oc.writeSavableArrayList((ArrayList) controlPoints, "controlPoints", null); oc.write(type, "type", SplineType.CatmullRom); - + float list[] = null; if (segmentsLength != null) { list = new float[segmentsLength.size()]; @@ -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)knots, "knots", null); + oc.writeSavableArrayList((ArrayList) 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(); diff --git a/jme3-core/src/main/java/com/jme3/math/Transform.java b/jme3-core/src/main/java/com/jme3/math/Transform.java index d9ac33ef0..47e6c17de 100644 --- a/jme3-core/src/main/java/com/jme3/math/Transform.java +++ b/jme3-core/src/main/java/com/jme3/math/Transform.java @@ -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 @@ -39,7 +39,7 @@ import java.io.IOException; /** * Started Date: Jul 16, 2004

* Represents a translation, rotation and scale in one object. - * + * * @author Jack Lindamood * @author Joshua Slack */ @@ -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,64 +138,82 @@ 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() { return rot; - } - + } + /** - * 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,56 +226,58 @@ 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 - .multLocal(translation) - .addLocal(parent.translation); + parent.rot + .multLocal(translation) + .addLocal(parent.translation); return this; } /** * 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); @@ -272,7 +298,7 @@ public final class Transform implements Savable, Cloneable, java.io.Serializable store.setScale(scale); return store; } - + public void fromTransformMatrix(Matrix4f mat) { TempVars vars = TempVars.get(); translation.set(mat.toTranslationVector(vars.vect1)); @@ -280,13 +306,13 @@ public final class Transform implements Savable, Cloneable, java.io.Serializable scale.set(mat.toScaleVector(vars.vect2)); vars.release(); } - + public Transform invert() { Transform t = new Transform(); t.fromTransformMatrix(toTransformMatrix().invertLocal()); return t; } - + /** * Loads the identity. Equal to translation=0,0,0 scale=1,1,1 rot=0,0,0,1. */ @@ -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" - + "[ " + rot.x + ", " + rot.y + ", " + rot.z + ", " + rot.w + "]\n" - + "[ " + scale.x + " , " + scale.y + ", " + scale.z + "]"; + 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 */ @@ -360,12 +388,12 @@ public final class Transform implements Savable, Cloneable, java.io.Serializable @Override 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 public Transform clone() { try { diff --git a/jme3-core/src/main/java/com/jme3/math/Vector3f.java b/jme3-core/src/main/java/com/jme3/math/Vector3f.java index bb009b9c3..75a03f302 100644 --- a/jme3-core/src/main/java/com/jme3/math/Vector3f.java +++ b/jme3-core/src/main/java/com/jme3/math/Vector3f.java @@ -29,7 +29,6 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - package com.jme3.math; import com.jme3.export.*; @@ -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 } /** - * * add 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 } /** - * * add 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 } /** - * * add 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 } /** - * * scaleAdd 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 } /** - * * scaleAdd 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 } /** - * * dot 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,8 +330,10 @@ 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(); - float resX = ((y * otherZ) - (z * otherY)); + if (result == null) { + result = new Vector3f(); + } + float resX = ((y * otherZ) - (z * otherY)); float resY = ((z * otherX) - (x * otherZ)); float resZ = ((x * otherY) - (y * otherX)); result.set(resX, resY, resZ); @@ -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,20 +392,20 @@ 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); } - + /** * Returns true if this vector is a unit vector (length() ~= 1), * returns false otherwise. - * + * * @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 } /** - * * mult 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 } /** - * * mult 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); } - /** * divide 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 Vector. */ 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; } - /** * divide 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 } /** - * * negate 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 } /** - * * negateLocal negates the internal values of this vector. * * @return this. @@ -670,7 +656,6 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable } /** - * * subtract 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 } /** - * * subtract * * @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 } /** - * * subtract 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; @@ -801,12 +784,13 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable } /** - * maxLocal computes the maximum value for each + * maxLocal computes the maximum value for each * component in this and other vector. The result is stored * in this vector. - * @param other + * + * @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 * minLocal computes the minimum value for each * component in this and other 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; @@ -837,7 +822,7 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable /** * angleBetween returns (in radians) the angle between two vectors. * It is assumed that both this vector and the given vector are unit vectors (iow, normalized). - * + * * @param otherVector a unit vector to find the angle against * @return the angle in radians. */ @@ -846,51 +831,60 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable float angle = FastMath.acos(dotProduct); return angle; } - + /** * 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; - return true; + 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; } public static void generateOrthonormalBasis(Vector3f u, Vector3f v, Vector3f w) { @@ -934,7 +928,7 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable /** * Saves this Vector3f into the given float[] object. - * + * * @param floats * The float[] to take this Vector3f. If null, a new float[3] is * created. @@ -960,17 +954,27 @@ 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; } - + /** * Returns true if this vector is similar to the specified vector within * some value of epsilon. @@ -995,6 +999,7 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable * hashCode 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 @@ -1061,7 +1066,7 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable this.z = z; return this; } - + /** * @param index * @return x value if index == 0, y value if index == 1 or z value if index == @@ -1080,7 +1085,7 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable } throw new IllegalArgumentException("index must be either 0, 1 or 2"); } - + /** * @param index * which field index in this vector to set. @@ -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"); } - } diff --git a/jme3-core/src/main/java/com/jme3/scene/mesh/VirtualIndexBuffer.java b/jme3-core/src/main/java/com/jme3/scene/mesh/VirtualIndexBuffer.java index dd57abee4..163cf6127 100644 --- a/jme3-core/src/main/java/com/jme3/scene/mesh/VirtualIndexBuffer.java +++ b/jme3-core/src/main/java/com/jme3/scene/mesh/VirtualIndexBuffer.java @@ -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 @@ -49,7 +49,7 @@ import java.nio.Buffer; *
  • {@link Mode#TriangleStrip}: 0, 1, 2 | 2, 1, 3 | 2, 3, 4 | ...
  • *
  • {@link Mode#TriangleFan}: 0, 1, 2 | 0, 2, 3 | 0, 3, 4 | ...
  • * - * + * * @author Kirill Vainer */ public class VirtualIndexBuffer extends IndexBuffer { @@ -58,8 +58,8 @@ public class VirtualIndexBuffer extends IndexBuffer { protected int numIndices = 0; 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(); } } @@ -154,15 +159,15 @@ public class VirtualIndexBuffer extends IndexBuffer { return null; } - @Override - public IndexBuffer put (int value) { - throw new UnsupportedOperationException("Does not represent index buffer"); - } + @Override + public IndexBuffer put(int value) { + throw new UnsupportedOperationException("Does not represent index buffer"); + } - @Override - public Format getFormat () { - // return largest size - return Format.UnsignedInt; - } + @Override + public Format getFormat() { + // return largest size + return Format.UnsignedInt; + } } diff --git a/jme3-core/src/main/java/com/jme3/scene/shape/Curve.java b/jme3-core/src/main/java/com/jme3/scene/shape/Curve.java index 063bbab11..a58766ede 100644 --- a/jme3-core/src/main/java/com/jme3/scene/shape/Curve.java +++ b/jme3-core/src/main/java/com/jme3/scene/shape/Curve.java @@ -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,12 +198,12 @@ public class Curve extends Mesh { * points */ private void createNurbMesh(int nbSubSegments) { - if(spline.getControlPoints() != null && spline.getControlPoints().size() > 0) { - if(nbSubSegments == 0) { - nbSubSegments = spline.getControlPoints().size() + 1; - } else { - nbSubSegments = spline.getControlPoints().size() * nbSubSegments + 1; - } + if (spline.getControlPoints() != null && spline.getControlPoints().size() > 0) { + if (nbSubSegments == 0) { + nbSubSegments = spline.getControlPoints().size() + 1; + } else { + nbSubSegments = spline.getControlPoints().size() * nbSubSegments + 1; + } float minKnot = spline.getMinNurbKnot(); float maxKnot = spline.getMaxNurbKnot(); float deltaU = (maxKnot - minKnot) / nbSubSegments; @@ -233,7 +233,7 @@ public class Curve extends Mesh { this.setBuffer(VertexBuffer.Type.Index, 2, indices); this.updateBound(); this.updateCounts(); - } + } } private void createLinearMesh() { diff --git a/jme3-core/src/main/java/com/jme3/texture/FrameBuffer.java b/jme3-core/src/main/java/com/jme3/texture/FrameBuffer.java index 2626cee90..3bd74a016 100644 --- a/jme3-core/src/main/java/com/jme3/texture/FrameBuffer.java +++ b/jme3-core/src/main/java/com/jme3/texture/FrameBuffer.java @@ -41,38 +41,38 @@ import java.util.ArrayList; *

    * FrameBuffers are rendering surfaces allowing * off-screen rendering and render-to-texture functionality. - * Instead of the scene rendering to the screen, it is rendered into the + * Instead of the scene rendering to the screen, it is rendered into the * FrameBuffer, the result can be either a texture or a buffer. *

    - * A FrameBuffer supports two methods of rendering, - * using a {@link Texture} or using a buffer. + * A FrameBuffer supports two methods of rendering, + * using a {@link Texture} or using a buffer. * When using a texture, the result of the rendering will be rendered * onto the texture, after which the texture can be placed on an object * and rendered as if the texture was uploaded from disk. - * When using a buffer, the result is rendered onto + * When using a buffer, the result is rendered onto * a buffer located on the GPU, the data of this buffer is not accessible * to the user. buffers are useful if one * wishes to retrieve only the color content of the scene, but still desires - * depth testing (which requires a depth buffer). + * depth testing (which requires a depth buffer). * Buffers can be copied to other framebuffers - * including the main screen, by using + * including the main screen, by using * {@link Renderer#copyFrameBuffer(com.jme3.texture.FrameBuffer, com.jme3.texture.FrameBuffer, boolean)}. - * The content of a {@link RenderBuffer} can be retrieved by using + * The content of a {@link RenderBuffer} can be retrieved by using * {@link Renderer#readFrameBuffer(com.jme3.texture.FrameBuffer, java.nio.ByteBuffer) }. *

    - * FrameBuffers have several attachment points, there are - * several color attachment points and a single depth + * FrameBuffers have several attachment points, there are + * several color attachment points and a single depth * attachment point. * The color attachment points support image formats such as * {@link Format#RGBA8}, allowing rendering the color content of the scene. - * The depth attachment point requires a depth image format. - * - * @see Renderer#setFrameBuffer(com.jme3.texture.FrameBuffer) - * + * The depth attachment point requires a depth image format. + * + * @see Renderer#setFrameBuffer(com.jme3.texture.FrameBuffer) + * * @author Kirill Vainer */ public class FrameBuffer extends NativeObject { - + public static final int SLOT_UNDEF = -1; public static final int SLOT_DEPTH = -100; public static final int SLOT_DEPTH_STENCIL = -101; @@ -86,7 +86,7 @@ public class FrameBuffer extends NativeObject { private boolean srgb; /** - * RenderBuffer represents either a texture or a + * RenderBuffer represents either a texture or a * buffer that will be rendered to. RenderBuffers * are attached to an attachment slot on a FrameBuffer. */ @@ -98,7 +98,7 @@ public class FrameBuffer extends NativeObject { int slot = SLOT_UNDEF; int face = -1; int layer = -1; - + /** * @return The image format of the render buffer. */ @@ -110,7 +110,7 @@ public class FrameBuffer extends NativeObject { * @return The texture to render to for this RenderBuffer * 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; } @@ -134,30 +134,30 @@ public class FrameBuffer extends NativeObject { public int getSlot() { return slot; } - + public int getFace() { 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{ - RenderBuffer destructClone = new RenderBuffer(); + } else { + RenderBuffer destructClone = new RenderBuffer(); destructClone.id = id; return destructClone; } } @Override - public String toString(){ - if (tex != null){ + public String toString() { + if (tex != null) { return "TextureTarget[format=" + format + "]"; - }else{ + } else { return "BufferTarget[format=" + format + "]"; } } @@ -173,28 +173,29 @@ public class FrameBuffer extends NativeObject { * of samples. If any textures are attached to this FrameBuffer, then * they must have the same number of samples as given in this constructor. *

    - * Note that if the {@link Renderer} does not expose the + * Note that if the {@link Renderer} does not expose the * {@link Caps#NonPowerOfTwoTextures}, then an exception will be thrown * if the width and height arguments are not power of two. - * + * * @param width The width to use * @param height The height to use * @param samples The number of samples to use for a multisampled * framebuffer, or 1 if the framebuffer should be singlesampled. - * + * * @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) - throw new IllegalArgumentException("FrameBuffer must have valid size."); + 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){ @@ -209,60 +210,68 @@ public class FrameBuffer extends NativeObject { /** * Enables the use of a depth buffer for this FrameBuffer. - * + * * @param format The format to use for the depth buffer. * @throws IllegalArgumentException If format 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; + depthBuf.slot = format.isDepthStencilFormat() ? SLOT_DEPTH_STENCIL : SLOT_DEPTH; depthBuf.format = format; } /** * Enables the use of a color buffer for this FrameBuffer. - * + * * @param format The format to use for the color buffer. * @throws IllegalArgumentException If format 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; colorBuf.format = format; - + colorBufs.clear(); 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"); + } } /** @@ -270,38 +279,43 @@ public class FrameBuffer extends NativeObject { * will be able to write several results into the renderbuffers * by using the gl_FragData array. Every slot in that * array maps into a color buffer attached to this framebuffer. - * + * * @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; } - + /** * If MRT is not enabled ({@link FrameBuffer#setMultiTarget(boolean) } is false) * then this specifies the color target to which the scene should be rendered. *

    * By default the value is 0. - * + * * @param index The color attachment index. * @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(); @@ -309,10 +323,10 @@ public class FrameBuffer extends NativeObject { /** * @return The color target to which the scene should be rendered. - * - * @see FrameBuffer#setTargetIndex(int) + * + * @see FrameBuffer#setTargetIndex(int) */ - public int getTargetIndex(){ + public int getTargetIndex() { return colorBufIndex; } @@ -321,27 +335,27 @@ public class FrameBuffer extends NativeObject { * This automatically clears all existing textures added previously * with {@link FrameBuffer#addColorTexture } and adds this texture as the * only target. - * + * * @param tex The color texture to set. */ - public void setColorTexture(Texture2D tex){ + public void setColorTexture(Texture2D tex) { clearColorTargets(); addColorTexture(tex); } - + /** * Set the color texture array to use for this framebuffer. * This automatically clears all existing textures added previously * with {@link FrameBuffer#addColorTexture } and adds this texture as the * only target. - * + * * @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); } - + /** * Set the color texture to use for this framebuffer. * This automatically clears all existing textures added previously @@ -359,47 +373,50 @@ public class FrameBuffer extends NativeObject { /** * Clears all color targets that were set or added previously. */ - public void clearColorTargets(){ + public void clearColorTargets() { colorBufs.clear(); } - /** + /** * Add a color buffer without a texture bound to it. * If MRT is enabled, then each subsequently added texture or buffer can be * rendered to through a shader that writes to the array gl_FragData. * If MRT is not enabled, then the index set with {@link FrameBuffer#setTargetIndex(int) } * is rendered to by the shader. - * + * * @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){ - 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(); colorBuf.format = format; - + colorBufs.add(colorBuf); } - + /** * Add a color texture to use for this framebuffer. * If MRT is enabled, then each subsequently added texture can be * rendered to through a shader that writes to the array gl_FragData. * If MRT is not enabled, then the index set with {@link FrameBuffer#setTargetIndex(int) } * is rendered to by the shader. - * + * * @param tex The texture to add. - * @see #addColorBuffer(com.jme3.texture.Image.Format) + * @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); @@ -411,19 +428,20 @@ public class FrameBuffer extends NativeObject { colorBufs.add(colorBuf); } - + /** * Add a color texture array to use for this framebuffer. * If MRT is enabled, then each subsequently added texture can be * rendered to through a shader that writes to the array gl_FragData. * If MRT is not enabled, then the index set with {@link FrameBuffer#setTargetIndex(int) } * is rendered to by the shader. - * + * * @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); @@ -436,8 +454,8 @@ public class FrameBuffer extends NativeObject { colorBufs.add(colorBuf); } - - /** + + /** * Add a color texture to use for this framebuffer. * If MRT is enabled, then each subsequently added texture can be * rendered to through a shader that writes to the array gl_FragData. @@ -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); @@ -465,39 +484,42 @@ public class FrameBuffer extends NativeObject { /** * Set the depth texture to use for this framebuffer. - * + * * @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); - + depthBuf = new RenderBuffer(); - depthBuf.slot = img.getFormat().isDepthStencilFormat() ? SLOT_DEPTH_STENCIL : SLOT_DEPTH; + depthBuf.slot = img.getFormat().isDepthStencilFormat() ? SLOT_DEPTH_STENCIL : SLOT_DEPTH; 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); - + depthBuf = new RenderBuffer(); - depthBuf.slot = img.getFormat().isDepthStencilFormat() ? SLOT_DEPTH_STENCIL : SLOT_DEPTH; + depthBuf.slot = img.getFormat().isDepthStencilFormat() ? SLOT_DEPTH_STENCIL : SLOT_DEPTH; depthBuf.tex = tex; depthBuf.format = img.getFormat(); depthBuf.layer = layer; } - + /** - * @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(); } @@ -505,21 +527,22 @@ 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); } /** * @return The color buffer with the index set by {@link #setTargetIndex(int)}, or null * if no color buffers are attached. - * If MRT is disabled, the first color buffer is returned. + * 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()) { - return colorBufs.get(0); - } + } + if (colorBufIndex < 0 || colorBufIndex >= colorBufs.size()) { + return colorBufs.get(0); + } return colorBufs.get(colorBufIndex); } @@ -554,16 +577,17 @@ 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) + .append("x").append(samples).append(", drawBuf=").append(mrtStr).append("]\n"); + 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"); + .append(") => ").append(colorBuf).append("\n"); } return sb.toString(); } @@ -571,32 +595,33 @@ public class FrameBuffer extends NativeObject { @Override public void resetObject() { this.id = -1; - + for (int i = 0; i < colorBufs.size(); i++) { 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); } - + /** * Specifies that the color values stored in this framebuffer are in SRGB * format. @@ -632,5 +657,4 @@ public class FrameBuffer extends NativeObject { public boolean isSrgb() { return srgb; } - } diff --git a/jme3-core/src/main/java/com/jme3/util/BufferUtils.java b/jme3-core/src/main/java/com/jme3/util/BufferUtils.java index 180297096..c81926f91 100644 --- a/jme3-core/src/main/java/com/jme3/util/BufferUtils.java +++ b/jme3-core/src/main/java/com/jme3/util/BufferUtils.java @@ -54,7 +54,7 @@ import java.util.concurrent.ConcurrentHashMap; /** * BufferUtils is a helper class for generating nio buffers from * jME data classes such as Vectors and ColorRGBA. - * + * * @author Joshua Slack * @version $Id: BufferUtils.java,v 1.16 2007/10/29 16:56:18 nca Exp $ */ @@ -74,7 +74,7 @@ public final class BufferUtils { * Set it to true if you want to enable direct memory tracking for debugging * purpose. Default is false. To print direct memory usage use * BufferUtils.printCurrentDirectMemory(StringBuilder store); - * + * * @param enabled */ public static void setTrackDirectMemoryEnabled(boolean enabled) { @@ -84,7 +84,7 @@ public final class BufferUtils { /** * Creates a clone of the given buffer. The clone's capacity is equal to the * given buffer's limit. - * + * * @param buf * The buffer to clone * @return The cloned buffer @@ -141,7 +141,7 @@ public final class BufferUtils { * Generate a new FloatBuffer using the given array of Vector3f objects. The * FloatBuffer will be 3 * data.length long and contain the vector data as * data[0].x, data[0].y, data[0].z, data[1].x... etc. - * + * * @param data * array of Vector3f objects to place into a new FloatBuffer */ @@ -164,7 +164,7 @@ public final class BufferUtils { /** * Generate a new FloatBuffer using the given array of Quaternion objects. * The FloatBuffer will be 4 * data.length long and contain the vector data. - * + * * @param data * array of Quaternion objects to place into a new FloatBuffer */ @@ -232,7 +232,7 @@ public final class BufferUtils { /** * Generate a new FloatBuffer using the given array of float primitives. - * + * * @param data * array of float primitives to place into a new FloatBuffer */ @@ -250,7 +250,7 @@ public final class BufferUtils { /** * Create a new FloatBuffer of an appropriate size to hold the specified * number of Vector3f object data. - * + * * @param vertices * number of vertices that need to be held by the newly created * buffer @@ -265,7 +265,7 @@ public final class BufferUtils { * Create a new FloatBuffer of an appropriate size to hold the specified * number of Vector3f object data only if the given buffer if not already * the right size. - * + * * @param buf * the buffer to first check and rewind * @param vertices @@ -285,7 +285,7 @@ public final class BufferUtils { /** * Sets the data contained in the given color into the FloatBuffer at the * specified index. - * + * * @param color * the data to insert * @param buf @@ -304,7 +304,7 @@ public final class BufferUtils { /** * Sets the data contained in the given quaternion into the FloatBuffer at * the specified index. - * + * * @param quat * the {@link Quaternion} to insert * @param buf @@ -343,7 +343,7 @@ public final class BufferUtils { /** * Sets the data contained in the given Vector3F into the FloatBuffer at the * specified index. - * + * * @param vector * the data to insert * @param buf @@ -369,7 +369,7 @@ public final class BufferUtils { /** * Updates the values of the given vector from the specified buffer at the * index provided. - * + * * @param vector * the vector to set data on * @param buf @@ -387,7 +387,7 @@ public final class BufferUtils { /** * Updates the values of the given vector from the specified buffer at the * index provided. - * + * * @param vector * the vector to set data on * @param buf @@ -405,7 +405,7 @@ public final class BufferUtils { /** * Generates a Vector3f array from the given FloatBuffer. - * + * * @param buff * the FloatBuffer to read from * @return a newly generated array of Vector3f objects @@ -424,7 +424,7 @@ public final class BufferUtils { * Copies a Vector3f from one position in the buffer to another. The index * values are in terms of vector number (eg, vector number 0 is positions * 0-2 in the FloatBuffer.) - * + * * @param buf * the buffer to copy from/to * @param fromPos @@ -438,7 +438,7 @@ public final class BufferUtils { /** * Normalize a Vector3f in-buffer. - * + * * @param buf * the buffer to find the Vector3f within * @param index @@ -456,7 +456,7 @@ public final class BufferUtils { /** * Add to a Vector3f in-buffer. - * + * * @param toAdd * the vector to add from * @param buf @@ -476,7 +476,7 @@ public final class BufferUtils { /** * Multiply and store a Vector3f in-buffer. - * + * * @param toMult * the vector to multiply against * @param buf @@ -497,7 +497,7 @@ public final class BufferUtils { /** * Checks to see if the given Vector3f is equals to the data stored in the * buffer at the given data index. - * + * * @param check * the vector to check against - null will return false. * @param buf @@ -521,7 +521,7 @@ public final class BufferUtils { * Generate a new FloatBuffer using the given array of Vector2f objects. The * FloatBuffer will be 2 * data.length long and contain the vector data as * data[0].x, data[0].y, data[1].x... etc. - * + * * @param data * array of Vector2f objects to place into a new FloatBuffer */ @@ -544,7 +544,7 @@ public final class BufferUtils { /** * Create a new FloatBuffer of an appropriate size to hold the specified * number of Vector2f object data. - * + * * @param vertices * number of vertices that need to be held by the newly created * buffer @@ -559,7 +559,7 @@ public final class BufferUtils { * Create a new FloatBuffer of an appropriate size to hold the specified * number of Vector2f object data only if the given buffer if not already * the right size. - * + * * @param buf * the buffer to first check and rewind * @param vertices @@ -579,7 +579,7 @@ public final class BufferUtils { /** * Sets the data contained in the given Vector2F into the FloatBuffer at the * specified index. - * + * * @param vector * the data to insert * @param buf @@ -595,7 +595,7 @@ public final class BufferUtils { /** * Updates the values of the given vector from the specified buffer at the * index provided. - * + * * @param vector * the vector to set data on * @param buf @@ -611,7 +611,7 @@ public final class BufferUtils { /** * Generates a Vector2f array from the given FloatBuffer. - * + * * @param buff * the FloatBuffer to read from * @return a newly generated array of Vector2f objects @@ -630,7 +630,7 @@ public final class BufferUtils { * Copies a Vector2f from one position in the buffer to another. The index * values are in terms of vector number (eg, vector number 0 is positions * 0-1 in the FloatBuffer.) - * + * * @param buf * the buffer to copy from/to * @param fromPos @@ -644,7 +644,7 @@ public final class BufferUtils { /** * Normalize a Vector2f in-buffer. - * + * * @param buf * the buffer to find the Vector2f within * @param index @@ -662,7 +662,7 @@ public final class BufferUtils { /** * Add to a Vector2f in-buffer. - * + * * @param toAdd * the vector to add from * @param buf @@ -682,7 +682,7 @@ public final class BufferUtils { /** * Multiply and store a Vector2f in-buffer. - * + * * @param toMult * the vector to multiply against * @param buf @@ -703,7 +703,7 @@ public final class BufferUtils { /** * Checks to see if the given Vector2f is equals to the data stored in the * buffer at the given data index. - * + * * @param check * the vector to check against - null will return false. * @param buf @@ -727,7 +727,7 @@ public final class BufferUtils { * Generate a new IntBuffer using the given array of ints. The IntBuffer * will be data.length long and contain the int data as data[0], data[1]... * etc. - * + * * @param data * array of ints to place into a new IntBuffer */ @@ -745,7 +745,7 @@ public final class BufferUtils { /** * Create a new int[] array and populate it with the given IntBuffer's * contents. - * + * * @param buff * the IntBuffer to read from * @return a new int array populated from the IntBuffer @@ -765,7 +765,7 @@ public final class BufferUtils { /** * Create a new float[] array and populate it with the given FloatBuffer's * contents. - * + * * @param buff * the FloatBuffer to read from * @return a new float array populated from the FloatBuffer @@ -785,7 +785,7 @@ public final class BufferUtils { //// -- GENERAL DOUBLE ROUTINES -- //// /** * Create a new DoubleBuffer of the specified size. - * + * * @param size * required number of double to store. * @return the new DoubleBuffer @@ -800,7 +800,7 @@ public final class BufferUtils { /** * Create a new DoubleBuffer of an appropriate size to hold the specified * number of doubles only if the given buffer if not already the right size. - * + * * @param buf * the buffer to first check and rewind * @param size @@ -823,7 +823,7 @@ public final class BufferUtils { * DoubleBuffer. The new DoubleBuffer is separate from the old one and * changes are not reflected across. If you want to reflect changes, * consider using Buffer.duplicate(). - * + * * @param buf * the DoubleBuffer to copy * @return the copy @@ -848,7 +848,7 @@ public final class BufferUtils { //// -- GENERAL FLOAT ROUTINES -- //// /** * Create a new FloatBuffer of the specified size. - * + * * @param size * required number of floats to store. * @return the new FloatBuffer @@ -862,7 +862,7 @@ public final class BufferUtils { /** * Copies floats from one position in the buffer to another. - * + * * @param buf * the buffer to copy from/to * @param fromPos @@ -885,7 +885,7 @@ public final class BufferUtils { * FloatBuffer. The new FloatBuffer is separate from the old one and changes * are not reflected across. If you want to reflect changes, consider using * Buffer.duplicate(). - * + * * @param buf * the FloatBuffer to copy * @return the copy @@ -910,7 +910,7 @@ public final class BufferUtils { //// -- GENERAL INT ROUTINES -- //// /** * Create a new IntBuffer of the specified size. - * + * * @param size * required number of ints to store. * @return the new IntBuffer @@ -925,7 +925,7 @@ public final class BufferUtils { /** * Create a new IntBuffer of an appropriate size to hold the specified * number of ints only if the given buffer if not already the right size. - * + * * @param buf * the buffer to first check and rewind * @param size @@ -948,7 +948,7 @@ public final class BufferUtils { * The new IntBuffer is separate from the old one and changes are not * reflected across. If you want to reflect changes, consider using * Buffer.duplicate(). - * + * * @param buf * the IntBuffer to copy * @return the copy @@ -973,7 +973,7 @@ public final class BufferUtils { //// -- GENERAL BYTE ROUTINES -- //// /** * Create a new ByteBuffer of the specified size. - * + * * @param size * required number of ints to store. * @return the new IntBuffer @@ -988,7 +988,7 @@ public final class BufferUtils { /** * Create a new ByteBuffer of an appropriate size to hold the specified * number of ints only if the given buffer if not already the right size. - * + * * @param buf * the buffer to first check and rewind * @param size @@ -1030,7 +1030,7 @@ public final class BufferUtils { * The new ByteBuffer is separate from the old one and changes are not * reflected across. If you want to reflect changes, consider using * Buffer.duplicate(). - * + * * @param buf * the ByteBuffer to copy * @return the copy @@ -1055,7 +1055,7 @@ public final class BufferUtils { //// -- GENERAL SHORT ROUTINES -- //// /** * Create a new ShortBuffer of the specified size. - * + * * @param size * required number of shorts to store. * @return the new ShortBuffer @@ -1070,7 +1070,7 @@ public final class BufferUtils { /** * Create a new ShortBuffer of an appropriate size to hold the specified * number of shorts only if the given buffer if not already the right size. - * + * * @param buf * the buffer to first check and rewind * @param size @@ -1104,7 +1104,7 @@ public final class BufferUtils { * ShortBuffer. The new ShortBuffer is separate from the old one and changes * are not reflected across. If you want to reflect changes, consider using * Buffer.duplicate(). - * + * * @param buf * the ShortBuffer to copy * @return the copy @@ -1130,7 +1130,7 @@ public final class BufferUtils { * Ensures there is at least the required number of entries * left after the current position of the buffer. If the buffer is too small * a larger one is created and the old one copied to the new buffer. - * + * * @param buffer * buffer that should be checked/copied (may be null) * @param required @@ -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 { } } } - } diff --git a/jme3-core/src/main/java/com/jme3/util/ReflectionAllocator.java b/jme3-core/src/main/java/com/jme3/util/ReflectionAllocator.java index a55d7c918..6564463b2 100644 --- a/jme3-core/src/main/java/com/jme3/util/ReflectionAllocator.java +++ b/jme3-core/src/main/java/com/jme3/util/ReflectionAllocator.java @@ -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 @@ -81,74 +81,74 @@ public final class ReflectionAllocator implements BufferAllocator { } catch (ClassNotFoundException ex) { return null; // the direct buffer implementation was not found } catch (Throwable t) { - if (t.getClass().getName().equals("java.lang.reflect.InaccessibleObjectException")) { - return null;// the class is in an unexported module - } else { - throw t; - } + if (t.getClass().getName().equals("java.lang.reflect.InaccessibleObjectException")) { + return null;// the class is in an unexported module + } else { + throw t; + } } } @Override /** * This function explicitly calls the Cleaner method of a direct buffer. - * + * * @param toBeDestroyed * The direct buffer that will be "cleaned". Utilizes reflection. - * + * */ public void destroyDirectBuffer(Buffer toBeDestroyed) { try { if (freeMethod != null) { freeMethod.invoke(toBeDestroyed); } else { - //TODO load the methods only once, store them into a cache (only for Java >= 9) - Method localCleanerMethod; - if (cleanerMethod == null) { - localCleanerMethod = loadMethod(toBeDestroyed.getClass().getName(), "cleaner"); - } else { - localCleanerMethod = cleanerMethod; - } - if (localCleanerMethod == null) { - Logger.getLogger(BufferUtils.class.getName()).log(Level.SEVERE, - "Buffer cannot be destroyed: {0}", toBeDestroyed); - } else { - Object cleaner = localCleanerMethod.invoke(toBeDestroyed); - if (cleaner != null) { - Method localCleanMethod; - if (cleanMethod == null) { - if (cleaner instanceof Runnable) { - // jdk.internal.ref.Cleaner implements Runnable in Java 9 - localCleanMethod = loadMethod(Runnable.class.getName(), "run"); - } else { - // sun.misc.Cleaner does not implement Runnable in Java < 9 - localCleanMethod = loadMethod(cleaner.getClass().getName(), "clean"); - } - } else { - localCleanMethod = cleanMethod; - } - if (localCleanMethod == null) { - Logger.getLogger(BufferUtils.class.getName()).log(Level.SEVERE, - "Buffer cannot be destroyed: {0}", toBeDestroyed); - } else { - localCleanMethod.invoke(cleaner); - } - } else { - Method localViewedBufferMethod; - if (viewedBufferMethod == null) { - localViewedBufferMethod = loadMethod(toBeDestroyed.getClass().getName(), "viewedBuffer"); - } else { - localViewedBufferMethod = viewedBufferMethod; - } - if (localViewedBufferMethod == null) { - Logger.getLogger(BufferUtils.class.getName()).log(Level.SEVERE, - "Buffer cannot be destroyed: {0}", toBeDestroyed); - } else { - // Try the alternate approach of getting the viewed - // buffer - // first - Object viewedBuffer = localViewedBufferMethod.invoke(toBeDestroyed); - if (viewedBuffer != null) { + //TODO load the methods only once, store them into a cache (only for Java >= 9) + Method localCleanerMethod; + if (cleanerMethod == null) { + localCleanerMethod = loadMethod(toBeDestroyed.getClass().getName(), "cleaner"); + } else { + localCleanerMethod = cleanerMethod; + } + if (localCleanerMethod == null) { + Logger.getLogger(BufferUtils.class.getName()).log(Level.SEVERE, + "Buffer cannot be destroyed: {0}", toBeDestroyed); + } else { + Object cleaner = localCleanerMethod.invoke(toBeDestroyed); + if (cleaner != null) { + Method localCleanMethod; + if (cleanMethod == null) { + if (cleaner instanceof Runnable) { + // jdk.internal.ref.Cleaner implements Runnable in Java 9 + localCleanMethod = loadMethod(Runnable.class.getName(), "run"); + } else { + // sun.misc.Cleaner does not implement Runnable in Java < 9 + localCleanMethod = loadMethod(cleaner.getClass().getName(), "clean"); + } + } else { + localCleanMethod = cleanMethod; + } + if (localCleanMethod == null) { + Logger.getLogger(BufferUtils.class.getName()).log(Level.SEVERE, + "Buffer cannot be destroyed: {0}", toBeDestroyed); + } else { + localCleanMethod.invoke(cleaner); + } + } else { + Method localViewedBufferMethod; + if (viewedBufferMethod == null) { + localViewedBufferMethod = loadMethod(toBeDestroyed.getClass().getName(), "viewedBuffer"); + } else { + localViewedBufferMethod = viewedBufferMethod; + } + if (localViewedBufferMethod == null) { + Logger.getLogger(BufferUtils.class.getName()).log(Level.SEVERE, + "Buffer cannot be destroyed: {0}", toBeDestroyed); + } else { + // Try the alternate approach of getting the viewed + // buffer + // first + Object viewedBuffer = localViewedBufferMethod.invoke(toBeDestroyed); + if (viewedBuffer != null) { if (viewedBuffer instanceof Buffer) { destroyDirectBuffer((Buffer) viewedBuffer); } @@ -157,10 +157,10 @@ public final class ReflectionAllocator implements BufferAllocator { } else { Logger.getLogger(BufferUtils.class.getName()).log(Level.SEVERE, "Buffer cannot be destroyed: {0}", toBeDestroyed); - } - } - } - } + } + } + } + } } } catch (IllegalAccessException ex) { Logger.getLogger(BufferUtils.class.getName()).log(Level.SEVERE, "{0}", ex);