Vector4 is a vector suitable for three-dimensional math, containing (x, y, z, w) components

Static variables

staticread onlyX_AXIS:Vector4

A constant representing the x axis (1, 0, 0)

staticread onlyY_AXIS:Vector4

A constant representing the y axis (0, 1, 0)

staticread onlyZ_AXIS:Vector4

A constant representing the z axis (0, 0, 1)

Static methods

staticinlineangleBetween(a:Vector4, b:Vector4):Float

Calculates the angle between two Vector4 coordinates

Parameters:

a

A Vector4 instance

b

A second Vector4 instance

Returns:

The calculated angle

staticinlinedistance(pt1:Vector4, pt2:Vector4):Float

Calculates the distance between two vectors

Parameters:

pt1

A Vector4 instance

pt2

A second Vector4 instance

Returns:

The distance between each vector

staticinlinedistanceSquared(pt1:Vector4, pt2:Vector4):Float

Calculates the squared distance between two vectors, (avoids the use of Math.sqrt for faster performance)

Parameters:

pt1

A Vector4 instance

pt2

A second Vector4 instance

Returns:

The square of the distance between each vector

Constructor

@:value({ w : 0., z : 0., y : 0., x : 0. })new(x:Float = 0., y:Float = 0., z:Float = 0., w:Float = 0.)

Creates a new Vector4 instance

Parameters:

x

(Optional) An initial x value (default is 0)

y

(Optional) An initial y value (default is 0)

z

(Optional) An initial z value (default is 0)

w

(Optional) An initial w value (default is 0)

Variables

read onlylength:Float

Get the length of this vector

read onlylengthSquared:Float

Get the squared length of this vector (avoiding the use of Math.sqrt for faster performance)

w:Float

The w component value

x:Float

The x component value

y:Float

The y component value

z:Float

The z component value

Methods

@:value({ result : null })inlineadd(a:Vector4, ?result:Vector4):Vector4

Adds two Vector4 instances together and returns the result

Parameters:

a

A Vector4 instance to add to the current one

result

(Optional) A Vector4 instance to store the result

Returns:

A Vector4 instance with the added value

inlineclone():Vector4

Creates a new Vector4 instance with the same values as the current one

Returns:

A new Vector4 instance with the same values

inlinecopyFrom(sourceVector4:Vector4):Void

Copies the x, y and z component values of another Vector4 instance

Parameters:

sourceVector4

A Vector4 instance to copy from

@:value({ result : null })inlinecrossProduct(a:Vector4, ?result:Vector4):Vector4

Performs vector multiplication between this vector and another Vector4 instance

Parameters:

a

A Vector4 instance to multiply by

result

(Optional) A Vector4 to use for the result

Returns:

A Vector4 instance with the result

inlinedecrementBy(a:Vector4):Void

Decrements the x, y and z component values by those in another Vector4 instance

Parameters:

a

A Vector4 instance to decrement the current vector by

inlinedotProduct(a:Vector4):Float

Calculates the dot product of the current vector with another Vector4 instance

Parameters:

a

A Vector4 instance to use in the dot product

Returns:

The calculated dot product value

@:value({ allFour : false })inlineequals(toCompare:Vector4, allFour:Bool = false):Bool

Whether two Vector4 instances have equal component values.

Comparing the w component value is optional.

Parameters:

toCompare

A Vector4 instance to compare against

allFour

(Optional) Whether to compare against the w component (default is false)

Returns:

Whether both instances have equal values

inlineincrementBy(a:Vector4):Void

Increments the x, y and z component values by those in a second Vector4 instance

Parameters:

a

A Vector4 instance to increment the current vector by

@:value({ allFour : false })inlinenearEquals(toCompare:Vector4, tolerance:Float, allFour:Bool = false):Bool

Whether two Vector4 instances have nearly equal component values. Comparison is performed within a given tolerance value.

Parameters:

toCompare

A Vector4 instance to compare against

tolerance

A floating point value determining how near the values must be to be considered near equal

allFour

(Optional) Whether to compare against the w component (default is false)

Returns:

Whether both instances have equal values, within the given tolerance

inlinenegate():Void

Negates the x, y and z values of the current vector (multiplying each value by -1)

inlinenormalize():Float

Divides the x, y and z component values by the length of the vector

inlineproject():Void

Divides the x, y and z component values by the w component value

inlinescaleBy(s:Float):Void

Scales the x, y and z component values by a scale value

Parameters:

s

The amount of scale to apply

inlinesetTo(xa:Float, ya:Float, za:Float):Void

Sets the x, y and z component values

Parameters:

xa

An x value

ya

A y value

za

A z value

@:value({ result : null })inlinesubtract(a:Vector4, ?result:Vector4):Vector4

Subtracts the values of a second Vector4 instance from the current one

Parameters:

a

A second Vector4 instance to substract

result

(Optional) A Vector4 instance to store the result

Returns:

A Vector4 instance containing the subtracted value