Turok EX Modding Guide

Scripts kVec3

Vectors represent a spatial offset – a distance in a specific direction. They form the basis of most spatial mathematics in the game. kVec3 uses the typical paradigm of maintaining an offset along each axis.

Technically, vectors and points are distinct and not interchangeable; however, Turok EX uses the common shortcut of using vectors to represent points, as they can implicitly be thought of as a point's offset from the origin.

Variables

float x, y, z

components of the vector

Constructors

void kVec3( float initX, float initY, float initZ )

initialize components to the given values

void kVec3( kVec3& v )

copy constructor

Methods

void Set( float newX, float newY, float newZ )

assign new values to each component

void Clear()

sets each component to 0.0

kVec3& Normalize()

normalize and return a reference to self

kVec3 Cross( kVec3& v )

returns the cross product, this × v

float Dot( kVec3& v )

returns the dot product, this • v

float Unit()

float UnitSq()

returns the length and squared length* of the vector, respectively

float Distance( kVec3& v )

float DistanceSq( kVec3& v )

returns the distance and squared distance* between the two vectors (treated as points), respectively

float ToPitch()

angle (in radians) of the vector above the x-y (horizontal) plane

float ToYaw()

angle (in radians) about the z-axis (vertical axis) between the vector and the y-axis

kQuat ToQuaternion()

kQuat ToQuat()

return a quaternion describing a rotation to the vector from (0,1,0)

kStr ToString()

returns "x y z"

kVec3& Randomize( float f )

randomizes and returns a reference to self

f = 1.0 seems to result in a unit vector with a random direction

f = 0.5 seems to jump around a length somewhere around 0.3 to 0.8

f = 2.0 seems to jump around, but overall increase over time

kVec3 Lerp( kVec3& v, float pct ) const

kVec3& Lerp( kVec3& v, float pct )

linear interpolation, this + (v-this)*pct

non-const version applies result to self, and returns reference to self

kVec3& CubicCurve( kVec3& v1, float f, kVec3& v2 )

kVec3& QuadraticCurve( kVec3& v1, float f, kVec3& v2, kVec3& v3 )

Operators

kVec3 + kVec3

kVec3 += kVec3

vector addition

kVec3 - kVec3

kVec3 -= kVec3

vector subtraction

-kVec3

negation

kVec3 * kVec3

kVec3 *= kVec3

componentwise multiplication, ( x1*x2, y1*y2, z1*z2 )

kVec3 * float

kVec3 *= float

scalar multiplication

kVec3 / kVec3

kVec3 /= kVec3

componentwise division, ( x1/x2, y1/y2, z1/z2 )

kVec3 / float

scalar division

kVec3 = kVec3

assignment