Creating, Placing, and Performing Basic Operations on Vectors

This section covers how to create and place vectors, as well as how to perform basic operations on them.

- Table of Contents -

What Is a Vector?

When working in 3D space, it's convenient to treat values in groups of three, like (X, Y, Z).

For example, a position in space is defined by its (X, Y, Z) coordinates. A direction in space is likewise represented by a set of three components (Vx, Vy, Vz), and the displacement of a moving object over a unit of time can be described similarly using (dx, dy, dz).

In this way, a vector is simply a group of three components treated as a single unit in 3D space.

In VCSSL, vectors can be created and placed in coordinate systems, allowing for convenient operations like coordinate transformations, dot products, and cross products.

Creating a Vector

To create a vector, use the newVector(...) function:

- Function Format -

int newVector ( float x, float y, float z )

The arguments x, y, and z specify the X, Y, and Z components of the vector.

This function creates a vector with those components and returns a unique ID assigned to it.

You can also create a copy of an existing vector by passing its ID:

- Function Format -

int newVector ( int copyID )

Placing a Vector

Once created, a vector can be placed into a coordinate system, just like models or polygons. To place a vector, use the mountVector(...) function.

- Function Format -

int mountVector ( int vectorID, int rendererID )
int mountVector ( int vectorID, int rendererID, int coordinateID )

These two variations allow you to:

Arguments:

Setting Vector Components

To set the components of a vector, use the setVector(...) function:

- Function Format -

void setVector ( int vectorID, float x, float y, float z )

Arguments:

This function updates the components of an existing vector.

Getting Vector Components

To retrieve the components of a vector, use the getVectorX(...), getVectorY(...), and getVectorZ(...) functions:

- Function Format -

float getVectorX ( int vectorID )
float getVectorY ( int vectorID )
float getVectorZ ( int vectorID )

Each function returns the X, Y, or Z component of the vector, respectively.

The "vectorID" argument specifies the target vector.

Dot Product

To calculate the dot product (inner product) of two vectors, use the getVectorInnerProduct(...) function:

- Function Format -

float getVectorInnerProduct ( int vectorID1, int vectorID2 )

Arguments:

This function returns the dot product of the two specified vectors.

Cross Product

To calculate the cross product of two vectors, use the getVectorCrossProduct(...) function:

- Function Format -

void getVectorCrossProduct (
  int vectorID1, int vectorID2, int crossVector
)

Arguments: