improve formatting & rm trailing whitespace (21 files in com.jme3.math)

master
Stephen Gold 5 years ago
parent 4c62d5008e
commit 5a2499ccbe
  1. 4
      jme3-core/src/main/java/com/jme3/math/AbstractTriangle.java
  2. 128
      jme3-core/src/main/java/com/jme3/math/ColorRGBA.java
  3. 1
      jme3-core/src/main/java/com/jme3/math/EaseFunction.java
  4. 7
      jme3-core/src/main/java/com/jme3/math/Easing.java
  5. 34
      jme3-core/src/main/java/com/jme3/math/Eigen3f.java
  6. 12
      jme3-core/src/main/java/com/jme3/math/FastMath.java
  7. 16
      jme3-core/src/main/java/com/jme3/math/Line.java
  8. 10
      jme3-core/src/main/java/com/jme3/math/LineSegment.java
  9. 5
      jme3-core/src/main/java/com/jme3/math/MathUtils.java
  10. 36
      jme3-core/src/main/java/com/jme3/math/Matrix3f.java
  11. 13
      jme3-core/src/main/java/com/jme3/math/Matrix4f.java
  12. 4
      jme3-core/src/main/java/com/jme3/math/Plane.java
  13. 19
      jme3-core/src/main/java/com/jme3/math/Quaternion.java
  14. 45
      jme3-core/src/main/java/com/jme3/math/Ray.java
  15. 43
      jme3-core/src/main/java/com/jme3/math/Rectangle.java
  16. 50
      jme3-core/src/main/java/com/jme3/math/Ring.java
  17. 2
      jme3-core/src/main/java/com/jme3/math/Spline.java
  18. 18
      jme3-core/src/main/java/com/jme3/math/Triangle.java
  19. 140
      jme3-core/src/main/java/com/jme3/math/Vector2f.java
  20. 35
      jme3-core/src/main/java/com/jme3/math/Vector3f.java
  21. 151
      jme3-core/src/main/java/com/jme3/math/Vector4f.java

