Isle
Loading...
Searching...
No Matches
Vector4 Class Reference

[AI] A four-dimensional vector, supporting operations relevant for matrix and quaternion math (homogeneous coordinates). More...

#include <vector.h>

Inheritance diagram for Vector4:
Collaboration diagram for Vector4:

Public Member Functions

 Vector4 (float *p_data)
 [AI] Constructs a Vector4 using external float storage. More...
 
 Vector4 (const float *p_data)
 [AI] Constructs a Vector4 using a const float pointer (pointer is reinterpreted as mutable). More...
 
void Clear () override
 [AI] Sets all four components to zero. More...
 
float LenSquared () const override
 [AI] Computes the squared magnitude of the 4D vector. More...
 
void Fill (const float &p_value) override
 [AI] Fill all four floats with p_value. More...
 
virtual void SetMatrixProduct (const float *p_vec, const float *p_mat)
 [AI] Set this vector to the result of a matrix-vector product: result = p_mat * p_vec. More...
 
virtual void SetMatrixProduct (const Vector4 &p_a, const float *p_b)
 [AI] Set this vector to result of matrix-vector product with source given as Vector4, matrix as pointer. More...
 
virtual int NormalizeQuaternion ()
 [AI] Normalize this quaternion (interpreted as vector) in place. More...
 
virtual int EqualsHamiltonProduct (const Vector4 &p_a, const Vector4 &p_b)
 [AI] Set this vector to the Hamilton product of two quaternion Vector4s. More...
 
float & operator[] (int idx)
 [AI] Indexes 0-3: returns reference to the fast access coordinate. More...
 
const float & operator[] (int idx) const
 [AI] Const version for coordinate access (0...3). More...
 
- Public Member Functions inherited from Vector3
 Vector3 (float *p_data)
 [AI] Construct a 3D vector pointing at external data storage. More...
 
 Vector3 (const float *p_data)
 [AI] Construct a 3D vector from const float* (pointer is cast to non-const in base). More...
 
void Clear () override
 [AI] Sets every coordinate (x, y, z) to zero. More...
 
float LenSquared () const override
 [AI] Computes the squared magnitude (x^2 + y^2 + z^2) of this vector. More...
 
virtual void EqualsCross (const Vector3 &p_a, const Vector3 &p_b)
 [AI] Sets this vector to be the cross product of p_a and p_b. More...
 
virtual void EqualsCross (const Vector3 &p_a, const float *p_b)
 [AI] Sets this vector to be the cross product of p_a and p_b, with b as a pointer. More...
 
virtual void EqualsCross (const float *p_a, const Vector3 &p_b)
 [AI] Sets this vector to be the cross product of p_a and p_b, with a as a pointer. More...
 
virtual void Fill (const float &p_value)
 [AI] Fills all coordinates with p_value. More...
 
- Public Member Functions inherited from Vector2
 Vector2 (float *p_data)
 [AI] Construct a 2D vector using an external float buffer. More...
 
 Vector2 (const float *p_data)
 [AI] Construct a 2D vector from a (likely constant) array of floats without copying (just pointer assignment). More...
 
virtual float * GetData ()
 [AI] Retrieves the mutable in-memory data pointer for this vector. More...
 
virtual const float * GetData () const
 [AI] Retrieves the immutable data pointer for this vector. More...
 
virtual void Clear ()
 [AI] Zeros all elements (sets all coordinates to 0.0). More...
 
virtual float Dot (const float *p_a, const float *p_b) const
 [AI] Compute the dot product of the two float arrays interpreted as vectors of 2 elements. More...
 
virtual float Dot (const Vector2 &p_a, const Vector2 &p_b) const
 [AI] Compute the dot product of two Vector2 objects. More...
 
virtual float Dot (const float *p_a, const Vector2 &p_b) const
 [AI] Compute the dot product given a pointer and a Vector2 (second param). More...
 
