Scripting API

Home Scripting API Index Class Overview

nlvm.math3d

Class Vector3f


public final class Vector3f
extends Object

Represents a vector of 3 floats. Objects of this class are mutable.

Field Summary

float x
float y
float z


Constructor Summary

Vector3f()
    Default constructor initializing all components to zero
Vector3f(float x, float y, float z)
    Constructs a vector using 3 components
Vector3f(Vector3f vec)
    Constructs a copy of vec


Method Summary

void add(float scalar)
  Add a scalar to all components of this
void add(Vector3f vec)
  Add a vector to this
void cross(Vector3f a, Vector3f b)
  Sets this to the cross product of a and b
float distance(Vector3f vec)
  Returns the distance between this and the argument vector
void div(float scalar)
  Divides a scalar from all components of this
void div(Vector3f vec)
  Divides a vector from this (component wise division)
float dot(Vector3f b)
  Computes the 3d dot product of this and a second vector
Vector3f dup()
  Creates a copy
bool equals(Object obj)
float length()
  Returns the euclidean length of this vector
void lerp(float t, Vector3f a, Vector3f b)
  Sets this to a linear interpolation between a and b
void mul(float scalar)
  Multiplies a scalar to all components of this
void mul(Vector3f vec)
  Multiplies a vector to this (component wise multiplication)
float normalize()
  Normalizes the vector (make the euclidean length to 1)
void set(float scalar)
  Sets all components of the vector with a scalar
void set(float x, float y, float z)
  Sets the vector using 3 components
void set(Vector3f vec)
  Sets the vector's elements from the elements of vec
void setZero()
  Sets the vector's elements to zero
float sqrDistance(Vector3f vec)
  Returns the squared distance between this and the argument vector
float sqrLength()
  Returns the squared euclidean length of this vector
void sub(float scalar)
  Subtract a scalar from all components of this
void sub(Vector3f vec)
  Subtract a vector from this
String toString()


Field Detail


x

public float x


y

public float y


z

public float z


Constructor Detail


Vector3f

public Vector3f()

Default constructor initializing all components to zero


Vector3f

public Vector3f(float x, float y, float z)

Constructs a vector using 3 components


Vector3f

public Vector3f(Vector3f vec)

Constructs a copy of vec


Method Detail


add

public final void add(float scalar)

Add a scalar to all components of this


add

public final void add(Vector3f vec)

Add a vector to this


cross

public final void cross(Vector3f a, Vector3f b)

Sets this to the cross product of a and b

Pseudo code: this = a (x) b. All parameters including this might be the same reference.

Parameters:

a - first vector
b - second vector

Since:
    2.2.4.3


distance

public final float distance(Vector3f vec)

Returns the distance between this and the argument vector

Parameters:

vec - the argument vector

Returns:
    the distance between this and vec

Since:
    2.2.4.3


div

public final void div(float scalar)

Divides a scalar from all components of this


div

public final void div(Vector3f vec)

Divides a vector from this (component wise division)


dot

public final float dot(Vector3f b)

Computes the 3d dot product of this and a second vector

Pseudo code: result = this.x*b.x + this.y*b.y + this.z*b.z

Parameters:

b - second vector

Returns:
    dot product of this and b

Since:
    2.6.2.0


dup

public final Vector3f dup()

Creates a copy


equals

public bool equals(Object obj)


length

public final float length()

Returns the euclidean length of this vector

Returns:
    the squared length of this


lerp

public final void lerp(float t, Vector3f a, Vector3f b)

Sets this to a linear interpolation between a and b

Pseudo code: this = (1-t) * a + t * b. All parameters including this might be the same reference.

Parameters:

a - first vector
b - second vector

mul

public final void mul(float scalar)

Multiplies a scalar to all components of this


mul

public final void mul(Vector3f vec)

Multiplies a vector to this (component wise multiplication)


normalize

public final float normalize()

Normalizes the vector (make the euclidean length to 1)

If the length is currently 0, the vector will be set to the zero vector Returns the length prior to normalization.


set

public final void set(float scalar)

Sets all components of the vector with a scalar

x, y, z will be set to scalar

Since:
    2.6.2.0


set

public final void set(float x, float y, float z)

Sets the vector using 3 components


set

public final void set(Vector3f vec)

Sets the vector's elements from the elements of vec


setZero

public final void setZero()

Sets the vector's elements to zero


sqrDistance

public final float sqrDistance(Vector3f vec)

Returns the squared distance between this and the argument vector

Is slightly faster than distance().

Parameters:

vec - the argument vector

Returns:
    the squared distance between this and vec

Since:
    2.2.4.3


sqrLength

public final float sqrLength()

Returns the squared euclidean length of this vector

Is slightly faster than length().

Returns:
    the squared length of this


sub

public final void sub(float scalar)

Subtract a scalar from all components of this


sub

public final void sub(Vector3f vec)

Subtract a vector from this


toString

public String toString()