|
Infinity Engine v0.6.20
C++ API Documentation
|
Template structure representing a 3-component vector. More...
#include <Vector3.hpp>
Public Member Functions | |
| constexpr | t_Vector3 () |
| Default constructor. | |
| constexpr | t_Vector3 (const t_Vector3 &v) |
| Copy constructor. | |
| constexpr t_Vector3 & | operator= (const t_Vector3 &)=default |
| Copy assignment operator. | |
| constexpr | t_Vector3 (T x, T y, T z) |
| Constructs a vector from component values. | |
| template<typename R > | |
| constexpr | t_Vector3 (const t_Vector3< R > &v) |
| Explicit type-converting constructor. | |
| T & | operator[] (size_t i) |
| Array subscript operator (mutable). | |
| T | operator[] (size_t i) const |
| Array subscript operator (const). | |
| void | set (T in_x, T in_y, T in_z) |
| Sets all three components simultaneously. | |
| T * | data () |
| Gets a mutable pointer to the underlying data. | |
| const T * | data () const |
| Gets a const pointer to the underlying data. | |
| template<typename R > | |
| t_Vector3 & | operator= (const t_Vector3< R > &rhs) |
| Type-converting assignment operator. | |
| t_Vector3 & | operator+= (const t_Vector3 &rhs) |
| Component-wise addition assignment. | |
| t_Vector3 & | operator-= (const t_Vector3 &rhs) |
| Component-wise subtraction assignment. | |
| t_Vector3 & | operator*= (T rhs) |
| Scalar multiplication assignment. | |
| t_Vector3 & | operator*= (const t_Vector3 &rhs) |
| Component-wise multiplication assignment. | |
| t_Vector3 & | operator/= (T rhs) |
| Scalar division assignment. | |
| operator bool () const noexcept | |
| Boolean conversion operator. | |
| t_Vector3< T > | normalized () const |
| Computes the normalized version of this vector. | |
| t_Vector3< T > | cross (const t_Vector3< T > &other) const |
| Computes the cross product with another vector. | |
| float | length () const |
| Computes the length (magnitude) of this vector. | |
| float | magnitude () const |
| Computes the magnitude of this vector. | |
| float | squaredMagnitude () const |
| Computes the squared magnitude of this vector. | |
| float | distance (const t_Vector3< T > &other) const |
| Computes the Euclidean distance to another vector. | |
| float | dot (const t_Vector3< T > &other) const |
| Computes the dot product with another vector. | |
| float | angle (const t_Vector3< T > &other) const |
| Computes the angle between this vector and another. | |
| t_Vector3< T > | abs () const |
| Computes the component-wise absolute value. | |
Static Public Member Functions | |
| static constexpr t_Vector3< T > | zero () |
| Returns a zero vector (0, 0, 0). | |
| static constexpr t_Vector3< T > | identity () |
| Returns an identity/zero vector (0, 0, 0). | |
| static constexpr t_Vector3< T > | left () |
| Returns the left direction vector (-1, 0, 0). | |
| static constexpr t_Vector3< T > | right () |
| Returns the right direction vector (1, 0, 0). | |
| static constexpr t_Vector3< T > | up () |
| Returns the up direction vector (0, 1, 0). | |
| static constexpr t_Vector3< T > | down () |
| Returns the down direction vector (0, -1, 0). | |
| static constexpr t_Vector3< T > | front () |
| Returns the front/forward direction vector (0, 0, 1). | |
| static constexpr t_Vector3< T > | back () |
| Returns the back/backward direction vector (0, 0, -1). | |
Public Attributes | ||
| union { | ||
| T value [3] | ||
| Array access to components. More... | ||
| struct { | ||
| T x | ||
| T y | ||
| T z | ||
| Cartesian coordinate interpretation. More... | ||
| } | ||
| struct { | ||
| T r | ||
| T g | ||
| T b | ||
| Color component interpretation. More... | ||
| } | ||
| struct { | ||
| T s | ||
| T t | ||
| T p | ||
| Texture coordinate interpretation. More... | ||
| } | ||
| }; | ||
| Union providing multiple interpretations of the same data. | ||
Template structure representing a 3-component vector.
t_Vector3 provides a versatile 3D vector implementation with support for multiple interpretations of the same underlying data through union members:
This flexibility makes it suitable for various use cases in procedural generation:
The template parameter allows instantiation with different numeric types (float, double, int, etc.) to match precision and performance requirements. Common specializations are provided via type aliases (Vector3, Vector3i, etc.).
Vector operations include:
Example usage:
| T | The numeric type for vector components (float, double, int, etc.). |
|
inlineconstexpr |
Default constructor.
Initializes all components to zero (or default value of T).
|
inlineconstexpr |
Copy constructor.
| v | Vector to copy from. |
|
inlineexplicitconstexpr |
Explicit type-converting constructor.
Constructs a vector from another vector with a different component type, performing static_cast on each component.
| R | The source component type. |
| v | Vector to convert from. |
Computes the component-wise absolute value.
Returns a vector where each component is the absolute value of the corresponding component in this vector.
Computes the angle between this vector and another.
Returns the angle in radians between the two vectors.
| other | The other vector. |
|
inlinestaticconstexpr |
Returns the back/backward direction vector (0, 0, -1).
|
inline |
Computes the cross product with another vector.
The cross product produces a vector perpendicular to both input vectors. The magnitude equals the area of the parallelogram formed by the vectors. The direction follows the right-hand rule.
| other | The other vector. |
|
inline |
Gets a const pointer to the underlying data.
Computes the dot product with another vector.
The dot product measures how much two vectors point in the same direction. Returns positive if vectors point in similar directions, negative if opposite, and zero if perpendicular.
| other | The other vector. |
|
inlinestaticconstexpr |
Returns the down direction vector (0, -1, 0).
|
inlinestaticconstexpr |
Returns the front/forward direction vector (0, 0, 1).
|
inlinestaticconstexpr |
Returns an identity/zero vector (0, 0, 0).
Alias for zero().
|
inlinestaticconstexpr |
Returns the left direction vector (-1, 0, 0).
|
inline |
|
inline |
Computes the magnitude of this vector.
Alias for length().
|
inline |
Computes the normalized version of this vector.
Returns a unit vector pointing in the same direction. If the vector is zero-length, returns a zero vector.
|
inlineexplicitnoexcept |
|
inline |
Component-wise multiplication assignment.
| rhs | Vector to multiply by component-wise. |
|
inline |
Scalar multiplication assignment.
| rhs | Scalar to multiply by. |
|
inline |
Component-wise addition assignment.
| rhs | Vector to add. |
|
inline |
Component-wise subtraction assignment.
| rhs | Vector to subtract. |
|
inline |
Scalar division assignment.
For floating-point types, multiplies by reciprocal for better performance. For integer types, performs standard division.
| rhs | Scalar to divide by. |
|
constexprdefault |
Copy assignment operator.
|
inline |
Type-converting assignment operator.
Assigns from a vector with a different component type, performing static_cast on each component.
| R | The source component type. |
| rhs | Vector to assign from. |
|
inline |
Array subscript operator (mutable).
| i | Component index (0, 1, or 2). |
|
inline |
Array subscript operator (const).
| i | Component index (0, 1, or 2). |
|
inlinestaticconstexpr |
Returns the right direction vector (1, 0, 0).
Sets all three components simultaneously.
| in_x | New x component value. |
| in_y | New y component value. |
| in_z | New z component value. |
|
inline |
Computes the squared magnitude of this vector.
More efficient than length() when you only need to compare lengths or don't need the actual distance value, as it avoids the sqrt operation.
Returns the up direction vector (0, 1, 0).
|
inlinestaticconstexpr |
Returns a zero vector (0, 0, 0).
| union { ... } Infinity::Types::Math::t_Vector3< T > |
Union providing multiple interpretations of the same data.
Allows accessing the three components as:
Color component interpretation.
Texture coordinate interpretation.
| T Infinity::Types::Math::t_Vector3< T >::value[3] |
Array access to components.
| T Infinity::Types::Math::t_Vector3< T >::x |
Cartesian coordinate interpretation.