virtual float Dot (const Vector2 &p_a, const float *p_b) const
 [AI] Compute the dot product given a Vector2 (first param) and a pointer (second param). More...
 
virtual float LenSquared () const
 [AI] Compute the squared length (magnitude^2) of the vector. More...
 
virtual int Unitize ()
 [AI] Scales the vector so its norm is 1 (unit vector). More...
 
virtual void operator+= (float p_value)
 [AI] In-place add a scalar to all coordinates. More...
 
virtual void operator+= (const float *p_other)
 [AI] In-place add vector elements via float pointer. More...
 
virtual void operator+= (const Vector2 &p_other)
 [AI] In-place add another Vector2. More...
 
virtual void operator-= (const float *p_other)
 [AI] In-place subtraction of vector pointed to by p_other. More...
 
virtual void operator-= (const Vector2 &p_other)
 [AI] In-place subtraction of another Vector2. More...
 
virtual void operator*= (const float *p_other)
 [AI] In-place per-element multiplication of this vector by another array. More...
 
virtual void operator*= (const Vector2 &p_other)
 [AI] In-place per-element multiplication by another Vector2. More...
 
virtual void operator*= (const float &p_value)
 [AI] In-place multiplication by a scalar. More...
 
virtual void operator/= (const float &p_value)
 [AI] In-place scalar division. More...
 
virtual void operator= (const float *p_other)
 [AI] Assigns this vector's elements from a pointer to two floats. More...
 
virtual void operator= (const Vector2 &p_other)
 [AI] Assigns this vector's elements from another Vector2. More...
 
float & operator[] (int idx)
 [AI] Accesses the idx-th float in the vector (0 or 1). More...
 
const float & operator[] (int idx) const
 [AI] Const version of the index operator. More...
 

Protected Member Functions

void AddImpl (const float *p_value) override
 [AI] Adds the values pointed to by p_value to this vector. More...
 
void AddImpl (float p_value) override
 [AI] Adds a scalar value to every element of this vector. More...
 
void SubImpl (const float *p_value) override
 [AI] Subtracts the vector specified by p_value from this vector. More...
 
void MulImpl (const float *p_value) override
 [AI] Multiplies this vector by another vector (per element). More...
 
void MulImpl (const float &p_value) override
 [AI] Multiplies this vector by a scalar value. More...
 
void DivImpl (const float &p_value) override
 [AI] Divides this vector by a scalar value. More...
 
float DotImpl (const float *p_a, const float *p_b) const override
 
void EqualsImpl (const float *p_data) override
 [AI] Assigns values from provided array to this vector. More...
 
- Protected Member Functions inherited from Vector3
void AddImpl (const float *p_value) override
 [AI] Adds the values pointed to by p_value to this vector. More...
 
void AddImpl (float p_value) override
 [AI] Adds a scalar value to every element of this vector. More...
 
void SubImpl (const float *p_value) override
 [AI] Subtracts the vector specified by p_value from this vector. More...
 
void MulImpl (const float *p_value) override
 [AI] Multiplies this vector by another vector (per element). More...
 
void MulImpl (const float &p_value) override
 [AI] Multiplies this vector by a scalar value. More...
 
void DivImpl (const float &p_value) override
 [AI] Divides this vector by a scalar value. More...
 
float DotImpl (const float *p_a, const float *p_b) const override
 
void EqualsImpl (const float *p_data) override
 [AI] Assigns values from provided array to this vector. More...
 
virtual void EqualsCrossImpl (const float *p_a, const float *p_b)
 [AI] Assigns this vector to the cross product of p_a and p_b. More...
 
- Protected Member Functions inherited from Vector2
virtual void AddImpl (const float *p_value)
 [AI] Adds the values pointed to by p_value to this vector. More...
 
virtual void AddImpl (float p_value)
 [AI] Adds a scalar value to every element of this vector. More...
 
