XVector4#
-
template<typename T>
class XVector4# Template class representing a 4-dimensional vector with x, y, z, and w components.
A template-based 4D vector class that provides basic vector operations including arithmetic operations, comparisons, and type conversions. This class is commonly used for homogeneous coordinates in 3D graphics and mathematical computations.
Note
This class includes validation macros in debug builds to ensure finite values
- Template Parameters:
T – The numeric type for vector components (typically float or double)
Public Functions
-
inline XVector4()#
Default constructor initializes all components to zero.
-
inline XVector4(T a)#
Constructor that initializes all components to the same value.
- Parameters:
a – [in] Value to assign to all components
-
inline XVector4(const T *p)#
Constructor that initializes components from an array.
- Parameters:
p – [in] Pointer to array of at least 4 elements
-
inline XVector4(T x_, T y_, T z_, T w_ = 1.0f)#
Constructor that initializes components with specific values.
- Parameters:
x_ – [in] X component value
y_ – [in] Y component value
z_ – [in] Z component value
w_ – [in] W component value (defaults to 1.0f)
-
inline XVector4(const Vec3 &v, float w)#
Constructor that creates a 4D vector from a 3D vector and w component.
- Parameters:
v – [in] 3D vector for x, y, z components
w – [in] W component value
-
inline operator T*()#
Conversion operator to non-const pointer to components.
- Returns:
Pointer to the first component (x)
-
inline operator const T*() const#
Conversion operator to const pointer to components.
- Returns:
Const pointer to the first component (x)
-
inline void Set(T x_, T y_, T z_, T w_)#
Sets all four components of the vector.
- Parameters:
x_ – [in] New x component value
y_ – [in] New y component value
z_ – [in] New z component value
w_ – [in] New w component value
-
inline XVector4<T> operator*(T scale) const#
Scalar multiplication operator.
- Parameters:
scale – [in] Scalar value to multiply with
- Returns:
New vector with each component multiplied by scale
-
inline XVector4<T> operator/(T scale) const#
Scalar division operator.
- Parameters:
scale – [in] Scalar value to divide by
- Returns:
New vector with each component divided by scale
-
inline XVector4<T> operator+(const XVector4<T> &v) const#
Vector addition operator.
- Parameters:
v – [in] Vector to add
- Returns:
New vector that is the sum of this vector and v
-
inline XVector4<T> operator-(const XVector4<T> &v) const#
Vector subtraction operator.
- Parameters:
v – [in] Vector to subtract
- Returns:
New vector that is the difference of this vector and v
-
inline XVector4<T> operator*(XVector4<T> scale) const#
Component-wise vector multiplication operator.
- Parameters:
scale – [in] Vector to multiply component-wise
- Returns:
New vector with components multiplied element-wise
-
inline XVector4<T> &operator*=(T scale)#
Scalar multiplication assignment operator.
- Parameters:
scale – [in] Scalar value to multiply with
- Returns:
Reference to this vector after multiplication
-
inline XVector4<T> &operator/=(T scale)#
Scalar division assignment operator.
- Parameters:
scale – [in] Scalar value to divide by
- Returns:
Reference to this vector after division
-
inline XVector4<T> &operator+=(const XVector4<T> &v)#
Vector addition assignment operator.
- Parameters:
v – [in] Vector to add
- Returns:
Reference to this vector after addition
-
inline XVector4<T> &operator-=(const XVector4<T> &v)#
Vector subtraction assignment operator.
- Parameters:
v – [in] Vector to subtract
- Returns:
Reference to this vector after subtraction
-
inline XVector4<T> &operator*=(const XVector4<T> &v)#
Component-wise vector multiplication assignment operator.
- Parameters:
v – [in] Vector to multiply component-wise
- Returns:
Reference to this vector after component-wise multiplication