Open 3D Engine AzCore API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
AZ::Vector4 Class Reference

#include <Vector4.h>

Public Member Functions

 AZ_TYPE_INFO (Vector4, "{0CE9FA36-1E3A-4C06-9254-B7C73A732053}")
 
 Vector4 ()=default
 Default constructor, components are uninitialized.
 
 Vector4 (const Vector4 &v)=default
 
 Vector4 (float x)
 Constructs vector with all components set to the same specified value.
 
 Vector4 (float x, float y, float z, float w)
 
 Vector4 (const Vector2 &source)
 Copies x,y components from a Vector2, set z = 0.0, w = 1.0.
 
 Vector4 (const Vector2 &source, float z)
 Copies x,y components from a Vector2, sets w = 1.0, specify z separately.
 
 Vector4 (const Vector2 &source, float z, float w)
 Copies x,y components from a Vector2, specify z and w separately.
 
 Vector4 (const Vector3 &source)
 Copies x,y,z components from a Vector3, sets w = 1.0.
 
 Vector4 (const Vector3 &source, float w)
 Copies x,y,z components from a Vector3, specify w separately.
 
 Vector4 (Simd::Vec4::FloatArgType value)
 For internal use only, arrangement of values in SIMD type is not guaranteed.
 
void StoreToFloat4 (float *values) const
 Stores the vector to an array of 4 floats. The floats need only be 4 byte aligned, 16 byte alignment is not required.
 
float GetX () const
 
float GetY () const
 
float GetZ () const
 
float GetW () const
 
void SetX (float x)
 
void SetY (float y)
 
void SetZ (float z)
 
void SetW (float w)
 
float GetElement (int32_t index) const
 Access component by index.
 
void Set (float x)
 Sets all components to the same specified value.
 
void Set (float x, float y, float z, float w)
 
void Set (const float values[])
 Sets components from an array of 4 floats, stored in xyzw order.
 
void Set (const Vector3 &v)
 Sets x,y,z components from a Vector3, sets w to 1.0.
 
void Set (const Vector3 &v, float w)
 Sets x,y,z components from a Vector3, specify w separately.
 
void Set (Simd::Vec4::FloatArgType v)
 Sets x,y,z,w components using a single simd vector4 float type.
 
void SetElement (int32_t index, float v)
 We recommend using SetX,Y,Z,W. SetElement can be slower.
 
Vector3 GetAsVector3 () const
 
float operator() (int32_t index) const
 
float GetLengthSq () const
 Returns squared length of the vector.
 
float GetLength () const
 Returns length of the vector, full accuracy.
 
float GetLengthEstimate () const
 Returns length of the vector, fast but low accuracy, uses raw estimate instructions.
 
float GetLengthReciprocal () const
 Returns 1/length, full accuracy.
 
float GetLengthReciprocalEstimate () const
 Returns 1/length of the vector, fast but low accuracy, uses raw estimate instructions.
 
Vector4 GetNormalized () const
 Returns normalized vector, full accuracy.
 
Vector4 GetNormalizedEstimate () const
 Returns normalized vector, fast but low accuracy, uses raw estimate instructions.
 
void Normalize ()
 Normalizes the vector in-place, full accuracy.
 
void NormalizeEstimate ()
 Normalizes the vector in-place, fast but low accuracy, uses raw estimate instructions.
 
bool IsNormalized (float tolerance=Constants::Tolerance) const
 
void SetLength (float length)
 Scales the vector to have the specified length, full accuracy.
 
void SetLengthEstimate (float length)
 Scales the vector to have the specified length, fast but low accuracy, uses raw estimate instructions.
 
float GetDistanceSq (const Vector4 &v) const
 Returns squared distance to another Vector4.
 
bool IsClose (const Vector4 &v, float tolerance=Constants::Tolerance) const
 Checks the vector is equal to another within a floating point tolerance.
 
bool IsZero (float tolerance=Constants::FloatEpsilon) const
 
bool operator== (const Vector4 &rhs) const
 
bool operator!= (const Vector4 &rhs) const
 
Vector4 Lerp (const Vector4 &dest, float t) const
 
Vector4 Slerp (const Vector4 &dest, float t) const
 
Vector4 Nlerp (const Vector4 &dest, float t) const
 
float Dot (const Vector4 &rhs) const
 Dot product of two vectors, uses all 4 components.
 
float Dot3 (const Vector3 &rhs) const
 Dot product of two vectors, using only the x,y,z components.
 
