DIFF

class vectorSource

Constants 4

static const vector Aside = "1 0 0"
static const vector Zero = "0 0 0"

Methods 28

proto float Normalize()

Normalizes vector. Returns length

Returns: float Length of origin vector

vector vec = "1 0 1";
float length = vec.Normalize();
Print( vec );
Print( length );

>> vec = <0.707107,0,0.707107>
>> length = 1.41421
proto native float LengthSq()

Returns squared length (magnitudeSqr)

Returns: float Length of vector

vector vec = "1 1 0";
float length = vec.LengthSq();
Print( length );

>> length = 2
proto static native float Distance(vector v1, vector v2)

Returns the distance between tips of two 3D vectors.

v1
vector 3D Vector 1
v2
vector 3D Vector 2

Returns: float Distance

float dist = vector.Distance( "1 2 3", "4 5 6" );
Print( dist );

>> dist = 5.19615
proto static native float DistanceSq(vector v1, vector v2)

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

v1
vector 3D Vector 1
v2
vector 3D Vector 2

Returns: float Squere distance

float dist = vector.DistanceSq( "0 0 0", "0 5 0" );
Print( dist );

>> dist = 25
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>
References Up
static vector Direction(vector p1, vector p2)

Returns direction vector from point p1 to point p2

p1
vector point from
p2
vector point to

Returns: vector direction vector

static vector RandomDir()

Returns randomly generated unit vector

Returns: randomly generated unit vector

vector vec = vector.RandomDir();
Print(vec);
Print(vec.Length());

>> <-0.179424,0.966825,0.181816>
>> 1
static vector RandomDir2D()

Returns randomly generated XZ unit vector with the Y(up) axis set to 0

Returns: randomly generated XZ unit vector

vector vec = vector.RandomDir();
Print(vec);
Print(vec.Length());

>> <0.631697,0,0.775216>
>> 1
vector GetRelAngles()

Returns relative angles between -180 and 180, not 0 to 360

Returns: float Relative angles

vector angles = "-45 190 160";
Print( angles.GetRelAngles() );

>> <-45,-170,160>
proto float VectorToYaw()

Returns yaw of vector

vec
vector Vector to convert yaw

Returns: float Yaw of vector

vector v1 = "0 1 0";
vector v2 = "0.7 0.7 0";
Print( v1.ToYaw() );
Print( v2.ToYaw() );

>> 90
>> 45
proto native static vector YawToVector(float yaw)

Returns vector of yaw

yaw
float Value of yaw

Returns: vector Yaw converted in vector

Print( vector.Yaw2Vector(90) );
Print( vector.Yaw2Vector(45) );

>> <0,1,0>
>> <0.707107,0.707107,0>
Referenced by RecoilBase.PostInit()
proto 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";
Print( v1.AnglesToVector() );
Print( v2.AnglesToVector() );

>> <0.707107,0,0.707107>
>> <0.12941,0.866025,0.482963>
proto void RotationMatrixFromAngles(out vector mat[3])

Creates rotation matrix from angles

ang
vector which contains angles
out mat
vector created rotation matrix
      vector mat[3];
vector ang = "70 15 45";
  	ang.RotationMatrixFromAngles( mat );
  	Print( mat );

>> <0.330366,0.0885213,-0.939693>,<0.458809,0.854988,0.241845>,<0.824835,-0.511037,0.241845>
proto vector Multiply4(vector mat[4])

Transforms position

mat
vector[4] transformation matrix
vec
vector position to transform

Returns: vector 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 vector Multiply3(vector mat[3])

Transforms vector

mat
vector[3] transformation matrix
vec
vector vector to transform

Returns: vector 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 vector InvMultiply4(vector mat[4])

Invert-transforms position

mat
vector[4] transformation matrix
vec
vector position to transform

Returns: vector 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 vector InvMultiply3(vector mat[3])

Invert-transforms vector

mat
vector[3] transformation matrix
vec
vector vector to transform

Returns: vector 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 static native vector Lerp(vector v1, vector v2, float t)

Lerp between two vectors

vector v1 = Vector(0,0,0);
vector v2 = Vector(5,6,1);
Print( vector.Lerp(v1, v2, 0.5) );
static vector RotateAroundZeroDeg(vector vec, vector axis, float angle)

Rotate a vector around 0,0,0 by an angle in degrees

vec
vector to rotate
axis
axis to rotate around
cosAngle
angle in degrees

Returns: vector transformed vector

References Math.Cos(), Dot(), Math.Sin()
Show 1 more, Math.DEG2RAD
static vector RotateAroundZeroRad(vector vec, vector axis, float angle)

Rotate a vector around 0,0,0 by an angle in radians

vec
vector to rotate
axis
axis to rotate around
cosAngle
angle in radians

Returns: vector transformed vector

References Math.Cos(), Dot(), and Math.Sin()
static vector RotateAroundZero(vector pos, vector axis, float cosAngle, float sinAngle)

Rotate a vector around 0,0,0

pos
vector to rotate
axis
axis to rotate around
cosAngle
cos of angle
sinAngle
sin of angle

Returns: vector transformed vector

References Dot()
static vector RotateAroundPoint(vector point, vector pos, vector axis, float cosAngle, float sinAngle)

Rotate a vector around point

point
point to rotate around
pos
vector to rotate
axis
axis to rotate around
cosAngle
cos of angle
sinAngle
sin of angle

Returns: vector transformed vector

static vector ArrayToVec(float arr[])

Convert static array of floats into a vector

arr
vector in array format

Returns: vector resulting vector

References Vector()