-
-
Notifications
You must be signed in to change notification settings - Fork 0
Vector3
Imagment edited this page Mar 27, 2025
·
11 revisions
Representation of 3D vectors and points. This class is used in places where 3D positions and vectors are needed.
Constructor | Description |
---|---|
Vector3(double x, double y, double z) |
Initializes a Vector3 with the given x , y , and z values. Defaults to (0.0, 0.0, 0.0) . |
Vector3(std::initializer_list<double> list) |
Initializes a Vector3 from an initializer list, filling missing components with 0.0 . |
static Vector3 from(double x, double y, double z) |
Creates a Vector3 with the given x , y , and z values. Equivalent to the standard constructor but can be used for clarity. |
Name | Description |
---|---|
Vector3Up |
Shorthand for writing Vector3(0, -1, 0)
|
Vector3Down |
Shorthand for writing Vector3(0, 1, 0)
|
Vector3Forward |
Shorthand for writing Vector3(0, 0, 1)
|
Vector3Backward |
Shorthand for writing Vector3(0, 0, -1)
|
Vector3Left |
Shorthand for writing Vector3(-1, 0, 0)
|
Vector3Right |
Shorthand for writing Vector3(1, 0, 0)
|
Vector3One |
Shorthand for writing Vector3(1, 1, 1)
|
Vector3Zero |
Shorthand for writing Vector3(0, 0, 0)
|
Name | Description |
---|---|
x |
The x-component of the vector. |
y |
The y-component of the vector. |
z |
The z-component of the vector. |
Name | Description |
---|---|
double magnitude() |
Returns the length (magnitude) of the vector. |
double magnitudeSqr() |
Returns the squared length (magnitude squared) of the vector. |
Vector3 normalized() |
Returns a unit vector (normalized vector) in the same direction as the original vector. |
double dotProduct(Vector3 v1, Vector3 v2) |
Returns the dot product of two Vector3 objects. |
Vector3 crossProduct(Vector3 v1, Vector3 v2) |
Returns the cross product of two Vector3 objects. |
double VectorAngle(Vector3 v1, Vector3 v2) |
Returns the angle between two Vector3 objects. |
Vector3 VectorLerp(Vector3 v1, Vector3 v2, double amount) |
Returns the linear interpolation between two Vector3 objects. |
Vector3 VectorReflect(Vector3 v, Vector3 normal) |
Returns the reflection of a Vector3 off a surface with a normal. |
Vector3 VectorMin(Vector3 v1, Vector3 v2) |
Returns the minimum of two Vector3 components. |
Vector3 VectorMax(Vector3 v1, Vector3 v2) |
Returns the maximum of two Vector3 components. |
Vector3 VectorRotate(Vector3 v, double angle) |
Returns a Vector3 rotated by a given angle around the Z-axis. |
Vector3 VectorMoveTowards(Vector3 v, Vector3 target, double maxDistance) |
Moves a Vector3 towards a target with a maximum distance. |
Vector3 VectorClamp(Vector3 v, Vector3 min, Vector3 max) |
Clamps a Vector3 between two other Vector3 objects. |
Vector3 VectorClampValue(Vector3 v, double min, double max) |
Clamps the magnitude of a Vector3 between minimum and maximum values. |
Vector3 VectorRefract(Vector3 v, Vector3 n, double r) |
Returns the refraction of a Vector3 through a surface with a normal and refraction ratio. |
Operator | Description |
---|---|
operator+ |
Adds two Vector3 objects component-wise. |
operator- |
Subtracts one Vector3 object from another component-wise. |
operator* |
Multiplies the vector by a scalar value. |
operator/ |
Divides the vector by a scalar value. |
operator+= |
Adds another Vector3 to the current vector and assigns the result back. |
operator-= |
Subtracts another Vector3 from the current vector and assigns the result back. |
operator*= |
Multiplies the current vector by a scalar and assigns the result back. |
operator/= |
Devides the current vector by a scalar and assigns the result back. |
operator== |
Checks if two Vector3 objects are equal by comparing x , y , and z components. |
operator!= |
Checks if two Vector3 objects are not equal by negating the result of the equality operator. |
operator< |
Compares two Vector3 objects lexicographically based on their x , y , and z components. |
operator[] (Accessor) |
Allows access to the x , y , or z component of the vector by index (0 for x , 1 for y , 2 for z ). Returns -1 for invalid indices. |
operator[] (Mutator) |
Allows modification of the x , y , or z component by index (0 for x , 1 for y , 2 for z ). Throws an exception for invalid indices. |