Skip to content

Class endstone::Vector

ClassList > 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.

constexpr endstone::Vector::Vector () = default


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:

  • x X component
  • y Y component
  • z Z component

function Vector [¾]

endstone::Vector::Vector (
    const  Vector & other
) = default

function Vector [4/4]

endstone::Vector::Vector (
    Vector && other
) noexcept

function angle

Gets the angle between this vector and another in radians.

inline float endstone::Vector::angle (
    const  Vector & other
) const

Parameters:

  • other The other vector

Returns:

angle in radians


function crossProduct

Calculates the cross-product of this vector with another.

inline constexpr  Vector & endstone::Vector::crossProduct (
    const  Vector & other
) 

The cross-product is defined as: * x = y1 * z2 - y2 * z1 * y = z1 * x2 - z2 * x1 * z = x1 * y2 - x2 * y1

Parameters:

  • other The other vector

Returns:

the same vector


function distance

Get the distance between this vector and another.

inline float endstone::Vector::distance (
    const  Vector & other
) const

Parameters:

  • other The other vector

Returns:

the distance


function distanceSquared

Get the squared distance between this vector and another.

inline constexpr  float endstone::Vector::distanceSquared (
    const  Vector & other
) const

Parameters:

  • other The 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.

inline constexpr  float endstone::Vector::dot (
    const  Vector & other
) const

Parameters:

  • other The other vector

Returns:

dot product


function getBlockX

Gets the floored value of the X component, indicating the block that this vector is contained with.

inline int endstone::Vector::getBlockX () const

Returns:

block X


function getBlockY

Gets the floored value of the Y component, indicating the block that this vector is contained with.

inline int endstone::Vector::getBlockY () const

Returns:

block y


function getBlockZ

Gets the floored value of the Z component, indicating the block that this vector is contained with.

inline int endstone::Vector::getBlockZ () const

Returns:

block z


function getCrossProduct

Calculates the cross-product of this vector with another without mutating the original.

inline constexpr  Vector endstone::Vector::getCrossProduct (
    const  Vector & other
) const

The cross-product is defined as: * x = y1 * z2 - y2 * z1 * y = z1 * x2 - z2 * x1 * z = x1 * y2 - x2 * y1

Parameters:

  • other The other vector

Returns:

a new vector


function getMidpoint

Gets a new midpoint vector between this vector and another.

inline constexpr  Vector endstone::Vector::getMidpoint (
    const  Vector & other
) const

Parameters:

  • other The other vector

Returns:

a new midpoint vector


function getX

Gets the X component.

inline constexpr  float endstone::Vector::getX () const

Returns:

The X component.


function getY

Gets the Y component.

inline constexpr  float endstone::Vector::getY () const

Returns:

The Y component.


function getZ

Gets the Z component.

inline constexpr  float endstone::Vector::getZ () const

Returns:

The Z component.


function isInAABB

Returns whether this vector is in an axis-aligned bounding box.

inline constexpr  bool endstone::Vector::isInAABB (
    const  Vector & min,
    const  Vector & max
) const

The minimum and maximum vectors given must be truly the minimum and maximum X, Y and Z components.

Parameters:

  • min Minimum vector
  • max Maximum vector

Returns:

whether this vector is in the AABB


function isInSphere

Returns whether this vector is within a sphere.

inline constexpr  bool endstone::Vector::isInSphere (
    const  Vector & origin,
    float radius
) const

Parameters:

  • origin Sphere origin.
  • radius Sphere radius

Returns:

whether this vector is in the sphere


function isNormalized

Returns if a vector is normalized.

inline bool endstone::Vector::isNormalized () const

Returns:

whether the vector is normalized


function isZero

Check whether or not each component of this vector is equal to 0.

inline constexpr  bool endstone::Vector::isZero () const

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).

inline float endstone::Vector::length () const

Returns:

the magnitude


function lengthSquared

Gets the magnitude of the vector squared.

inline constexpr  float endstone::Vector::lengthSquared () const

Returns:

the magnitude


function midpoint

Sets this vector to the midpoint between this vector and another.

inline constexpr  Vector & endstone::Vector::midpoint (
    const  Vector & other
) 

Parameters:

  • other The other vector

Returns:

this same vector (now a midpoint)


function normalize

Converts this vector to a unit vector (a vector with length of 1).

inline Vector & endstone::Vector::normalize () 

Returns:

the same vector


function normalizeZeros