virtual void SubImpl (const float *p_value)
 [AI] Subtracts the vector specified by p_value from this vector. More...
 
virtual void MulImpl (const float *p_value)
 [AI] Multiplies this vector by another vector (per element). More...
 
virtual void MulImpl (const float &p_value)
 [AI] Multiplies this vector by a scalar value. More...
 
virtual void DivImpl (const float &p_value)
 [AI] Divides this vector by a scalar value. More...
 
virtual float DotImpl (const float *p_a, const float *p_b) const
 [AI] Computes the dot product of two arrays interpreted as vectors. More...
 
virtual void SetData (float *p_data)
 [AI] Set the internal data pointer to external storage. More...
 
virtual void EqualsImpl (const float *p_data)
 [AI] Assigns values from provided array to this vector. More...
 

Friends

class Mx4DPointFloat
 

Additional Inherited Members

- Protected Attributes inherited from Vector2
float * m_data
 [AI] Pointer to externally provided float storage (owned elsewhere). More...
 

Detailed Description

[AI] A four-dimensional vector, supporting operations relevant for matrix and quaternion math (homogeneous coordinates).

Inherits from Vector3.

[AI] Adds 4D-specific functions: matrix product, quaternion normalization, and quaternion Hamilton products. Facilitates 3D transformations and animation math.

Definition at line 365 of file vector.h.

Constructor & Destructor Documentation

◆ Vector4() [1/2]

Vector4::Vector4 ( float *  p_data)
inline

[AI] Constructs a Vector4 using external float storage.

Parameters
p_dataPointer to at least 4 floats. [AI]

Definition at line 412 of file vector.h.

◆ Vector4() [2/2]

Vector4::Vector4 ( const float *  p_data)
inline

[AI] Constructs a Vector4 using a const float pointer (pointer is reinterpreted as mutable).

Parameters
p_dataConst pointer to at least 4 floats. [AI]
Attention
[AI] Used in legacy code and for complicated construction scenarios. [AI]

Definition at line 419 of file vector.h.

Member Function Documentation

◆ AddImpl() [1/2]

void Vector4::AddImpl ( const float *  p_value)
inlineoverrideprotectedvirtual

[AI] Adds the values pointed to by p_value to this vector.

[AI] Implements vector addition for Vector4 using a float array as input.

[AI] Adds a 2D float array to the vector data in-place.

Parameters
p_valuePointer to an array containing values to add. [AI]

This is used for vector addition with an array.

Parameters
p_valuePointer to a float array containing the values to add.

[AI] Each component of the input array is added to the corresponding component of the vector. The length must be 2.

This method adds the elements of p_value (assumed to be an array of at least four floats) to this vector's components, modifying all four entries including the w component. Calls Vector3::AddImpl for the first three elements and adds the fourth explicitly.

Parameters
p_valuePointer to an array of four floats to add to the vector components. [AI]

Reimplemented from Vector3.

◆ AddImpl() [2/2]

void Vector4::AddImpl ( float  p_value)
inlineoverrideprotectedvirtual

[AI] Adds a scalar value to every element of this vector.

[AI] Adds a scalar value to all four components of the vector.

[AI] Adds a scalar value to both components of the vector.

Parameters
p_valueThe value to add to each coordinate. [AI]
p_valueThe scalar value to add.

[AI] The scalar is added to both x and y components.

Each component (x, y, z, w) has p_value added to it.

Parameters
p_valueScalar value to add to each component. [AI]

Reimplemented from Vector3.

◆ Clear()

void Vector4::Clear ( )
inlineoverridevirtual

[AI] Sets all four components to zero.

[AI] Sets all four components of the vector to zero.

Uses memset to set all data entries to 0.

Reimplemented from Vector3.

◆ DivImpl()

void Vector4::DivImpl ( const float &  p_value)
inlineoverrideprotectedvirtual

[AI] Divides this vector by a scalar value.

