public class SimpleVector
extends java.lang.Object
implements java.io.Serializable
Modifier and Type | Field and Description |
---|---|
static SimpleVector |
ORIGIN
A SimpleVector representing the origin (0,0,0)
|
float |
x
The x component of the vector
|
float |
y
The y component of the vector
|
float |
z
The z component of the vector
|
Constructor and Description |
---|
SimpleVector()
Creates a new SimpleVector and sets the x,y and z components to zero
|
SimpleVector(double x,
double y,
double z)
Creates a new SimpleVector by setting the x,y and z components of the
vector.
|
SimpleVector(float[] vector)
Creates a new SimpleVector from an array[3] of floats
|
SimpleVector(float x,
float y,
float z)
Creates a new SimpleVector by setting the x,y and z components of the
vector
|
SimpleVector(SimpleVector s)
Creates a new SimpleVector from an existing one
|
Modifier and Type | Method and Description |
---|---|
void |
add(SimpleVector vec)
Adds another SimpleVector to this SimpleVector without creating a new
instance.
|
SimpleVector |
calcAdd(SimpleVector vec)
Add two SimpleVectors to a new SimpleVector.
|
float |
calcAngle(SimpleVector vec)
Calculates the angle between this SimpleVector and another one.
|
float |
calcAngleFast(SimpleVector vec)
Calculates the angle between this SimpleVector and another one.
|
SimpleVector |
calcCross(SimpleVector vec)
Calculates the cross product of two SimpleVectors.
|
float |
calcDot(SimpleVector vec)
Calculates the dot product of two SimpleVectors.
|
SimpleVector |
calcSub(SimpleVector vec)
Calculates the difference vector of two SimpleVectors.
|
static SimpleVector |
create()
Another way to create a SimpleVector.
|
static SimpleVector |
create(float x,
float y,
float z)
Another way to create a SimpleVector.
|
static SimpleVector |
create(SimpleVector sv)
Another way to create a SimpleVector.
|
float |
distance(SimpleVector pos)
Returns the distance between this SimpleVector and another position
vector.
|
boolean |
equals(java.lang.Object obj)
Overrides the equals()-method from java.lang.Object.
|
Matrix |
getRotationMatrix()
Creates a rotation matrix that can be used to rotate a vector pointing to
(0,0,1) to match the direction of this vector.
|
Matrix |
getRotationMatrix(Matrix mat)
Creates a rotation matrix that can be used to rotate a vector pointing to
(0,0,1) to match the direction of this vector.
|
Matrix |
getRotationMatrix(Matrix mat,
SimpleVector up)
Creates a rotation matrix that can be used to rotate a vector pointing to
(0,0,1) to match the direction of this vector.
|
Matrix |
getRotationMatrix(SimpleVector up)
Creates a rotation matrix that can be used to rotate a vector pointing to
(0,0,1) to match the direction of this vector.
|
int |
hashCode()
Overrides hashCode() from java.lang.Object.
|
float |
length()
Gives the length of this SimpleVector
|
void |
makeEqualLength(SimpleVector vec)
Makes this SimpleVector the length of another SimpleVector, but only if
its longer than this.
|
void |
matMul(Matrix mat)
Multiplies the SimpleVector with a matrix, i.e. it applies the matrix's
transformation to the SimpleVector.
|
SimpleVector |
normalize()
Normalizes a SimpleVector and returns a normalized vector as a new
SimpleVector.
|
SimpleVector |
normalize(SimpleVector sv)
Normalizes a SimpleVector and returns a normalized vector as a new
SimpleVector.
|
SimpleVector |
reflect(SimpleVector faceNormal)
Reflects this vector on a plane with the given normal.
|
void |
rotate(Matrix mat)
Similar to matMul(), but uses only the rotational part of the matrix.
|
SimpleVector |
rotate(SimpleVector rotVector)
Rotates this SimpleVector using the angles (x,y,z) of rotVector.
|
void |
rotateAxis(SimpleVector axis,
float angle)
Rotates the vector around an arbitrary axis.
|
void |
rotateX(float angle)
Rotates the SimpleVector around the x-axis.
|
void |
rotateY(float angle)
Rotates the SimpleVector around the y-axis.
|
void |
rotateZ(float angle)
Rotates the SimpleVector around the z-axis.
|
void |
scalarMul(float scalar)
Multiplies the SimpleVector with a scalar.
|
void |
set(float x,
float y,
float z)
Sets the x,y and z values of the SimpleVector to the given floats.
|
void |
set(SimpleVector s)
Sets the x,y and z values of this SimpleVector to the ones of the given
SimpleVector.
|
void |
sub(SimpleVector vec)
Subtracts another SimpleVector from this SimpleVector without creating a
new instance.
|
float[] |
toArray()
Returns an float[3]-array containing the components of the vector so that
[0]=x, [1]=y and [2]=z.
|
java.lang.String |
toString()
Returns this SimpleVector as a String.
|
public static final SimpleVector ORIGIN
public float x
public float y
public float z
public SimpleVector(float x, float y, float z)
x
- the x componenty
- the y componentz
- the z componentpublic SimpleVector(double x, double y, double z)
x
- the x componenty
- the y componentz
- the z componentpublic SimpleVector(SimpleVector s)
s
- the SimpleVector to "copy"public SimpleVector()
public SimpleVector(float[] vector)
vector
- the array containing the x, y and z components of the vector
in [0],[1] and [2].public static SimpleVector create()
public static SimpleVector create(SimpleVector sv)
sv
- the source vectorpublic static SimpleVector create(float x, float y, float z)
x
- the x componenty
- the y componentz
- the z componentpublic void set(float x, float y, float z)
public void set(SimpleVector s)
public float[] toArray()
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
obj
- the SimpleVector that should be compared to this onepublic int hashCode()
hashCode
in class java.lang.Object
public SimpleVector rotate(SimpleVector rotVector)
rotVector
- the rotation vector containing the angles for the rotations
around x,y and z axis.public void rotate(Matrix mat)
mat
- Matrix the rotation matrixmatMul(com.threed.jpct.Matrix)
public void rotateAxis(SimpleVector axis, float angle)
axis
- a direction-vector pointing into the axis directionangle
- the angle of the rotationpublic SimpleVector reflect(SimpleVector faceNormal)
faceNormal
- the face normal of the reflective planepublic void rotateX(float angle)
angle
- the anglepublic void rotateY(float angle)
angle
- the anglepublic void rotateZ(float angle)
angle
- the anglepublic SimpleVector normalize()
public SimpleVector normalize(SimpleVector sv)
sv
- the SimpleVector to fillpublic float length()
public SimpleVector calcCross(SimpleVector vec)
vec
- the second SimpleVectorpublic float calcDot(SimpleVector vec)
vec
- the second SimpleVectorpublic SimpleVector calcSub(SimpleVector vec)
vec
- the second SimpleVectorpublic SimpleVector calcAdd(SimpleVector vec)
vec
- the second SimpleVectorpublic float distance(SimpleVector pos)
public float calcAngleFast(SimpleVector vec)
vec
- the other vectorpublic float calcAngle(SimpleVector vec)
vec
- the other vectorpublic void scalarMul(float scalar)
scalar
- the scalar to multiply withpublic void matMul(Matrix mat)
mat
- Matrix the matrix (usually a rotation or a translation matrix)public void add(SimpleVector vec)
vec
- the SimpleVector to addpublic void sub(SimpleVector vec)
vec
- the SimpleVector to subtractpublic void makeEqualLength(SimpleVector vec)
vec
- the SimpleVector that defines the lengthpublic Matrix getRotationMatrix()
public Matrix getRotationMatrix(SimpleVector up)
up
- the up vector used in the calculationpublic Matrix getRotationMatrix(Matrix mat)
mat
- the Matrix to fillpublic Matrix getRotationMatrix(Matrix mat, SimpleVector up)
up
- the up vector used in the calculationmat
- the Matrix to fill