|
@@ -1,5 +1,5 @@
|
|
/*
|
|
/*
|
|
- * Copyright (c) 2009-2021 jMonkeyEngine
|
|
|
|
|
|
+ * Copyright (c) 2009-2022 jMonkeyEngine
|
|
* All rights reserved.
|
|
* All rights reserved.
|
|
*
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* Redistribution and use in source and binary forms, with or without
|
|
@@ -37,7 +37,7 @@ import java.util.logging.Logger;
|
|
|
|
|
|
/**
|
|
/**
|
|
* A vector composed of 3 single-precision components, used to represent
|
|
* A vector composed of 3 single-precision components, used to represent
|
|
- * locations, offsets, and directions in 3-dimensional space.
|
|
|
|
|
|
+ * locations, offsets, velocities, and directions in 3-dimensional space.
|
|
*
|
|
*
|
|
* <p>Methods with names ending in "Local" modify the current instance. They are
|
|
* <p>Methods with names ending in "Local" modify the current instance. They are
|
|
* used to cut down on the creation of new instances.
|
|
* used to cut down on the creation of new instances.
|
|
@@ -177,12 +177,12 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
|
|
|
|
|
|
/**
|
|
/**
|
|
* Adds a specified vector and returns the sum in a 3rd vector. The current
|
|
* Adds a specified vector and returns the sum in a 3rd vector. The current
|
|
- * instance is unaffected unless it's <code>result</code>.
|
|
|
|
|
|
+ * instance is unaffected unless it's {@code result}.
|
|
*
|
|
*
|
|
* @param vec the vector to add (not null, unaffected unless it's
|
|
* @param vec the vector to add (not null, unaffected unless it's
|
|
- * <code>result</code>)
|
|
|
|
|
|
+ * {@code result})
|
|
* @param result storage for the sum (not null)
|
|
* @param result storage for the sum (not null)
|
|
- * @return <code>result</code> (for chaining)
|
|
|
|
|
|
+ * @return {@code result} (for chaining)
|
|
*/
|
|
*/
|
|
public Vector3f add(Vector3f vec, Vector3f result) {
|
|
public Vector3f add(Vector3f vec, Vector3f result) {
|
|
result.x = x + vec.x;
|
|
result.x = x + vec.x;
|
|
@@ -195,7 +195,7 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
|
|
* Adds the argument and returns the (modified) current instance. If the
|
|
* Adds the argument and returns the (modified) current instance. If the
|
|
* argument is null, null is returned.
|
|
* argument is null, null is returned.
|
|
*
|
|
*
|
|
- * @param vec the vector to add (unaffected unless it's <code>this</code>)
|
|
|
|
|
|
+ * @param vec the vector to add (unaffected unless it's {@code this})
|
|
* or null for none
|
|
* or null for none
|
|
* @return the (modified) current instance or null
|
|
* @return the (modified) current instance or null
|
|
*/
|
|
*/
|
|
@@ -298,7 +298,7 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
|
|
* new instance. The current instance is unaffected.
|
|
* new instance. The current instance is unaffected.
|
|
*
|
|
*
|
|
* @param v the right factor (not null, unaffected)
|
|
* @param v the right factor (not null, unaffected)
|
|
- * @return <code>this</code> cross <code>v</code> (a new Vector3f)
|
|
|
|
|
|
+ * @return {@code this} cross {@code v} (a new Vector3f)
|
|
*/
|
|
*/
|
|
public Vector3f cross(Vector3f v) {
|
|
public Vector3f cross(Vector3f v) {
|
|
return cross(v, null);
|
|
return cross(v, null);
|
|
@@ -307,13 +307,13 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
|
|
/**
|
|
/**
|
|
* Calculates a cross product with a specified vector and returns the
|
|
* Calculates a cross product with a specified vector and returns the
|
|
* product in a 3rd vector. The current instance is unaffected unless it's
|
|
* product in a 3rd vector. The current instance is unaffected unless it's
|
|
- * <code>result</code>.
|
|
|
|
|
|
+ * {@code result}.
|
|
*
|
|
*
|
|
* @param v the right factor (not null, unaffected unless it's
|
|
* @param v the right factor (not null, unaffected unless it's
|
|
- * <code>result</code>)
|
|
|
|
|
|
+ * {@code result})
|
|
* @param result storage for the product, or null for a new Vector3f
|
|
* @param result storage for the product, or null for a new Vector3f
|
|
- * @return <code>this</code> cross <code>v</code> (either
|
|
|
|
- * <code>result</code> or a new Vector3f)
|
|
|
|
|
|
+ * @return {@code this} cross {@code v} (either {@code result} or a new
|
|
|
|
+ * Vector3f)
|
|
*/
|
|
*/
|
|
public Vector3f cross(Vector3f v, Vector3f result) {
|
|
public Vector3f cross(Vector3f v, Vector3f result) {
|
|
return cross(v.x, v.y, v.z, result);
|
|
return cross(v.x, v.y, v.z, result);
|
|
@@ -322,14 +322,14 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
|
|
/**
|
|
/**
|
|
* Calculates a cross product with specified components and returns the
|
|
* Calculates a cross product with specified components and returns the
|
|
* product in the specified vector. The current instance is unaffected
|
|
* product in the specified vector. The current instance is unaffected
|
|
- * unless it's <code>result</code>.
|
|
|
|
|
|
+ * unless it's {@code result}.
|
|
*
|
|
*
|
|
* @param otherX the X component of the right factor
|
|
* @param otherX the X component of the right factor
|
|
* @param otherY the Y component of the right factor
|
|
* @param otherY the Y component of the right factor
|
|
* @param otherZ the Z component of the right factor
|
|
* @param otherZ the Z component of the right factor
|
|
* @param result storage for the product, or null for a new Vector3f
|
|
* @param result storage for the product, or null for a new Vector3f
|
|
- * @return <code>this</code> cross <code>v</code> (either
|
|
|
|
- * <code>result</code> or a new Vector3f)
|
|
|
|
|
|
+ * @return {@code this} cross (X,Y,Z) (either {@code result} or a new
|
|
|
|
+ * Vector3f)
|
|
*/
|
|
*/
|
|
public Vector3f cross(float otherX, float otherY, float otherZ, Vector3f result) {
|
|
public Vector3f cross(float otherX, float otherY, float otherZ, Vector3f result) {
|
|
if (result == null) {
|
|
if (result == null) {
|
|
@@ -489,11 +489,11 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
|
|
/**
|
|
/**
|
|
* Multiplies with the specified scalar and returns the product in the
|
|
* Multiplies with the specified scalar and returns the product in the
|
|
* specified vector. The current instance is unaffected, unless it's
|
|
* specified vector. The current instance is unaffected, unless it's
|
|
- * <code>product</code>.
|
|
|
|
|
|
+ * {@code product}.
|
|
*
|
|
*
|
|
* @param scalar the scaling factor
|
|
* @param scalar the scaling factor
|
|
* @param product storage for the product, or null for a new Vector3f
|
|
* @param product storage for the product, or null for a new Vector3f
|
|
- * @return either <code>product</code> or a new Vector3f
|
|
|
|
|
|
+ * @return either {@code product} or a new Vector3f
|
|
*/
|
|
*/
|
|
public Vector3f mult(float scalar, Vector3f product) {
|
|
public Vector3f mult(float scalar, Vector3f product) {
|
|
if (null == product) {
|
|
if (null == product) {
|
|
@@ -523,7 +523,7 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
|
|
* Multiplies component-wise by the argument and returns the (modified)
|
|
* Multiplies component-wise by the argument and returns the (modified)
|
|
* current instance. If the argument is null, null is returned.
|
|
* current instance. If the argument is null, null is returned.
|
|
*
|
|
*
|
|
- * @param vec the scale vector (unaffected unless it's <code>this</code>) or
|
|
|
|
|
|
+ * @param vec the scale vector (unaffected unless it's {@code this}) or
|
|
* null for none
|
|
* null for none
|
|
* @return the (modified) current instance (for chaining) or null
|
|
* @return the (modified) current instance (for chaining) or null
|
|
*/
|
|
*/
|
|
@@ -587,12 +587,12 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
|
|
* Multiplies component-wise with the specified vector and returns the
|
|
* Multiplies component-wise with the specified vector and returns the
|
|
* product in a 3rd vector. If the argument is null, null is returned.
|
|
* product in a 3rd vector. If the argument is null, null is returned.
|
|
* Either way, the current instance is unaffected, unless it's
|
|
* Either way, the current instance is unaffected, unless it's
|
|
- * <code>store</code>.
|
|
|
|
|
|
+ * {@code store}.
|
|
*
|
|
*
|
|
- * @param vec the scale vector (unaffected unless it's <code>store</code>)
|
|
|
|
|
|
+ * @param vec the scale vector (unaffected unless it's {@code store})
|
|
* or null for none
|
|
* or null for none
|
|
* @param store storage for the product, or null for a new Vector3f
|
|
* @param store storage for the product, or null for a new Vector3f
|
|
- * @return either <code>store</code> or a new Vector3f or null
|
|
|
|
|
|
+ * @return either {@code store} or a new Vector3f or null
|
|
*/
|
|
*/
|
|
public Vector3f mult(Vector3f vec, Vector3f store) {
|
|
public Vector3f mult(Vector3f vec, Vector3f store) {
|
|
if (null == vec) {
|
|
if (null == vec) {
|
|
@@ -659,8 +659,8 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Divides component-wise by the specified components and returns the quotient
|
|
|
|
- * as a new instance. The current instance is unaffected.
|
|
|
|
|
|
+ * Divides component-wise by the specified components and returns the
|
|
|
|
+ * quotient as a new instance. The current instance is unaffected.
|
|
*
|
|
*
|
|
* @param x the divisor for the X component
|
|
* @param x the divisor for the X component
|
|
* @param y the divisor for the Y component
|
|
* @param y the divisor for the Y component
|
|
@@ -675,7 +675,8 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
|
|
* Divides component-wise by the argument and returns the (modified) current
|
|
* Divides component-wise by the argument and returns the (modified) current
|
|
* instance.
|
|
* instance.
|
|
*
|
|
*
|
|
- * @param divisor the divisor (not null, unaffected)
|
|
|
|
|
|
+ * @param divisor the divisor (not null, unaffected unless it's
|
|
|
|
+ * {@code this})
|
|
* @return the (modified) current instance (for chaining)
|
|
* @return the (modified) current instance (for chaining)
|
|
*/
|
|
*/
|
|
public Vector3f divideLocal(Vector3f divisor) {
|
|
public Vector3f divideLocal(Vector3f divisor) {
|
|
@@ -721,8 +722,8 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
|
|
* Subtracts the argument and returns the (modified) current instance. If
|
|
* Subtracts the argument and returns the (modified) current instance. If
|
|
* the argument is null, null is returned.
|
|
* the argument is null, null is returned.
|
|
*
|
|
*
|
|
- * @param vec the vector to subtract (unaffected unless it's
|
|
|
|
- * <code>this</code>) or null for none
|
|
|
|
|
|
+ * @param vec the vector to subtract (unaffected unless it's {@code this})
|
|
|
|
+ * or null for none
|
|
* @return the (modified) current instance or null
|
|
* @return the (modified) current instance or null
|
|
*/
|
|
*/
|
|
public Vector3f subtractLocal(Vector3f vec) {
|
|
public Vector3f subtractLocal(Vector3f vec) {
|
|
@@ -739,12 +740,12 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
|
|
/**
|
|
/**
|
|
* Subtracts the specified vector and returns the difference in a 3rd
|
|
* Subtracts the specified vector and returns the difference in a 3rd
|
|
* vector. The current instance is unaffected unless it's
|
|
* vector. The current instance is unaffected unless it's
|
|
- * <code>result</code>.
|
|
|
|
|
|
+ * {@code result}.
|
|
*
|
|
*
|
|
* @param vec the vector to subtract (not null, unaffected unless it's
|
|
* @param vec the vector to subtract (not null, unaffected unless it's
|
|
- * <code>result</code>)
|
|
|
|
|
|
+ * {@code result})
|
|
* @param result storage for the difference, or null for a new Vector3f
|
|
* @param result storage for the difference, or null for a new Vector3f
|
|
- * @return either <code>result</code> or a new Vector3f
|
|
|
|
|
|
+ * @return either {@code result} or a new Vector3f
|
|
*/
|
|
*/
|
|
public Vector3f subtract(Vector3f vec, Vector3f result) {
|
|
public Vector3f subtract(Vector3f vec, Vector3f result) {
|
|
if (result == null) {
|
|
if (result == null) {
|
|
@@ -1010,7 +1011,8 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
|
|
* unaffected.
|
|
* unaffected.
|
|
*
|
|
*
|
|
* @param o the object to compare (may be null, unaffected)
|
|
* @param o the object to compare (may be null, unaffected)
|
|
- * @return true if equal, otherwise false
|
|
|
|
|
|
+ * @return true if {@code this} and {@code o} have identical values,
|
|
|
|
+ * otherwise false
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public boolean equals(Object o) {
|
|
public boolean equals(Object o) {
|
|
@@ -1061,10 +1063,10 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Returns a hash code. If two vectors are logically equivalent, they will
|
|
|
|
- * return the same hash code. The current instance is unaffected.
|
|
|
|
|
|
+ * Returns a hash code. If two vectors have identical values, they will
|
|
|
|
+ * have the same hash code. The current instance is unaffected.
|
|
*
|
|
*
|
|
- * @return the hash code value
|
|
|
|
|
|
+ * @return a 32-bit value for use in hashing
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public int hashCode() {
|
|
public int hashCode() {
|
|
@@ -1076,12 +1078,13 @@ public final class Vector3f implements Savable, Cloneable, java.io.Serializable
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Returns a string representation. The current instance is unaffected. The
|
|
|
|
- * format is:
|
|
|
|
- *
|
|
|
|
- * <p>(XX.XXXX, YY.YYYY, ZZ.ZZZZ)
|
|
|
|
|
|
+ * Returns a string representation of the vector, which is unaffected.
|
|
|
|
+ * For example, the +X direction vector is represented by:
|
|
|
|
+ * <pre>
|
|
|
|
+ * (1.0, 0.0, 0.0)
|
|
|
|
+ * </pre>
|
|
*
|
|
*
|
|
- * @return the string representation
|
|
|
|
|
|
+ * @return the string representation (not null, not empty)
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public String toString() {
|
|
public String toString() {
|