Converts each component of value -0.0 to0.0 .

inline constexpr  Vector & endstone::Vector::normalizeZeros () 

Returns:

This vector.


function operator!=

inline bool endstone::Vector::operator!= (
    const  Vector & other
) noexcept const

function operator*

inline constexpr  Vector endstone::Vector::operator* (
    const  Vector & other
) const

function operator*

template<std::convertible_to< float > T>
inline constexpr  Vector endstone::Vector::operator* (
    T scalar
) const

function operator*=

inline Vector & endstone::Vector::operator*= (
    const  Vector & other
) 

function operator+

inline constexpr  Vector endstone::Vector::operator+ (
    const  Vector & other
) const

function operator+

template<std::convertible_to< float > T>
inline constexpr  Vector endstone::Vector::operator+ (
    T scalar
) const

function operator+=

inline Vector & endstone::Vector::operator+= (
    const  Vector & other
) 

function operator-

inline constexpr  Vector endstone::Vector::operator- (
    const  Vector & other
) const

function operator-

template<std::convertible_to< float > T>
inline constexpr  Vector endstone::Vector::operator- (
    T scalar
) const

function operator-=

inline Vector & endstone::Vector::operator-= (
    const  Vector & other
) 

function operator/

inline constexpr  Vector endstone::Vector::operator/ (
    const  Vector & other
) const

function operator/

template<std::convertible_to< float > T>
inline constexpr  Vector endstone::Vector::operator/ (
    T scalar
) const

function operator/=

inline Vector & endstone::Vector::operator/= (
    const  Vector & other
) 

function operator=

Vector & endstone::Vector::operator= (
    const  Vector & other
) = default

function operator=

Vector & endstone::Vector::operator= (
    Vector && other
) noexcept

function operator==

inline bool endstone::Vector::operator== (
    const  Vector & other
) noexcept const

function rotateAroundAxis

Rotates the vector around a given arbitrary axis in 3-dimensional space.

inline Vector & endstone::Vector::rotateAroundAxis (
    const  Vector & axis,
    float angle
) 

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:

  • axis the axis to rotate the vector around. If the passed vector is not of length 1, it gets normalized before using it for the rotation.
  • angle the 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.

inline Vector & endstone::Vector::rotateAroundNonUnitAxis (
    const  Vector & axis,
    float angle
) 

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:

  • axis the axis to rotate the vector around.
  • angle the angle to rotate the vector around the axis

Returns:

the same vector


function rotateAroundX

Rotates the vector around the x-axis.

inline Vector & endstone::Vector::rotateAroundX (
    float angle
) 

Parameters:

  • angle the 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.

inline Vector & endstone::Vector::rotateAroundY (
    float angle
) 

Parameters:

  • angle the 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.

inline Vector & endstone::Vector::rotateAroundZ (
    float angle
) 

Parameters:

  • angle the angle to rotate the vector about. This angle is passed in radians

Returns:

the same vector


function setX

Set the X component.

template<std::convertible_to< float > T>
inline constexpr  Vector & endstone::Vector::setX (
    T x
) 

Parameters:

  • x The new X component.

Returns:

This vector.


function setY

Set the Y component.

template<std::convertible_to< float > T>
inline constexpr  Vector & endstone::Vector::setY (
    T y
) 

Parameters:

  • y The new Y component.

Returns:

This vector.


function setZ

Set the Z component.

template<std::convertible_to< float > T>
inline constexpr  Vector & endstone::Vector::setZ (
    T z
) 

Parameters:

  • z The new Z component.

Returns:

This vector.


function zero

Zero this vector's components.

inline constexpr  Vector & endstone::Vector::zero () 

Returns:

the same vector


Protected Attributes Documentation

variable x_

float endstone::Vector::x_;

variable y_

float endstone::Vector::y_;

variable z_

float endstone::Vector::z_;

Friends Documentation

friend operator*

template<typename  T>
inline Vector endstone::Vector::operator* (
    T scalar,
    const  Vector & v
) 

friend operator+

template<typename  T>
inline Vector endstone::Vector::operator+ (
    T scalar,
    const  Vector & v
) 

friend operator-

template<typename  T>
inline Vector endstone::Vector::operator- (
    T scalar,
    const  Vector & v
) 

friend operator/

template<typename  T>
inline Vector endstone::Vector::operator/ (
    T scalar,
    const  Vector & v
) 


The documentation for this class was generated from the following file include/endstone/util/vector.h