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.
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 -
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 -
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 coordinateID )
These two variations allow you to:
- Place the vector in the world coordinate system (first form).
- Place the vector in any specified coordinate system (second form).
Arguments:
- vectorID: The ID of the vector to place.
- rendererID: The ID of the renderer.
- coordinateID: The ID of the coordinate system to place the vector in (if omitted, it defaults to the world coordinate system).
Setting Vector Components
To set the components of a vector, use the setVector(...) function:
- Function Format -
Arguments:
- vectorID: The ID of the vector to modify.
- x, y, z: The X, Y, and Z components to assign to the vector.
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 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 -
Arguments:
- vectorID1: The ID of the first vector.
- vectorID2: The ID of the second vector.
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 -
int vectorID1, int vectorID2, int crossVector
)
Arguments:
- vectorID1: The ID of the first vector.
- vectorID2: The ID of the second vector.
- crossVector: The ID of the vector where the result will be stored. This vector must be created in advance, but its contents will be overwritten by this function, so the initial values don't matter.
- 3D Computer Graphics
- Setting Up the Foundation
- Mouse Control and Animation
- Using the Framework
- Creating and Placing Light Sources (and Adjusting Their Properties)
- Creating and Placing Models / Standard Models
- Creating and Placing Polygons, and Various Types of Polygons
- Moving 3D Objects
- Rotating 3D Objects
- Scaling 3D Objects
- Flipping 3D Objects
- Setting Colors for 3D Objects
- Configuring the Shape of 3D Objects
- Fill Settings for 3D Objects
- Material Settings for 3D Objects
- Understanding Coordinate Systems: Concepts, Creation, and Placement
- Moving Coordinate Systems
- Walking Coordinate Systems
- Controlling the Origin Position of a Coordinate System
- Rotating Coordinate Systems
- Spinning a Coordinate System
- Euler Angle-Based Attitude Control of Coordinate Systems
- Camera Work
- Creating, Placing, and Performing Basic Operations on Vectors
- Coordinate Transformations
- Screen Projection
- Collision Detection