HighMap library (C++)
|
Vec3 class for basic manipulation of 3D vectors. More...
#include <algebra.hpp>
Public Member Functions | |
Vec3 () | |
Default constructor initializing the vector to (0, 0, 0). | |
Vec3 (T x, T y, T z) | |
Parameterized constructor initializing the vector to given values. | |
Vec3 (const std::vector< T > &vec) | |
Constructs a Vec3 object from a std::vector. | |
bool | operator== (const Vec3 &other_vec) const |
Equality operator. | |
bool | operator!= (const Vec3 &other_vec) const |
Inequality operator. | |
Vec3 & | operator/= (const T value) |
Division-assignment operator. | |
Vec3 | operator/ (const Vec3 &other_vec) const |
Division operator. | |
Vec3 | operator* (const Vec3 &other_vec) const |
Multiplication operator. | |
Vec3 | operator+ (const Vec3 &other_vec) const |
Addition operator. | |
Vec3 | operator- (const Vec3 &other_vec) const |
Subtraction operator. | |
Vec3 | operator* (T scalar) const |
Scalar multiplication (Vec3 * scalar). | |
T | magnitude () const |
Calculate the magnitude (length) of the vector. | |
void | normalize () |
Normalize the vector to have a magnitude of 1. | |
T | sum () const |
Calculate the sum of the vector components. | |
Public Attributes | |
T | x |
T | y |
T | z |
The x, y, and z components of the vector. | |
Friends | |
Vec3 | operator* (T scalar, const Vec3 &vec) |
Scalar multiplication (scalar * Vec3). | |
Vec3 | cross (const Vec3 v1, const Vec3 v2) |
Friend function to calculate the cross product of two vectors. | |
float | dot (const Vec3 v1, const Vec3 v2) |
Friend function to calculate the dot product of two vectors. | |
Vec3 class for basic manipulation of 3D vectors.
This class provides basic operations for 3D vectors, such as addition, subtraction, multiplication, division, and dot product calculation. The class supports various data types through templating.
T | Data type for the vector components (e.g., int, float, double). |
|
inline |
Default constructor initializing the vector to (0, 0, 0).
Initializes the x, y, and z components to zero.
|
inline |
Parameterized constructor initializing the vector to given values.
x | The x component of the vector. |
y | The y component of the vector. |
z | The z component of the vector. |
|
inline |
Constructs a Vec3 object from a std::vector.
This constructor takes a vector containing exactly three elements and assigns the first element to x
, the second element to y
, and the third to z
.
T | The type of elements in the vector (e.g., float, int, double). |
vec | A const reference to a vector of size 3, where the first element corresponds to x , the second to y , and the third to z . |
std::invalid_argument | If the vector does not contain exactly three elements. |
|
inline |
Equality operator.
Compares two vectors for equality.
other_vec | The vector to compare with. |
|
inline |
Inequality operator.
Compares two vectors for inequality.
other_vec | The vector to compare with. |
|
inline |
Division-assignment operator.
Divides all components of the vector by a scalar value and assigns the result.
value | The scalar value to divide by. |
|
inline |
Division operator.
Divides each component of the vector by the corresponding component of another vector.
other_vec | The vector to divide by. |
|
inline |
Multiplication operator.
Multiplies each component of the vector by the corresponding component of another vector.
other_vec | The vector to multiply by. |
|
inline |
Addition operator.
Adds each component of the vector to the corresponding component of another vector.
other_vec | The vector to add. |
|
inline |
Subtraction operator.
Subtracts each component of another vector from the corresponding component of this vector.
other_vec | The vector to subtract. |
|
inline |
|
inline |
Calculate the magnitude (length) of the vector.
|
inline |
Normalize the vector to have a magnitude of 1.
This method modifies the vector in place. If the vector has zero length, the components remain unchanged to avoid division by zero.
|
inline |
Calculate the sum of the vector components.
Scalar multiplication (scalar * Vec3).
Multiplies each component of the vector by a scalar value. This function allows expressions where the scalar is on the left side of the multiplication operator.
scalar | The scalar value to multiply with. |
vec | The vector to multiply. |
Friend function to calculate the cross product of two vectors.
The cross product results in a vector that is perpendicular to the plane formed by the two input vectors.
v1 | The first vector. |
v2 | The second vector. |
Friend function to calculate the dot product of two vectors.
The dot product is the sum of the products of the corresponding components of the vectors.
v1 | The first vector. |
v2 | The second vector. |
T hmap::Vec3< T >::x |
T hmap::Vec3< T >::y |
T hmap::Vec3< T >::z |
The x, y, and z components of the vector.