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

[AI] 3D vector class, providing vector and cross-product operations in 3D space. More...

#include <vector.h>

Inheritance diagram for Vector3:
Collaboration diagram for Vector3:

Public Member Functions

 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...
 
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 Mx3DPointFloat
 

Additional Inherited Members

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

Detailed Description

[AI] 3D vector class, providing vector and cross-product operations in 3D space.

Inherits from Vector2 to add the third coordinate and cross product facilities.

[AI] Only adds methods specific to 3D (e.g., cross-product), all storage uses the (externally managed) m_data float pointer from Vector2.

Definition at line 249 of file vector.h.

Constructor & Destructor Documentation

◆ Vector3() [1/2]

Vector3::Vector3 ( float *  p_data)
inline

[AI] Construct a 3D vector pointing at external data storage.

Parameters
p_dataPointer to at least 3 floats for component values. [AI]

Definition at line 303 of file vector.h.

◆ Vector3() [2/2]

Vector3::Vector3 ( const float *  p_data)
inline

[AI] Construct a 3D vector from const float* (pointer is cast to non-const in base).

Parameters
p_dataSource array pointer (only cast, never copied). [AI]
Attention
[AI] Legal in codebase but dangerous if const storage is used elsewhere! [AI]

Definition at line 315 of file vector.h.

Member Function Documentation

◆ AddImpl() [1/2]

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

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

Adds a float array (size 3) component-wise to this vector.

[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.

[AI]

Parameters
p_valuePointer to float array to add (float[3]). [AI]

Reimplemented from Vector2.

Reimplemented in Vector4.

◆ AddImpl() [2/2]

void Vector3::AddImpl ( float  p_value)
inlineoverrideprotectedvirtual

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

Adds a scalar value to each component of this 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.

[AI]

Parameters
p_valueScalar value to add. [AI]

Reimplemented from Vector2.

Reimplemented in Vector4.

◆ Clear()

void Vector3::Clear ( )
inlineoverridevirtual

[AI] Sets every coordinate (x, y, z) to zero.

Sets all three components of this vector to zero. [AI].

Reimplemented from Vector2.

Reimplemented in Vector4.

◆ DivImpl()

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

[AI] Divides this vector by a scalar value.

Divides each component of this 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.

[AI]

Parameters
p_valueScalar value to divide. [AI]

Reimplemented from Vector2.

Reimplemented in Vector4.

◆ DotImpl()

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

Computes the dot product of two float arrays representing 3D vectors.

[AI]

Parameters
p_aPointer to the first vector (float[3]). [AI]
p_bPointer to the second vector (float[3]). [AI]
Returns
Dot product of the two vectors. [AI]

Reimplemented from Vector2.

Reimplemented in Vector4.

◆ EqualsCross() [1/3]

void Vector3::EqualsCross ( const float *  p_a,
const Vector3 p_b 
)
inlinevirtual

[AI] Sets this vector to be the cross product of p_a and p_b, with a as a pointer.

Sets this vector to the cross product of a float array and a Vector3.

Parameters
p_aPointer operand. [AI]
p_bVector3 operand. [AI]

[AI]

Parameters
p_aPointer to the first input vector (float[3]). [AI]
p_bInput Vector3. [AI]

◆ EqualsCross() [2/3]

void Vector3::EqualsCross ( const Vector3 p_a,
const float *  p_b 
)
inlinevirtual

[AI] Sets this vector to be the cross product of p_a and p_b, with b as a pointer.

Sets this vector to the cross product of a Vector3 and a float array.

Parameters
p_aVector3 operand. [AI]
p_bPointer operand. [AI]

[AI]

Parameters
p_aInput Vector3. [AI]
p_bPointer to the second input vector (float[3]). [AI]

◆ EqualsCross() [3/3]

void Vector3::EqualsCross ( const Vector3 p_a,
const Vector3 p_b 
)
inlinevirtual

[AI] Sets this vector to be the cross product of p_a and p_b.

Sets this vector to the cross product of two Vector3 objects.

Parameters
p_aFirst operand. [AI]
p_bSecond operand. [AI]

[AI]

Parameters
p_aFirst input vector. [AI]
p_bSecond input vector. [AI]

◆ EqualsCrossImpl()

void Vector3::EqualsCrossImpl ( const float *  p_a,
const float *  p_b 
)
inlineprotectedvirtual

[AI] Assigns this vector to the cross product of p_a and p_b.

Computes the cross product of two 3D vectors represented as float arrays, stores the result in this vector.

Parameters
p_aPointer to first 3-element vector. [AI]
p_bPointer to second 3-element vector. [AI]

[AI]

Parameters
p_aPointer to the first input vector (float[3]). [AI]
p_bPointer to the second input vector (float[3]). [AI]

◆ EqualsImpl()

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

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

Sets the internal data of this vector to the contents of the provided float 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.

[AI]

Parameters
p_dataPointer to float array (float[3]) to copy. [AI]

Reimplemented from Vector2.

Reimplemented in Vector4.

◆ Fill()

void Vector3::Fill ( const float &  p_value)
inlinevirtual

[AI] Fills all coordinates with p_value.

Sets each component of this vector to the given scalar value.

Parameters
p_valueFill value. [AI]

[AI]

Parameters
p_valueValue to set for all components. [AI]

Reimplemented in Vector4.

◆ LenSquared()

float Vector3::LenSquared ( ) const
inlineoverridevirtual

[AI] Computes the squared magnitude (x^2 + y^2 + z^2) of this vector.

Computes the squared length of this vector (avoids sqrt for efficiency).

Returns
Squared length. [AI]

[AI]

Returns
Squared length of the vector. [AI]

Reimplemented from Vector2.

Reimplemented in Vector4.

◆ MulImpl() [1/2]

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

[AI] Multiplies this vector by a scalar value.

Multiplies each component of this vector by a scalar value.

[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.

[AI]

Parameters
p_valueScalar value to multiply. [AI]

Reimplemented from Vector2.

Reimplemented in Vector4.

◆ MulImpl() [2/2]

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

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

Multiplies this vector component-wise by a float array (size 3).

[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.

[AI]

Parameters
p_valuePointer to float array to multiply (float[3]). [AI]

Reimplemented from Vector2.

Reimplemented in Vector4.

◆ SubImpl()

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

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

Subtracts a float array (size 3) component-wise from this vector.

[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.

[AI]

Parameters
p_valuePointer to float array to subtract (float[3]). [AI]

Reimplemented from Vector2.

Reimplemented in Vector4.

Friends And Related Function Documentation

◆ Mx3DPointFloat

friend class Mx3DPointFloat
friend

Definition at line 355 of file vector.h.


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