mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-20 00:51:20 -08:00
Merge remote-tracking branch 'gui/main' into merge-gui-and-server
This commit is contained in:
commit
ae94de39b1
430 files changed
+44297
-50
No files matched your search
@@ -0,0 +1,665 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2012 jMonkeyEngine All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* *
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package com.jme3.math;
|
||||
|
||||
import io.eiren.math.FloatMath;
|
||||
|
||||
|
||||
/**
|
||||
* <code>ColorRGBA</code> defines a color made from a collection of red, green
|
||||
* and blue values. An alpha value determines is transparency. All values must
|
||||
* be between 0 and 1. If any value is set higher or lower than these
|
||||
* constraints they are clamped to the min or max. That is, if a value smaller
|
||||
* than zero is set the value clamps to zero. If a value higher than 1 is
|
||||
* passed, that value is clamped to 1. However, because the attributes r, g, b,
|
||||
* a are public for efficiency reasons, they can be directly modified with
|
||||
* invalid values. The client should take care when directly addressing the
|
||||
* values. A call to clamp will assure that the values are within the
|
||||
* constraints.
|
||||
*
|
||||
* @author Mark Powell
|
||||
* @version $Id: ColorRGBA.java,v 1.29 2007/09/09 18:25:14 irrisor Exp $
|
||||
*/
|
||||
public final class ColorRGBA implements Cloneable, java.io.Serializable {
|
||||
|
||||
static final long serialVersionUID = 1;
|
||||
/**
|
||||
* The color black (0,0,0).
|
||||
*/
|
||||
public static final ColorRGBA Black = new ColorRGBA(0f, 0f, 0f, 1f);
|
||||
/**
|
||||
* The color white (1,1,1).
|
||||
*/
|
||||
public static final ColorRGBA White = new ColorRGBA(1f, 1f, 1f, 1f);
|
||||
/**
|
||||
* The color gray (.2,.2,.2).
|
||||
*/
|
||||
public static final ColorRGBA DarkGray = new ColorRGBA(0.2f, 0.2f, 0.2f, 1.0f);
|
||||
/**
|
||||
* The color gray (.5,.5,.5).
|
||||
*/
|
||||
public static final ColorRGBA Gray = new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f);
|
||||
/**
|
||||
* The color gray (.8,.8,.8).
|
||||
*/
|
||||
public static final ColorRGBA LightGray = new ColorRGBA(0.8f, 0.8f, 0.8f, 1.0f);
|
||||
/**
|
||||
* The color red (1,0,0).
|
||||
*/
|
||||
public static final ColorRGBA Red = new ColorRGBA(1f, 0f, 0f, 1f);
|
||||
/**
|
||||
* The color green (0,1,0).
|
||||
*/
|
||||
public static final ColorRGBA Green = new ColorRGBA(0f, 1f, 0f, 1f);
|
||||
/**
|
||||
* The color blue (0,0,1).
|
||||
*/
|
||||
public static final ColorRGBA Blue = new ColorRGBA(0f, 0f, 1f, 1f);
|
||||
/**
|
||||
* The color yellow (1,1,0).
|
||||
*/
|
||||
public static final ColorRGBA Yellow = new ColorRGBA(1f, 1f, 0f, 1f);
|
||||
/**
|
||||
* The color magenta (1,0,1).
|
||||
*/
|
||||
public static final ColorRGBA Magenta = new ColorRGBA(1f, 0f, 1f, 1f);
|
||||
/**
|
||||
* The color cyan (0,1,1).
|
||||
*/
|
||||
public static final ColorRGBA Cyan = new ColorRGBA(0f, 1f, 1f, 1f);
|
||||
/**
|
||||
* The color orange (251/255, 130/255,0).
|
||||
*/
|
||||
public static final ColorRGBA Orange = new ColorRGBA(251f / 255f, 130f / 255f, 0f, 1f);
|
||||
/**
|
||||
* The color brown (65/255, 40/255, 25/255).
|
||||
*/
|
||||
public static final ColorRGBA Brown = new ColorRGBA(65f / 255f, 40f / 255f, 25f / 255f, 1f);
|
||||
/**
|
||||
* The color pink (1, 0.68, 0.68).
|
||||
*/
|
||||
public static final ColorRGBA Pink = new ColorRGBA(1f, 0.68f, 0.68f, 1f);
|
||||
/**
|
||||
* The black color with no alpha (0, 0, 0, 0).
|
||||
*/
|
||||
public static final ColorRGBA BlackNoAlpha = new ColorRGBA(0f, 0f, 0f, 0f);
|
||||
/**
|
||||
* The red component of the color. 0 is none and 1 is maximum red.
|
||||
*/
|
||||
public float r;
|
||||
/**
|
||||
* The green component of the color. 0 is none and 1 is maximum green.
|
||||
*/
|
||||
public float g;
|
||||
/**
|
||||
* The blue component of the color. 0 is none and 1 is maximum blue.
|
||||
*/
|
||||
public float b;
|
||||
/**
|
||||
* The alpha component of the color. 0 is transparent and 1 is opaque.
|
||||
*/
|
||||
public float a;
|
||||
|
||||
/**
|
||||
* Constructor instantiates a new <code>ColorRGBA</code> object. This color
|
||||
* is the default "white" with all values 1.
|
||||
*/
|
||||
public ColorRGBA() {
|
||||
r = g = b = a = 1.0f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor instantiates a new <code>ColorRGBA</code> object. The values
|
||||
* are defined as passed parameters. These values are then clamped to insure
|
||||
* that they are between 0 and 1.
|
||||
*
|
||||
* @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>.
|
||||
* @param a The alpha component of this <code>ColorRGBA</code>.
|
||||
*/
|
||||
public ColorRGBA(float r, float g, float b, float a) {
|
||||
this.r = r;
|
||||
this.g = g;
|
||||
this.b = b;
|
||||
this.a = a;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
this.a = rgba.a;
|
||||
this.r = rgba.r;
|
||||
this.g = rgba.g;
|
||||
this.b = rgba.b;
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>set</code> sets the RGBA values of this <code>ColorRGBA</code>. The
|
||||
* values are then clamped to insure that they are between 0 and 1.
|
||||
*
|
||||
* @param r The red component of this color.
|
||||
* @param g The green component of this color.
|
||||
* @param b The blue component of this color.
|
||||
* @param a The alpha component of this color.
|
||||
* @return this
|
||||
*/
|
||||
public ColorRGBA set(float r, float g, float b, float a) {
|
||||
this.r = r;
|
||||
this.g = g;
|
||||
this.b = b;
|
||||
this.a = a;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <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.
|
||||
* @return this
|
||||
*/
|
||||
public ColorRGBA set(ColorRGBA rgba) {
|
||||
if (rgba == null) {
|
||||
r = 0;
|
||||
g = 0;
|
||||
b = 0;
|
||||
a = 0;
|
||||
} else {
|
||||
r = rgba.r;
|
||||
g = rgba.g;
|
||||
b = rgba.b;
|
||||
a = rgba.a;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public ColorRGBA setR(float r) {
|
||||
this.r = r;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ColorRGBA setG(float g) {
|
||||
this.g = g;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ColorRGBA setB(float b) {
|
||||
this.b = b;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ColorRGBA setA(float a) {
|
||||
this.a = a;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>clamp</code> insures that all values are between 0 and 1. If any
|
||||
* are less than 0 they are set to zero. If any are more than 1 they are set
|
||||
* to one.
|
||||
*/
|
||||
public void clamp() {
|
||||
if (r < 0) {
|
||||
r = 0;
|
||||
} else if (r > 1) {
|
||||
r = 1;
|
||||
}
|
||||
|
||||
if (g < 0) {
|
||||
g = 0;
|
||||
} else if (g > 1) {
|
||||
g = 1;
|
||||
}
|
||||
|
||||
if (b < 0) {
|
||||
b = 0;
|
||||
} else if (b > 1) {
|
||||
b = 1;
|
||||
}
|
||||
|
||||
if (a < 0) {
|
||||
a = 0;
|
||||
} else if (a > 1) {
|
||||
a = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <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() {
|
||||
return new float[] { r, g, b, a };
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public float[] getColorArray(float[] store) {
|
||||
store[0] = r;
|
||||
store[1] = g;
|
||||
store[2] = b;
|
||||
store[3] = a;
|
||||
return store;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the alpha component value of this <code>ColorRGBA</code>.
|
||||
*
|
||||
* @return The alpha component value.
|
||||
*/
|
||||
public float getAlpha() {
|
||||
return a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the red component value of this <code>ColorRGBA</code>.
|
||||
*
|
||||
* @return The red component value.
|
||||
*/
|
||||
public float getRed() {
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the blue component value of this <code>ColorRGBA</code>.
|
||||
*
|
||||
* @return The blue component value.
|
||||
*/
|
||||
public float getBlue() {
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the green component value of this <code>ColorRGBA</code>.
|
||||
*
|
||||
* @return The green component value.
|
||||
*/
|
||||
public float getGreen() {
|
||||
return g;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public void interpolate(ColorRGBA finalColor, float changeAmnt) {
|
||||
this.r = (1 - changeAmnt) * this.r + changeAmnt * finalColor.r;
|
||||
this.g = (1 - changeAmnt) * this.g + changeAmnt * finalColor.g;
|
||||
this.b = (1 - changeAmnt) * this.b + changeAmnt * finalColor.b;
|
||||
this.a = (1 - changeAmnt) * this.a + changeAmnt * finalColor.a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this <code>ColorRGBA</code> to the interpolation by changeAmnt from
|
||||
* beginColor to finalColor: this=(1-changeAmnt)*beginColor + changeAmnt *
|
||||
* finalColor
|
||||
*
|
||||
* @param beginColor The begining color (changeAmnt=0).
|
||||
* @param finalColor The final color to interpolate towards (changeAmnt=1).
|
||||
* @param changeAmnt An amount between 0.0 - 1.0 representing a precentage
|
||||
* change from beginColor towards finalColor.
|
||||
*/
|
||||
public void interpolate(ColorRGBA beginColor, ColorRGBA finalColor, float changeAmnt) {
|
||||
this.r = (1 - changeAmnt) * beginColor.r + changeAmnt * finalColor.r;
|
||||
this.g = (1 - changeAmnt) * beginColor.g + changeAmnt * finalColor.g;
|
||||
this.b = (1 - changeAmnt) * beginColor.b + changeAmnt * finalColor.b;
|
||||
this.a = (1 - changeAmnt) * beginColor.a + changeAmnt * finalColor.a;
|
||||
}
|
||||
|
||||
/**
|
||||
* <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() {
|
||||
ColorRGBA rVal = new ColorRGBA(0, 0, 0, 1);
|
||||
rVal.r = FastMath.nextRandomFloat();
|
||||
rVal.g = FastMath.nextRandomFloat();
|
||||
rVal.b = FastMath.nextRandomFloat();
|
||||
return rVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public ColorRGBA mult(ColorRGBA c) {
|
||||
return new ColorRGBA(c.r * r, c.g * g, c.b * b, c.a * a);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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>. 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
|
||||
*/
|
||||
public ColorRGBA mult(float scalar) {
|
||||
return new ColorRGBA(scalar * r, scalar * g, scalar * b, scalar * a);
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiplies each r,g,b,a of this <code>ColorRGBA</code> by the given
|
||||
* scalar and returns the result (this). Used as a way of making colors
|
||||
* dimmer or brighter.
|
||||
*
|
||||
* @param scalar The scalar to multiply by.
|
||||
* @return this*c
|
||||
*/
|
||||
public ColorRGBA multLocal(float scalar) {
|
||||
this.r *= scalar;
|
||||
this.g *= scalar;
|
||||
this.b *= scalar;
|
||||
this.a *= scalar;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public ColorRGBA add(ColorRGBA c) {
|
||||
return new ColorRGBA(c.r + r, c.g + g, c.b + b, c.a + a);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public ColorRGBA addLocal(ColorRGBA c) {
|
||||
set(c.r + r, c.g + g, c.b + b, c.a + a);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiplies alpha component by the given scalar and returns the result as
|
||||
* a new color.
|
||||
*/
|
||||
public ColorRGBA dilute(float scalarA) {
|
||||
return new ColorRGBA(r, g, b, a * scalarA);
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiplies alpha component by the given scalar and returns the result
|
||||
* (this).
|
||||
*/
|
||||
public ColorRGBA diluteLocal(float scalarA) {
|
||||
this.a *= scalarA;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>toString</code> returns the string representation of this
|
||||
* <code>ColorRGBA</code>. The format of the string is:<br>
|
||||
* <Class Name>: [R=RR.RRRR, G=GG.GGGG, B=BB.BBBB, A=AA.AAAA]
|
||||
*
|
||||
* @return The string representation of this <code>ColorRGBA</code>.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Color[" + r + ", " + g + ", " + b + ", " + a + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ColorRGBA clone() {
|
||||
try {
|
||||
return (ColorRGBA) super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
throw new AssertionError(); // can not happen
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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>. If null, a new <code>float[4]</code> is created.
|
||||
* @return The array, with r,g,b,a float values in that order.
|
||||
*/
|
||||
public float[] toArray(float[] floats) {
|
||||
if (floats == null) {
|
||||
floats = new float[4];
|
||||
}
|
||||
floats[0] = r;
|
||||
floats[1] = g;
|
||||
floats[2] = b;
|
||||
floats[3] = a;
|
||||
return floats;
|
||||
}
|
||||
|
||||
public ColorRGBA fromArray(float[] floats) {
|
||||
r = floats[0];
|
||||
g = floats[1];
|
||||
b = floats[2];
|
||||
a = floats[3];
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <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.
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof ColorRGBA)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
|
||||
ColorRGBA comp = (ColorRGBA) o;
|
||||
if (!FloatMath.equalsWithEpsilon(r, comp.r, FastMath.ZERO_TOLERANCE)) {
|
||||
return false;
|
||||
}
|
||||
if (!FloatMath.equalsWithEpsilon(g, comp.g, FastMath.ZERO_TOLERANCE)) {
|
||||
return false;
|
||||
}
|
||||
if (!FloatMath.equalsWithEpsilon(b, comp.b, FastMath.ZERO_TOLERANCE)) {
|
||||
return false;
|
||||
}
|
||||
if (!FloatMath.equalsWithEpsilon(a, comp.a, FastMath.ZERO_TOLERANCE)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* <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
|
||||
public int hashCode() {
|
||||
int hash = 37;
|
||||
hash += 37 * hash + Float.floatToIntBits(r);
|
||||
hash += 37 * hash + Float.floatToIntBits(g);
|
||||
hash += 37 * hash + Float.floatToIntBits(b);
|
||||
hash += 37 * hash + Float.floatToIntBits(a);
|
||||
return hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
byte[] store = new byte[4];
|
||||
store[0] = (byte) ((int) (r * 255) & 0xFF);
|
||||
store[1] = (byte) ((int) (g * 255) & 0xFF);
|
||||
store[2] = (byte) ((int) (b * 255) & 0xFF);
|
||||
store[3] = (byte) ((int) (a * 255) & 0xFF);
|
||||
return store;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
int argb = (((int) (a * 255) & 0xFF) << 24)
|
||||
| (((int) (r * 255) & 0xFF) << 16)
|
||||
| (((int) (g * 255) & 0xFF) << 8)
|
||||
| (((int) (b * 255) & 0xFF));
|
||||
return argb;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
int rgba = (((int) (r * 255) & 0xFF) << 24)
|
||||
| (((int) (g * 255) & 0xFF) << 16)
|
||||
| (((int) (b * 255) & 0xFF) << 8)
|
||||
| (((int) (a * 255) & 0xFF));
|
||||
return rgba;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
int abgr = (((int) (a * 255) & 0xFF) << 24)
|
||||
| (((int) (b * 255) & 0xFF) << 16)
|
||||
| (((int) (g * 255) & 0xFF) << 8)
|
||||
| (((int) (r * 255) & 0xFF));
|
||||
return abgr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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>.
|
||||
*/
|
||||
public void fromIntARGB(int color) {
|
||||
a = ((byte) (color >> 24) & 0xFF) / 255f;
|
||||
r = ((byte) (color >> 16) & 0xFF) / 255f;
|
||||
g = ((byte) (color >> 8) & 0xFF) / 255f;
|
||||
b = ((byte) (color) & 0xFF) / 255f;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public void fromIntRGBA(int color) {
|
||||
r = ((byte) (color >> 24) & 0xFF) / 255f;
|
||||
g = ((byte) (color >> 16) & 0xFF) / 255f;
|
||||
b = ((byte) (color >> 8) & 0xFF) / 255f;
|
||||
a = ((byte) (color) & 0xFF) / 255f;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 to
|
||||
* use for shaders assignment.
|
||||
*
|
||||
* @return A <code>Vector3f</code> containing the RGB value of this
|
||||
* <code>ColorRGBA</code>.
|
||||
*/
|
||||
public Vector3f toVector3f() {
|
||||
return new Vector3f(r, g, b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform this <code>ColorRGBA</code> to a <code>Vector4f</code> using x
|
||||
* = r, y = g, z = b, w = a. This method is useful to use for shaders
|
||||
* assignment.
|
||||
*
|
||||
* @return A <code>Vector4f</code> containing the RGBA value of this
|
||||
* <code>ColorRGBA</code>.
|
||||
*/
|
||||
public Vector4f toVector4f() {
|
||||
return new Vector4f(r, g, b, a);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,399 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2012 jMonkeyEngine
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package com.jme3.math;
|
||||
|
||||
/**
|
||||
* Started Date: Jul 16, 2004<br>
|
||||
* <br>
|
||||
* Represents a translation, rotation and scale in one object.
|
||||
*
|
||||
* @author Jack Lindamood
|
||||
* @author Joshua Slack
|
||||
*/
|
||||
public final class Transform implements Cloneable, java.io.Serializable {
|
||||
|
||||
static final long serialVersionUID = 1;
|
||||
|
||||
public static final Transform IDENTITY = new Transform();
|
||||
|
||||
private Quaternion rot = new Quaternion();
|
||||
private Vector3f translation = new Vector3f();
|
||||
private Vector3f scale = new Vector3f(1, 1, 1);
|
||||
|
||||
public Transform(Vector3f translation, Quaternion rot) {
|
||||
this.translation.set(translation);
|
||||
this.rot.set(rot);
|
||||
}
|
||||
|
||||
public Transform(Vector3f translation, Quaternion rot, Vector3f scale) {
|
||||
this(translation, rot);
|
||||
this.scale.set(scale);
|
||||
}
|
||||
|
||||
public Transform(Vector3f translation) {
|
||||
this(translation, Quaternion.IDENTITY);
|
||||
}
|
||||
|
||||
public Transform(Quaternion rot) {
|
||||
this(Vector3f.ZERO, rot);
|
||||
}
|
||||
|
||||
public Transform() {
|
||||
this(Vector3f.ZERO, Quaternion.IDENTITY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this rotation to the given Quaternion value.
|
||||
*
|
||||
* @param rot The new rotation for this matrix.
|
||||
* @return this
|
||||
*/
|
||||
public Transform setRotation(Quaternion rot) {
|
||||
this.rot.set(rot);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this translation to the given value.
|
||||
*
|
||||
* @param trans The new translation for this matrix.
|
||||
* @return this
|
||||
*/
|
||||
public Transform setTranslation(Vector3f trans) {
|
||||
this.translation.set(trans);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the translation vector in this matrix.
|
||||
*
|
||||
* @return translation vector.
|
||||
*/
|
||||
public Vector3f getTranslation() {
|
||||
return translation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this scale to the given value.
|
||||
*
|
||||
* @param scale The new scale for this matrix.
|
||||
* @return this
|
||||
*/
|
||||
public Transform setScale(Vector3f scale) {
|
||||
this.scale.set(scale);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this scale to the given value.
|
||||
*
|
||||
* @param scale The new scale for this matrix.
|
||||
* @return this
|
||||
*/
|
||||
public Transform setScale(float scale) {
|
||||
this.scale.set(scale, scale, scale);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the scale vector in this matrix.
|
||||
*
|
||||
* @return scale vector.
|
||||
*/
|
||||
public Vector3f getScale() {
|
||||
return scale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores this translation value into the given vector3f. If trans is null,
|
||||
* a new vector3f is created to hold the value. The value, once stored, is
|
||||
* returned.
|
||||
*
|
||||
* @param trans The store location for this matrix's translation.
|
||||
* @return The value of this matrix's translation.
|
||||
*/
|
||||
public Vector3f getTranslation(Vector3f trans) {
|
||||
if (trans == null)
|
||||
trans = new Vector3f();
|
||||
trans.set(this.translation);
|
||||
return trans;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores this rotation value into the given Quaternion. If quat is null, a
|
||||
* new Quaternion is created to hold the value. The value, once stored, is
|
||||
* returned.
|
||||
*
|
||||
* @param quat The store location for this matrix's rotation.
|
||||
* @return The value of this matrix's rotation.
|
||||
*/
|
||||
public Quaternion getRotation(Quaternion quat) {
|
||||
if (quat == null)
|
||||
quat = new Quaternion();
|
||||
quat.set(rot);
|
||||
return quat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the rotation quaternion in this matrix.
|
||||
*
|
||||
* @return rotation quaternion.
|
||||
*/
|
||||
public Quaternion getRotation() {
|
||||
return rot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores this scale value into the given vector3f. If scale is null, a new
|
||||
* vector3f is created to hold the value. The value, once stored, is
|
||||
* returned.
|
||||
*
|
||||
* @param scale The store location for this matrix's scale.
|
||||
* @return The value of this matrix's scale.
|
||||
*/
|
||||
public Vector3f getScale(Vector3f scale) {
|
||||
if (scale == null)
|
||||
scale = new Vector3f();
|
||||
scale.set(this.scale);
|
||||
return scale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this matrix to the interpolation between the first matrix and the
|
||||
* second by delta amount.
|
||||
*
|
||||
* @param t1 The begining transform.
|
||||
* @param t2 The ending transform.
|
||||
* @param delta An amount between 0 and 1 representing how far to
|
||||
* interpolate from t1 to t2.
|
||||
*/
|
||||
public void interpolateTransforms(Transform t1, Transform t2, float delta) {
|
||||
this.rot.slerp(t1.rot, t2.rot, delta);
|
||||
this.translation.interpolate(t1.translation, t2.translation, delta);
|
||||
this.scale.interpolate(t1.scale, t2.scale, delta);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the values of this matrix acording to it's parent. Very similar
|
||||
* to the concept of Node/Spatial transforms.
|
||||
*
|
||||
* @param parent The parent matrix.
|
||||
* @return This matrix, after combining.
|
||||
*/
|
||||
public Transform combineWithParent(Transform parent) {
|
||||
scale.multLocal(parent.scale);
|
||||
// rot.multLocal(parent.rot);
|
||||
parent.rot.mult(rot, rot);
|
||||
|
||||
// This here, is evil code
|
||||
// parent
|
||||
// .rot
|
||||
// .multLocal(translation)
|
||||
// .multLocal(parent.scale)
|
||||
// .addLocal(parent.translation);
|
||||
|
||||
translation.multLocal(parent.scale);
|
||||
parent.rot
|
||||
.multLocal(translation)
|
||||
.addLocal(parent.translation);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as {@link #combineWithParent(Transform)}, but assumes that rotation
|
||||
* is global, so it's not modified.
|
||||
*
|
||||
* @param parent
|
||||
* @return
|
||||
*/
|
||||
public Transform combineWithParentGlobalRotation(Transform parent) {
|
||||
scale.multLocal(parent.scale);
|
||||
translation.multLocal(parent.scale);
|
||||
|
||||
parent.rot
|
||||
.multLocal(translation)
|
||||
.addLocal(parent.translation);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this matrix's translation to the given x,y,z values.
|
||||
*
|
||||
* @param x This matrix's new x translation.
|
||||
* @param y This matrix's new y translation.
|
||||
* @param z This matrix's new z translation.
|
||||
* @return this
|
||||
*/
|
||||
public Transform setTranslation(float x, float y, float z) {
|
||||
translation.set(x, y, z);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this matrix's scale to the given x,y,z values.
|
||||
*
|
||||
* @param x This matrix's new x scale.
|
||||
* @param y This matrix's new y scale.
|
||||
* @param z This matrix's new z scale.
|
||||
* @return this
|
||||
*/
|
||||
public Transform setScale(float x, float y, float z) {
|
||||
scale.set(x, y, z);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector3f transformVector(final Vector3f in, Vector3f store) {
|
||||
if (store == null)
|
||||
store = new Vector3f();
|
||||
|
||||
// multiply with scale first, then rotate, finally translate (cf.
|
||||
// Eberly)
|
||||
return rot.mult(store.set(in).multLocal(scale), store).addLocal(translation);
|
||||
}
|
||||
|
||||
public Vector3f transformInverseVector(final Vector3f in, Vector3f store) {
|
||||
if (store == null)
|
||||
store = new Vector3f();
|
||||
|
||||
// The author of this code should look above and take the inverse of
|
||||
// that
|
||||
// But for some reason, they didnt ..
|
||||
// in.subtract(translation, store).divideLocal(scale);
|
||||
// rot.inverse().mult(store, store);
|
||||
|
||||
in.subtract(translation, store);
|
||||
rot.inverse().mult(store, store);
|
||||
store.divideLocal(scale);
|
||||
|
||||
return store;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the identity. Equal to translation=0,0,0 scale=1,1,1 rot=0,0,0,1.
|
||||
*/
|
||||
public void loadIdentity() {
|
||||
translation.set(0, 0, 0);
|
||||
scale.set(1, 1, 1);
|
||||
rot.set(0, 0, 0, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName()
|
||||
+ "[ "
|
||||
+ translation.x
|
||||
+ ", "
|
||||
+ translation.y
|
||||
+ ", "
|
||||
+ translation.z
|
||||
+ "]\n"
|
||||
+ "[ "
|
||||
+ rot.x
|
||||
+ ", "
|
||||
+ rot.y
|
||||
+ ", "
|
||||
+ rot.z
|
||||
+ ", "
|
||||
+ rot.w
|
||||
+ "]\n"
|
||||
+ "[ "
|
||||
+ scale.x
|
||||
+ " , "
|
||||
+ scale.y
|
||||
+ ", "
|
||||
+ scale.z
|
||||
+ "]";
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this matrix to be equal to the given matrix.
|
||||
*
|
||||
* @param matrixQuat The matrix to be equal to.
|
||||
* @return this
|
||||
*/
|
||||
public Transform set(Transform matrixQuat) {
|
||||
this.translation.set(matrixQuat.translation);
|
||||
this.rot.set(matrixQuat.rot);
|
||||
this.scale.set(matrixQuat.scale);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((rot == null) ? 0 : rot.hashCode());
|
||||
result = prime * result + ((scale == null) ? 0 : scale.hashCode());
|
||||
result = prime * result + ((translation == null) ? 0 : translation.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Transform other = (Transform) obj;
|
||||
if (rot == null) {
|
||||
if (other.rot != null)
|
||||
return false;
|
||||
} else if (!rot.equals(other.rot))
|
||||
return false;
|
||||
if (scale == null) {
|
||||
if (other.scale != null)
|
||||
return false;
|
||||
} else if (!scale.equals(other.scale))
|
||||
return false;
|
||||
if (translation == null) {
|
||||
if (other.translation != null)
|
||||
return false;
|
||||
} else if (!translation.equals(other.translation))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Transform clone() {
|
||||
try {
|
||||
Transform tq = (Transform) super.clone();
|
||||
tq.rot = rot.clone();
|
||||
tq.scale = scale.clone();
|
||||
tq.translation = translation.clone();
|
||||
return tq;
|
||||
} catch (CloneNotSupportedException e) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,718 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2012 jMonkeyEngine
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package com.jme3.math;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInput;
|
||||
import java.io.ObjectOutput;
|
||||
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 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.
|
||||
*/
|
||||
public float x;
|
||||
/**
|
||||
* the y value of the vector.
|
||||
*/
|
||||
public float y;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public Vector2f(float x, float y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Vector2f with x and y set to 0. Equivalent to Vector2f(0,0).
|
||||
*/
|
||||
public Vector2f() {
|
||||
x = y = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Vector2f that contains the passed vector's information
|
||||
*
|
||||
* @param vector2f The vector to copy
|
||||
*/
|
||||
public Vector2f(Vector2f vector2f) {
|
||||
this.x = vector2f.x;
|
||||
this.y = vector2f.y;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @return this vector
|
||||
*/
|
||||
public Vector2f set(float x, float y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* set the x and y values of the vector from another vector
|
||||
*
|
||||
* @param vec the vector to copy from
|
||||
* @return this vector
|
||||
*/
|
||||
public Vector2f set(Vector2f vec) {
|
||||
this.x = vec.x;
|
||||
this.y = vec.y;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <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.
|
||||
*/
|
||||
public Vector2f add(Vector2f vec) {
|
||||
if (null == vec) {
|
||||
logger.warning("Provided vector is null, null returned.");
|
||||
return null;
|
||||
}
|
||||
return new Vector2f(x + vec.x, y + vec.y);
|
||||
}
|
||||
|
||||
/**
|
||||
* <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
|
||||
*/
|
||||
public Vector2f addLocal(Vector2f vec) {
|
||||
if (null == vec) {
|
||||
logger.warning("Provided vector is null, null returned.");
|
||||
return null;
|
||||
}
|
||||
x += vec.x;
|
||||
y += vec.y;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <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 value to add to y
|
||||
* @return this
|
||||
*/
|
||||
public Vector2f addLocal(float addX, float addY) {
|
||||
x += addX;
|
||||
y += addY;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <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 The vector to store the result in.
|
||||
* @return The result vector, after adding.
|
||||
*/
|
||||
public Vector2f add(Vector2f vec, Vector2f result) {
|
||||
if (null == vec) {
|
||||
logger.warning("Provided vector is null, null returned.");
|
||||
return null;
|
||||
}
|
||||
if (result == null)
|
||||
result = new Vector2f();
|
||||
result.x = x + vec.x;
|
||||
result.y = y + vec.y;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* <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.
|
||||
*/
|
||||
public float dot(Vector2f vec) {
|
||||
if (null == vec) {
|
||||
logger.warning("Provided vector is null, 0 returned.");
|
||||
return 0;
|
||||
}
|
||||
return x * vec.x + y * vec.y;
|
||||
}
|
||||
|
||||
/**
|
||||
* <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.
|
||||
* @return the cross product vector.
|
||||
*/
|
||||
public Vector3f cross(Vector2f v) {
|
||||
return new Vector3f(0, 0, determinant(v));
|
||||
}
|
||||
|
||||
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 An amount between 0.0 - 1.0 representing a percentage
|
||||
* change from this towards finalVec
|
||||
*/
|
||||
public Vector2f interpolate(Vector2f finalVec, float changeAmnt) {
|
||||
this.x = (1 - changeAmnt) * this.x + changeAmnt * finalVec.x;
|
||||
this.y = (1 - changeAmnt) * this.y + changeAmnt * finalVec.y;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this vector to the interpolation by changeAmnt from beginVec to
|
||||
* finalVec this=(1-changeAmnt)*beginVec + changeAmnt * finalVec
|
||||
*
|
||||
* @param beginVec The begining vector (delta=0)
|
||||
* @param finalVec The final vector to interpolate towards (delta=1)
|
||||
* @param changeAmnt An amount between 0.0 - 1.0 representing a precentage
|
||||
* change from beginVec towards finalVec
|
||||
*/
|
||||
public Vector2f interpolate(
|
||||
Vector2f beginVec,
|
||||
Vector2f finalVec,
|
||||
float changeAmnt
|
||||
) {
|
||||
this.x = (1 - changeAmnt) * beginVec.x + changeAmnt * finalVec.x;
|
||||
this.y = (1 - changeAmnt) * beginVec.y + changeAmnt * finalVec.y;
|
||||
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(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;
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>length</code> calculates the magnitude of this vector.
|
||||
*
|
||||
* @return the length or magnitude of the vector.
|
||||
*/
|
||||
public float length() {
|
||||
return FastMath.sqrt(lengthSquared());
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>lengthSquared</code> calculates the squared value of the magnitude
|
||||
* of the vector.
|
||||
*
|
||||
* @return the magnitude squared of the vector.
|
||||
*/
|
||||
public float lengthSquared() {
|
||||
return x * x + y * y;
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>distanceSquared</code> calculates the distance squared between this
|
||||
* vector and vector v.
|
||||
*
|
||||
* @param v the second vector to determine the distance squared.
|
||||
* @return the distance squared between the two vectors.
|
||||
*/
|
||||
public float distanceSquared(Vector2f v) {
|
||||
double dx = x - v.x;
|
||||
double dy = y - v.y;
|
||||
return (float) (dx * dx + dy * dy);
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>distanceSquared</code> calculates the distance squared between this
|
||||
* vector and vector v.
|
||||
*
|
||||
* @param otherX The X coordinate of the v vector
|
||||
* @param otherY The Y coordinate of the v vector
|
||||
* @return the distance squared between the two vectors.
|
||||
*/
|
||||
public float distanceSquared(float otherX, float otherY) {
|
||||
double dx = x - otherX;
|
||||
double dy = y - otherY;
|
||||
return (float) (dx * dx + dy * dy);
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>distance</code> calculates the distance between this vector and
|
||||
* vector v.
|
||||
*
|
||||
* @param v the second vector to determine the distance.
|
||||
* @return the distance between the two vectors.
|
||||
*/
|
||||
public float distance(Vector2f v) {
|
||||
return FastMath.sqrt(distanceSquared(v));
|
||||
}
|
||||
|
||||
/**
|
||||
* <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.
|
||||
*/
|
||||
public Vector2f mult(float scalar) {
|
||||
return new Vector2f(x * scalar, y * scalar);
|
||||
}
|
||||
|
||||
/**
|
||||
* <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
|
||||
*/
|
||||
public Vector2f multLocal(float scalar) {
|
||||
x *= scalar;
|
||||
y *= scalar;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>multLocal</code> multiplies 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 mult to this vector.
|
||||
* @return this
|
||||
*/
|
||||
public Vector2f multLocal(Vector2f vec) {
|
||||
if (null == vec) {
|
||||
logger.warning("Provided vector is null, null returned.");
|
||||
return null;
|
||||
}
|
||||
x *= vec.x;
|
||||
y *= vec.y;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 The vector2f to store the result in.
|
||||
* @return product, after multiplication.
|
||||
*/
|
||||
public Vector2f mult(float scalar, Vector2f product) {
|
||||
if (null == product) {
|
||||
product = new Vector2f();
|
||||
}
|
||||
|
||||
product.x = x * scalar;
|
||||
product.y = y * scalar;
|
||||
return product;
|
||||
}
|
||||
|
||||
/**
|
||||
* <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>.
|
||||
*/
|
||||
public Vector2f divide(float scalar) {
|
||||
return new Vector2f(x / scalar, y / scalar);
|
||||
}
|
||||
|
||||
/**
|
||||
* <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
|
||||
*/
|
||||
public Vector2f divideLocal(float scalar) {
|
||||
x /= scalar;
|
||||
y /= scalar;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <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() {
|
||||
return new Vector2f(-x, -y);
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>negateLocal</code> negates the internal values of this vector.
|
||||
*
|
||||
* @return this.
|
||||
*/
|
||||
public Vector2f negateLocal() {
|
||||
x = -x;
|
||||
y = -y;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <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.
|
||||
*/
|
||||
public Vector2f subtract(Vector2f vec) {
|
||||
return subtract(vec, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* <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 the vector to store the result in. It is safe for this to be
|
||||
* the same as vec. If null, a new vector is created.
|
||||
* @return the result vector.
|
||||
*/
|
||||
public Vector2f subtract(Vector2f vec, Vector2f store) {
|
||||
if (store == null)
|
||||
store = new Vector2f();
|
||||
store.x = x - vec.x;
|
||||
store.y = y - vec.y;
|
||||
return store;
|
||||
}
|
||||
|
||||
/**
|
||||
* <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 value to subtract from y
|
||||
* @return this
|
||||
*/
|
||||
public Vector2f subtract(float valX, float valY) {
|
||||
return new Vector2f(x - valX, y - valY);
|
||||
}
|
||||
|
||||
/**
|
||||
* <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
|
||||
*/
|
||||
public Vector2f subtractLocal(Vector2f vec) {
|
||||
if (null == vec) {
|
||||
logger.warning("Provided vector is null, null returned.");
|
||||
return null;
|
||||
}
|
||||
x -= vec.x;
|
||||
y -= vec.y;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <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 value to subtract from y
|
||||
* @return this
|
||||
*/
|
||||
public Vector2f subtractLocal(float valX, float valY) {
|
||||
x -= valX;
|
||||
y -= valY;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>normalize</code> returns the unit vector of this vector.
|
||||
*
|
||||
* @return unit vector of this vector.
|
||||
*/
|
||||
public Vector2f normalize() {
|
||||
float length = length();
|
||||
if (length != 0) {
|
||||
return divide(length);
|
||||
}
|
||||
|
||||
return divide(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>normalizeLocal</code> makes this vector into a unit vector of
|
||||
* itself.
|
||||
*
|
||||
* @return this.
|
||||
*/
|
||||
public Vector2f normalizeLocal() {
|
||||
float length = length();
|
||||
if (length != 0) {
|
||||
return divideLocal(length);
|
||||
}
|
||||
|
||||
return divideLocal(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* <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.
|
||||
*/
|
||||
public float smallestAngleBetween(Vector2f otherVector) {
|
||||
float dotProduct = dot(otherVector);
|
||||
float angle = FastMath.acos(dotProduct);
|
||||
return angle;
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>angleBetween</code> returns (in radians) the angle required to
|
||||
* rotate a ray represented by this vector to lie colinear to 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.
|
||||
*/
|
||||
public float angleBetween(Vector2f otherVector) {
|
||||
float angle = FastMath.atan2(otherVector.y, otherVector.x)
|
||||
- FastMath.atan2(y, x);
|
||||
return angle;
|
||||
}
|
||||
|
||||
public float getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public Vector2f setX(float x) {
|
||||
this.x = x;
|
||||
return this;
|
||||
}
|
||||
|
||||
public float getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public Vector2f setY(float y) {
|
||||
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>, <code>y</code>) to polar coordinates
|
||||
* (r, <i>theta</i>).
|
||||
*
|
||||
* @return the angle in radians. [-pi, pi)
|
||||
*/
|
||||
public float getAngle() {
|
||||
return FastMath.atan2(y, x);
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>zero</code> resets this vector's data to zero internally.
|
||||
*/
|
||||
public Vector2f zero() {
|
||||
x = y = 0;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>hashCode</code> returns a unique code for this vector object based
|
||||
* on it's values. If two vectors are logically equivalent, they will return
|
||||
* the same hash code value.
|
||||
*
|
||||
* @return the hash code value of this vector.
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 37;
|
||||
hash += 37 * hash + Float.floatToIntBits(x);
|
||||
hash += 37 * hash + Float.floatToIntBits(y);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector2f clone() {
|
||||
try {
|
||||
return (Vector2f) super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
throw new AssertionError(); // can not happen
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves this Vector2f into the given float[] object.
|
||||
*
|
||||
* @param floats The float[] to take this Vector2f. If null, a new float[2]
|
||||
* is created.
|
||||
* @return The array, with X, Y float values in that order
|
||||
*/
|
||||
public float[] toArray(float[] floats) {
|
||||
if (floats == null) {
|
||||
floats = new float[2];
|
||||
}
|
||||
floats[0] = x;
|
||||
floats[1] = y;
|
||||
return floats;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @return true if they are equal
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof Vector2f)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Vector2f comp = (Vector2f) o;
|
||||
if (Float.compare(x, comp.x) != 0)
|
||||
return false;
|
||||
if (Float.compare(y, comp.y) != 0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* <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
|
||||
public String toString() {
|
||||
return "(" + x + ", " + y + ")";
|
||||
}
|
||||
|
||||
/**
|
||||
* Used with serialization. Not to be called manually.
|
||||
*
|
||||
* @param in ObjectInput
|
||||
* @throws IOException
|
||||
* @throws ClassNotFoundException
|
||||
* @see java.io.Externalizable
|
||||
*/
|
||||
public void readExternal(ObjectInput in) throws IOException,
|
||||
ClassNotFoundException {
|
||||
x = in.readFloat();
|
||||
y = in.readFloat();
|
||||
}
|
||||
|
||||
/**
|
||||
* Used with serialization. Not to be called manually.
|
||||
*
|
||||
* @param out ObjectOutput
|
||||
* @throws IOException
|
||||
* @see java.io.Externalizable
|
||||
*/
|
||||
public void writeExternal(ObjectOutput out) throws IOException {
|
||||
out.writeFloat(x);
|
||||
out.writeFloat(y);
|
||||
}
|
||||
|
||||
public void rotateAroundOrigin(float angle, boolean 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;
|
||||
y = newY;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,971 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2012 jMonkeyEngine
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package com.jme3.math;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
||||
/**
|
||||
* <code>Vector4f</code> defines a Vector for a four float value tuple.
|
||||
* <code>Vector4f</code> can represent any four dimensional value, such as a
|
||||
* vertex, a normal, etc. Utility methods are also included to aid in
|
||||
* mathematical calculations.
|
||||
*
|
||||
* @author Maarten Steur
|
||||
*/
|
||||
public final class Vector4f implements Cloneable, java.io.Serializable {
|
||||
|
||||
static final long serialVersionUID = 1;
|
||||
|
||||
private static final Logger logger = Logger.getLogger(Vector4f.class.getName());
|
||||
|
||||
public final static Vector4f ZERO = new Vector4f(0, 0, 0, 0);
|
||||
public final static Vector4f NAN = new Vector4f(Float.NaN, Float.NaN, Float.NaN, Float.NaN);
|
||||
public final static Vector4f UNIT_X = new Vector4f(1, 0, 0, 0);
|
||||
public final static Vector4f UNIT_Y = new Vector4f(0, 1, 0, 0);
|
||||
public final static Vector4f UNIT_Z = new Vector4f(0, 0, 1, 0);
|
||||
public final static Vector4f UNIT_W = new Vector4f(0, 0, 0, 1);
|
||||
public final static Vector4f UNIT_XYZW = new Vector4f(1, 1, 1, 1);
|
||||
public final static Vector4f POSITIVE_INFINITY = new Vector4f(
|
||||
Float.POSITIVE_INFINITY,
|
||||
Float.POSITIVE_INFINITY,
|
||||
Float.POSITIVE_INFINITY,
|
||||
Float.POSITIVE_INFINITY
|
||||
);
|
||||
public final static Vector4f NEGATIVE_INFINITY = new Vector4f(
|
||||
Float.NEGATIVE_INFINITY,
|
||||
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.
|
||||
*/
|
||||
public float w;
|
||||
|
||||
/**
|
||||
* Constructor instantiates a new <code>Vector3f</code> with default values
|
||||
* of (0,0,0).
|
||||
*
|
||||
*/
|
||||
public Vector4f() {
|
||||
x = y = z = w = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public Vector4f(float x, float y, float z, float w) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
this.set(copy);
|
||||
}
|
||||
|
||||
/**
|
||||
* <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.
|
||||
* @return this vector
|
||||
*/
|
||||
public Vector4f set(float x, float y, float z, float w) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.w = w;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>set</code> sets the x,y,z values of the vector by copying the
|
||||
* supplied vector.
|
||||
*
|
||||
* @param vect the vector to copy.
|
||||
* @return this vector
|
||||
*/
|
||||
public Vector4f set(Vector4f vect) {
|
||||
this.x = vect.x;
|
||||
this.y = vect.y;
|
||||
this.z = vect.z;
|
||||
this.w = vect.w;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* <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.
|
||||
*/
|
||||
public Vector4f add(Vector4f vec) {
|
||||
if (null == vec) {
|
||||
logger.warning("Provided vector is null, null returned.");
|
||||
return null;
|
||||
}
|
||||
return new Vector4f(x + vec.x, y + vec.y, z + vec.z, w + vec.w);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* <code>add</code> adds the values of a provided vector storing the values
|
||||
* in the supplied vector.
|
||||
*
|
||||
* @param vec the vector to add to this
|
||||
* @param result the vector to store the result in
|
||||
* @return result returns the supplied result vector.
|
||||
*/
|
||||
public Vector4f add(Vector4f vec, Vector4f result) {
|
||||
result.x = x + vec.x;
|
||||
result.y = y + vec.y;
|
||||
result.z = z + vec.z;
|
||||
result.w = w + vec.w;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* <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
|
||||
*/
|
||||
public Vector4f addLocal(Vector4f vec) {
|
||||
if (null == vec) {
|
||||
logger.warning("Provided vector is null, null returned.");
|
||||
return null;
|
||||
}
|
||||
x += vec.x;
|
||||
y += vec.y;
|
||||
z += vec.z;
|
||||
w += vec.w;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* <code>add</code> adds the provided values to this vector, creating a new
|
||||
* vector that is then returned.
|
||||
*
|
||||
* @param addX the x value to add.
|
||||
* @param addY the y value to add.
|
||||
* @param addZ the z value to add.
|
||||
* @return the result vector.
|
||||
*/
|
||||
public Vector4f add(float addX, float addY, float addZ, float addW) {
|
||||
return new Vector4f(x + addX, y + addY, z + addZ, w + addW);
|
||||
}
|
||||
|
||||
/**
|
||||
* <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 value to add to y
|
||||
* @param addZ value to add to z
|
||||
* @return this
|
||||
*/
|
||||
public Vector4f addLocal(float addX, float addY, float addZ, float addW) {
|
||||
x += addX;
|
||||
y += addY;
|
||||
z += addZ;
|
||||
w += addW;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* <code>scaleAdd</code> multiplies this vector by a scalar then adds the
|
||||
* given Vector3f.
|
||||
*
|
||||
* @param scalar the value to multiply this vector by.
|
||||
* @param add the value to add
|
||||
*/
|
||||
public Vector4f scaleAdd(float scalar, Vector4f add) {
|
||||
x = x * scalar + add.x;
|
||||
y = y * scalar + add.y;
|
||||
z = z * scalar + add.z;
|
||||
w = w * scalar + add.w;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* <code>scaleAdd</code> multiplies the given vector by a scalar then adds
|
||||
* the given vector.
|
||||
*
|
||||
* @param scalar the value to multiply this vector by.
|
||||
* @param mult the value to multiply the scalar by
|
||||
* @param add the value to add
|
||||
*/
|
||||
public Vector4f scaleAdd(float scalar, Vector4f mult, Vector4f add) {
|
||||
this.x = mult.x * scalar + add.x;
|
||||
this.y = mult.y * scalar + add.y;
|
||||
this.z = mult.z * scalar + add.z;
|
||||
this.w = mult.w * scalar + add.w;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* <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.
|
||||
*/
|
||||
public float dot(Vector4f vec) {
|
||||
if (null == vec) {
|
||||
logger.warning("Provided vector is null, 0 returned.");
|
||||
return 0;
|
||||
}
|
||||
return x * vec.x + y * vec.y + z * vec.z + w * vec.w;
|
||||
}
|
||||
|
||||
public Vector4f project(Vector4f other) {
|
||||
float n = this.dot(other); // A . B
|
||||
float d = other.lengthSquared(); // |B|^2
|
||||
return new Vector4f(other).normalizeLocal().multLocal(n / d);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this vector is a unit vector (length() ~= 1), returns
|
||||
* false otherwise.
|
||||
*
|
||||
* @return true if this vector is a unit vector (length() ~= 1), or false
|
||||
* otherwise.
|
||||
*/
|
||||
public boolean isUnitVector() {
|
||||
float len = length();
|
||||
return 0.99f < len && len < 1.01f;
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>length</code> calculates the magnitude of this vector.
|
||||
*
|
||||
* @return the length or magnitude of the vector.
|
||||
*/
|
||||
public float length() {
|
||||
return FastMath.sqrt(lengthSquared());
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>lengthSquared</code> calculates the squared value of the magnitude
|
||||
* of the vector.
|
||||
*
|
||||
* @return the magnitude squared of the vector.
|
||||
*/
|
||||
public float lengthSquared() {
|
||||
return x * x + y * y + z * z + w * w;
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>distanceSquared</code> calculates the distance squared between this
|
||||
* vector and vector v.
|
||||
*
|
||||
* @param v the second vector to determine the distance squared.
|
||||
* @return the distance squared between the two vectors.
|
||||
*/
|
||||
public float distanceSquared(Vector4f v) {
|
||||
double dx = x - v.x;
|
||||
double dy = y - v.y;
|
||||
double dz = z - v.z;
|
||||
double dw = w - v.w;
|
||||
return (float) (dx * dx + dy * dy + dz * dz + dw * dw);
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>distance</code> calculates the distance between this vector and
|
||||
* vector v.
|
||||
*
|
||||
* @param v the second vector to determine the distance.
|
||||
* @return the distance between the two vectors.
|
||||
*/
|
||||
public float distance(Vector4f v) {
|
||||
return FastMath.sqrt(distanceSquared(v));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* <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.
|
||||
*/
|
||||
public Vector4f mult(float scalar) {
|
||||
return new Vector4f(x * scalar, y * scalar, z * scalar, w * scalar);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* <code>mult</code> multiplies this vector by a scalar. The resultant
|
||||
* vector is supplied as the second parameter and returned.
|
||||
*
|
||||
* @param scalar the scalar to multiply this vector by.
|
||||
* @param product the product to store the result in.
|
||||
* @return product
|
||||
*/
|
||||
public Vector4f mult(float scalar, Vector4f product) {
|
||||
if (null == product) {
|
||||
product = new Vector4f();
|
||||
}
|
||||
|
||||
product.x = x * scalar;
|
||||
product.y = y * scalar;
|
||||
product.z = z * scalar;
|
||||
product.w = w * scalar;
|
||||
return product;
|
||||
}
|
||||
|
||||
/**
|
||||
* <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
|
||||
*/
|
||||
public Vector4f multLocal(float scalar) {
|
||||
x *= scalar;
|
||||
y *= scalar;
|
||||
z *= scalar;
|
||||
w *= scalar;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>multLocal</code> multiplies 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 mult to this vector.
|
||||
* @return this
|
||||
*/
|
||||
public Vector4f multLocal(Vector4f vec) {
|
||||
if (null == vec) {
|
||||
logger.warning("Provided vector is null, null returned.");
|
||||
return null;
|
||||
}
|
||||
x *= vec.x;
|
||||
y *= vec.y;
|
||||
z *= vec.z;
|
||||
w *= vec.w;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>multLocal</code> multiplies this vector by 3 scalars internally,
|
||||
* and returns a handle to this vector for easy chaining of calls.
|
||||
*
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
* @param w
|
||||
* @return this
|
||||
*/
|
||||
public Vector4f multLocal(float x, float y, float z, float w) {
|
||||
this.x *= x;
|
||||
this.y *= y;
|
||||
this.z *= z;
|
||||
this.w *= w;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>multLocal</code> multiplies 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 mult to this vector.
|
||||
* @return this
|
||||
*/
|
||||
public Vector4f mult(Vector4f vec) {
|
||||
if (null == vec) {
|
||||
logger.warning("Provided vector is null, null returned.");
|
||||
return null;
|
||||
}
|
||||
return mult(vec, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>multLocal</code> multiplies 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 mult to this vector.
|
||||
* @param store result vector (null to create a new vector)
|
||||
* @return this
|
||||
*/
|
||||
public Vector4f mult(Vector4f vec, Vector4f store) {
|
||||
if (null == vec) {
|
||||
logger.warning("Provided vector is null, null returned.");
|
||||
return null;
|
||||
}
|
||||
if (store == null)
|
||||
store = new Vector4f();
|
||||
return store.set(x * vec.x, y * vec.y, z * vec.z, w * vec.w);
|
||||
}
|
||||
|
||||
/**
|
||||
* <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>.
|
||||
*/
|
||||
public Vector4f divide(float scalar) {
|
||||
scalar = 1f / scalar;
|
||||
return new Vector4f(x * scalar, y * scalar, z * scalar, w * scalar);
|
||||
}
|
||||
|
||||
/**
|
||||
* <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
|
||||
*/
|
||||
public Vector4f divideLocal(float scalar) {
|
||||
scalar = 1f / scalar;
|
||||
x *= scalar;
|
||||
y *= scalar;
|
||||
z *= scalar;
|
||||
w *= scalar;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>divide</code> divides the values of this vector by a scalar and
|
||||
* returns the result. The values of this vector remain untouched.
|
||||
*
|
||||
* @param scalar the value to divide this vectors attributes by.
|
||||
* @return the result <code>Vector</code>.
|
||||
*/
|
||||
public Vector4f divide(Vector4f scalar) {
|
||||
return new Vector4f(x / scalar.x, y / scalar.y, z / scalar.z, w / scalar.w);
|
||||
}
|
||||
|
||||
/**
|
||||
* <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
|
||||
*/
|
||||
public Vector4f divideLocal(Vector4f scalar) {
|
||||
x /= scalar.x;
|
||||
y /= scalar.y;
|
||||
z /= scalar.z;
|
||||
w /= scalar.w;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* <code>negate</code> returns the negative of this vector. All values are
|
||||
* negated and set to a new vector.
|
||||
*
|
||||
* @return the negated vector.
|
||||
*/
|
||||
public Vector4f negate() {
|
||||
return new Vector4f(-x, -y, -z, -w);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* <code>negateLocal</code> negates the internal values of this vector.
|
||||
*
|
||||
* @return this.
|
||||
*/
|
||||
public Vector4f negateLocal() {
|
||||
x = -x;
|
||||
y = -y;
|
||||
z = -z;
|
||||
w = -w;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* <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.
|
||||
*
|
||||
* @param vec the vector to subtract from this vector.
|
||||
* @return the result vector.
|
||||
*/
|
||||
public Vector4f subtract(Vector4f vec) {
|
||||
return new Vector4f(x - vec.x, y - vec.y, z - vec.z, w - vec.w);
|
||||
}
|
||||
|
||||
/**
|
||||
* <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
|
||||
*/
|
||||
public Vector4f subtractLocal(Vector4f vec) {
|
||||
if (null == vec) {
|
||||
logger.warning("Provided vector is null, null returned.");
|
||||
return null;
|
||||
}
|
||||
x -= vec.x;
|
||||
y -= vec.y;
|
||||
z -= vec.z;
|
||||
w -= vec.w;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* <code>subtract</code>
|
||||
*
|
||||
* @param vec the vector to subtract from this
|
||||
* @param result the vector to store the result in
|
||||
* @return result
|
||||
*/
|
||||
public Vector4f subtract(Vector4f vec, Vector4f result) {
|
||||
if (result == null) {
|
||||
result = new Vector4f();
|
||||
}
|
||||
result.x = x - vec.x;
|
||||
result.y = y - vec.y;
|
||||
result.z = z - vec.z;
|
||||
result.w = w - vec.w;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* <code>subtract</code> subtracts the provided values from this vector,
|
||||
* creating a new vector that is then returned.
|
||||
*
|
||||
* @param subtractX the x value to subtract.
|
||||
* @param subtractY the y value to subtract.
|
||||
* @param subtractZ the z value to subtract.
|
||||
* @param subtractW the w value to subtract.
|
||||
* @return the result vector.
|
||||
*/
|
||||
public Vector4f subtract(float subtractX, float subtractY, float subtractZ, float subtractW) {
|
||||
return new Vector4f(x - subtractX, y - subtractY, z - subtractZ, w - subtractW);
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>subtractLocal</code> subtracts the provided values from this vector
|
||||
* internally, and returns a handle to this vector for easy chaining of
|
||||
* calls.
|
||||
*
|
||||
* @param subtractX the x value to subtract.
|
||||
* @param subtractY the y value to subtract.
|
||||
* @param subtractZ the z value to subtract.
|
||||
* @param subtractW the w value to subtract.
|
||||
* @return this
|
||||
*/
|
||||
public Vector4f subtractLocal(
|
||||
float subtractX,
|
||||
float subtractY,
|
||||
float subtractZ,
|
||||
float subtractW
|
||||
) {
|
||||
x -= subtractX;
|
||||
y -= subtractY;
|
||||
z -= subtractZ;
|
||||
w -= subtractW;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>normalize</code> returns the unit vector of this vector.
|
||||
*
|
||||
* @return unit vector of this vector.
|
||||
*/
|
||||
public Vector4f normalize() {
|
||||
// float length = length();
|
||||
// if (length != 0) {
|
||||
// return divide(length);
|
||||
// }
|
||||
//
|
||||
// return divide(1);
|
||||
float length = x * x + y * y + z * z + w * w;
|
||||
if (length != 1f && length != 0f) {
|
||||
length = 1.0f / FastMath.sqrt(length);
|
||||
return new Vector4f(x * length, y * length, z * length, w * length);
|
||||
}
|
||||
return clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>normalizeLocal</code> makes this vector into a unit vector of
|
||||
* itself.
|
||||
*
|
||||
* @return this.
|
||||
*/
|
||||
public Vector4f normalizeLocal() {
|
||||
// NOTE: this implementation is more optimized
|
||||
// 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) {
|
||||
length = 1.0f / FastMath.sqrt(length);
|
||||
x *= length;
|
||||
y *= length;
|
||||
z *= length;
|
||||
w *= length;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>maxLocal</code> computes the maximum value for each component in
|
||||
* this and <code>other</code> vector. The result is stored in this vector.
|
||||
*
|
||||
* @param other
|
||||
*/
|
||||
public 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;
|
||||
w = other.w > w ? other.w : w;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>minLocal</code> computes the minimum value for each component in
|
||||
* this and <code>other</code> vector. The result is stored in this vector.
|
||||
*
|
||||
* @param other
|
||||
*/
|
||||
public 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;
|
||||
w = other.w < w ? other.w : w;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>zero</code> resets this vector's data to zero internally.
|
||||
*/
|
||||
public Vector4f zero() {
|
||||
x = y = z = w = 0;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>angleBetween</code> returns (in radians) the angle between two
|
||||
* vectors. It is assumed that both this vector and the given vector are
|
||||
* unit vectors (iow, normalized).
|
||||
*
|
||||
* @param otherVector a unit vector to find the angle against
|
||||
* @return the angle in radians.
|
||||
*/
|
||||
public float angleBetween(Vector4f otherVector) {
|
||||
float dotProduct = dot(otherVector);
|
||||
float angle = FastMath.acos(dotProduct);
|
||||
return angle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this vector to the interpolation by changeAmnt from this to the
|
||||
* finalVec this=(1-changeAmnt)*this + changeAmnt * finalVec
|
||||
*
|
||||
* @param finalVec The final vector to interpolate towards
|
||||
* @param changeAmnt An amount between 0.0 - 1.0 representing a precentage
|
||||
* change from this towards finalVec
|
||||
*/
|
||||
public Vector4f interpolate(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;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this vector to the interpolation by changeAmnt from beginVec to
|
||||
* finalVec this=(1-changeAmnt)*beginVec + changeAmnt * finalVec
|
||||
*
|
||||
* @param beginVec the beging vector (changeAmnt=0)
|
||||
* @param finalVec The final vector to interpolate towards
|
||||
* @param changeAmnt An amount between 0.0 - 1.0 representing a precentage
|
||||
* change from beginVec towards finalVec
|
||||
*/
|
||||
public Vector4f interpolate(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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector4f clone() {
|
||||
try {
|
||||
return (Vector4f) super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
throw new AssertionError(); // can not happen
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves this Vector3f into the given float[] object.
|
||||
*
|
||||
* @param floats The float[] to take this Vector3f. If null, a new float[3]
|
||||
* is created.
|
||||
* @return The array, with X, Y, Z float values in that order
|
||||
*/
|
||||
public float[] toArray(float[] floats) {
|
||||
if (floats == null) {
|
||||
floats = new float[4];
|
||||
}
|
||||
floats[0] = x;
|
||||
floats[1] = y;
|
||||
floats[2] = z;
|
||||
floats[3] = w;
|
||||
return floats;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @return true if they are equal
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof Vector4f)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>hashCode</code> returns a unique code for this vector object based
|
||||
* on it's values. If two vectors are logically equivalent, they will return
|
||||
* the same hash code value.
|
||||
*
|
||||
* @return the hash code value of this vector.
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 37;
|
||||
hash += 37 * hash + Float.floatToIntBits(x);
|
||||
hash += 37 * hash + Float.floatToIntBits(y);
|
||||
hash += 37 * hash + Float.floatToIntBits(z);
|
||||
hash += 37 * hash + Float.floatToIntBits(w);
|
||||
return hash;
|
||||
}
|
||||
|
||||
/**
|
||||
* <code>toString</code> returns the string representation of this vector.
|
||||
* The format is:
|
||||
*
|
||||
* org.jme.math.Vector3f [X=XX.XXXX, Y=YY.YYYY, Z=ZZ.ZZZZ, W=WW.WWWW]
|
||||
*
|
||||
* @return the string representation of this vector.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "(" + x + ", " + y + ", " + z + ", " + w + ")";
|
||||
}
|
||||
|
||||
public float getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public Vector4f setX(float x) {
|
||||
this.x = x;
|
||||
return this;
|
||||
}
|
||||
|
||||
public float getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public Vector4f setY(float y) {
|
||||
this.y = y;
|
||||
return this;
|
||||
}
|
||||
|
||||
public float getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public Vector4f setZ(float z) {
|
||||
this.z = z;
|
||||
return this;
|
||||
}
|
||||
|
||||
public float getW() {
|
||||
return w;
|
||||
}
|
||||
|
||||
public Vector4f setW(float w) {
|
||||
this.w = w;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param index
|
||||
* @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.
|
||||
*/
|
||||
public float get(int index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
return x;
|
||||
case 1:
|
||||
return y;
|
||||
case 2:
|
||||
return z;
|
||||
case 3:
|
||||
return w;
|
||||
}
|
||||
throw new IllegalArgumentException("index must be either 0, 1, 2 or 3");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param index which field index in this vector to set.
|
||||
* @param value to set to one of x, y, z or w.
|
||||
* @throws IllegalArgumentException if index is not one of 0, 1, 2, 3.
|
||||
*/
|
||||
public void set(int index, float value) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
x = value;
|
||||
return;
|
||||
case 1:
|
||||
y = value;
|
||||
return;
|
||||
case 2:
|
||||
z = value;
|
||||
return;
|
||||
case 3:
|
||||
w = value;
|
||||
return;
|
||||
}
|
||||
throw new IllegalArgumentException("index must be either 0, 1, 2 or 3");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2012 jMonkeyEngine
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package com.jme3.system;
|
||||
|
||||
/**
|
||||
* <code>NanoTimer</code> is a System.nanoTime implementation of
|
||||
* <code>Timer</code>. This is primarily useful for headless applications
|
||||
* running on a server.
|
||||
*
|
||||
* @author Matthew D. Hicks
|
||||
*/
|
||||
public class NanoTimer extends Timer {
|
||||
|
||||
private static final long TIMER_RESOLUTION = 1000000000L;
|
||||
private static final float INVERSE_TIMER_RESOLUTION = 1f / TIMER_RESOLUTION;
|
||||
|
||||
private long startTime;
|
||||
private long previousTime;
|
||||
private float tpf;
|
||||
private float fps;
|
||||
private long currentTime;
|
||||
|
||||
public NanoTimer() {
|
||||
startTime = System.nanoTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the time in seconds. The timer starts at 0.0 seconds.
|
||||
*
|
||||
* @return the current time in seconds
|
||||
*/
|
||||
|
||||
protected long getTimeInternal() {
|
||||
return System.nanoTime() - startTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTimeInSeconds() {
|
||||
return getTime() * INVERSE_TIMER_RESOLUTION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTime() {
|
||||
return currentTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getResolution() {
|
||||
return TIMER_RESOLUTION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getFrameRate() {
|
||||
return fps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getTimePerFrame() {
|
||||
return tpf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
currentTime = getTimeInternal();
|
||||
tpf = (currentTime - previousTime) * (1.0f / TIMER_RESOLUTION);
|
||||
fps = 1.0f / tpf;
|
||||
previousTime = getTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
startTime = System.nanoTime();
|
||||
currentTime = getTimeInternal();
|
||||
previousTime = getTime();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2012 jMonkeyEngine
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package com.jme3.system;
|
||||
|
||||
/**
|
||||
* <code>Timer</code> is the base class for a high resolution timer. It is
|
||||
* created from getTimer("display system")
|
||||
*
|
||||
* @author Mark Powell
|
||||
* @version $Id: Timer.java,v 1.18 2007/03/09 10:19:34 rherlitz Exp $
|
||||
*/
|
||||
public abstract class Timer {
|
||||
|
||||
/**
|
||||
* Returns the current time in ticks. A tick is an arbitrary measure of time
|
||||
* defined by the timer implementation. The number of ticks per second is
|
||||
* given by <code>getResolution()</code>. The timer starts at 0 ticks.
|
||||
*
|
||||
* @return a long value representing the current time
|
||||
*/
|
||||
public abstract long getTime();
|
||||
|
||||
/**
|
||||
* Returns the time in seconds. The timer starts at 0.0 seconds.
|
||||
*
|
||||
* @return the current time in seconds
|
||||
*/
|
||||
public float getTimeInSeconds() {
|
||||
return getTime() / (float) getResolution();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the resolution of the timer.
|
||||
*
|
||||
* @return the number of timer ticks per second
|
||||
*/
|
||||
public abstract long getResolution();
|
||||
|
||||
/**
|
||||
* Returns the "calls per second". If this is called every frame, then it
|
||||
* will return the "frames per second".
|
||||
*
|
||||
* @return The "calls per second".
|
||||
*/
|
||||
public abstract float getFrameRate();
|
||||
|
||||
/**
|
||||
* Returns the time, in seconds, between the last call and the current one.
|
||||
*
|
||||
* @return Time between this call and the last one.
|
||||
*/
|
||||
public abstract float getTimePerFrame();
|
||||
|
||||
/**
|
||||
* <code>update</code> recalculates the frame rate based on the previous
|
||||
* call to update. It is assumed that update is called each frame.
|
||||
*/
|
||||
public abstract void update();
|
||||
|
||||
/**
|
||||
* Reset the timer to 0. Clear any tpf history.
|
||||
*/
|
||||
public abstract void reset();
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2012 jMonkeyEngine
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package com.jme3.util;
|
||||
|
||||
import com.jme3.math.*;
|
||||
|
||||
|
||||
/**
|
||||
* Temporary variables assigned to each thread. Engine classes may access these
|
||||
* temp variables with TempVars.get(), all retrieved TempVars instances must be
|
||||
* returned via TempVars.release(). This returns an available instance of the
|
||||
* TempVar class ensuring this particular instance is never used elsewhere in
|
||||
* the mean time.
|
||||
*/
|
||||
public class TempVars {
|
||||
|
||||
/**
|
||||
* Allow X instances of TempVars in a single thread.
|
||||
*/
|
||||
private static final int STACK_SIZE = 5;
|
||||
|
||||
/**
|
||||
* <code>TempVarsStack</code> contains a stack of TempVars. Every time
|
||||
* TempVars.get() is called, a new entry is added to the stack, and the
|
||||
* index incremented. When TempVars.release() is called, the entry is
|
||||
* checked against the current instance and then the index is decremented.
|
||||
*/
|
||||
private static class TempVarsStack {
|
||||
|
||||
int index = 0;
|
||||
TempVars[] tempVars = new TempVars[STACK_SIZE];
|
||||
}
|
||||
|
||||
/**
|
||||
* ThreadLocal to store a TempVarsStack for each thread. This ensures each
|
||||
* thread has a single TempVarsStack that is used only in method calls in
|
||||
* that thread.
|
||||
*/
|
||||
private static final ThreadLocal<TempVarsStack> varsLocal = new ThreadLocal<TempVarsStack>() {
|
||||
|
||||
@Override
|
||||
public TempVarsStack initialValue() {
|
||||
return new TempVarsStack();
|
||||
}
|
||||
};
|
||||
/**
|
||||
* This instance of TempVars has been retrieved but not released yet.
|
||||
*/
|
||||
private boolean isUsed = false;
|
||||
|
||||
private TempVars() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Acquire an instance of the TempVar class. You have to release the
|
||||
* instance after use by calling the release() method. If more than
|
||||
* STACK_SIZE (currently 5) instances are requested in a single thread then
|
||||
* an ArrayIndexOutOfBoundsException will be thrown.
|
||||
*
|
||||
* @return A TempVar instance
|
||||
*/
|
||||
public static TempVars get() {
|
||||
TempVarsStack stack = varsLocal.get();
|
||||
|
||||
TempVars instance = stack.tempVars[stack.index];
|
||||
|
||||
if (instance == null) {
|
||||
// Create new
|
||||
instance = new TempVars();
|
||||
|
||||
// Put it in there
|
||||
stack.tempVars[stack.index] = instance;
|
||||
}
|
||||
|
||||
stack.index++;
|
||||
|
||||
instance.isUsed = true;
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases this instance of TempVars. Once released, the contents of the
|
||||
* TempVars are undefined. The TempVars must be released in the opposite
|
||||
* order that they are retrieved, e.g. Acquiring vars1, then acquiring
|
||||
* vars2, vars2 MUST be released first otherwise an exception will be
|
||||
* thrown.
|
||||
*/
|
||||
public void release() {
|
||||
if (!isUsed) {
|
||||
throw new IllegalStateException("This instance of TempVars was already released!");
|
||||
}
|
||||
|
||||
isUsed = false;
|
||||
|
||||
TempVarsStack stack = varsLocal.get();
|
||||
|
||||
// Return it to the stack
|
||||
stack.index--;
|
||||
|
||||
// Check if it is actually there
|
||||
if (stack.tempVars[stack.index] != this) {
|
||||
throw new IllegalStateException(
|
||||
"An instance of TempVars has not been released in a called method!"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Color
|
||||
*/
|
||||
public final ColorRGBA color = new ColorRGBA();
|
||||
/**
|
||||
* General vectors.
|
||||
*/
|
||||
public final Vector3f vect1 = new Vector3f();
|
||||
public final Vector3f vect2 = new Vector3f();
|
||||
public final Vector3f vect3 = new Vector3f();
|
||||
public final Vector3f vect4 = new Vector3f();
|
||||
public final Vector3f vect5 = new Vector3f();
|
||||
public final Vector3f vect6 = new Vector3f();
|
||||
public final Vector3f vect7 = new Vector3f();
|
||||
// seems the maximum number of vector used is 7 in com.jme3.bounding.java
|
||||
public final Vector3f vect8 = new Vector3f();
|
||||
public final Vector3f vect9 = new Vector3f();
|
||||
public final Vector3f vect10 = new Vector3f();
|
||||
public final Vector4f vect4f = new Vector4f();
|
||||
public final Vector3f[] tri = { new Vector3f(),
|
||||
new Vector3f(),
|
||||
new Vector3f() };
|
||||
/**
|
||||
* 2D vector
|
||||
*/
|
||||
public final Vector2f vect2d = new Vector2f();
|
||||
public final Vector2f vect2d2 = new Vector2f();
|
||||
/**
|
||||
* General matrices.
|
||||
*/
|
||||
public final Matrix3f tempMat3 = new Matrix3f();
|
||||
public final Matrix4f tempMat4 = new Matrix4f();
|
||||
public final Matrix4f tempMat42 = new Matrix4f();
|
||||
/**
|
||||
* General quaternions.
|
||||
*/
|
||||
public final Quaternion quat1 = new Quaternion();
|
||||
public final Quaternion quat2 = new Quaternion();
|
||||
|
||||
public final float[] matrixWrite = new float[16];
|
||||
}
|
||||
Reference in new issue
Block a user