void Homogenize ()
 Homogenizes the vector, i.e. divides all components by w.
 
Vector3 GetHomogenized () const
 Returns the homogenized vector, i.e. divides all components by w, return value is a Vector3.
 
Vector4 operator- () const
 
Vector4 operator+ (const Vector4 &rhs) const
 
Vector4 operator- (const Vector4 &rhs) const
 
Vector4 operator* (const Vector4 &rhs) const
 
Vector4 operator/ (const Vector4 &rhs) const
 
Vector4 operator* (float multiplier) const
 
Vector4 operator/ (float divisor) const
 
Vector4operator+= (const Vector4 &rhs)
 
Vector4operator-= (const Vector4 &rhs)
 
Vector4operator*= (const Vector4 &rhs)
 
Vector4operator/= (const Vector4 &rhs)
 
Vector4operator*= (float multiplier)
 
Vector4operator/= (float divisor)
 
Vector4 GetSin () const
 Gets the sine of each component.
 
Vector4 GetCos () const
 Gets the cosine of each component.
 
void GetSinCos (Vector4 &sin, Vector4 &cos) const
 Gets the sine and cosine of each component, quicker than calling GetSin and GetCos separately.
 
Vector4 GetAcos () const
 Gets the arccosine of each component.
 
Vector4 GetAtan () const
 Gets the arctangent of each component.
 
Vector4 GetExpEstimate () const
 Gets an estimate of the exponential function for each component.
 
Vector4 GetAngleMod () const
 Wraps the angle in each component into the [-pi,pi] range.
 
float Angle (const Vector4 &v) const
 
float AngleDeg (const Vector4 &v) const
 
float AngleSafe (const Vector4 &v) const
 Calculates the closest angle(radians) towards the given vector with in the [0, pi] range.
 
float AngleSafeDeg (const Vector4 &v) const
 Calculates the closest angle(degrees) towards the given vector with in the [0, 180] range.
 
Vector4 GetAbs () const
 Takes the absolute value of each component of the vector.
 
Vector4 GetReciprocal () const
 Returns the reciprocal of each component of the vector.
 
Vector4 GetReciprocalEstimate () const
 Returns the reciprocal of each component of the vector, fast but low accuracy, uses raw estimate instructions.
 
bool IsFinite () const
 Returns true if the vector contains no nan or inf values, false if at least one element is not finite.
 
Simd::Vec4::FloatType GetSimdValue () const
 Returns the underlying SIMD vector.
 
void SetSimdValue (Simd::Vec4::FloatArgType value)
 Directly sets the underlying SIMD vector.
 
float NormalizeWithLength ()
 
float NormalizeWithLengthEstimate ()
 
Vector4 GetNormalizedSafe (float tolerance=Constants::Tolerance) const
 
Vector4 GetNormalizedSafeEstimate (float tolerance=Constants::Tolerance) const
 
void NormalizeSafe (float tolerance=Constants::Tolerance)
 
void NormalizeSafeEstimate (float tolerance=Constants::Tolerance)
 
float NormalizeSafeWithLength (float tolerance=Constants::Tolerance)
 
float NormalizeSafeWithLengthEstimate (float tolerance=Constants::Tolerance)
 
float GetDistance (const Vector4 &v) const
 
float GetDistanceEstimate (const Vector4 &v) const
 
bool IsLessThan (const Vector4 &rhs) const
 
bool IsLessEqualThan (const Vector4 &rhs) const
 
bool IsGreaterThan (const Vector4 &rhs) const
 
bool IsGreaterEqualThan (const Vector4 &rhs) const
 
Vector4 GetFloor () const
 
Vector4 GetCeil () const
 
Vector4 GetRound () const
 
Vector4 GetMin (const Vector4 &v) const
 
Vector4 GetMax (const Vector4 &v) const
 
Vector4 GetClamp (const Vector4 &min, const Vector4 &max) const
 

Static Public Member Functions

static void Reflect (ReflectContext *context)
 
static Vector4 CreateZero ()
 Creates a vector with all components set to zero, more efficient than calling Vector4(0.0f).
 
static Vector4 CreateOne ()
 Creates a vector with all components set to one.
 
static Vector4 CreateAxisX (float length=1.0f)
 
static Vector4 CreateAxisY (float length=1.0f)
 
static Vector4 CreateAxisZ (float length=1.0f)
 
static Vector4 CreateAxisW (float length=1.0f)
 
