Enfusion Script API
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
vector Interface Reference

Public Member Functions

proto external void Normalize ()
 Normalizes vector.
 
proto external float NormalizeSize ()
 Normalizes vector.
 
proto external vector Normalized ()
 return normalized vector (keeps the orginal vector untouched)
 
proto external float Length ()
 Returns length of vector (magnitude)
 
proto external float LengthSq ()
 Returns squared length (magnitudeSqr)
 
proto external vector Perpend ()
 Returns perpendicular vector.
 
proto external vector MapAngles (float fFromRange=360, float fToLow=-180, float fToHigh=180)
 Re-map angles from one range to another.
 
proto external float ToYaw ()
 Returns yaw of vector (use XZ plane).
 
proto external vector VectorToAngles ()
 Converts vector to spherical coordinates with radius = 1.
 
proto external vector AnglesToVector ()
 Converts spherical coordinates (yaw, pitch, roll in degrees) to unit length vector.
 
proto external void QuatFromAngles (out float quat[4])
 Create quaternion from angles (yaw pitch roll in degrees)
 
proto external vector Multiply4 (vector mat[4])
 Transforms position.
 
proto external vector Multiply3 (vector mat[3])
 Transforms vector.
 
proto external vector InvMultiply4 (vector mat[4])
 Invert-transforms position.
 
proto external vector InvMultiply3 (vector mat[3])
 Invert-transforms vector.
 
proto external string ToString (bool beautify=true)
 

Static Public Member Functions

static proto float Distance (vector v1, vector v2)
 Returns the distance between tips of two 3D vectors.
 
static proto float DistanceXZ (vector v1, vector v2)
 
static proto float DistanceSq (vector v1, vector v2)
 Returns the squere distance between tips of two 3D vectors.
 
static proto float DistanceSqXZ (vector v1, vector v2)
 
static proto vector Direction (vector p1, vector p2)
 Returns direction vector from point p1 to point p2.
 
static proto float Dot (vector v1, vector v2)
 Returns Dot product of vector v1 and vector v2.
 
static proto float DotXZ (vector v1, vector v2)
 
static proto vector FromYaw (float yaw)
 Returns vector of yaw (in XZ plane)
 
static proto vector Lerp (vector v1, vector v2, float t)
 Lerp between two vectors.
 

Static Public Attributes

static const vector Up = "0 1 0"
 
static const vector Right = "1 0 0"
 
static const vector Forward = "0 0 1"
 
static const vector Zero = "0 0 0"
 
static const vector One = "1 1 1"
 

Member Function Documentation

◆ AnglesToVector()

proto external vector vector.AnglesToVector ( )

Converts spherical coordinates (yaw, pitch, roll in degrees) to unit length vector.

Returns
normalized direction vector
vector v1 = "45 0 0";
vector v2 = "15 60 0";
>> <0.707107,0,0.707107>
>> <0.12941,0.866025,0.482963>
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
Definition: vector.c:13
proto external vector AnglesToVector()
Converts spherical coordinates (yaw, pitch, roll in degrees) to unit length vector.

◆ Direction()

static proto vector vector.Direction ( vector  p1,
vector  p2 
)
static

Returns direction vector from point p1 to point p2.

Parameters
p1vector point from
p2vector point to
Returns
vector direction vector

◆ Distance()

static proto float vector.Distance ( vector  v1,
vector  v2 
)
static

Returns the distance between tips of two 3D vectors.

Parameters
v1vector 3D Vector 1
v2vector 3D Vector 2
Returns
float Distance
float dist = vector.Distance( "1 2 3", "4 5 6" );
Print( dist );
>> dist = 5.19615
static proto float Distance(vector v1, vector v2)
Returns the distance between tips of two 3D vectors.

◆ DistanceSq()

static proto float vector.DistanceSq ( vector  v1,
vector  v2 
)
static

Returns the squere distance between tips of two 3D vectors.

Parameters
v1vector 3D Vector 1
v2vector 3D Vector 2
Returns
float Squere distance
float dist = vector.DistanceSq( "0 0 0", "0 5 0" );
Print( dist );
>> dist = 25
static proto float DistanceSq(vector v1, vector v2)
Returns the squere distance between tips of two 3D vectors.

◆ DistanceSqXZ()

static proto float vector.DistanceSqXZ ( vector  v1,
vector  v2 
)
static

◆ DistanceXZ()

static proto float vector.DistanceXZ ( vector  v1,
vector  v2 
)
static

◆ Dot()

static proto float vector.Dot ( vector  v1,
vector  v2 
)
static

Returns Dot product of vector v1 and vector v2.

Parameters
v1vector input vector
v2vector input vector
Returns
float dot product

◆ DotXZ()

static proto float vector.DotXZ ( vector  v1,
vector  v2 
)
static

◆ FromYaw()

static proto vector vector.FromYaw ( float  yaw)
static

Returns vector of yaw (in XZ plane)

Parameters
yawfloat Value of yaw (in degrees)
Returns
vector Yaw converted in vector (in XZ plane)
>> <1,0,0>
>> <0.707107,0,0.707107>
static proto vector FromYaw(float yaw)
Returns vector of yaw (in XZ plane)

◆ InvMultiply3()

proto external vector vector.InvMultiply3 ( vector  mat[3])

Invert-transforms vector.

Parameters
mattransformation matrix
Returns
Transformed vector
vector mat[3] = { "1.5 2.5 0", "0.1 1.3 0", "0 0 1" }; // rotation matrix
vector vec = "1 1 1";
Print( vec.InvMultiply3(mat) );
>> <4,1.4,1>
proto external vector InvMultiply3(vector mat[3])
Invert-transforms vector.

◆ InvMultiply4()

proto external vector vector.InvMultiply4 ( vector  mat[4])