@ -38,7 +38,6 @@ import com.jme3.collision.CollisionResults;
* A Collidable with a triangular shape.
*/
public abstract class AbstractTriangle implements Collidable {
/**
* Determine the location of the first vertex.
*
@ -77,8 +76,7 @@ public abstract class AbstractTriangle implements Collidable {
* @return the number of collisions found
*/
@Override
public int collideWith(Collidable other, CollisionResults results){
public int collideWith(Collidable other, CollisionResults results) {
return other.collideWith(this, results);
}
}

@ -36,13 +36,12 @@ import java.io.IOException;
/**
* <code>ColorRGBA</code> defines a color made from a collection of red, green
* and blue values stored in Linear color space. An alpha value determines is
* transparency.
* transparency.
*
* @author Mark Powell
* @version $Id: ColorRGBA.java,v 1.29 2007/09/09 18:25:14 irrisor Exp $
*/
public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable {
static final float GAMMA = 2.2f;
static final long serialVersionUID = 1;
@ -133,10 +132,11 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
/**
* Constructor instantiates a new <code>ColorRGBA</code> object. The
* values are defined as passed parameters.
* values are defined as passed parameters.
* these values are assumed to be in linear space and stored as is.
* If you want to assign sRGB values use
* If you want to assign sRGB values use
* {@link ColorRGBA#setAsSrgb(float, float, float, float) }
*
* @param r The red component of this color.
* @param g The green component of this <code>ColorRGBA</code>.
* @param b The blue component of this <code>ColorRGBA</code>.
@ -152,6 +152,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
/**
* Copy constructor creates a new <code>ColorRGBA</code> object, based on
* a provided color.
*
* @param rgba The <code>ColorRGBA</code> object to copy.
*/
public ColorRGBA(ColorRGBA rgba) {
@ -162,11 +163,11 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
}
/**
* <code>set</code> sets the RGBA values of this <code>ColorRGBA</code>.
* <code>set</code> sets the RGBA values of this <code>ColorRGBA</code>.
* these values are assumed to be in linear space and stored as is.
* If you want to assign sRGB values use
* If you want to assign sRGB values use
* {@link ColorRGBA#setAsSrgb(float, float, float, float) }
*
*
* @param r The red component of this color.
* @param g The green component of this color.
* @param b The blue component of this color.
@ -182,7 +183,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
}
/**
* <code>set</code> sets the values of this <code>ColorRGBA</code> to those
* <code>set</code> sets the values of this <code>ColorRGBA</code> to those
* set by a parameter color.
*
* @param rgba The color to set this <code>ColorRGBA</code> to.
@ -214,9 +215,10 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
}
/**
* <code>getColorArray</code> retrieves the color values of this
* <code>ColorRGBA</code> as a four element <code>float</code> array in the
* <code>getColorArray</code> retrieves the color values of this
* <code>ColorRGBA</code> as a four element <code>float</code> array in the
* order: r,g,b,a.
*
* @return The <code>float</code> array that contains the color components.
*/
public float[] getColorArray() {
@ -226,6 +228,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
/**
* Stores the current r,g,b,a values into the given array. The given array must have a
* length of 4 or greater, or an array index out of bounds exception will be thrown.
*
* @param store The <code>float</code> array to store the values into.
* @return The <code>float</code> array after storage.
*/
@ -239,6 +242,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
/**
* Retrieves the alpha component value of this <code>ColorRGBA</code>.
*
* @return The alpha component value.
*/
public float getAlpha() {
@ -247,6 +251,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
/**
* Retrieves the red component value of this <code>ColorRGBA</code>.
*
* @return The red component value.
*/
public float getRed() {
@ -255,6 +260,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
/**
* Retrieves the blue component value of this <code>ColorRGBA</code>.
*
* @return The blue component value.
*/
public float getBlue() {
@ -263,6 +269,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
/**
* Retrieves the green component value of this <code>ColorRGBA</code>.
*
* @return The green component value.
*/
public float getGreen() {
@ -270,12 +277,13 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
}
/**
* Sets this <code>ColorRGBA</code> to the interpolation by changeAmnt from
* Sets this <code>ColorRGBA</code> to the interpolation by changeAmnt from
* this to the finalColor:
* this=(1-changeAmnt)*this + changeAmnt * finalColor
*
* @param finalColor The final color to interpolate towards.
* @param changeAmnt An amount between 0.0 - 1.0 representing a percentage
* change from this towards finalColor.
* change from this towards finalColor.
* @return this ColorRGBA
*/
public ColorRGBA interpolateLocal(ColorRGBA finalColor, float changeAmnt) {
@ -287,9 +295,10 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
}
/**
* Sets this <code>ColorRGBA</code> to the interpolation by changeAmnt from
* Sets this <code>ColorRGBA</code> to the interpolation by changeAmnt from
* beginColor to finalColor:
* this=(1-changeAmnt)*beginColor + changeAmnt * finalColor
*
* @param beginColor The beginning color (changeAmnt=0).
* @param finalColor The final color to interpolate towards (changeAmnt=1).
* @param changeAmnt An amount between 0.0 - 1.0 representing a percentage
@ -307,6 +316,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
/**
* <code>randomColor</code> is a utility method that generates a random
* opaque color.
*
* @return a random <code>ColorRGBA</code> with an alpha set to 1.
*/
public static ColorRGBA randomColor() {
@ -318,9 +328,10 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
}
/**
* Multiplies each r,g,b,a of this <code>ColorRGBA</code> by the corresponding
* r,g,b,a of the given color and returns the result as a new <code>ColorRGBA</code>.
* Multiplies each r,g,b,a of this <code>ColorRGBA</code> by the corresponding
* r,g,b,a of the given color and returns the result as a new <code>ColorRGBA</code>.
* Used as a way of combining colors and lights.
*
* @param c The color to multiply by.
* @return The new <code>ColorRGBA</code>. this*c
*/
@ -330,8 +341,9 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
/**
* Multiplies each r,g,b,a of this <code>ColorRGBA</code> by the given scalar and
* returns the result as a new <code>ColorRGBA</code>.
* returns the result as a new <code>ColorRGBA</code>.
* Used as a way of making colors dimmer or brighter.
*
* @param scalar The scalar to multiply by.
* @return The new <code>ColorRGBA</code>. this*scalar
*/
@ -341,8 +353,9 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
/**
* Multiplies each r,g,b,a of this <code>ColorRGBA</code> by the given scalar and
* returns the result (this).
* returns the result (this).
* Used as a way of making colors dimmer or brighter.
*
* @param scalar The scalar to multiply by.
* @return this*c
*/
@ -355,9 +368,10 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
}
/**
* Adds each r,g,b,a of this <code>ColorRGBA</code> by the corresponding
* Adds each r,g,b,a of this <code>ColorRGBA</code> by the corresponding
* r,g,b,a of the given color and returns the result as a new <code>ColorRGBA</code>.
* Used as a way of combining colors and lights.
*
* @param c The color to add.
* @return The new <code>ColorRGBA</code>. this+c
*/
@ -366,9 +380,10 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
}
/**
* Adds each r,g,b,a of this <code>ColorRGBA</code> by the r,g,b,a the given
* color and returns the result (this).
* Adds each r,g,b,a of this <code>ColorRGBA</code> by the r,g,b,a the given
* color and returns the result (this).
* Used as a way of combining colors and lights.
*
* @param c The color to add.
* @return this+c
*/
@ -381,6 +396,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
* <code>toString</code> returns the string representation of this <code>ColorRGBA</code>.
* The format of the string is:<br>
* Color[R.RRRR, G.GGGG, B.BBBB, A.AAAA]
*
* @return The string representation of this <code>ColorRGBA</code>.
*/
@Override
@ -404,7 +420,8 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
/**
* Saves this <code>ColorRGBA</code> into the given <code>float</code> array.
* @param floats The <code>float</code> array to take this <code>ColorRGBA</code>.
*
* @param floats The <code>float</code> array to take this <code>ColorRGBA</code>.
* If null, a new <code>float[4]</code> is created.
* @return The array, with r,g,b,a float values in that order.
*/
@ -423,6 +440,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
* <code>equals</code> returns true if this <code>ColorRGBA</code> is logically equivalent
* to a given color. That is, if all the components of the two colors are the same.
* False is returned otherwise.
*
* @param o The object to compare against.
* @return true if the colors are equal, false otherwise.
*/
@ -456,6 +474,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
* <code>hashCode</code> returns a unique code for this <code>ColorRGBA</code> based
* on its values. If two colors are logically equivalent, they will return
* the same hash code value.
*
* @return The hash code value of this <code>ColorRGBA</code>.
*/
@Override
@ -467,7 +486,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
hash += 37 * hash + Float.floatToIntBits(a);
return hash;
}
/**
* Serialize this color to the specified exporter, for example when
* saving to a J3O file.
@ -499,9 +518,11 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
b = capsule.readFloat("b", 0);
a = capsule.readFloat("a", 0);
}
/**
* Retrieves the component values of this <code>ColorRGBA</code> as
* a four element <code>byte</code> array in the order: r,g,b,a.
*
* @return the <code>byte</code> array that contains the color components.
*/
public byte[] asBytesRGBA() {
@ -514,9 +535,10 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
}
/**
* Retrieves the component values of this <code>ColorRGBA</code> as an
* <code>int</code> in a,r,g,b order.
* Retrieves the component values of this <code>ColorRGBA</code> as an
* <code>int</code> in a,r,g,b order.
* Bits 24-31 are alpha, 16-23 are red, 8-15 are green, 0-7 are blue.
*
* @return The integer representation of this <code>ColorRGBA</code> in a,r,g,b order.
*/
public int asIntARGB() {
@ -528,9 +550,10 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
}
/**
* Retrieves the component values of this <code>ColorRGBA</code> as an
* Retrieves the component values of this <code>ColorRGBA</code> as an
* <code>int</code> in r,g,b,a order.
* Bits 24-31 are red, 16-23 are green, 8-15 are blue, 0-7 are alpha.
*
* @return The integer representation of this <code>ColorRGBA</code> in r,g,b,a order.
*/
public int asIntRGBA() {
@ -540,10 +563,12 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
| (((int) (a * 255) & 0xFF));
return rgba;
}
/**
* Retrieves the component values of this <code>ColorRGBA</code> as an
* Retrieves the component values of this <code>ColorRGBA</code> as an
* <code>int</code> in a,b,g,r order.
* Bits 24-31 are alpha, 16-23 are blue, 8-15 are green, 0-7 are red.
*
* @return The integer representation of this <code>ColorRGBA</code> in a,b,g,r order.
*/
public int asIntABGR() {
@ -553,10 +578,12 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
| (((int) (r * 255) & 0xFF));
return abgr;
}
/**
* Sets the component values of this <code>ColorRGBA</code> with the given
* Sets the component values of this <code>ColorRGBA</code> with the given
* combined ARGB <code>int</code>.
* Bits 24-31 are alpha, bits 16-23 are red, bits 8-15 are green, bits 0-7 are blue.
*
* @param color The integer ARGB value used to set this <code>ColorRGBA</code>.
* @return this
*/
@ -567,9 +594,11 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
b = ((byte) (color) & 0xFF) / 255f;
return this;
}
/**
* Sets the RGBA values of this <code>ColorRGBA</code> with the given combined RGBA value
* Sets the RGBA values of this <code>ColorRGBA</code> with the given combined RGBA value
* Bits 24-31 are red, bits 16-23 are green, bits 8-15 are blue, bits 0-7 are alpha.
*
* @param color The integer RGBA value used to set this object.
* @return this
*/
@ -580,9 +609,11 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
a = ((byte) (color) & 0xFF) / 255f;
return this;
}
/**
* Sets the RGBA values of this <code>ColorRGBA</code> with the given combined ABGR value
* Sets the RGBA values of this <code>ColorRGBA</code> with the given combined ABGR value
* Bits 24-31 are alpha, bits 16-23 are blue, bits 8-15 are green, bits 0-7 are red.
*
* @param color The integer ABGR value used to set this object.
* @return this
*/
@ -598,6 +629,7 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
* Transform this <code>ColorRGBA</code> to a <code>Vector3f</code> using
* x = r, y = g, z = b. The Alpha value is not used.
* This method is useful for shader assignments.
*
* @return A <code>Vector3f</code> containing the RGB value of this <code>ColorRGBA</code>.
*/
public Vector3f toVector3f() {
@ -608,53 +640,54 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
* Transform this <code>ColorRGBA</code> to a <code>Vector4f</code> using
* x = r, y = g, z = b, w = a.
* This method is useful for shader assignments.
*
* @return A <code>Vector4f</code> containing the RGBA value of this <code>ColorRGBA</code>.
*/
public Vector4f toVector4f() {
return new Vector4f(r, g, b, a);
}
/**
* Sets the rgba channels of this color in sRGB color space.
* You probably want to use this method if the color is picked by the use
* in a color picker from a GUI.
*
*
* Note that the values will be gamma corrected to be stored in linear space
* GAMMA value is 2.2
*
*
* Note that no correction will be performed on the alpha channel as it
* conventionally doesn't represent a color itself
*
*
* @param r the red value in sRGB color space
* @param g the green value in sRGB color space
* @param b the blue value in sRGB color space
* @param a the alpha value
*
* @param a the alpha value
*
* @return this ColorRGBA with updated values.
*/
public ColorRGBA setAsSrgb(float r, float g, float b, float a){
this.r = (float)Math.pow(r, GAMMA);
this.b = (float)Math.pow(b, GAMMA);
this.g = (float)Math.pow(g, GAMMA);
public ColorRGBA setAsSrgb(float r, float g, float b, float a) {
this.r = (float) Math.pow(r, GAMMA);
this.b = (float) Math.pow(b, GAMMA);
this.g = (float) Math.pow(g, GAMMA);
this.a = a;
return this;
}
/**
* Get the color in sRGB color space as a <code>ColorRGBA</code>.
*
* Note that linear values stored in the ColorRGBA will be gamma corrected
*
* Note that linear values stored in the ColorRGBA will be gamma corrected
* and returned as a ColorRGBA.
*
*
* The x attribute will be fed with the r channel in sRGB space.
* The y attribute will be fed with the g channel in sRGB space.
* The z attribute will be fed with the b channel in sRGB space.
* The w attribute will be fed with the a channel.
*
* Note that no correction will be performed on the alpha channel as it
*
* Note that no correction will be performed on the alpha channel as it
* conventionally doesn't represent a color itself.
*
*
* @return the color in sRGB color space as a ColorRGBA.
*/
public ColorRGBA getAsSrgb() {
@ -666,5 +699,4 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
srgb.a = a;
return srgb;
}
}

@ -4,7 +4,6 @@ package com.jme3.math;
* Created by Nehon on 26/03/2017.
*/
public interface EaseFunction {
/**
* @param value a value from 0 to 1. Passing a value out of this range will have unexpected behavior.
* @return the blended value

@ -5,8 +5,6 @@ package com.jme3.math;
* Created by Nehon on 26/03/2017.
*/
public class Easing {
/**
* a function that always returns 0
*/
@ -66,7 +64,6 @@ public class Easing {
}
};
/**
* Out Elastic and bounce
*/
@ -122,11 +119,9 @@ public class Easing {
public static EaseFunction inOutElastic = new InOut(inElastic, outElastic);
public static EaseFunction inOutBounce = new InOut(inBounce, outBounce);
/**
* Extra functions
*/
public static EaseFunction smoothStep = new EaseFunction() {
@Override
public float apply(float t) {
@ -185,6 +180,4 @@ public class Easing {
return 1f - func.apply(1f - value);
}
}
}

@ -35,12 +35,11 @@ import java.util.logging.Level;
import java.util.logging.Logger;
/**
* A calculator for the eigenvectors and eigenvalues of a Matrix3f.
* A calculator for the eigenvectors and eigenvalues of a Matrix3f.
*/
public class Eigen3f implements java.io.Serializable {
static final long serialVersionUID = 1;
private static final Logger logger = Logger.getLogger(Eigen3f.class
.getName());
@ -50,14 +49,13 @@ public class Eigen3f implements java.io.Serializable {
static final double ONE_THIRD_DOUBLE = 1.0 / 3.0;
static final double ROOT_THREE_DOUBLE = Math.sqrt(3.0);
/**
* Instantiate an empty calculator.
*/
public Eigen3f() {
}
/**
* Calculate the eigenvalues and eigenvectors of the specified matrix.
*
@ -93,7 +91,7 @@ public class Eigen3f implements java.io.Serializable {
maxRows[0] = new Vector3f();
maxRows[1] = new Vector3f();
maxRows[2] = new Vector3f();
for (int i = 0; i < 3; i++) {
Matrix3f tempMatrix = new Matrix3f(scaledData);
tempMatrix.m00 -= eigenValues[i];
@ -155,7 +153,7 @@ public class Eigen3f implements java.io.Serializable {
/**
* Scale the matrix so its entries are in [-1,1]. The scaling is applied
* only when at least one matrix entry has magnitude larger than 1.
*
*
* @return the max magnitude in this matrix
*/
private float scaleMatrix(Matrix3f mat) {
@ -192,7 +190,8 @@ public class Eigen3f implements java.io.Serializable {
}
/**
* Compute the eigenvectors of the given Matrix, using the
* Compute the eigenvectors of the given Matrix, using the
*
* @param mat
* @param vect
* @param index1
@ -280,14 +279,14 @@ public class Eigen3f implements java.io.Serializable {
}
}
eigenVectors[index3].cross(eigenVectors[index1], eigenVectors[index2]);
eigenVectors[index3].cross(eigenVectors[index1], eigenVectors[index2]);
}
/**
* Check the rank of the given Matrix to determine if it is positive. While
* doing so, store the max magnitude entry in the given float store and the
* max row of the matrix in the Vector store.
*
*
* @param matrix
* the Matrix3f to analyze.
* @param maxMagnitudeStore
@ -322,7 +321,7 @@ public class Eigen3f implements java.io.Serializable {
/**
* Generate the base eigen values of the given matrix using double precision
* math.
*
*
* @param mat
* the Matrix3f to analyze.
* @param rootsStore
@ -396,7 +395,7 @@ public class Eigen3f implements java.io.Serializable {
/**
* Test the Eigen3f class.
*
*
* @param args ignored
*/
public static void main(String[] args) {
@ -404,8 +403,9 @@ public class Eigen3f implements java.io.Serializable {
Eigen3f eigenSystem = new Eigen3f(mat);
logger.info("eigenvalues = ");
for (int i = 0; i < 3; i++)
for (int i = 0; i < 3; i++) {
logger.log(Level.FINE, "{0} ", eigenSystem.getEigenValue(i));
}
logger.info("eigenvectors = ");
for (int i = 0; i < 3; i++) {
@ -425,7 +425,7 @@ public class Eigen3f implements java.io.Serializable {
/**
* Read the indexed eigenvalue.
*
*
* @param i which value to read (0, 1, or 2)
* @return the previously calculated eigenvalue
*/
@ -435,7 +435,7 @@ public class Eigen3f implements java.io.Serializable {
/**
* Access the indexed eigenvector.
*
*
* @param i which vector to read (0, 1, or 2)
* @return the pre-existing eigenvector
*/
@ -445,7 +445,7 @@ public class Eigen3f implements java.io.Serializable {
/**
* Access the array of eigenvalues.
*
*
* @return the pre-existing array
*/
public float[] getEigenValues() {
@ -454,7 +454,7 @@ public class Eigen3f implements java.io.Serializable {
/**
* Access the array of eigenvectors.
*
*
* @return the pre-existing array of vectors
*/
public Vector3f[] getEigenVectors() {

@ -267,6 +267,7 @@ final public class FastMath {
* [-T 2-T T-2 T ]
* where T is the curve tension
* the result is a value between p1 and p2, t=0 for p1, t=1 for p2
*
* @param u value from 0 to 1
* @param T The tension of the curve
* @param p0 control point 0
@ -294,6 +295,7 @@ final public class FastMath {
* [-T 2-T T-2 T ]
* where T is the tension of the curve
* the result is a value between p1 and p2, t=0 for p1, t=1 for p2
*
* @param u value from 0 to 1
* @param T The tension of the curve
* @param p0 control point 0
@ -323,6 +325,7 @@ final public class FastMath {
* [-T 2-T T-2 T ]
* where T is the tension of the curve
* the result is a value between p1 and p2, t=0 for p1, t=1 for p2
*
* @param u value from 0 to 1
* @param T The tension of the curve
* @param p0 control point 0
@ -344,6 +347,7 @@ final public class FastMath {
* [ 1.0 0.0 0.0 0.0 ]
* where T is the curve tension
* the result is a value between p1 and p3, t=0 for p1, t=1 for p3
*
* @param u value from 0 to 1
* @param p0 control point 0
* @param p1 control point 1
@ -370,6 +374,7 @@ final public class FastMath {
* [ 1.0 0.0 0.0 0.0 ]
* where T is the tension of the curve
* the result is a value between p1 and p3, t=0 for p1, t=1 for p3
*
* @param u value from 0 to 1
* @param p0 control point 0
* @param p1 control point 1
@ -398,6 +403,7 @@ final public class FastMath {
* [ 1.0 0.0 0.0 0.0 ]
* where T is the tension of the curve
* the result is a value between p1 and p3, t=0 for p1, t=1 for p3
*
* @param u value from 0 to 1
* @param p0 control point 0
* @param p1 control point 1
@ -1001,10 +1007,8 @@ final public class FastMath {
}
/**
* @param x
* the value whose sign is to be adjusted.
* @param y
* the value whose sign is to be used.
* @param x the value whose sign is to be adjusted.
* @param y the value whose sign is to be used.
* @return x with its sign changed to match the sign of y.
*/
public static float copysign(float x, float y) {

@ -40,12 +40,11 @@ import java.nio.FloatBuffer;
/**
* <code>Line</code> defines a line. Where a line is defined as infinite along
* two points. The two points of the line are defined as the origin and direction.
*
*
* @author Mark Powell
* @author Joshua Slack
*/
public class Line implements Savable, Cloneable, java.io.Serializable {
static final long serialVersionUID = 1;
private Vector3f origin;
@ -64,6 +63,7 @@ public class Line implements Savable, Cloneable, java.io.Serializable {
/**
* Constructor instantiates a new <code>Line</code> object. The origin
* and direction are set via the parameters.
*
* @param origin the origin of the line.
* @param direction the direction of the line.
*/
@ -73,8 +73,8 @@ public class Line implements Savable, Cloneable, java.io.Serializable {
}
/**
*
* <code>getOrigin</code> returns the origin of the line.
*
* @return the origin of the line.
*/
public Vector3f getOrigin() {
@ -82,8 +82,8 @@ public class Line implements Savable, Cloneable, java.io.Serializable {
}
/**
*
* <code>setOrigin</code> sets the origin of the line.
*
* @param origin the origin of the line.
*/
public void setOrigin(Vector3f origin) {
@ -91,8 +91,8 @@ public class Line implements Savable, Cloneable, java.io.Serializable {
}
/**
*
* <code>getDirection</code> returns the direction of the line.
*
* @return the direction of the line.
*/
public Vector3f getDirection() {
@ -100,8 +100,8 @@ public class Line implements Savable, Cloneable, java.io.Serializable {
}
/**
*
* <code>setDirection</code> sets the direction of the line.
*
* @param direction the direction of the line.
*/
public void setDirection(Vector3f direction) {
@ -203,8 +203,8 @@ public class Line implements Savable, Cloneable, java.io.Serializable {
}
/**
*
* <code>random</code> determines a random point along the line.
*
* @return a random point on the line.
*/
public Vector3f random() {
@ -213,7 +213,7 @@ public class Line implements Savable, Cloneable, java.io.Serializable {
/**
* <code>random</code> determines a random point along the line.
*
*
* @param result Vector to store result in
* @return a random point on the line.
*/

@ -50,7 +50,6 @@ import java.io.IOException;
* @author Joshua Slack
*/
public class LineSegment implements Cloneable, Savable, java.io.Serializable {
static final long serialVersionUID = 1;
private Vector3f origin;
@ -650,7 +649,7 @@ public class LineSegment implements Cloneable, Savable, java.io.Serializable {
/**
* Determine the location of this segment's positive end.
*
*
* @param store storage for the result (modified if not null)
* @return a location vector (either store or a new vector)
*/
@ -663,7 +662,7 @@ public class LineSegment implements Cloneable, Savable, java.io.Serializable {
/**
* Determine the location of this segment's negative end.
*
*
* @param store storage for the result (modified if not null)
* @return a location vector (either store or a new vector)
*/
@ -724,7 +723,7 @@ public class LineSegment implements Cloneable, Savable, java.io.Serializable {
/**
* <p>Evaluates whether a given point is contained within the axis aligned bounding box
* that contains this LineSegment.</p><p>This function is float error aware.</p>
*
*
* @param point the location of the input point (not null, unaffected)
* @return true if contained in the box, otherwise false
*/
@ -736,13 +735,12 @@ public class LineSegment implements Cloneable, Savable, java.io.Serializable {
* <p>Evaluates whether a given point is contained within the axis aligned bounding box
* that contains this LineSegment.</p><p>This function accepts an error parameter, which
* is added to the extent of the bounding box.</p>
*
*
* @param point the location of the input point (not null, unaffected)
* @param error the desired margin for error
* @return true if contained in the box, otherwise false
*/
public boolean isPointInsideBounds(Vector3f point, float error) {
if (FastMath.abs(point.x - origin.x) > FastMath.abs(direction.x * extent) + error) {
return false;
}

@ -7,7 +7,6 @@ import com.jme3.util.TempVars;
* Created by Nehon on 23/04/2017.
*/
public class MathUtils {
/**
* Calculate the natural logarithm of a unit quaternion.
*
@ -157,7 +156,6 @@ public class MathUtils {
private static Quaternion spline(Quaternion qnm1, Quaternion qn, Quaternion qnp1, Quaternion store, Quaternion tmp) {
Quaternion invQn = new Quaternion(-qn.x, -qn.y, -qn.z, qn.w);
log(invQn.mult(qnp1), tmp);
log(invQn.mult(qnm1), store);
store.addLocal(tmp).multLocal(-1f / 4f);
@ -168,7 +166,6 @@ public class MathUtils {
//return qn * (((qni * qnm1).log() + (qni * qnp1).log()) / -4).exp();
}
//! spherical cubic interpolation
public static Quaternion squad(Quaternion q0, Quaternion q1, Quaternion q2, Quaternion q3, Quaternion a, Quaternion b, float t, Quaternion store) {
@ -187,7 +184,6 @@ public class MathUtils {
// return slerpNoInvert(c, d, 2 * t * (1 - t));
}
/**
* Returns the shortest distance between a Ray and a segment.
* The segment is defined by a start position and an end position in world space
@ -266,5 +262,4 @@ public class MathUtils {
vars.release();
return length;
}
}

@ -120,7 +120,6 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
*/
public Matrix3f(float m00, float m01, float m02, float m10, float m11,
float m12, float m20, float m21, float m22) {
this.m00 = m00;
this.m01 = m01;
this.m02 = m02;
@ -304,7 +303,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
}
float mag = 1.0f / FastMath.sqrt(
m00 * m00
m00 * m00
+ m10 * m10
+ m20 * m20);
@ -313,7 +312,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
store.m20 = m20 * mag;
mag = 1.0f / FastMath.sqrt(
m01 * m01
m01 * m01
+ m11 * m11
+ m21 * m21);
@ -340,8 +339,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
* <code>getColumn</code> returns one of three columns specified by the
* parameter. This column is returned as a <code>Vector3f</code> object.
*
* @param i
* the column to retrieve. Must be between 0 and 2.
* @param i the column to retrieve. Must be between 0 and 2.
* @return the column specified by the index.
*/
public Vector3f getColumn(int i) {
@ -352,8 +350,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
* <code>getColumn</code> returns one of three columns specified by the
* parameter. This column is returned as a <code>Vector3f</code> object.
*
* @param i
* the column to retrieve. Must be between 0 and 2.
* @param i the column to retrieve. Must be between 0 and 2.
* @param store
* the vector object to store the result in. if null, a new one
* is created.
@ -390,8 +387,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
* <code>getColumn</code> returns one of three rows as specified by the
* parameter. This row is returned as a <code>Vector3f</code> object.
*
* @param i
* the row to retrieve. Must be between 0 and 2.
* @param i the row to retrieve. Must be between 0 and 2.
* @return the row specified by the index.
*/
public Vector3f getRow(int i) {
@ -402,8 +398,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
* <code>getRow</code> returns one of three rows as specified by the
* parameter. This row is returned as a <code>Vector3f</code> object.
*
* @param i
* the row to retrieve. Must be between 0 and 2.
* @param i the row to retrieve. Must be between 0 and 2.
* @param store
* the vector object to store the result in. if null, a new one
* is created.
@ -520,14 +515,12 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
* <code>setColumn</code> sets a particular column of this matrix to that
* represented by the provided vector.
*
* @param i
* the column to set.
* @param i the column to set.
* @param column
* the data to set.
* @return this
*/
public Matrix3f setColumn(int i, Vector3f column) {
if (column == null) {
logger.warning("Column is null. Ignoring.");
return this;
@ -559,14 +552,12 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
* <code>setRow</code> sets a particular row of this matrix to that
* represented by the provided vector.
*
* @param i
* the row to set.
* @param i the row to set.
* @param row
* the data to set.
* @return this
*/
public Matrix3f setRow(int i, Vector3f row) {
if (row == null) {
logger.warning("Row is null. Ignoring.");
return this;
@ -598,10 +589,8 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
* <code>set</code> places a given value into the matrix at the given
* position.
*
* @param i
* the row index.
* @param j
* the column index.
* @param i the row index.
* @param j the column index.
* @param value
* the value for (i, j).
* @return this
@ -858,7 +847,6 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
* @return a matrix3f object containing the result of this operation
*/
public Matrix3f mult(Matrix3f mat, Matrix3f product) {
float temp00, temp01, temp02;
float temp10, temp11, temp12;
float temp20, temp21, temp22;
@ -914,7 +902,6 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
* @return The given product vector.
*/
public Vector3f mult(Vector3f vec, Vector3f product) {
if (null == product) {
product = new Vector3f();
}
@ -1230,8 +1217,7 @@ public final class Matrix3f implements Savable, Cloneable, java.io.Serializable
/**
* are these two matrices the same? they are is they both have the same mXX values.
*
* @param o
* the object to compare for equality
* @param o the object to compare for equality
* @return true if they are equal
*/
@Override

@ -55,7 +55,6 @@ import java.util.logging.Logger;
* @author Joshua Slack
*/
public final class Matrix4f implements Savable, Cloneable, java.io.Serializable {
static final long serialVersionUID = 1;
private static final Logger logger = Logger.getLogger(Matrix4f.class.getName());
@ -1940,12 +1939,9 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
/**
* Sets the scale.
*
* @param x
* the X scale
* @param y
* the Y scale
* @param z
* the Z scale
* @param x the X scale
* @param y the Y scale
* @param z the Z scale
*/
public void setScale(float x, float y, float z) {
@ -2324,8 +2320,7 @@ public final class Matrix4f implements Savable, Cloneable, java.io.Serializable
/**
* are these two matrices the same? they are is they both have the same mXX values.
*
* @param o
* the object to compare for equality
* @param o the object to compare for equality
* @return true if they are equal
*/
@Override

@ -309,8 +309,8 @@ public class Plane implements Savable, Cloneable, java.io.Serializable {
}
/**
* De-serialize this plane from the specified importer, for example
* when loading from a J3O file.
* De-serialize this plane from the specified importer, for example when
* loading from a J3O file.
*
* @param e (not null)
* @throws IOException from the importer

@ -602,8 +602,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
* by the parameter. This column is returned as a <code>Vector3f</code>
* object.
*
* @param i
* the column to retrieve. Must be between 0 and 2.
* @param i the column to retrieve. Must be between 0 and 2.
* @return the column specified by the index.
*/
public Vector3f getRotationColumn(int i) {
@ -615,8 +614,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
* by the parameter. This column is returned as a <code>Vector3f</code>
* object. The value is retrieved as if this quaternion was first normalized.
*
* @param i
* the column to retrieve. Must be between 0 and 2.
* @param i the column to retrieve. Must be between 0 and 2.
* @param store
* the vector object to store the result in. if null, a new one
* is created.
@ -748,8 +746,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
* the first quaternion.
* @param q2
* the second quaternion.
* @param t
* the amount to interpolate between the two quaternions.
* @param t the amount to interpolate between the two quaternions.
* @return this
*/
public Quaternion slerp(Quaternion q1, Quaternion q2, float t) {
@ -935,8 +932,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
* The result is returned as a new quaternion. It should be noted that
* quaternion multiplication is not commutative so q * p != p * q.
*
* @param q
* the quaternion to multiply this quaternion by.
* @param q the quaternion to multiply this quaternion by.
* @return the new quaternion.
*/
public Quaternion mult(Quaternion q) {
@ -1178,8 +1174,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
* <code>dot</code> calculates and returns the dot product of this
* quaternion with that of the parameter quaternion.
*
* @param q
* the quaternion to calculate the dot product of.
* @param q the quaternion to calculate the dot product of.
* @return the dot product of this and the parameter quaternion.
*/
public float dot(Quaternion q) {
@ -1292,8 +1287,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
* <code>equals</code> determines if two quaternions are logically equal,
* that is, if the values of (x, y, z, w) are the same for both quaternions.
*
* @param o
* the object to compare for equality
* @param o the object to compare for equality
* @return true if they are equal, false otherwise.
*/
@Override
@ -1469,6 +1463,7 @@ public final class Quaternion implements Savable, Cloneable, java.io.Serializabl
/**
* FIXME: This seems to have singularity type issues with angle == 0, possibly others such as PI.
*
* @param store
* A Quaternion to store our result in. If null, a new one is
* created.

@ -46,23 +46,20 @@ import java.io.IOException;
* defined by the following equation: {@literal
* R(t) = origin + t*direction for t >= 0.
* }
*
* @author Mark Powell
* @author Joshua Slack
*/
public final class Ray implements Savable, Cloneable, Collidable, java.io.Serializable {
static final long serialVersionUID = 1;
/**
* The ray's beginning point.
/**
* The ray's beginning point.
*/
public Vector3f origin = new Vector3f();
/**
* The direction of the ray.
/**
* The direction of the ray.
*/
public Vector3f direction = new Vector3f(0, 0, 1);
/**
* The length of the ray (defaults to +Infinity).
*/
@ -79,6 +76,7 @@ public final class Ray implements Savable, Cloneable, Collidable, java.io.Serial
/**
* Constructor instantiates a new <code>Ray</code> object. The origin and
* direction are given.
*
* @param origin the origin of the ray.
* @param direction the direction the ray travels in.
*/
@ -87,15 +85,17 @@ public final class Ray implements Savable, Cloneable, Collidable, java.io.Serial
setDirection(direction);
}
/**
/*
* <code>intersect</code> determines if the Ray intersects a triangle.
*
* @param t the Triangle to test against.
* @return true if the ray collides.
*/
// public boolean intersect(Triangle t) {
// return intersect(t.get(0), t.get(1), t.get(2));
// }
/**
/*
* <code>intersect</code> determines if the Ray intersects a triangle
* defined by the specified points.
*
@ -110,13 +110,14 @@ public final class Ray implements Savable, Cloneable, Collidable, java.io.Serial
// public boolean intersect(Vector3f v0,Vector3f v1,Vector3f v2){
// return intersectWhere(v0, v1, v2, null);
// }
/**
* <code>intersectWhere</code> determines if the Ray intersects a triangle. It then
* stores the point of intersection in the given loc vector
* <code>intersectWhere</code> determines if the Ray intersects a triangle.
* It then stores the point of intersection in the given loc vector
*
* @param t the Triangle to test against.
* @param loc
* storage vector to save the collision point in (if the ray
* collides)
* @param loc storage vector to save the collision point in (if the ray
* collides)
* @return true if the ray collides.
*/
public boolean intersectWhere(Triangle t, Vector3f loc) {
@ -363,7 +364,6 @@ public final class Ray implements Savable, Cloneable, Collidable, java.io.Serial
}
/**
*
* @param p
* @param loc
* @return true if the ray collides with the given Plane
@ -437,8 +437,8 @@ public final class Ray implements Savable, Cloneable, Collidable, java.io.Serial
}
/**
*
* <code>setOrigin</code> sets the origin of the ray.
*
* @param origin the origin of the ray.
*/
public void setOrigin(Vector3f origin) {
@ -449,7 +449,7 @@ public final class Ray implements Savable, Cloneable, Collidable, java.io.Serial
* <code>getLimit</code> returns the limit of the ray, aka the length.
* If the limit is not infinity, then this ray is a line with length <code>
* limit</code>.
*
*
* @return the limit of the ray, aka the length.
*/
public float getLimit() {
@ -458,16 +458,17 @@ public final class Ray implements Savable, Cloneable, Collidable, java.io.Serial
/**
* <code>setLimit</code> sets the limit of the ray.
*
* @param limit the limit of the ray.
* @see Ray#getLimit()
* @see Ray#getLimit()
*/
public void setLimit(float limit) {
this.limit = limit;
}
/**
*
* <code>getDirection</code> retrieves the direction vector of the ray.
*
* @return the direction of the ray.
*/
public Vector3f getDirection() {
@ -475,8 +476,8 @@ public final class Ray implements Savable, Cloneable, Collidable, java.io.Serial
}
/**
*
* <code>setDirection</code> sets the direction vector of the ray.
*
* @param direction the direction of the ray.
*/
public void setDirection(Vector3f direction) {
@ -486,7 +487,7 @@ public final class Ray implements Savable, Cloneable, Collidable, java.io.Serial
/**
* Copies information from a source ray into this ray.
*
*
* @param source
* the ray to copy information from
*/

@ -34,19 +34,15 @@ package com.jme3.math;
import com.jme3.export.*;
import java.io.IOException;
/**
*
* <code>Rectangle</code> defines a finite plane within three dimensional space
* that is specified via three points (A, B, C). These three points define a
* triangle with the fourth point defining the rectangle ((B + C) - A.
*
*
* @author Mark Powell
* @author Joshua Slack
*/
public final class Rectangle implements Savable, Cloneable, java.io.Serializable {
static final long serialVersionUID = 1;
private Vector3f a, b, c;
@ -54,7 +50,6 @@ public final class Rectangle implements Savable, Cloneable, java.io.Serializable
/**
* Constructor creates a new <code>Rectangle</code> with no defined corners.
* A, B, and C must be set to define a valid rectangle.
*
*/
public Rectangle() {
a = new Vector3f();
@ -65,13 +60,10 @@ public final class Rectangle implements Savable, Cloneable, java.io.Serializable
/**
* Constructor creates a new <code>Rectangle</code> with defined A, B, and C
* points that define the area of the rectangle.
*
* @param a
* the first corner of the rectangle.
* @param b
* the second corner of the rectangle.
* @param c
* the third corner of the rectangle.
*
* @param a the first corner of the rectangle.
* @param b the second corner of the rectangle.
* @param c the third corner of the rectangle.
*/
public Rectangle(Vector3f a, Vector3f b, Vector3f c) {
this.a = a;
@ -81,7 +73,7 @@ public final class Rectangle implements Savable, Cloneable, java.io.Serializable
/**
* <code>getA</code> returns the first point of the rectangle.
*
*
* @return the first point of the rectangle.
*/
public Vector3f getA() {
@ -90,9 +82,8 @@ public final class Rectangle implements Savable, Cloneable, java.io.Serializable
/**
* <code>setA</code> sets the first point of the rectangle.
*
* @param a
* the first point of the rectangle.
*
* @param a the first point of the rectangle.
*/
public void setA(Vector3f a) {
this.a = a;
@ -100,7 +91,7 @@ public final class Rectangle implements Savable, Cloneable, java.io.Serializable
/**
* <code>getB</code> returns the second point of the rectangle.
*
*
* @return the second point of the rectangle.
*/
public Vector3f getB() {
@ -109,9 +100,8 @@ public final class Rectangle implements Savable, Cloneable, java.io.Serializable
/**
* <code>setB</code> sets the second point of the rectangle.
*
* @param b
* the second point of the rectangle.
*
* @param b the second point of the rectangle.
*/
public void setB(Vector3f b) {
this.b = b;
@ -119,7 +109,7 @@ public final class Rectangle implements Savable, Cloneable, java.io.Serializable
/**
* <code>getC</code> returns the third point of the rectangle.
*
*
* @return the third point of the rectangle.
*/
public Vector3f getC() {
@ -128,9 +118,8 @@ public final class Rectangle implements Savable, Cloneable, java.io.Serializable
/**
* <code>setC</code> sets the third point of the rectangle.
*
* @param c
* the third point of the rectangle.
*
* @param c the third point of the rectangle.
*/
public void setC(Vector3f c) {
this.c = c;
@ -139,7 +128,7 @@ public final class Rectangle implements Savable, Cloneable, java.io.Serializable
/**
* <code>random</code> returns a random point within the plane defined by:
* A, B, C, and (B + C) - A.
*
*
* @return a random point within the rectangle.
*/
public Vector3f random() {
@ -149,7 +138,7 @@ public final class Rectangle implements Savable, Cloneable, java.io.Serializable
/**
* <code>random</code> returns a random point within the plane defined by:
* A, B, C, and (B + C) - A.
*
*
* @param result
* Vector to store result in
* @return a random point within the rectangle.

@ -34,20 +34,17 @@ package com.jme3.math;
import com.jme3.export.*;
import java.io.IOException;
/**
* <code>Ring</code> defines a flat ring or disk within three dimensional
* space that is specified via the ring's center point, an up vector, an inner
* radius, and an outer radius.
*
*
* @author Andrzej Kapolka
* @author Joshua Slack
*/
public final class Ring implements Savable, Cloneable, java.io.Serializable {
static final long serialVersionUID = 1;
private Vector3f center, up;
private float innerRadius, outerRadius;
private transient static Vector3f b1 = new Vector3f(), b2 = new Vector3f();
@ -67,7 +64,7 @@ public final class Ring implements Savable, Cloneable, java.io.Serializable {
/**
* Constructor creates a new <code>Ring</code> with defined center point,
* up vector, and inner and outer radii.
*
*
* @param center
* the center of the ring.
* @param up
@ -87,7 +84,7 @@ public final class Ring implements Savable, Cloneable, java.io.Serializable {
/**
* <code>getCenter</code> returns the center of the ring.
*
*
* @return the center of the ring.
*/
public Vector3f getCenter() {
@ -96,7 +93,7 @@ public final class Ring implements Savable, Cloneable, java.io.Serializable {
/**
* <code>setCenter</code> sets the center of the ring.
*
*
* @param center
* the center of the ring.
*/
@ -106,7 +103,7 @@ public final class Ring implements Savable, Cloneable, java.io.Serializable {
/**
* <code>getUp</code> returns the ring's up vector.
*
*
* @return the ring's up vector.
*/
public Vector3f getUp() {
@ -115,7 +112,7 @@ public final class Ring implements Savable, Cloneable, java.io.Serializable {
/**
* <code>setUp</code> sets the ring's up vector.
*
*
* @param up
* the ring's up vector.
*/
@ -125,7 +122,7 @@ public final class Ring implements Savable, Cloneable, java.io.Serializable {
/**
* <code>getInnerRadius</code> returns the ring's inner radius.
*
*
* @return the ring's inner radius.
*/
public float getInnerRadius() {
@ -134,7 +131,7 @@ public final class Ring implements Savable, Cloneable, java.io.Serializable {
/**
* <code>setInnerRadius</code> sets the ring's inner radius.
*
*
* @param innerRadius
* the ring's inner radius.
*/
@ -144,7 +141,7 @@ public final class Ring implements Savable, Cloneable, java.io.Serializable {
/**
* <code>getOuterRadius</code> returns the ring's outer radius.
*
*
* @return the ring's outer radius.
*/
public float getOuterRadius() {
@ -153,7 +150,7 @@ public final class Ring implements Savable, Cloneable, java.io.Serializable {
/**
* <code>setOuterRadius</code> sets the ring's outer radius.
*
*
* @param outerRadius
* the ring's outer radius.
*/
@ -162,9 +159,8 @@ public final class Ring implements Savable, Cloneable, java.io.Serializable {
}
/**
*
* <code>random</code> returns a random point within the ring.
*
*
* @return a random point within the ring.
*/
public Vector3f random() {
@ -172,9 +168,8 @@ public final class Ring implements Savable, Cloneable, java.io.Serializable {
}
/**
*
* <code>random</code> returns a random point within the ring.
*
*
* @param result Vector to store result in
* @return a random point within the ring.
*/
@ -182,13 +177,12 @@ public final class Ring implements Savable, Cloneable, java.io.Serializable {
if (result == null) {
result = new Vector3f();
}
// compute a random radius according to the ring area distribution
float inner2 = innerRadius * innerRadius, outer2 = outerRadius
* outerRadius, r = FastMath.sqrt(inner2
+ FastMath.nextRandomFloat() * (outer2 - inner2)), theta = FastMath
.nextRandomFloat()
* FastMath.TWO_PI;
float inner2 = innerRadius * innerRadius,
outer2 = outerRadius * outerRadius,
r = FastMath.sqrt(inner2 + FastMath.nextRandomFloat() * (outer2 - inner2)),
theta = FastMath.nextRandomFloat() * FastMath.TWO_PI;
up.cross(Vector3f.UNIT_X, b1);
if (b1.lengthSquared() < FastMath.FLT_EPSILON) {
up.cross(Vector3f.UNIT_Y, b1);
@ -212,10 +206,8 @@ public final class Ring implements Savable, Cloneable, java.io.Serializable {
@Override
public void read(JmeImporter e) throws IOException {
InputCapsule capsule = e.getCapsule(this);
center = (Vector3f) capsule.readSavable("center",
Vector3f.ZERO.clone());
up = (Vector3f) capsule
.readSavable("up", Vector3f.UNIT_Z.clone());
center = (Vector3f) capsule.readSavable("center", Vector3f.ZERO.clone());
up = (Vector3f) capsule.readSavable("up", Vector3f.UNIT_Z.clone());
innerRadius = capsule.readFloat("innerRadius", 0f);
outerRadius = capsule.readFloat("outerRadius", 1f);
}
@ -231,4 +223,4 @@ public final class Ring implements Savable, Cloneable, java.io.Serializable {
throw new AssertionError();
}
}
}
}

@ -388,7 +388,7 @@ public class Spline implements Savable {
/**
* returns this spline control points
*
*
* @return the pre-existing list
*/
public List<Vector3f> getControlPoints() {

@ -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
@ -40,12 +40,11 @@ import java.io.IOException;
* <code>Triangle</code> defines an object for containing triangle information.
* The triangle is defined by a collection of three {@link Vector3f}
* objects.
*
*
* @author Mark Powell
* @author Joshua Slack
*/
public class Triangle extends AbstractTriangle implements Savable, Cloneable, java.io.Serializable {
static final long serialVersionUID = 1;
private Vector3f pointa = new Vector3f();
@ -67,6 +66,7 @@ public class Triangle extends AbstractTriangle implements Savable, Cloneable, ja
* supplied vectors as the points. It is recommended that the vertices
* be supplied in a counter clockwise winding to support normals for a
* right handed coordinate system.
*
* @param p1 the first point of the triangle.
* @param p2 the second point of the triangle.
* @param p3 the third point of the triangle.
@ -230,8 +230,7 @@ public class Triangle extends AbstractTriangle implements Savable, Cloneable, ja
}
/**
* calculateCenter finds the average point of the triangle.
*
* calculateCenter finds the average point of the triangle.
*/
public void calculateCenter() {
if (center == null) {
@ -258,6 +257,7 @@ public class Triangle extends AbstractTriangle implements Savable, Cloneable, ja
/**
* obtains the center point of this triangle (average of the three triangles)
*
* @return the center point.
*/
public Vector3f getCenter() {
@ -269,6 +269,7 @@ public class Triangle extends AbstractTriangle implements Savable, Cloneable, ja
/**
* sets the center point of this triangle (average of the three triangles)
*
* @param center the center point.
*/
public void setCenter(Vector3f center) {
@ -278,7 +279,7 @@ public class Triangle extends AbstractTriangle implements Savable, Cloneable, ja
/**
* obtains the unit length normal vector of this triangle, if set or
* calculated
*
*
* @return the normal vector
*/
public Vector3f getNormal() {
@ -290,6 +291,7 @@ public class Triangle extends AbstractTriangle implements Savable, Cloneable, ja
/**
* sets the normal vector of this triangle (to conform, must be unit length)
*
* @param normal the normal vector.
*/
public void setNormal(Vector3f normal) {
@ -298,6 +300,7 @@ public class Triangle extends AbstractTriangle implements Savable, Cloneable, ja
/**
* obtains the projection of the vertices relative to the line origin.
*
* @return the projection of the triangle.
*/
public float getProjection() {
@ -306,6 +309,7 @@ public class Triangle extends AbstractTriangle implements Savable, Cloneable, ja
/**
* sets the projection of the vertices relative to the line origin.
*
* @param projection the projection of the triangle.
*/
public void setProjection(float projection) {
@ -314,6 +318,7 @@ public class Triangle extends AbstractTriangle implements Savable, Cloneable, ja
/**
* obtains an index that this triangle represents if it is contained in a OBBTree.
*
* @return the index in an OBBtree
*/
public int getIndex() {
@ -322,6 +327,7 @@ public class Triangle extends AbstractTriangle implements Savable, Cloneable, ja
/**
* sets an index that this triangle represents if it is contained in a OBBTree.
*
* @param index the index in an OBBtree
*/
public void setIndex(int index) {

@ -39,18 +39,16 @@ import java.util.logging.Logger;
/**
* <code>Vector2f</code> defines a Vector for a two float value vector.
*
*
* @author Mark Powell
* @author Joshua Slack
*/
public final class Vector2f implements Savable, Cloneable, java.io.Serializable {
static final long serialVersionUID = 1;
private static final Logger logger = Logger.getLogger(Vector2f.class.getName());
public static final Vector2f ZERO = new Vector2f(0f, 0f);
public static final Vector2f UNIT_XY = new Vector2f(1f, 1f);
/**
* the x value of the vector.
*/
@ -62,11 +60,9 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
/**
* Creates a Vector2f with the given initial x and y values.
*
* @param x
* The x value of this Vector2f.
* @param y
* The y value of this Vector2f.
*
* @param x The x value of this Vector2f.
* @param y The y value of this Vector2f.
*/
public Vector2f(float x, float y) {
this.x = x;
@ -82,7 +78,7 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
/**
* Creates a new Vector2f that contains the passed vector's information
*
*
* @param vector2f
* The vector to copy
*/
@ -93,11 +89,9 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
/**
* set the x and y values of the vector
*
* @param x
* the x value of the vector.
* @param y
* the y value of the vector.
*
* @param x the x value of the vector.
* @param y the y value of the vector.
* @return this vector
*/
public Vector2f set(float x, float y) {
@ -108,7 +102,7 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
/**
* set the x and y values of the vector from another vector
*
*
* @param vec
* the vector to copy from
* @return this vector
@ -123,7 +117,7 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
* <code>add</code> adds a provided vector to this vector creating a
* resultant vector which is returned. If the provided vector is null, null
* is returned.
*
*
* @param vec
* the vector to add to this.
* @return the resultant vector.
@ -140,7 +134,7 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
* <code>addLocal</code> adds a provided vector to this vector internally,
* and returns a handle to this vector for easy chaining of calls. If the
* provided vector is null, null is returned.
*
*
* @param vec
* the vector to add to this vector.
* @return this
@ -159,7 +153,7 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
* <code>addLocal</code> adds the provided values to this vector
* internally, and returns a handle to this vector for easy chaining of
* calls.
*
*
* @param addX
* value to add to x
* @param addY
@ -175,7 +169,7 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
/**
* <code>add</code> adds this vector by <code>vec</code> and stores the
* result in <code>result</code>.
*
*
* @param vec
* The vector to add.
* @param result
@ -187,8 +181,9 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
logger.warning("Provided vector is null, null returned.");
return null;
}
if (result == null)
if (result == null) {
result = new Vector2f();
}
result.x = x + vec.x;
result.y = y + vec.y;
return result;
@ -197,7 +192,7 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
/**
* <code>dot</code> calculates the dot product of this vector with a
* provided vector. If the provided vector is null, 0 is returned.
*
*
* @param vec
* the vector to dot with this vector.
* @return the resultant dot product of this vector and a given vector.
@ -213,9 +208,8 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
/**
* <code>cross</code> calculates the cross product of this vector with a
* parameter vector v.
*
* @param v
* the vector to take the cross product of with this.
*
* @param v the vector to take the cross product of with this.
* @return the cross product vector.
*/
public Vector3f cross(Vector2f v) {
@ -225,11 +219,11 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
public float determinant(Vector2f v) {
return (x * v.y) - (y * v.x);
}
/**
* 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
@ -246,7 +240,7 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
/**
* Sets this vector to the interpolation by changeAmnt from beginVec to
* finalVec this=(1-changeAmnt)*beginVec + changeAmnt * finalVec
*
*
* @param beginVec
* The beginning vector (delta=0)
* @param finalVec
@ -266,23 +260,29 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
/**
* 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(Vector2f vector) {
if (vector == null) return false;
if (Float.isNaN(vector.x) ||
Float.isNaN(vector.y)) return false;
if (Float.isInfinite(vector.x) ||
Float.isInfinite(vector.y)) return false;
return true;
if (vector == null) {
return false;
}
if (Float.isNaN(vector.x)
|| Float.isNaN(vector.y)) {
return false;
}
if (Float.isInfinite(vector.x)
|| Float.isInfinite(vector.y)) {
return false;
}
return true;
}
/**
* <code>length</code> calculates the magnitude of this vector.
*
*
* @return the length or magnitude of the vector.
*/
public float length() {
@ -292,7 +292,7 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
/**
* <code>lengthSquared</code> calculates the squared value of the
* magnitude of the vector.
*
*
* @return the magnitude squared of the vector.
*/
public float lengthSquared() {
@ -340,7 +340,7 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
/**
* <code>mult</code> multiplies this vector by a scalar. The resultant
* vector is returned.
*
*
* @param scalar
* the value to multiply this vector by.
* @return the new vector.
@ -352,7 +352,7 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
/**
* <code>multLocal</code> multiplies this vector by a scalar internally,
* and returns a handle to this vector for easy chaining of calls.
*
*
* @param scalar
* the value to multiply this vector by.
* @return this
@ -367,7 +367,7 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
* <code>multLocal</code> multiplies a provided vector by this vector
* internally, and returns a handle to this vector for easy chaining of
* calls. If the provided vector is null, null is returned.
*
*
* @param vec
* the vector to mult to this vector.
* @return this
@ -386,7 +386,7 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
* Multiplies this Vector2f's x and y by the scalar and stores the result in
* product. The result is returned for chaining. Similar to
* product=this*scalar;
*
*
* @param scalar
* The scalar to multiply by.
* @param product
@ -406,7 +406,7 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
/**
* <code>divide</code> divides the values of this vector by a scalar and
* returns the result. The values of this vector remain untouched.
*
*
* @param scalar
* the value to divide this vectors attributes by.
* @return the result <code>Vector</code>.
@ -419,7 +419,7 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
* <code>divideLocal</code> divides this vector by a scalar internally,
* and returns a handle to this vector for easy chaining of calls. Dividing
* by zero will result in an exception.
*
*
* @param scalar
* the value to divides this vector by.
* @return this
@ -433,7 +433,7 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
/**
* <code>negate</code> returns the negative of this vector. All values are
* negated and set to a new vector.
*
*
* @return the negated vector.
*/
public Vector2f negate() {
@ -442,7 +442,7 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
/**
* <code>negateLocal</code> negates the internal values of this vector.
*
*
* @return this.
*/
public Vector2f negateLocal() {
@ -455,7 +455,7 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
* <code>subtract</code> subtracts the values of a given vector from those
* of this vector creating a new vector object. If the provided vector is
* null, an exception is thrown.
*
*
* @param vec
* the vector to subtract from this vector.
* @return the result vector.
@ -468,7 +468,7 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
* <code>subtract</code> subtracts the values of a given vector from those
* of this vector storing the result in the given vector object. If the
* provided vector is null, an exception is thrown.
*
*
* @param vec
* the vector to subtract from this vector.
* @param store
@ -477,8 +477,9 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
* @return the result vector.
*/
public Vector2f subtract(Vector2f vec, Vector2f store) {
if (store == null)
if (store == null) {
store = new Vector2f();
}
store.x = x - vec.x;
store.y = y - vec.y;
return store;
@ -487,7 +488,7 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
/**
* <code>subtract</code> subtracts the given x,y values from those of this
* vector creating a new vector object.
*
*
* @param valX
* value to subtract from x
* @param valY
@ -502,7 +503,7 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
* <code>subtractLocal</code> subtracts a provided vector to this vector
* internally, and returns a handle to this vector for easy chaining of
* calls. If the provided vector is null, null is returned.
*
*
* @param vec
* the vector to subtract
* @return this
@ -521,7 +522,7 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
* <code>subtractLocal</code> subtracts the provided values from this
* vector internally, and returns a handle to this vector for easy chaining
* of calls.
*
*
* @param valX
* value to subtract from x
* @param valY
@ -536,7 +537,7 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
/**
* <code>normalize</code> returns the unit vector of this vector.
*
*
* @return unit vector of this vector.
*/
public Vector2f normalize() {
@ -551,7 +552,7 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
/**
* <code>normalizeLocal</code> makes this vector into a unit vector of
* itself.
*
*
* @return this.
*/
public Vector2f normalizeLocal() {
@ -567,7 +568,7 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
* <code>smallestAngleBetween</code> returns (in radians) the minimum
* 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.
@ -583,7 +584,7 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
* rotate a ray represented by this vector to be colinear with a ray
* described by the given vector. It is assumed that both this vector and
* the given vector are unit vectors (iow, normalized).
*
*
* @param otherVector
* the "destination" unit vector
* @return the angle in radians.
@ -593,7 +594,7 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
- FastMath.atan2(y, x);
return angle;
}
public float getX() {
return x;
}
@ -611,11 +612,12 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
this.y = y;
return this;
}
/**
* <code>getAngle</code> returns (in radians) the angle represented by
* this Vector2f as expressed by a conversion from rectangular coordinates (<code>x</code>,&nbsp;<code>y</code>)
* to polar coordinates (r,&nbsp;<i>theta</i>).
*
*
* @return the angle in radians. [-pi, pi)
*/
public float getAngle() {
@ -636,7 +638,7 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
* <code>hashCode</code> returns a unique code for this vector object
* based on its values. If two vectors are logically equivalent, they will
* return the same hash code value.
*
*
* @return the hash code value of this vector.
*/
@Override
@ -658,7 +660,7 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
/**
* Saves this Vector2f into the given float[] object.
*
*
* @param floats
* The float[] to take this Vector2f. If null, a new float[2] is
* created.
@ -676,9 +678,8 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
/**
* are these two vectors the same? they are is they both have the same x and
* y values.
*
* @param o
* the object to compare for equality
*
* @param o the object to compare for equality
* @return true if they are equal
*/
@Override
@ -692,13 +693,15 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
}
Vector2f comp = (Vector2f) o;
if (Float.compare(x, comp.x) != 0)
if (Float.compare(x, comp.x) != 0) {
return false;
if (Float.compare(y, comp.y) != 0)
}
if (Float.compare(y, comp.y) != 0) {
return false;
}
return true;
}
/**
* Returns true if this vector is similar to the specified vector within
* some value of epsilon.
@ -724,7 +727,7 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
* <code>toString</code> returns the string representation of this vector
* object. The format of the string is such: com.jme.math.Vector2f
* [X=XX.XXXX, Y=YY.YYYY]
*
*
* @return the string representation of this vector.
*/
@Override
@ -734,7 +737,7 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
/**
* Used with serialization. Not to be called manually.
*
*
* @param in
* ObjectInput
* @throws IOException
@ -749,7 +752,7 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
/**
* Used with serialization. Not to be called manually.
*
*
* @param out
* ObjectOutput
* @throws IOException
@ -775,8 +778,9 @@ public final class Vector2f implements Savable, Cloneable, java.io.Serializable
}
public void rotateAroundOrigin(float angle, boolean cw) {
if (cw)
if (cw) {
angle = -angle;
}
float newX = FastMath.cos(angle) * x - FastMath.sin(angle) * y;
float newY = FastMath.sin(angle) * x + FastMath.cos(angle) * y;
x = newX;

@ -93,12 +93,9 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
* Constructor instantiates a new <code>Vector3f</code> with provides
* values.
*
* @param x
* the x value of the vector.
* @param y
* the y value of the vector.
* @param z
* the z value of the vector.
* @param x the x value of the vector.
* @param y the y value of the vector.
* @param z the z value of the vector.
*/
public Vector3f(float x, float y, float z) {
this.x = x;
@ -109,6 +106,7 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
/**
* Constructor instantiates a new <code>Vector3f</code> that is a copy
* of the provided vector
*
* @param copy The Vector3f to copy
*/
public Vector3f(Vector3f copy) {
@ -119,12 +117,9 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
* <code>set</code> sets the x,y,z values of the vector based on passed
* parameters.
*
* @param x
* the x value of the vector.
* @param y
* the y value of the vector.
* @param z
* the z value of the vector.
* @param x the x value of the vector.
* @param y the y value of the vector.
* @param z the z value of the vector.
* @return this vector
*/
public Vector3f set(float x, float y, float z) {
@ -295,8 +290,7 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
* <code>cross</code> calculates the cross product of this vector with a
* parameter vector v.
*
* @param v
* the vector to take the cross product of with this.
* @param v the vector to take the cross product of with this.
* @return the cross product vector.
*/
public Vector3f cross(Vector3f v) {
@ -307,8 +301,7 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
* <code>cross</code> calculates the cross product of this vector with a
* parameter vector v. The result is stored in <code>result</code>
*
* @param v
* the vector to take the cross product of with this.
* @param v the vector to take the cross product of with this.
* @param result
* the vector to store the cross product result.
* @return result, after receiving the cross product vector.
@ -346,8 +339,7 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
* <code>crossLocal</code> calculates the cross product of this vector
* with a parameter vector v.
*
* @param v
* the vector to take the cross product of with this.
* @param v the vector to take the cross product of with this.
* @return this.
*/
public Vector3f crossLocal(Vector3f v) {
@ -817,6 +809,7 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
/**
* <code>zero</code> resets this vector's data to zero internally.
*
* @return this
*/
public Vector3f zero() {
@ -955,8 +948,7 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
* are these two vectors the same? they are is they both have the same x,y,
* and z values.
*
* @param o
* the object to compare for equality
* @param o the object to compare for equality
* @return true if they are equal
*/
@Override
@ -1080,8 +1072,7 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
/**
* @param index
* @return x value if index == 0, y value if index == 1 or z value if index ==
* 2
* @return x value if index == 0, y value if index == 1 or z value if index == 2
* @throws IllegalArgumentException
* if index is not one of 0, 1, 2.
*/

@ -66,22 +66,18 @@ public final class Vector4f 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.
*/
public float z;
/**
* the w value of the vector.
*/
@ -100,14 +96,10 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
* Constructor instantiates a new <code>Vector4f</code> with provides
* values.
*
* @param x
* the x value of the vector.
* @param y
* the y value of the vector.
* @param z
* the z value of the vector.
* @param w
* the w value of the vector.
* @param x the x value of the vector.
* @param y the y value of the vector.
* @param z the z value of the vector.
* @param w the w value of the vector.
*/
public Vector4f(float x, float y, float z, float w) {
this.x = x;
@ -119,6 +111,7 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
/**
* Constructor instantiates a new <code>Vector3f</code> that is a copy
* of the provided vector
*
* @param copy The Vector3f to copy
*/
public Vector4f(Vector4f copy) {
@ -129,14 +122,10 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
* <code>set</code> sets the x,y,z,w values of the vector based on passed
* parameters.
*
* @param x
* the x value of the vector.
* @param y
* the y value of the vector.
* @param z
* the z value of the vector.
* @param w
* the w value of the vector.
* @param x the x value of the vector.
* @param y the y value of the vector.
* @param z the z value of the vector.
* @param w the w value of the vector.
* @return this vector
*/
public Vector4f set(float x, float y, float z, float w) {
@ -164,7 +153,6 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
}
/**
*
* <code>add</code> adds a provided vector to this vector creating a
* resultant vector which is returned. If the provided vector is null, null
* is returned.
@ -182,7 +170,6 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
}
/**
*
* <code>add</code> adds the values of a provided vector storing the
* values in the supplied vector.
*
@ -222,7 +209,6 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
}
/**
*
* <code>add</code> adds the provided values to this vector, creating a
* new vector that is then returned.
*
@ -264,7 +250,6 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
}
/**
*
* <code>scaleAdd</code> multiplies this vector by a scalar then adds the
* given Vector3f.
*
@ -283,7 +268,6 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
}
/**
*
* <code>scaleAdd</code> multiplies the given vector by a scalar then adds
* the given vector.
*
@ -304,7 +288,6 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
}
/**
*
* <code>dot</code> calculates the dot product of this vector with a
* provided vector. If the provided vector is null, 0 is returned.
*
@ -320,10 +303,10 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
return x * vec.x + y * vec.y + z * vec.z + w * vec.w;
}
public Vector4f project(Vector4f other){
public Vector4f project(Vector4f other) {
float n = this.dot(other); // A . B
float d = other.lengthSquared(); // |B|^2
return new Vector4f(other).multLocal(n/d);
return new Vector4f(other).multLocal(n / d);
}
/**
@ -333,7 +316,7 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
* @return true if this vector is a unit vector (length() ~= 1),
* or false otherwise.
*/
public boolean isUnitVector(){
public boolean isUnitVector() {
float len = length();
return 0.99f < len && len < 1.01f;
}
@ -384,7 +367,6 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
}
/**
*
* <code>mult</code> multiplies this vector by a scalar. The resultant
* vector is returned.
*
@ -397,7 +379,6 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
}
/**
*
* <code>mult</code> multiplies this vector by a scalar. The resultant
* vector is supplied as the second parameter and returned.
*
@ -505,7 +486,9 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
logger.warning("Provided vector is null, null returned.");
return null;
}
if (store == null) store = new Vector4f();
if (store == null) {
store = new Vector4f();
}
return store.set(x * vec.x, y * vec.y, z * vec.z, w * vec.w);
}
@ -518,7 +501,7 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
* @return the result <code>Vector</code>.
*/
public Vector4f divide(float scalar) {
scalar = 1f/scalar;
scalar = 1f / scalar;
return new Vector4f(x * scalar, y * scalar, z * scalar, w * scalar);
}
@ -532,7 +515,7 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
* @return this
*/
public Vector4f divideLocal(float scalar) {
scalar = 1f/scalar;
scalar = 1f / scalar;
x *= scalar;
y *= scalar;
z *= scalar;
@ -570,7 +553,6 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
}
/**
*
* <code>negate</code> returns the negative of this vector. All values are
* negated and set to a new vector.
*
@ -581,7 +563,6 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
}
/**
*
* <code>negateLocal</code> negates the internal values of this vector.
*
* @return this.
@ -595,7 +576,6 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
}
/**
*
* <code>subtract</code> subtracts the values of a given vector from those
* of this vector creating a new vector object. If the provided vector is
* null, null is returned.
@ -630,7 +610,6 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
}
/**
*
* <code>subtract</code>
*
* @param vec
@ -640,7 +619,7 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
* @return result
*/
public Vector4f subtract(Vector4f vec, Vector4f result) {
if(result == null) {
if (result == null) {
result = new Vector4f();
}
result.x = x - vec.x;
@ -651,7 +630,6 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
}
/**
*
* <code>subtract</code> subtracts the provided values from this vector,
* creating a new vector that is then returned.
*
@ -705,7 +683,7 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
//
// return divide(1);
float length = x * x + y * y + z * z + w * w;
if (length != 1f && length != 0f){
if (length != 1f && length != 0f) {
length = 1.0f / FastMath.sqrt(length);
return new Vector4f(x * length, y * length, z * length, w * length);
}
@ -723,7 +701,7 @@ public final class Vector4f 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 + w * w;
if (length != 1f && length != 0f){
if (length != 1f && length != 0f) {
length = 1.0f / FastMath.sqrt(length);
x *= length;
y *= length;
@ -737,10 +715,11 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
* <code>maxLocal</code> computes the maximum value for each
* component in this and <code>other</code> vector. The result is stored
* in this vector.
*
* @param other
* @return this
*/
public Vector4f maxLocal(Vector4f other){
public Vector4f maxLocal(Vector4f other) {
x = other.x > x ? other.x : x;
y = other.y > y ? other.y : y;
z = other.z > z ? other.z : z;
@ -752,10 +731,11 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
* <code>minLocal</code> computes the minimum value for each
* component in this and <code>other</code> vector. The result is stored
* in this vector.
*
* @param other
* @return this
*/
public Vector4f minLocal(Vector4f other){
public Vector4f minLocal(Vector4f other) {
x = other.x < x ? other.x : x;
y = other.y < y ? other.y : y;
z = other.z < z ? other.z : z;
@ -789,53 +769,62 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
/**
* Sets this vector to the interpolation by changeAmnt from this to the finalVec
* this=(1-changeAmnt)*this + changeAmnt * finalVec
*
* @param finalVec The final vector to interpolate towards
* @param changeAmnt An amount between 0.0 - 1.0 representing a percentage
* change from this towards finalVec
* @return this
*/
public Vector4f interpolateLocal(Vector4f 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.w=(1-changeAmnt)*this.w + changeAmnt*finalVec.w;
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.w = (1 - changeAmnt) * this.w + changeAmnt * finalVec.w;
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
* @return this
*/
public Vector4f interpolateLocal(Vector4f beginVec,Vector4f 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;
this.w=(1-changeAmnt)*beginVec.w + changeAmnt*finalVec.w;
public Vector4f interpolateLocal(Vector4f beginVec, Vector4f 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;
this.w = (1 - changeAmnt) * beginVec.w + changeAmnt * finalVec.w;
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(Vector4f vector) {
if (vector == null) return false;
if (Float.isNaN(vector.x) ||
Float.isNaN(vector.y) ||
Float.isNaN(vector.z)||
Float.isNaN(vector.w)) return false;
if (Float.isInfinite(vector.x) ||
Float.isInfinite(vector.y) ||
Float.isInfinite(vector.z) ||
Float.isInfinite(vector.w)) return false;
return true;
if (vector == null) {
return false;
}
if (Float.isNaN(vector.x)
|| Float.isNaN(vector.y)
|| Float.isNaN(vector.z)
|| Float.isNaN(vector.w)) {
return false;
}
if (Float.isInfinite(vector.x)
|| Float.isInfinite(vector.y)
|| Float.isInfinite(vector.z)
|| Float.isInfinite(vector.w)) {
return false;
}
return true;
}
@Override
@ -870,24 +859,35 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
* are these two vectors the same? they are is they both have the same x,y,
* and z values.
*
* @param o
* the object to compare for equality
* @param o the object to compare for equality
* @return true if they are equal
*/
@Override
public boolean equals(Object o) {
if (!(o instanceof Vector4f)) { return false; }
if (!(o instanceof Vector4f)) {
return false;
}
if (this == o) { return true; }
if (this == o) {
return true;
}
Vector4f comp = (Vector4f) 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(w,comp.w) != 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;
}
if (Float.compare(w, comp.w) != 0) {
return false;
}
return true;
}
/**
* Returns true if this vector is similar to the specified vector within
* some value of epsilon.
@ -919,6 +919,7 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
* <code>hashCode</code> returns a unique code for this vector object based
* on its values. If two vectors are logically equivalent, they will return
* the same hash code value.
*
* @return the hash code value of this vector.
*/
@Override
@ -1000,8 +1001,7 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
/**
* @param index
* @return x value if index == 0, y value if index == 1 or z value if index ==
* 2
* @return x value if index == 0, y value if index == 1 or z value if index == 2
* @throws IllegalArgumentException
* if index is not one of 0, 1, 2.
*/
@ -1040,9 +1040,8 @@ public final class Vector4f implements Savable, Cloneable, java.io.Serializable
return;
case 3:
w = value;
return;
return;
}
throw new IllegalArgumentException("index must be either 0, 1, 2 or 3");
}
}

Loading…
Cancel
Save