static Vector4 CreateFromFloat4 (const float *values)
 Sets components from an array of 4 floats, stored in xyzw order.
 
static Vector4 CreateFromVector3 (const Vector3 &v)
 Copies x,y,z components from a Vector3, sets w to 1.0.
 
static Vector4 CreateFromVector3AndFloat (const Vector3 &v, float w)
 Copies x,y,z components from a Vector3, specify w separately.
 
static Vector4 CreateSelectCmpEqual (const Vector4 &cmp1, const Vector4 &cmp2, const Vector4 &vA, const Vector4 &vB)
 operation r.x = (cmp1.x == cmp2.x) ? vA.x : vB.x per component.
 
static Vector4 CreateSelectCmpGreaterEqual (const Vector4 &cmp1, const Vector4 &cmp2, const Vector4 &vA, const Vector4 &vB)
 operation ( r.x = (cmp1.x >= cmp2.x) ? vA.x : vB.x ) per component.
 
static Vector4 CreateSelectCmpGreater (const Vector4 &cmp1, const Vector4 &cmp2, const Vector4 &vA, const Vector4 &vB)
 operation ( r.x = (cmp1.x > cmp2.x) ? vA.x : vB.x ) per component.
 

Protected Attributes

union {
   Simd::Vec4::FloatType   m_value
 
   float   m_values [4]
 
   struct {
      float   m_x
 
      float   m_y
 
      float   m_z
 
      float   m_w
 
   } 
 
}; 
 

Detailed Description

A vector class with 4 components. To convert back to a Vector3, call the GetHomogenized function.

Member Function Documentation

◆ Angle()

AZ_MATH_INLINE float AZ::Vector4::Angle ( const Vector4 v) const

Calculates the closest angle(radians) towards the given vector with in the [0, pi] range. Note: It's unsafe if any of the vectors are (0, 0, 0, 0)

◆ AngleDeg()

AZ_MATH_INLINE float AZ::Vector4::AngleDeg ( const Vector4 v) const

Calculates the closest angle(degrees) towards the given vector with in the [0, 180] range. Note: It's unsafe if any of the vectors are (0, 0, 0, 0)

◆ GetDistance()

AZ_MATH_INLINE float AZ::Vector4::GetDistance ( const Vector4 v) const

Returns distance to another Vector4.

◆ GetFloor()

AZ_MATH_INLINE Vector4 AZ::Vector4::GetFloor ( ) const

Floor/Ceil/Round functions, operate on each component individually, result will be a new Vector4.

◆ GetMin()

AZ_MATH_INLINE Vector4 AZ::Vector4::GetMin ( const Vector4 v) const

Min/Max functions, operate on each component individually, result will be a new Vector4.

◆ GetNormalizedSafe()

AZ_MATH_INLINE Vector4 AZ::Vector4::GetNormalizedSafe ( float  tolerance = Constants::Tolerance) const

Safe normalization, returns (0,0,0,0) if the length of the vector is too small.

◆ IsLessThan()

AZ_MATH_INLINE bool AZ::Vector4::IsLessThan ( const Vector4 rhs) const

Comparison functions, not implemented as operators to improve code clarity. These functions return true only if all components pass the comparison test.

◆ Lerp()

AZ_MATH_INLINE Vector4 AZ::Vector4::Lerp ( const Vector4 dest,
float  t 
) const

Linear interpolation between this vector and a destination.

Returns
(this)(1-t) + dest*t

◆ Nlerp()

AZ_MATH_INLINE Vector4 AZ::Vector4::Nlerp ( const Vector4 dest,
float  t 
) const

Normalized linear interpolation between this vector and a destination. Linearly interpolates between the two vectors and normalizes the result.

◆ NormalizeWithLength()

AZ_MATH_INLINE float AZ::Vector4::NormalizeWithLength ( )

Normalizes the vector in-place and returns the previous length. This takes a few more instructions than calling Normalize().

◆ operator()()

AZ_MATH_INLINE float AZ::Vector4::operator() ( int32_t  index) const

Indexed access using operator().

Note
This is a convenience method, as it can be slower than using GetX, GetY, etc.

◆ Reflect()

static void AZ::Vector4::Reflect ( ReflectContext context)
static

AzCore Reflection.

Parameters
contextreflection context

◆ Slerp()

AZ_MATH_INLINE Vector4 AZ::Vector4::Slerp ( const Vector4 dest,
float  t 
) const

Spherical linear interpolation between normalized vectors. Interpolates along the great circle connecting the two vectors.


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