[AI] Divides all components of the vector by a scalar value.

[AI] Divides both components of the vector by a scalar.

Parameters
p_valueScalar divisor. [AI]
p_valueThe scalar value to divide by.

[AI] Both components are divided by the scalar. No zero check.

Each component (x, y, z, w) is divided by p_value.

Parameters
p_valueScalar divisor. [AI]

Reimplemented from Vector3.

◆ DotImpl()

float Vector4::DotImpl ( const float *  p_a,
const float *  p_b 
) const
inlineoverrideprotectedvirtual

[AI] Calculates the dot product for two float[4] arrays as if they are 4D vectors.

The dot product includes all four components.

Parameters
p_aFirst operand, array of 4 floats. [AI]
p_bSecond operand, array of 4 floats. [AI]
Returns
The scalar dot product of the two input vectors. [AI]

Reimplemented from Vector3.

◆ EqualsHamiltonProduct()

int Vector4::EqualsHamiltonProduct ( const Vector4 p_a,
const Vector4 p_b 
)
inlinevirtual

[AI] Set this vector to the Hamilton product of two quaternion Vector4s.

[AI] Sets this vector to the Hamilton product of two quaternions (Vector4s).

Parameters
p_aFirst quaternion as Vector4. [AI]
p_bSecond quaternion as Vector4. [AI]
Returns
Status/result code. [AI]

The result is the quaternion multiplication of p_a and p_b, written into this. Uses Vector3 cross product for the vector part and a combination of scalar and vector terms for the real part.

Parameters
p_aLeft operand quaternion. [AI]
p_bRight operand quaternion. [AI]
Returns
Always returns 0. [AI]

◆ EqualsImpl()

void Vector4::EqualsImpl ( const float *  p_data)
inlineoverrideprotectedvirtual

[AI] Assigns values from provided array to this vector.

[AI] Sets the vector's components to those in a float[4] array.

[AI] Copies the values from a float array into the vector's data.

Parameters
p_dataPointer to array to copy from. [AI]
p_dataPointer to float array containing the values to copy.

[AI] Uses memcpy for fast assignment of both vector components.

Performs a memcpy for all four components.

Parameters
p_dataPointer to an array of four floats to copy from. [AI]

Reimplemented from Vector3.

◆ Fill()

void Vector4::Fill ( const float &  p_value)
inlineoverridevirtual

[AI] Fill all four floats with p_value.

[AI] Sets all components of the vector to the given value.

Parameters
p_valueThe value to assign everywhere. [AI]

Fills x, y, z, w with p_value.

Parameters
p_valueThe value to assign to all components. [AI]

Reimplemented from Vector3.

◆ LenSquared()

float Vector4::LenSquared ( ) const
inlineoverridevirtual

[AI] Computes the squared magnitude of the 4D vector.

[AI] Computes the squared length (norm) of the Vector4.

Returns
Squared length. [AI]

Returns x^2 + y^2 + z^2 + w^2.

Returns
Squared length of the vector. [AI]

Reimplemented from Vector3.

◆ MulImpl() [1/2]

void Vector4::MulImpl ( const float &  p_value)
inlineoverrideprotectedvirtual

[AI] Multiplies this vector by a scalar value.

[AI] Multiplies all components of the vector by a scalar.

[AI] Multiplies both components of the vector by a scalar.

Parameters
p_valueScalar multiplier. [AI]
p_valueThe scalar value to multiply by.

[AI] Both components are multiplied by the scalar.

Each component (x, y, z, w) is multiplied by p_value.

Parameters
p_valueScalar multiplier. [AI]

Reimplemented from Vector3.

◆ MulImpl() [2/2]

void Vector4::MulImpl ( const float *  p_value)
inlineoverrideprotectedvirtual

[AI] Multiplies this vector by another vector (per element).

[AI] Multiplies each component of the vector by the corresponding element of p_value.

