SmartFoxServer 3 C++ Client API 3.1.0-beta
Client API for SmartFoxServer 3
Loading...
Searching...
No Matches
sfs3::entities::SFSVector3 Struct Reference

A class representing a Vector in 3D space. More...

#include <SFSVector3.h>

Public Member Functions

float lengthSquared () const
 Returns the squared length of this vector.
float length () const
 Returns the length (magnitude) of this vector.
bool isNormalized () const
 Returns true if the vector is normalized, i.e.
SFSVector3 sum (const SFSVector3 &vec) const
 Returns a new vector that is the sum of this vector and the specified vector.
SFSVector3 sub (const SFSVector3 &vec) const
 Returns a new vector that is the result of subtracting the specified vector from this vector.
SFSVector3 mult (const SFSVector3 &vec) const
 Returns a new vector that is the component-wise multiplication of this vector and the specified vector.
SFSVector3 divide (const SFSVector3 &vec) const
 Returns a new vector that is the component-wise division of this vector by the specified vector.
SFSVector3 normalize () const
 Returns a new vector that is the normalized (unit length) version of this vector.
float dot (const SFSVector3 &vec) const
 Returns the dot product of this vector and the specified vector.
SFSVector3 cross (const SFSVector3 &vec) const
 Returns the cross product of this vector and the specified vector.
float distanceTo (const SFSVector3 &vec) const
 Returns the Euclidean distance between this vector and the specified vector.
float distanceSquaredTo (const SFSVector3 &vec) const
 Returns the squared distance between this vector and the specified vector.
SFSVector3 abs () const
 Returns a new vector with all components in absolute values.
SFSVector3 min (const SFSVector3 &vec) const
 Returns a new vector with the component-wise minimum of this vector and the specified vector.
SFSVector3 max (const SFSVector3 &vec) const
 Returns a new vector with the component-wise maximum of this vector and the specified vector.
SFSVector3 floor () const
 Returns a new vector with all components rounded down to the nearest integer.
SFSVector3 ceil () const
 Returns a new vector with all components rounded up to the nearest integer.
SFSVector3 round () const
 Returns a new vector with all components rounded to the nearest integer, with halfway cases rounded towards positive infinity (-1.5 rounds to -1.0).
SFSVector3 lerp (const SFSVector3 &vec, float weight) const
 Returns the result of the linear interpolation between this vector and the specified vector by the specified weight.
SFSVector3 rotate (const SFSVector3 &axis, float angle) const
 Returns a new vector that is the result of rotating this vector around the specified axis by the specified angle, using Rodrigues' rotation formula.

Detailed Description

A class representing a Vector in 3D space.

NOTE: equality and hashing are value-based (x,y,z); mutating a component while the instance is used as a key in a hash-based container will corrupt lookups.

Member Function Documentation

◆ lengthSquared()

float sfs3::entities::SFSVector3::lengthSquared ( ) const
inline

Returns the squared length of this vector.

Cheaper than length(), and enough whenever lengths are only compared to each other.

Returns
the squared length of the vector

◆ length()

float sfs3::entities::SFSVector3::length ( ) const
inline

Returns the length (magnitude) of this vector.

Returns
the length of the vector

◆ isNormalized()

bool sfs3::entities::SFSVector3::isNormalized ( ) const
inline

Returns true if the vector is normalized, i.e.

its length is approximately equal to 1.

Returns
true if the vector is normalized, false otherwise

◆ sum()

SFSVector3 sfs3::entities::SFSVector3::sum ( const SFSVector3 & vec) const
inline

Returns a new vector that is the sum of this vector and the specified vector.

Parameters
vecthe vector to add
Returns
a new vector representing the sum

◆ sub()

SFSVector3 sfs3::entities::SFSVector3::sub ( const SFSVector3 & vec) const
inline

Returns a new vector that is the result of subtracting the specified vector from this vector.

Parameters
vecthe vector to subtract
Returns
a new vector representing the difference

◆ mult()

SFSVector3 sfs3::entities::SFSVector3::mult ( const SFSVector3 & vec) const
inline

Returns a new vector that is the component-wise multiplication of this vector and the specified vector.

Parameters
vecthe vector to multiply with
Returns
a new vector representing the component-wise product

◆ divide()

SFSVector3 sfs3::entities::SFSVector3::divide ( const SFSVector3 & vec) const
inline