Invert-transforms position.

Parameters
mattransformation matrix
Returns
transformed position
vector mat[4] = { "1 0 0 0", "0 1 0 0", "0 0 1 1", "3 1 2 1" }; // translation matrix
vector pos = "1 1 1";
Print( pos.InvMultiply4(mat) );
>> <-2,0,-1>
proto external vector InvMultiply4(vector mat[4])
Invert-transforms position.

◆ Length()

proto external float vector.Length ( )

Returns length of vector (magnitude)

Returns
float Length of vector
vector vec = "1 0 1";
float length = vec.Length();
Print( length );
>> length = 1.41421
proto external float Length()
Returns length of vector (magnitude)

◆ LengthSq()

proto external float vector.LengthSq ( )

Returns squared length (magnitudeSqr)

Returns
float Length of vector
vector vec = "1 1 0";
float length = vec.LengthSq();
Print( length );
>> length = 2
proto external float LengthSq()
Returns squared length (magnitudeSqr)

◆ Lerp()

static proto vector vector.Lerp ( vector  v1,
vector  v2,
float  t 
)
static

Lerp between two vectors.

vector v1 = Vector(0,0,0);
vector v2 = Vector(5,6,1);
Print( vector.Lerp(v1, v2, 0.5) );
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
static proto vector Lerp(vector v1, vector v2, float t)
Lerp between two vectors.

◆ MapAngles()

proto external vector vector.MapAngles ( float  fFromRange = 360,
float  fToLow = -180,
float  fToHigh = 180 
)

Re-map angles from one range to another.

Returns
float re-maped angles
vector angles = "-45 190 160";
Print( angles.MapAngles(360, -Math.PI, Math.PI) );
>> <-0.785398,-2.96706,2.79253>
Definition: Math.c:13
static const float PI
Definition: Math.c:17
proto external vector MapAngles(float fFromRange=360, float fToLow=-180, float fToHigh=180)
Re-map angles from one range to another.

◆ Multiply3()

proto external vector vector.Multiply3 ( vector  mat[3])

Transforms vector.

Parameters
mattransformation matrix
Returns
transformed vector
vector mat[3] = { "2 0 0", "0 3 0", "0 0 1" }; // scale matrix
vector vec = "1 1 1";
Print( vec.Multiply3(mat) );
>> <2,3,1>
proto external vector Multiply3(vector mat[3])
Transforms vector.

◆ Multiply4()

proto external vector vector.Multiply4 ( vector  mat[4])

Transforms position.

Parameters
mattransformation matrix
Returns
transformed position
vector mat[4] = { "1 0 0 0", "0 1 0 0", "0 0 1 1", "3 1 2 1" }; // translation matrix
vector pos = "1 1 1";
Print( pos.Multiply4(mat) );
>> <4,2,3>
proto external vector Multiply4(vector mat[4])
Transforms position.

◆ Normalize()

proto external void vector.Normalize ( )

Normalizes vector.

vector vec = "1 0 1";
vec.Normalize();
Print( vec );
>> vec = <0.707107,0,0.707107>
proto external void Normalize()
Normalizes vector.

◆ Normalized()

proto external vector vector.Normalized ( )

return normalized vector (keeps the orginal vector untouched)

◆ NormalizeSize()

proto external float vector.NormalizeSize ( )

Normalizes vector.

Returns its length.

Warning
Slower than calling Normalize() because additional calculations are necessary. Use Normalize() if the vector length is not needed.
Returns
float Length of origin vector
vector vec = "1 0 1";
float length = vec.NormalizeSize();
Print( vec );
Print( length );
>> vec = <0.707107,0,0.707107>
>> length = 1.41421
proto external float NormalizeSize()
Normalizes vector.

◆ Perpend()

proto external vector vector.Perpend ( )

Returns perpendicular vector.

Perpendicular vector is computed as cross product between input vector and up vector (0, 1, 0).

Returns
vector perpendicular vector
vector vec = "1 0 0";
Print( vec.Perpend() );
>> <0,0,1>
proto external vector Perpend()
Returns perpendicular vector.

◆ QuatFromAngles()

proto external void vector.QuatFromAngles ( out float  quat[4])

Create quaternion from angles (yaw pitch roll in degrees)

float q[4];
vector ang = "70 15 45";
ang.QuatFromAngles( q );
Print( q );
>> {-0.316402,0.484465,-0.241626,0.778973}
proto external void QuatFromAngles(out float quat[4])
Create quaternion from angles (yaw pitch roll in degrees)

◆ ToString()

proto external string vector.ToString ( bool  beautify = true)

◆ ToYaw()

proto external float vector.ToYaw ( )

Returns yaw of vector (use XZ plane).

Returns
Yaw of vector in degrees
vector v1 = "1 0 0";
vector v2 = "0.7 0 0.7";
Print( v1.ToYaw() );
Print( v2.ToYaw() );
>> 90
>> 45
proto external float ToYaw()
Returns yaw of vector (use XZ plane).

◆ VectorToAngles()

proto external vector vector.VectorToAngles ( )

Converts vector to spherical coordinates with radius = 1.

Returns
vector spherical coordinates (yaw, pitch, roll in degrees)
vector v1 = "1 0 1";
vector v2 = "1 1 1";
>> <45,-0,0>
>> <45,35.2644,0>
proto external vector VectorToAngles()
Converts vector to spherical coordinates with radius = 1.

Member Data Documentation

◆ Forward

const vector vector.Forward = "0 0 1"
static

◆ One

const vector vector.One = "1 1 1"
static

◆ Right

const vector vector.Right = "1 0 0"
static

◆ Up

const vector vector.Up = "0 1 0"
static

◆ Zero

const vector vector.Zero = "0 0 0"
static

The documentation for this interface was generated from the following file: