vector and Vector(float, float,float)

From NWN Lexicon
Jump to: navigation, search

Note: Mediawiki doesn't allow both this to exist as lowercase (data type) and uppercase (function) variants so both are on this page at once.

vector Data Type

A vector is a structure of three floats, useful for defining positions and orientation vectors. To access the components of the vector, you can use the dot operator to get the x, y, and z components of the vector. The default value of a vector is [ 0.0, 0.0, 0.0 ] (or x = 0.0, y = 0.0, z = 0.0).

You define a vector by using the Vector command (see below for full details):

vector vVector = Vector(0.0, 0.0, 0.0);

You can alter individual parts of the vector later using the Dot Operator with x, y and z as parameters:

vector vVector = Vector(10.0, 10.0, 10.0);
vVector.x = 20.0; // Vector is now [20.0, 10.0, 1.0]

If you have a function declaration needing a default vector value you can use it in this way:

void MyFunction(vector vVector = [0.0,0.0,0.0]);

Example

vector v = GetPosition(OBJECT_SELF) - GetPosition(oidTargetObject);
vector v2 = Vector(1.0f, 2.0f, 3.0f);
PrintFloat(v2.x);
float fDistanceToTarget = sqrt(v.x * v.x + v.y * v.y + v.z * v.z);

Vector(float, float, float)

Creates a vector (position) from three points.

vector Vector(
    float fX = 0.0f,
    float fY = 0.0f,
    float fZ = 0.0f
);

Parameters

fX
x point of a triangle. (Default: 0.0f)
fY
y point of a triangle. (Default: 0.0f)
fZ
z point of a triangle. (Default: 0.0f)

Description

Returns a vector with the specified point values of fX, fY, and fZ.

Remarks

A common use for this command is when creating a new location based on an objects location.

You can get an objects position vector by using GetPosition, or a position vector from a location using GetPositionFromLocation.

You can change the values of a set vector by using the dot operator.

Version

1.61

See Also

functions:

VectorToAngle GetPosition GetPositionFromLocation



author: Charles Feduke, editor: Lilac Soul