Returns a new vector that is the component-wise division of this vector by the specified vector.

If any component of the divisor is zero, the result will be Infinity or NaN.

Parameters
vecthe vector to divide by
Returns
a new vector representing the component-wise quotient

◆ normalize()

SFSVector3 sfs3::entities::SFSVector3::normalize ( ) const
inline

Returns a new vector that is the normalized (unit length) version of this vector.

If this vector has zero length, returns a zero vector.

Returns
a new normalized vector

◆ dot()

float sfs3::entities::SFSVector3::dot ( const SFSVector3 & vec) const
inline

Returns the dot product of this vector and the specified vector.

The dot product will be 0 for a right angle (90 degrees), greater than 0 for angles narrower than 90 degrees and lower than 0 for angles wider than 90 degrees. When using unit (normalized) vectors, the result will always be between -1.0 (180 degree angle) when the vectors are facing opposite directions, and 1.0 (0 degree angle) when the vectors are aligned.

Parameters
vecthe vector to compute the dot product with
Returns
the dot product

◆ cross()

SFSVector3 sfs3::entities::SFSVector3::cross ( const SFSVector3 & vec) const
inline

Returns the cross product of this vector and the specified vector.

The cross product is a vector perpendicular to both vectors.

Parameters
vecthe vector to compute the cross product with
Returns
a new vector representing the cross product

◆ distanceTo()

float sfs3::entities::SFSVector3::distanceTo ( const SFSVector3 & vec) const
inline

Returns the Euclidean distance between this vector and the specified vector.

Parameters
vecthe vector to measure distance to
Returns
the distance between the two vectors

◆ distanceSquaredTo()

float sfs3::entities::SFSVector3::distanceSquaredTo ( const SFSVector3 & vec) const
inline

Returns the squared distance between this vector and the specified vector.

This is more efficient than distanceTo() when comparing distances.

Parameters
vecthe vector to measure squared distance to
Returns
the squared distance between the two vectors

◆ abs()

SFSVector3 sfs3::entities::SFSVector3::abs ( ) const
inline

Returns a new vector with all components in absolute values.

Returns
a new vector with absolute values

◆ min()

SFSVector3 sfs3::entities::SFSVector3::min ( const SFSVector3 & vec) const
inline

Returns a new vector with the component-wise minimum of this vector and the specified vector.

Parameters
vecthe vector to compare with
Returns
a new vector with the minimum components

◆ max()

SFSVector3 sfs3::entities::SFSVector3::max ( const SFSVector3 & vec) const
inline

Returns a new vector with the component-wise maximum of this vector and the specified vector.

Parameters
vecthe vector to compare with
Returns
a new vector with the maximum components

◆ floor()

SFSVector3 sfs3::entities::SFSVector3::floor ( ) const
inline

Returns a new vector with all components rounded down to the nearest integer.

Returns
a new vector with floored components

◆ ceil()

SFSVector3 sfs3::entities::SFSVector3::ceil ( ) const
inline

Returns a new vector with all components rounded up to the nearest integer.

Returns
a new vector with ceiling components

◆ round()

SFSVector3 sfs3::entities::SFSVector3::round ( ) const
inline

Returns a new vector with all components rounded to the nearest integer, with halfway cases rounded towards positive infinity (-1.5 rounds to -1.0).

Returns
a new vector with rounded components

◆ lerp()

SFSVector3 sfs3::entities::SFSVector3::lerp ( const SFSVector3 & vec,
float weight ) const
inline

Returns the result of the linear interpolation between this vector and the specified vector by the specified weight.

The weight range is 0.0 to 1.0, representing the amount of interpolation. Values outside this range will extrapolate.

Parameters
vecthe target vector to interpolate towards
weightthe interpolation weight (0.0 = this vector, 1.0 = target vector)
Returns
a new interpolated vector

◆ rotate()

SFSVector3 sfs3::entities::SFSVector3::rotate ( const SFSVector3 & axis,
float angle ) const

Returns a new vector that is the result of rotating this vector around the specified axis by the specified angle, using Rodrigues' rotation formula.

The axis must be a normalized vector: if it isn't, no rotation is applied and a copy of this vector is returned unchanged (a warning is logged).

Parameters
axisthe axis to rotate around (must be a normalized vector)
anglethe angle to rotate by, in radians
Returns
a new rotated vector

The documentation for this struct was generated from the following files: