Vector3
Class representing a 3D vector with x, y, z components.
A 3D vector is an ordered triplet of numbers (labeled x, y, and z),
which can be used to represent a point in 3D space, a direction and
length, or any arbitrary ordered triplet of numbers.
- Mathematical operations (add, subtract, multiply, divide)
- Vector operations (dot product, cross product, normalization)
- Geometric operations (distance, angle, projection)
- Coordinate system conversions (spherical, cylindrical)
- Integration with libogc guVector and GX matrices
Methods
Vector3()
Default constructor - creates a vector at origin (0, 0, 0)
Vector3(f32 x, f32 y, f32 z)
Value constructor for common init path
| x | X component of the vector | 0.0f |
| y | Y component of the vector | 0.0f |
| z | Z component of the vector | 0.0f |
Vector3(const guVector& v)
Constructor from guVector for GX integration
| v | guVector to copy from |
Vector3& set(f32 x, f32 y, f32 z)
Sets the vector components
| x | X component value | |
| y | Y component value | |
| z | Z component value |
Vector3& setScalar(f32 scalar)
Sets all components to the same value
| scalar | Value to set for all components |
Vector3& setX(f32 x)
Sets the x component
| x | X component value |
Vector3& setY(f32 y)
Sets the y component
| y | Y component value |
Vector3& setZ(f32 z)
Sets the z component
| z | Z component value |
Vector3& setComponent(u32 index, f32 value)
Sets component by index (0=x, 1=y, 2=z)
| index | Component index (0, 1, or 2) | |
| value | Value to set |
f32 getComponent(u32 index) const
Gets component by index (0=x, 1=y, 2=z)
| index | Component index (0, 1, or 2) |
Vector3 clone() const
Creates a copy of this vector
Vector3& copy(const Vector3& v)
Copies values from another vector
| v | Source vector |
Vector3& copy(const guVector& v)
Copies values from a guVector
| v | guVector to copy from |
guVector getGuVector() const
Converts this vector to a guVector
operator guVector() const
Implicit conversion to guVector for GameCube library calls
Vector3& operator=(const guVector& v)
Assignment from guVector
| v | guVector to copy from |
Vector3& add(const Vector3& v)
Adds another vector to this one
| v | Vector to add |
Vector3& addScalar(f32 s)
Adds scalar to all components
| s | Scalar value to add |
Vector3& addVectors(const Vector3& a, const Vector3& b)
Sets this vector to a + b
| a | First vector | |
| b | Second vector |
Vector3& addScaledVector(const Vector3& v, f32 s)
Adds scaled vector to this one
| v | Vector to scale and add | |
| s | Scale factor |
Vector3& sub(const Vector3& v)
Subtracts another vector from this one
| v | Vector to subtract |
Vector3& subScalar(f32 s)
Subtracts scalar from all components
| s | Scalar value to subtract |
Vector3& subVectors(const Vector3& a, const Vector3& b)
Sets this vector to a - b
| a | First vector | |
| b | Second vector |
Vector3& multiply(const Vector3& v)
Multiplies this vector by another component-wise
| v | Vector to multiply by |
Vector3& multiplyScalar(f32 scalar)
Multiplies all components by scalar
| scalar | Scalar value to multiply by |
Vector3& multiplyVectors(const Vector3& a, const Vector3& b)
Sets this vector to a * b component-wise
| a | First vector | |
| b | Second vector |
Vector3& divide(const Vector3& v)
Divides this vector by another component-wise
| v | Vector to divide by |
Vector3& divideScalar(f32 scalar)
Divides all components by scalar
| scalar | Scalar value to divide by |
Vector3& applyEuler(const Euler& euler)
Applies Euler rotation to this vector
| euler | Euler angles to apply |
Vector3& applyAxisAngle(const Vector3& axis, f32 angle)
Applies rotation around axis by angle
| axis | Rotation axis (normalized) | |
| angle | Rotation angle in radians |
Vector3& applyMatrix3(const Mtx33& m)
Applies 3x3 matrix transformation
| m | 3x3 matrix to apply |
Vector3& applyNormalMatrix(const Mtx33& m)
Applies normal matrix and normalizes result
| m | Normal matrix to apply |
Vector3& applyMatrix4(const Mtx& m)
Applies 3x4 matrix transformation
| m | 3x4 matrix to apply |
Vector3& applyQuaternion(const Quaternion& q)
Applies quaternion rotation to this vector
| q | Quaternion to apply |
Vector3& project(const class Camera& camera)
Projects vector from world to camera NDC space
| camera | Camera to project with |
Vector3& unproject(const class Camera& camera)
Unprojects vector from camera NDC to world space
| camera | Camera to unproject with |
Vector3& transformDirection(const Mtx& m)
Transforms direction vector by matrix and normalizes
| m | Matrix to transform with |
Vector3& min(const Vector3& v)
Sets each component to minimum of this and v
| v | Vector to compare with |
Vector3& max(const Vector3& v)
Sets each component to maximum of this and v
| v | Vector to compare with |
Vector3& clamp(const Vector3& min, const Vector3& max)
Clamps each component between min and max vectors
| min | Minimum values for each component | |
| max | Maximum values for each component |
Vector3& clampScalar(f32 minVal, f32 maxVal)
Clamps each component between scalar values
| minVal | Minimum value for all components | |
| maxVal | Maximum value for all components |
Vector3& clampLength(f32 min, f32 max)
Clamps vector length between min and max values
| min | Minimum length | |
| max | Maximum length |
Vector3& floor()
Rounds each component down to nearest integer
Vector3& ceil()
Rounds each component up to nearest integer
Vector3& round()
Rounds each component to nearest integer
Vector3& roundToZero()
Rounds each component toward zero
Vector3& negate()
Negates all components
f32 dot(const Vector3& v) const
Calculates dot product with another vector
| v | Vector to dot with |
f32 lengthSq() const
Calculates squared length of vector
f32 length() const
Calculates length of vector
f32 manhattanLength() const
Calculates Manhattan length of vector
Vector3& normalize()
Normalizes vector to unit length
Vector3& setLength(f32 length)
Sets vector to specified length while preserving direction
| length | Desired length |
Vector3& lerp(const Vector3& v, f32 alpha)
Linearly interpolates toward another vector
| v | Target vector | |
| alpha | Interpolation factor (0-1) |
Vector3& lerpVectors(const Vector3& v1, const Vector3& v2, f32 alpha)
Sets this vector to lerp between v1 and v2
| v1 | First vector | |
| v2 | Second vector | |
| alpha | Interpolation factor (0-1) |
Vector3& cross(const Vector3& v)
Sets this vector to cross product with v
| v | Vector to cross with |
Vector3& crossVectors(const Vector3& a, const Vector3& b)
Sets this vector to cross product of a and b
| a | First vector | |
| b | Second vector |
Vector3& projectOnVector(const Vector3& v)
Projects this vector onto another vector
| v | Vector to project onto |
Vector3& projectOnPlane(const Vector3& planeNormal)
Projects this vector onto plane defined by normal
| planeNormal | Plane normal vector |
Vector3& reflect(const Vector3& normal)
Reflects vector off plane with given normal
| normal | Plane normal vector |
f32 angleTo(const Vector3& v) const
Calculates angle between this vector and another
| v | Vector to measure angle to |
f32 distanceTo(const Vector3& v) const
Calculates distance to another vector
| v | Target vector |
f32 distanceToSquared(const Vector3& v) const
Calculates squared distance to another vector
| v | Target vector |
f32 manhattanDistanceTo(const Vector3& v) const
Calculates Manhattan distance to another vector
| v | Target vector |
Vector3& setFromSpherical(const Spherical& s)
Sets vector from spherical coordinates object
| s | Spherical coordinates |
Vector3& setFromSphericalCoords(f32 radius, f32 phi, f32 theta)
Sets vector from spherical coordinate values
| radius | Radius from origin | |
| phi | Polar angle from y-axis | |
| theta | Azimuthal angle from x-axis |
Vector3& setFromCylindrical(const Cylindrical& c)
Sets vector from cylindrical coordinates object
| c | Cylindrical coordinates |
Vector3& setFromCylindricalCoords(f32 radius, f32 theta, f32 y)
Sets vector from cylindrical coordinate values
| radius | Radius from y-axis | |
| theta | Azimuthal angle from x-axis | |
| y | Height along y-axis |
Vector3& setFromMatrixPosition(const Mtx& m)
Sets vector to translation part of 3x4 matrix
| m | 3x4 transformation matrix |
Vector3& setFromMatrixScale(const Mtx& m)
Sets vector to scale factors from 3x4 matrix
| m | 3x4 transformation matrix |
Vector3& setFromMatrixColumn(const Mtx& m, u32 index)
Sets vector from specified column of 3x4 matrix
| m | 3x4 matrix | |
| index | Column index (0-3) |
Vector3& setFromMatrix3Column(const Mtx33& m, u32 index)
Sets vector from specified column of 3x3 matrix
| m | 3x3 matrix | |
| index | Column index (0-2) |
Vector3& setFromEuler(const Euler& e)
Sets vector from Euler angles object
| e | Euler angles |
Vector3& setFromColor(const Color& c)
Sets vector from RGB color components
| c | Color object |
bool equals(const Vector3& v) const
Checks if this vector equals another
| v | Vector to compare with |
Vector3& fromArray(const f32* array, u32 offset)
Sets vector from array of floats
| array | Array of float values | |
| offset | Starting offset in array |
f32* toArray(f32* array, u32 offset) const
Writes vector components to array
| array | Target array (nullptr for static temp) | |
| offset | Starting offset in array |
Vector3& fromBufferAttribute(const class BufferAttribute& attribute, u32 index)
Sets vector from GPU buffer attribute
| attribute | Buffer attribute to read from | |
| index | Vertex index in buffer |
Vector3& random()
Sets vector to random values between 0 and 1
Vector3& randomDirection()
Sets vector to random unit direction
Vector3& operator+=(const Vector3& v)
Adds another vector to this one
| v | Vector to add |
Vector3& operator-=(const Vector3& v)
Subtracts another vector from this one
| v | Vector to subtract |
Vector3& operator*=(f32 scalar)
Multiplies all components by scalar
| scalar | Scalar value to multiply by |
Vector3& operator/=(f32 scalar)
Divides all components by scalar
| scalar | Scalar value to divide by |
bool operator==(const Vector3& v) const
Checks if this vector equals another
| v | Vector to compare with |
bool operator!=(const Vector3& v) const
Checks if this vector does not equal another
| v | Vector to compare with |
Properties
| id | u32 | Unique identifier |
| isVector3 | bool | Read-only tag |
| name | string | Optional display name |
| uuid | string | UUID string |
| x | f32 | X component |
| y | f32 | Y component |
| z | f32 | Z component |