[AI] Multiplies the vector by another 2D float array component-wise.

Parameters
p_valuePointer to the vector to multiply with. [AI]
p_valuePointer to a float array containing the values to multiply by.

[AI] Each component of the vector is multiplied by the corresponding component in the input array.

Multiplies x, y, z using Vector3::MulImpl and multiplies w by p_value[3].

Parameters
p_valuePointer to an array of four floats for component-wise multiplication. [AI]

Reimplemented from Vector3.

◆ NormalizeQuaternion()

int Vector4::NormalizeQuaternion ( )
inlinevirtual

[AI] Normalize this quaternion (interpreted as vector) in place.

[AI] Normalizes the vector as a quaternion.

Result is 0 if success.

Returns
Status code. [AI]

If x, y, z components' squared length is nonzero, the quaternion is normalized:

  • w is set to cos(theta)
  • (x, y, z) is scaled based on sin(theta)/sqrt(length) If not, returns -1 as error.

    [AI] This is useful for ensuring a quaternion used for rotations is normalized.

Returns
0 if succeeded, -1 if cannot normalize due to zero length of spatial part. [AI]

◆ operator[]() [1/2]

float & Vector4::operator[] ( int  idx)
inline

[AI] Indexes 0-3: returns reference to the fast access coordinate.

Parameters
idx0-based index. [AI]

Definition at line 470 of file vector.h.

◆ operator[]() [2/2]

const float & Vector4::operator[] ( int  idx) const
inline

[AI] Const version for coordinate access (0...3).

Parameters
idxCoordinate index. [AI]

Definition at line 476 of file vector.h.

◆ SetMatrixProduct() [1/2]

void Vector4::SetMatrixProduct ( const float *  p_vec,
const float *  p_mat 
)
inlinevirtual

[AI] Set this vector to the result of a matrix-vector product: result = p_mat * p_vec.

[AI] Sets the vector as a matrix product of a 4D vector with a 4x4 matrix (column-major).

Parameters
p_vecPointer to the input vector (length 4). [AI]
p_matPointer to 4x4 matrix (row-major). [AI]

The product is: m_data[i] = sum_over_j(p_vec[j] * p_mat[j*4 + i])

Parameters
p_vecThe 4D input vector as an array. [AI]
p_matThe 4x4 matrix as a flat array of 16 floats (column-major order). [AI]

◆ SetMatrixProduct() [2/2]

void Vector4::SetMatrixProduct ( const Vector4 p_a,
const float *  p_b 
)
inlinevirtual

[AI] Set this vector to result of matrix-vector product with source given as Vector4, matrix as pointer.

[AI] Sets this vector as the product of another Vector4 and a 4x4 matrix.

Parameters
p_aVector4 to multiply. [AI]
p_bMatrix pointer. [AI]

Calls SetMatrixProduct with the internal data of p_a.

Parameters
p_aThe input Vector4. [AI]
p_bPointer to a flat array of 16 floats representing a 4x4 matrix. [AI]

◆ SubImpl()

void Vector4::SubImpl ( const float *  p_value)
inlineoverrideprotectedvirtual

[AI] Subtracts the vector specified by p_value from this vector.

[AI] Subtracts the elements of a float array from the vector's components.

[AI] Subtracts a 2D float array from the vector data in-place.

Parameters
p_valuePointer to array to subtract. [AI]
p_valuePointer to a float array containing the values to subtract.

[AI] Each component of the input array is subtracted from the corresponding component of the vector. The length must be 2.

Performs component-wise subtraction for x,y,z (via Vector3::SubImpl) and then subtracts the fourth element from w.

Parameters
p_valueArray of at least four floats to subtract. [AI]

Reimplemented from Vector3.

Friends And Related Function Documentation

◆ Mx4DPointFloat

friend class Mx4DPointFloat
friend

Definition at line 478 of file vector.h.


The documentation for this class was generated from the following files: