Class endstone::Vector¶
Represents a 3-dimensional vector.
#include <endstone/util/vector.h>
Public Functions¶
| Type | Name |
|---|---|
| constexpr | Vector () = default Construct the vector with all components as 0. |
| constexpr | Vector (T x, T y, T z) Construct the vector with provided components. |
| Vector (const Vector & other) = default |
|
| Vector (Vector && other) noexcept |
|
| float | angle (const Vector & other) const Gets the angle between this vector and another in radians. |
| constexpr Vector & | crossProduct (const Vector & other) Calculates the cross-product of this vector with another. |
| float | distance (const Vector & other) const Get the distance between this vector and another. |
| constexpr float | distanceSquared (const Vector & other) const Get the squared distance between this vector and another. |
| constexpr float | dot (const Vector & other) const Calculates the dot product of this vector with another. The dot product is defined as x1*x2+y1*y2+z1*z2. The returned value is a scalar. |
| int | getBlockX () const Gets the floored value of the X component, indicating the block that this vector is contained with. |
| int | getBlockY () const Gets the floored value of the Y component, indicating the block that this vector is contained with. |
| int | getBlockZ () const Gets the floored value of the Z component, indicating the block that this vector is contained with. |
| constexpr Vector | getCrossProduct (const Vector & other) const Calculates the cross-product of this vector with another without mutating the original. |
| constexpr Vector | getMidpoint (const Vector & other) const Gets a new midpoint vector between this vector and another. |
| constexpr float | getX () const Gets the X component. |
| constexpr float | getY () const Gets the Y component. |
| constexpr float | getZ () const Gets the Z component. |
| constexpr bool | isInAABB (const Vector & min, const Vector & max) const Returns whether this vector is in an axis-aligned bounding box. |
| constexpr bool | isInSphere (const Vector & origin, float radius) const Returns whether this vector is within a sphere. |
| bool | isNormalized () const Returns if a vector is normalized. |
| constexpr bool | isZero () const Check whether or not each component of this vector is equal to 0. |
| float | length () const Gets the magnitude of the vector, defined as sqrt(x2+y2+z^2). |
| constexpr float | lengthSquared () const Gets the magnitude of the vector squared. |
| constexpr Vector & | midpoint (const Vector & other) Sets this vector to the midpoint between this vector and another. |
| Vector & | normalize () Converts this vector to a unit vector (a vector with length of 1). |
| constexpr Vector & | normalizeZeros () Converts each component of value -0.0 to0.0 . |
| bool | operator!= (const Vector & other) noexcept const |
| constexpr Vector | operator* (const Vector & other) const |
| constexpr Vector | operator* (T scalar) const |
| Vector & | operator*= (const Vector & other) |
| constexpr Vector | operator+ (const Vector & other) const |
| constexpr Vector | operator+ (T scalar) const |
| Vector & | operator+= (const Vector & other) |
| constexpr Vector | operator- (const Vector & other) const |
| constexpr Vector | operator- (T scalar) const |
| Vector & | operator-= (const Vector & other) |
| constexpr Vector | operator/ (const Vector & other) const |
| constexpr Vector | operator/ (T scalar) const |
| Vector & | operator/= (const Vector & other) |
| Vector & | operator= (const Vector & other) = default |
| Vector & | operator= (Vector && other) noexcept |
| bool | operator== (const Vector & other) noexcept const |
| Vector & | rotateAroundAxis (const Vector & axis, float angle) Rotates the vector around a given arbitrary axis in 3-dimensional space. |
| Vector & | rotateAroundNonUnitAxis (const Vector & axis, float angle) Rotates the vector around a given arbitrary axis in 3-dimensional space. |
| Vector & | rotateAroundX (float angle) Rotates the vector around the x-axis. |
| Vector & | rotateAroundY (float angle) Rotates the vector around the y-axis. |
| Vector & | rotateAroundZ (float angle) Rotates the vector around the z-axis. |
| constexpr Vector & | setX (T x) Set the X component. |
| constexpr Vector & | setY (T y) Set the Y component. |
| constexpr Vector & | setZ (T z) Set the Z component. |
| constexpr Vector & | zero () Zero this vector's components. |
Protected Attributes¶
| Type | Name |
|---|---|
| float | x_ = 0.0 |
| float | y_ = 0.0 |
| float | z_ = 0.0 |
Public Functions Documentation¶
function Vector [¼]¶
Construct the vector with all components as 0.
function Vector [2/4]¶
Construct the vector with provided components.
template<std::convertible_to< float > T>
inline constexpr endstone::Vector::Vector (
T x,
T y,
T z
)
Parameters:
xX componentyY componentzZ component
function Vector [¾]¶
function Vector [4/4]¶
function angle¶
Gets the angle between this vector and another in radians.
Parameters:
otherThe other vector
Returns:
angle in radians
function crossProduct¶
Calculates the cross-product of this vector with another.
The cross-product is defined as: * x = y1 * z2 - y2 * z1 * y = z1 * x2 - z2 * x1 * z = x1 * y2 - x2 * y1
Parameters:
otherThe other vector
Returns:
the same vector
function distance¶
Get the distance between this vector and another.
Parameters:
otherThe other vector
Returns:
the distance
function distanceSquared¶
Get the squared distance between this vector and another.
Parameters:
otherThe other vector
Returns:
the distance
function dot¶
Calculates the dot product of this vector with another. The dot product is defined as x1*x2+y1*y2+z1*z2. The returned value is a scalar.
Parameters:
otherThe other vector
Returns:
dot product
function getBlockX¶
Gets the floored value of the X component, indicating the block that this vector is contained with.
Returns:
block X
function getBlockY¶
Gets the floored value of the Y component, indicating the block that this vector is contained with.
Returns:
block y
function getBlockZ¶
Gets the floored value of the Z component, indicating the block that this vector is contained with.
Returns:
block z
function getCrossProduct¶
Calculates the cross-product of this vector with another without mutating the original.
The cross-product is defined as: * x = y1 * z2 - y2 * z1 * y = z1 * x2 - z2 * x1 * z = x1 * y2 - x2 * y1
Parameters:
otherThe other vector
Returns:
a new vector
function getMidpoint¶
Gets a new midpoint vector between this vector and another.
Parameters:
otherThe other vector
Returns:
a new midpoint vector
function getX¶
Gets the X component.
Returns:
The X component.
function getY¶
Gets the Y component.
Returns:
The Y component.
function getZ¶
Gets the Z component.
Returns:
The Z component.
function isInAABB¶
Returns whether this vector is in an axis-aligned bounding box.
The minimum and maximum vectors given must be truly the minimum and maximum X, Y and Z components.
Parameters:
minMinimum vectormaxMaximum vector
Returns:
whether this vector is in the AABB
function isInSphere¶
Returns whether this vector is within a sphere.
Parameters:
originSphere origin.radiusSphere radius
Returns:
whether this vector is in the sphere
function isNormalized¶
Returns if a vector is normalized.
Returns:
whether the vector is normalized
function isZero¶
Check whether or not each component of this vector is equal to 0.
Returns:
true if equal to zero, false if at least one component is non-zero
function length¶
Gets the magnitude of the vector, defined as sqrt(x2+y2+z^2).
Returns:
the magnitude
function lengthSquared¶
Gets the magnitude of the vector squared.
Returns:
the magnitude
function midpoint¶
Sets this vector to the midpoint between this vector and another.
Parameters:
otherThe other vector
Returns:
this same vector (now a midpoint)
function normalize¶
Converts this vector to a unit vector (a vector with length of 1).
Returns:
the same vector
function normalizeZeros¶
Converts each component of value -0.0 to0.0 .
Returns:
This vector.
function operator!=¶
function operator*¶
function operator*¶
template<std::convertible_to< float > T>
inline constexpr Vector endstone::Vector::operator* (
T scalar
) const
function operator*=¶
function operator+¶
function operator+¶
template<std::convertible_to< float > T>
inline constexpr Vector endstone::Vector::operator+ (
T scalar
) const
function operator+=¶
function operator-¶
function operator-¶
template<std::convertible_to< float > T>
inline constexpr Vector endstone::Vector::operator- (
T scalar
) const
function operator-=¶
function operator/¶
function operator/¶
template<std::convertible_to< float > T>
inline constexpr Vector endstone::Vector::operator/ (
T scalar
) const
function operator/=¶
function operator=¶
function operator=¶
function operator==¶
function rotateAroundAxis¶
Rotates the vector around a given arbitrary axis in 3-dimensional space.
Rotation will follow the general Right-Hand-Rule, which means rotation will be counterclockwise when the axis is pointing towards the observer.
This method will always make sure the provided axis is a unit vector, to not modify the length of the vector when rotating. If you are experienced with the scaling of a non-unit axis vector, you can use rotateAroundNonUnitAxis(Vector, float).
Parameters:
axisthe axis to rotate the vector around. If the passed vector is not of length 1, it gets normalized before using it for the rotation.anglethe angle to rotate the vector around the axis
Returns:
the same vector
function rotateAroundNonUnitAxis¶
Rotates the vector around a given arbitrary axis in 3-dimensional space.
Rotation will follow the general Right-Hand-Rule, which means rotation will be counterclockwise when the axis is pointing towards the observer.
Note that the vector length will change accordingly to the axis vector length. If the provided axis is not a unit vector, the rotated vector will not have its previous length. The scaled length of the resulting vector will be related to the axis vector. If you are not sure about the scaling of the vector, use rotateAroundAxis(Vector, float).
Parameters:
axisthe axis to rotate the vector around.anglethe angle to rotate the vector around the axis
Returns:
the same vector
function rotateAroundX¶
Rotates the vector around the x-axis.
Parameters:
anglethe angle to rotate the vector about. This angle is passed in radians
Returns:
the same vector
function rotateAroundY¶
Rotates the vector around the y-axis.
Parameters:
anglethe angle to rotate the vector about. This angle is passed in radians
Returns:
the same vector
function rotateAroundZ¶
Rotates the vector around the z-axis.
Parameters:
anglethe angle to rotate the vector about. This angle is passed in radians
Returns:
the same vector
function setX¶
Set the X component.
Parameters:
xThe new X component.
Returns:
This vector.
function setY¶
Set the Y component.
Parameters:
yThe new Y component.
Returns:
This vector.
function setZ¶
Set the Z component.
Parameters:
zThe new Z component.
Returns:
This vector.
function zero¶
Zero this vector's components.
Returns:
the same vector
Protected Attributes Documentation¶
variable x_¶
variable y_¶
variable z_¶
Friends Documentation¶
friend operator*¶
friend operator+¶
friend operator-¶
friend operator/¶
The documentation for this class was generated from the following file include/endstone/util/vector.h