Leviathan  0.8.0.0
Leviathan game engine
Leviathan::Float4 Struct Reference

#include <Types.h>

Public Member Functions

DLLEXPORT Float4 () noexcept=default
 
DLLEXPORT Float4 (float f1, float f2, float f3, float f4)
 
DLLEXPORT Float4 (Float2 floats, float f3, float f4)
 
DLLEXPORT Float4 (Float3 floats, float f4)
 
DLLEXPORT Float4 (float data)
 
DLLEXPORT bool HasInvalidValues () const noexcept
 
DLLEXPORT void CheckForNans () const
 
DLLEXPORT float & operator[] (int nindex)
 
DLLEXPORT operator float * () noexcept
 return first value of {X, Y, Z, W} as a pointer More...
 
DLLEXPORT Float4 operator+ (const Float4 &other) const noexcept
 
DLLEXPORT Float4operator+= (const Float4 &other) noexcept
 
DLLEXPORT Float4 operator- (const Float4 &other) const noexcept
 
DLLEXPORT Float4operator-= (const Float4 &other) noexcept
 
DLLEXPORT Float4 operator- () const noexcept
 
DLLEXPORT Float4 operator+ () const noexcept
 
DLLEXPORT Float4 operator* (const Float4 &other) const noexcept
 
DLLEXPORT Float4operator*= (const Float4 &other) noexcept
 
DLLEXPORT Float4 operator/ (float val) const
 
DLLEXPORT Float4operator/= (float val)
 
DLLEXPORT Float4 operator* (float val) const noexcept
 
DLLEXPORT Float4operator*= (float val) noexcept
 
DLLEXPORT Float4 operator/ (const Float4 &other) const
 
DLLEXPORT Float4operator/= (const Float4 &other)
 
DLLEXPORT bool operator< (const Float4 &other) const noexcept
 
DLLEXPORT bool operator<= (const Float4 &other) const noexcept
 
DLLEXPORT bool operator> (const Float4 &other) const noexcept
 
DLLEXPORT bool operator>= (const Float4 &other) const noexcept
 
DLLEXPORT bool operator== (const Float4 &other) const noexcept
 
DLLEXPORT bool operator!= (const Float4 &other) const noexcept
 
DLLEXPORT float GetX () const noexcept
 
DLLEXPORT float GetY () const noexcept
 
DLLEXPORT float GetZ () const noexcept
 
DLLEXPORT float GetW () const noexcept
 
DLLEXPORT void SetX (float val)
 
DLLEXPORT void SetY (float val)
 
DLLEXPORT void SetZ (float val)
 
DLLEXPORT void SetW (float val)
 
DLLEXPORT float HAdd () const noexcept
 
DLLEXPORT float HAddAbs () const noexcept
 
DLLEXPORT Float4 MinElements (const Float4 &other) const noexcept
 
DLLEXPORT Float4 MaxElements (const Float4 &other) const noexcept
 
DLLEXPORT Float4 Clamp (const Float4 &min, const Float4 &max) const noexcept
 
DLLEXPORT float Dot (const Float4 &val) const noexcept
 
DLLEXPORT float Length () const noexcept
 
DLLEXPORT float LengthSquared () const noexcept
 
DLLEXPORT Float4 Normalize () const
 
DLLEXPORT Float4 NormalizeSafe (const Float4 &safer=Float4(1, 0, 0, 0)) const noexcept
 
DLLEXPORT bool IsNormalized () const noexcept
 
DLLEXPORT Float4 Lerp (const Float4 &other, float f) const noexcept
 
DLLEXPORT Float4 Slerp (const Float4 &other, float f) const
 
DLLEXPORT bool Compare (const Float4 &other, float tolerance) const noexcept
 
DLLEXPORT Float3 ToAxis () const
 
DLLEXPORT float ToAngle () const noexcept
 
DLLEXPORT Float4 Inverse () const noexcept
 Inverts a quaternion. More...
 
DLLEXPORT Float3 RotateVector (const Float3 &vector) const
 Rotates a vector by this quaternion. More...
 
DLLEXPORT Float4 (const Ogre::Quaternion &quat)
 
DLLEXPORT Float4 (const Ogre::ColourValue &colour)
 
DLLEXPORT operator Ogre::Quaternion () const
 
DLLEXPORT operator Ogre::ColourValue () const
 
DLLEXPORT operator Ogre::Vector4 () const
 
DLLEXPORT Float4 (const btQuaternion &colour)
 
DLLEXPORT operator btQuaternion () const
 
DLLEXPORT Float3 QuaternionToEuler () const noexcept
 
DLLEXPORT Float4 QuaternionMultiply (const Float4 &other) const noexcept
 
DLLEXPORT Float4 QuaternionReverse () const noexcept
 
 VALUE_TYPE (Float4)
 

Static Public Member Functions

static DLLEXPORT Float4 CreateQuaternionFromAngles (const Float3 &angles)
 
static DLLEXPORT Float4 IdentityQuaternion () noexcept
 
static DLLEXPORT Float4 QuaternionLookAt (const Float3 &sourcepoint, const Float3 &target)
 
static DLLEXPORT Float4 CreateQuaternionFromAxisAngle (const Float3 &axis, float angle) noexcept
 
static DLLEXPORT Float4 CreateAxisAngleFromEuler (const Float3 &angles)
 
static DLLEXPORT const Float4GetColourBlack ()
 
static DLLEXPORT const Float4GetColourWhite ()
 
static DLLEXPORT const Float4GetColourTransparent ()
 

Public Attributes

float X = 0
 
float Y = 0
 
float Z = 0
 
float W = 0
 

Static Public Attributes

static const Float4 ColourBlack = Float4(0, 0, 0, 1)
 
static const Float4 ColourWhite = Float4(1, 1, 1, 1)
 
static const Float4 ColourTransparent = Float4(0, 0, 0, 0)
 

Detailed Description

Definition at line 1249 of file Types.h.

Constructor & Destructor Documentation

◆ Float4() [1/8]

DLLEXPORT Leviathan::Float4::Float4 ( )
inlinedefaultnoexcept

◆ Float4() [2/8]

DLLEXPORT Leviathan::Float4::Float4 ( float  f1,
float  f2,
float  f3,
float  f4 
)
inline

Definition at line 1253 of file Types.h.

1253  :
1254  X(f1), Y(f2), Z(f3), W(f4)
1255  {
1256  DO_NAN_CHECK;
1257  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ Float4() [3/8]

DLLEXPORT Leviathan::Float4::Float4 ( Float2  floats,
float  f3,
float  f4 
)
inline

Definition at line 1259 of file Types.h.

1259  :
1260  X(floats.X), Y(floats.Y), Z(f3), W(f4)
1261  {
1262  DO_NAN_CHECK;
1263  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ Float4() [4/8]

DLLEXPORT Leviathan::Float4::Float4 ( Float3  floats,
float  f4 
)
inline

Definition at line 1265 of file Types.h.

1265  :
1266  X(floats.X), Y(floats.Y), Z(floats.Z), W(f4)
1267  {
1268  DO_NAN_CHECK;
1269  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ Float4() [5/8]

DLLEXPORT Leviathan::Float4::Float4 ( float  data)
inlineexplicit

Definition at line 1271 of file Types.h.

1271  : X(data), Y(data), Z(data), W(data)
1272  {
1273  DO_NAN_CHECK;
1274  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ Float4() [6/8]

DLLEXPORT Leviathan::Float4::Float4 ( const Ogre::Quaternion &  quat)
inline

Definition at line 1682 of file Types.h.

1683  {
1684  // copy values //
1685  X = quat.x;
1686  Y = quat.y;
1687  Z = quat.z;
1688  W = quat.w;
1689  DO_NAN_CHECK;
1690  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ Float4() [7/8]

DLLEXPORT Leviathan::Float4::Float4 ( const Ogre::ColourValue &  colour)
inline

Definition at line 1692 of file Types.h.

1693  {
1694  // copy values //
1695  X = colour.r;
1696  Y = colour.g;
1697  Z = colour.b;
1698  W = colour.a;
1699  DO_NAN_CHECK;
1700  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ Float4() [8/8]

DLLEXPORT Leviathan::Float4::Float4 ( const btQuaternion &  colour)
inline

Definition at line 1718 of file Types.h.

1719  {
1720  // copy values //
1721  X = colour.x();
1722  Y = colour.y();
1723  Z = colour.z();
1724  W = colour.w();
1725  DO_NAN_CHECK;
1726  }
#define DO_NAN_CHECK
Definition: Types.h:20

Member Function Documentation

◆ CheckForNans()

DLLEXPORT void Leviathan::Float4::CheckForNans ( ) const
inline

Definition at line 1282 of file Types.h.

1283  {
1284  if(HasInvalidValues()) {
1285  DEBUG_BREAK;
1286  throw std::runtime_error("Float4 has NaNs (or infinites in it) in it!");
1287  }
1288  }
DLLEXPORT bool HasInvalidValues() const noexcept
Definition: Types.h:1276

◆ Clamp()

DLLEXPORT Float4 Leviathan::Float4::Clamp ( const Float4 min,
const Float4 max 
) const
inlinenoexcept

Definition at line 1525 of file Types.h.

1526  {
1527  const Float4 minval = this->MinElements(max);
1528  return min.MaxElements(minval);
1529  }
DLLEXPORT Float4() noexcept=default
DLLEXPORT Float4 MinElements(const Float4 &other) const noexcept
Definition: Types.h:1512

◆ Compare()

DLLEXPORT bool Leviathan::Float4::Compare ( const Float4 other,
float  tolerance 
) const
inlinenoexcept

Definition at line 1617 of file Types.h.

1618  {
1619  const Float4 difference = (*this) - other;
1620  return difference.Dot(difference) < tolerance * tolerance;
1621  }
DLLEXPORT Float4() noexcept=default

◆ CreateAxisAngleFromEuler()

static DLLEXPORT Float4 Leviathan::Float4::CreateAxisAngleFromEuler ( const Float3 angles)
inlinestatic

Definition at line 1837 of file Types.h.

1838  {
1839  throw std::exception();
1840  // return Float4();
1841  }

◆ CreateQuaternionFromAngles()

static DLLEXPORT Float4 Leviathan::Float4::CreateQuaternionFromAngles ( const Float3 angles)
inlinestatic

Definition at line 1736 of file Types.h.

1737  {
1738  // multiplied by 0.5 to get double the value //
1739  const float cosx = cosf(0.5f * angles.X);
1740  const float cosy = cosf(0.5f * angles.Y);
1741  const float cosz = cosf(0.5f * angles.Z);
1742 
1743  const float sinx = sinf(0.5f * angles.X);
1744  const float siny = sinf(0.5f * angles.Y);
1745  const float sinz = sinf(0.5f * angles.Z);
1746 
1747  return Float4(
1748  // compute quaternion //
1749  // X
1750  cosz * cosy * sinx - sinz * siny * cosx,
1751  // Y
1752  cosz * siny * cosx + sinz * cosy * sinx,
1753  // Z
1754  sinz * cosy * cosx - cosz * siny * sinx,
1755  // W
1756  cosz * cosy * cosx * sinz * siny * sinx);
1757  }
DLLEXPORT Float4() noexcept=default

◆ CreateQuaternionFromAxisAngle()

static DLLEXPORT Float4 Leviathan::Float4::CreateQuaternionFromAxisAngle ( const Float3 axis,
float  angle 
)
inlinestaticnoexcept
Note
axis must be normalized

This resource is a life saver: http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm

Definition at line 1828 of file Types.h.

1830  {
1831  const float s = static_cast<float>(std::sin(angle / 2.0));
1832  const float w = static_cast<float>(std::cos(angle / 2.0));
1833  return Float4(axis * s, w);
1834  }
DLLEXPORT Float4() noexcept=default

◆ Dot()

DLLEXPORT float Leviathan::Float4::Dot ( const Float4 val) const
inlinenoexcept

Definition at line 1533 of file Types.h.

1534  {
1535  return X * val.X + Y * val.Y + Z * val.Z + W * val.W;
1536  }

◆ GetColourBlack()

DLLEXPORT const Float4 & Leviathan::Float4::GetColourBlack ( )
static

Definition at line 30 of file Types.cpp.

31 {
32  return ColourBlack;
33 }
static const Float4 ColourBlack
Definition: Types.h:1851

◆ GetColourTransparent()

DLLEXPORT const Float4 & Leviathan::Float4::GetColourTransparent ( )
static

Definition at line 40 of file Types.cpp.

41 {
42  return ColourTransparent;
43 }
static const Float4 ColourTransparent
Definition: Types.h:1853

◆ GetColourWhite()

DLLEXPORT const Float4 & Leviathan::Float4::GetColourWhite ( )
static

Definition at line 35 of file Types.cpp.

36 {
37  return ColourWhite;
38 }
static const Float4 ColourWhite
Definition: Types.h:1852

◆ GetW()

DLLEXPORT float Leviathan::Float4::GetW ( ) const
inlinenoexcept

Definition at line 1469 of file Types.h.

1470  {
1471  return W;
1472  }

◆ GetX()

DLLEXPORT float Leviathan::Float4::GetX ( ) const
inlinenoexcept

Definition at line 1454 of file Types.h.

1455  {
1456  return X;
1457  }

◆ GetY()

DLLEXPORT float Leviathan::Float4::GetY ( ) const
inlinenoexcept

Definition at line 1459 of file Types.h.

1460  {
1461  return Y;
1462  }

◆ GetZ()

DLLEXPORT float Leviathan::Float4::GetZ ( ) const
inlinenoexcept

Definition at line 1464 of file Types.h.

1465  {
1466  return Z;
1467  }

◆ HAdd()

DLLEXPORT float Leviathan::Float4::HAdd ( ) const
inlinenoexcept

Definition at line 1500 of file Types.h.

1501  {
1502  return X + Y + Z + W;
1503  }

◆ HAddAbs()

DLLEXPORT float Leviathan::Float4::HAddAbs ( ) const
inlinenoexcept

Definition at line 1506 of file Types.h.

1507  {
1508  return std::abs(X) + std::abs(Y) + std::abs(Z) + std::abs(W);
1509  }

◆ HasInvalidValues()

DLLEXPORT bool Leviathan::Float4::HasInvalidValues ( ) const
inlinenoexcept

Definition at line 1276 of file Types.h.

1277  {
1278  return !std::isfinite(X) || !std::isfinite(Y) || !std::isfinite(Z) ||
1279  !std::isfinite(W);
1280  }
#define isfinite
Definition: jsoncpp.cpp:4247

◆ IdentityQuaternion()

static DLLEXPORT Float4 Leviathan::Float4::IdentityQuaternion ( )
inlinestaticnoexcept

Definition at line 1798 of file Types.h.

1799  {
1800  return Float4(0.f, 0.f, 0.f, 1.f);
1801  }
DLLEXPORT Float4() noexcept=default

◆ Inverse()

DLLEXPORT Float4 Leviathan::Float4::Inverse ( ) const
inlinenoexcept

Inverts a quaternion.

Definition at line 1644 of file Types.h.

1645  {
1646  const auto length = Length();
1647  if(length > 0.0f) {
1648  const auto inverted = 1.0f / length;
1649  return Float4(-X * inverted, -Y * inverted, -Z * inverted, W * inverted);
1650  } else {
1651  // Invalid inversing
1652  return Float4(0.f);
1653  }
1654  }
DLLEXPORT Float4() noexcept=default
DLLEXPORT float Length() const noexcept
Definition: Types.h:1539

◆ IsNormalized()

DLLEXPORT bool Leviathan::Float4::IsNormalized ( ) const
inlinenoexcept

Definition at line 1575 of file Types.h.

1576  {
1577  // is absolute -1.f under normalization tolerance //
1578  return fabs(X * X + Y * Y + Z * Z + W * W - 1.0f) < NORMALIZATION_TOLERANCE;
1579  }
constexpr float NORMALIZATION_TOLERANCE
For checking vector normalization.
Definition: Define.h:44

◆ Length()

DLLEXPORT float Leviathan::Float4::Length ( ) const
inlinenoexcept

Definition at line 1539 of file Types.h.

1540  {
1541  return std::sqrt(LengthSquared());
1542  }
DLLEXPORT float LengthSquared() const noexcept
Definition: Types.h:1544

◆ LengthSquared()

DLLEXPORT float Leviathan::Float4::LengthSquared ( ) const
inlinenoexcept

Definition at line 1544 of file Types.h.

1545  {
1546  return X * X + Y * Y + Z * Z + W * W;
1547  }

◆ Lerp()

DLLEXPORT Float4 Leviathan::Float4::Lerp ( const Float4 other,
float  f 
) const
inlinenoexcept

Definition at line 1583 of file Types.h.

1584  {
1585  return Float4((other.X - X) * f + X, (other.Y - Y) * f + Y, (other.Z - Z) * f + Z,
1586  (other.W - W) * f + W);
1587  }
DLLEXPORT Float4() noexcept=default

◆ MaxElements()

DLLEXPORT Float4 Leviathan::Float4::MaxElements ( const Float4 other) const
inlinenoexcept

Definition at line 1518 of file Types.h.

1519  {
1520  return Float4(X > other.X ? X : other.X, Y > other.Y ? Y : other.Y,
1521  Z > other.Z ? Z : other.Z, W > other.W ? W : other.W);
1522  }
DLLEXPORT Float4() noexcept=default

◆ MinElements()

DLLEXPORT Float4 Leviathan::Float4::MinElements ( const Float4 other) const
inlinenoexcept

Definition at line 1512 of file Types.h.

1513  {
1514  return Float4(X < other.X ? X : other.X, Y < other.Y ? Y : other.Y,
1515  Z < other.Z ? Z : other.Z, W < other.W ? W : other.W);
1516  }
DLLEXPORT Float4() noexcept=default

◆ Normalize()

DLLEXPORT Float4 Leviathan::Float4::Normalize ( ) const
inline

Definition at line 1550 of file Types.h.

1551  {
1552  const float length = Length();
1553 
1554  if(length == 0) {
1555  // Returns an identity quaternion
1556  return Float4(0, 0, 0, 1);
1557  }
1558 
1559  return (*this) / length;
1560  }
DLLEXPORT Float4() noexcept=default
DLLEXPORT float Length() const noexcept
Definition: Types.h:1539

◆ NormalizeSafe()

DLLEXPORT Float4 Leviathan::Float4::NormalizeSafe ( const Float4 safer = Float4(1, 0, 0, 0)) const
inlinenoexcept

Definition at line 1563 of file Types.h.

1565  {
1566  // security //
1567  LEVIATHAN_ASSERT(safer.IsNormalized(), "safer not normalized");
1568  if(LengthSquared() == 0)
1569  return safer;
1570  const float length = Length();
1571  return (*this) / length;
1572  }
DLLEXPORT float Length() const noexcept
Definition: Types.h:1539
#define LEVIATHAN_ASSERT(x, msg)
Definition: Define.h:92
DLLEXPORT float LengthSquared() const noexcept
Definition: Types.h:1544

◆ operator btQuaternion()

DLLEXPORT Leviathan::Float4::operator btQuaternion ( ) const
inline

Definition at line 1728 of file Types.h.

1729  {
1730  return btQuaternion(X, Y, Z, W);
1731  }

◆ operator float *()

DLLEXPORT Leviathan::Float4::operator float * ( )
inlinenoexcept

return first value of {X, Y, Z, W} as a pointer

Definition at line 1307 of file Types.h.

1308  {
1309  // this should be always confirmed to work //
1310  return &X;
1311  }

◆ operator Ogre::ColourValue()

DLLEXPORT Leviathan::Float4::operator Ogre::ColourValue ( ) const
inline

Definition at line 1708 of file Types.h.

1709  {
1710  return Ogre::ColourValue(X, Y, Z, W);
1711  }

◆ operator Ogre::Quaternion()

DLLEXPORT Leviathan::Float4::operator Ogre::Quaternion ( ) const
inline

Definition at line 1702 of file Types.h.

1703  {
1704  // Ogre has these in different order
1705  return Ogre::Quaternion(W, X, Y, Z);
1706  }

◆ operator Ogre::Vector4()

DLLEXPORT Leviathan::Float4::operator Ogre::Vector4 ( ) const
inline

Definition at line 1713 of file Types.h.

1714  {
1715  return Ogre::Vector4(X, Y, Z, W);
1716  }

◆ operator!=()

DLLEXPORT bool Leviathan::Float4::operator!= ( const Float4 other) const
inlinenoexcept

Definition at line 1447 of file Types.h.

1448  {
1449  return X != other.X || Y != other.Y || Z != other.Z || W != other.W;
1450  }

◆ operator*() [1/2]

DLLEXPORT Float4 Leviathan::Float4::operator* ( const Float4 other) const
inlinenoexcept

Definition at line 1357 of file Types.h.

1358  {
1359  return Float4(X * other.X, Y * other.Y, Z * other.Z, W * other.W);
1360  }
DLLEXPORT Float4() noexcept=default

◆ operator*() [2/2]

DLLEXPORT Float4 Leviathan::Float4::operator* ( float  val) const
inlinenoexcept

Definition at line 1389 of file Types.h.

1390  {
1391  return Float4(X * val, Y * val, Z * val, W * val);
1392  }
DLLEXPORT Float4() noexcept=default

◆ operator*=() [1/2]

DLLEXPORT Float4& Leviathan::Float4::operator*= ( const Float4 other)
inlinenoexcept

Definition at line 1362 of file Types.h.

1363  {
1364  X *= other.X;
1365  Y *= other.Y;
1366  Z *= other.Z;
1367  W *= other.W;
1368  DO_NAN_CHECK;
1369  return *this;
1370  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ operator*=() [2/2]

DLLEXPORT Float4& Leviathan::Float4::operator*= ( float  val)
inlinenoexcept

Definition at line 1394 of file Types.h.

1395  {
1396  X *= val;
1397  Y *= val;
1398  Z *= val;
1399  W *= val;
1400  DO_NAN_CHECK;
1401  return *this;
1402  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ operator+() [1/2]

DLLEXPORT Float4 Leviathan::Float4::operator+ ( const Float4 other) const
inlinenoexcept

Definition at line 1315 of file Types.h.

1316  {
1317  return Float4(X + other.X, Y + other.Y, Z + other.Z, W + other.W);
1318  }
DLLEXPORT Float4() noexcept=default

◆ operator+() [2/2]

DLLEXPORT Float4 Leviathan::Float4::operator+ ( ) const
inlinenoexcept

Definition at line 1351 of file Types.h.

1352  {
1353  return Float4(*this);
1354  }
DLLEXPORT Float4() noexcept=default

◆ operator+=()

DLLEXPORT Float4& Leviathan::Float4::operator+= ( const Float4 other)
inlinenoexcept

Definition at line 1320 of file Types.h.

1321  {
1322  X += other.X;
1323  Y += other.Y;
1324  Z += other.Z;
1325  W += other.W;
1326  return *this;
1327  }

◆ operator-() [1/2]

DLLEXPORT Float4 Leviathan::Float4::operator- ( const Float4 other) const
inlinenoexcept

Definition at line 1330 of file Types.h.

1331  {
1332  return Float4(X - other.X, Y - other.Y, Z - other.Z, W - other.W);
1333  }
DLLEXPORT Float4() noexcept=default

◆ operator-() [2/2]

DLLEXPORT Float4 Leviathan::Float4::operator- ( ) const
inlinenoexcept

Definition at line 1345 of file Types.h.

1346  {
1347  return Float4(-X, -Y, -Z, -W);
1348  }
DLLEXPORT Float4() noexcept=default

◆ operator-=()

DLLEXPORT Float4& Leviathan::Float4::operator-= ( const Float4 other)
inlinenoexcept

Definition at line 1335 of file Types.h.

1336  {
1337  X -= other.X;
1338  Y -= other.Y;
1339  Z -= other.Z;
1340  W -= other.W;
1341  return *this;
1342  }

◆ operator/() [1/2]

DLLEXPORT Float4 Leviathan::Float4::operator/ ( float  val) const
inline

Definition at line 1373 of file Types.h.

1374  {
1375  return Float4(X / val, Y / val, Z / val, W / val);
1376  }
DLLEXPORT Float4() noexcept=default

◆ operator/() [2/2]

DLLEXPORT Float4 Leviathan::Float4::operator/ ( const Float4 other) const
inline

Definition at line 1405 of file Types.h.

1406  {
1407  return Float4(X / other.X, Y / other.Y, Z / other.Z, W / other.W);
1408  }
DLLEXPORT Float4() noexcept=default

◆ operator/=() [1/2]

DLLEXPORT Float4& Leviathan::Float4::operator/= ( float  val)
inline

Definition at line 1378 of file Types.h.

1379  {
1380  X /= val;
1381  Y /= val;
1382  Z /= val;
1383  W /= val;
1384  DO_NAN_CHECK;
1385  return *this;
1386  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ operator/=() [2/2]

DLLEXPORT Float4& Leviathan::Float4::operator/= ( const Float4 other)
inline

Definition at line 1410 of file Types.h.

1411  {
1412  X /= other.X;
1413  Y /= other.Y;
1414  Z /= other.Z;
1415  W /= other.W;
1416  DO_NAN_CHECK;
1417  return *this;
1418  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ operator<()

DLLEXPORT bool Leviathan::Float4::operator< ( const Float4 other) const
inlinenoexcept

Definition at line 1422 of file Types.h.

1423  {
1424  return std::tie(X, Y, Z, W) < std::tie(other.X, other.Y, other.Z, other.W);
1425  }

◆ operator<=()

DLLEXPORT bool Leviathan::Float4::operator<= ( const Float4 other) const
inlinenoexcept

Definition at line 1427 of file Types.h.

1428  {
1429  return std::tie(X, Y, Z, W) <= std::tie(other.X, other.Y, other.Z, other.W);
1430  }

◆ operator==()

DLLEXPORT bool Leviathan::Float4::operator== ( const Float4 other) const
inlinenoexcept

Definition at line 1442 of file Types.h.

1443  {
1444  return X == other.X && Y == other.Y && Z == other.Z && W == other.W;
1445  }

◆ operator>()

DLLEXPORT bool Leviathan::Float4::operator> ( const Float4 other) const
inlinenoexcept

Definition at line 1432 of file Types.h.

1433  {
1434  return std::tie(X, Y, Z, W) > std::tie(other.X, other.Y, other.Z, other.W);
1435  }

◆ operator>=()

DLLEXPORT bool Leviathan::Float4::operator>= ( const Float4 other) const
inlinenoexcept

Definition at line 1437 of file Types.h.

1438  {
1439  return std::tie(X, Y, Z, W) >= std::tie(other.X, other.Y, other.Z, other.W);
1440  }

◆ operator[]()

DLLEXPORT float& Leviathan::Float4::operator[] ( int  nindex)
inline

Definition at line 1291 of file Types.h.

1292  {
1293  switch(nindex) {
1294  case 0: return X;
1295  case 1: return Y;
1296  case 2: return Z;
1297  case 3: return W;
1298  default: break;
1299  }
1300 
1301  LEVIATHAN_ASSERT(0, "invalid [] access");
1302  return X;
1303  }
#define LEVIATHAN_ASSERT(x, msg)
Definition: Define.h:92

◆ QuaternionLookAt()

static DLLEXPORT Float4 Leviathan::Float4::QuaternionLookAt ( const Float3 sourcepoint,
const Float3 target 
)
inlinestatic

Definition at line 1804 of file Types.h.

1806  {
1807  const auto forward = (target - sourcepoint).NormalizeSafe();
1808  const float dot = Float3::UnitVForward.Dot(forward);
1809 
1810  if(std::abs(dot - (-1.0f)) < 0.000001f) {
1811  // Assumes up is Float3(0, 1, 0)
1812  return Float4(Float3::UnitVUp, 3.1415926535897932f);
1813  }
1814 
1815  if(std::abs(dot - 1.0f) < 0.000001f) {
1816  return Float4::IdentityQuaternion();
1817  }
1818 
1819  const float rotAngle = std::acos(dot);
1820  const Float3 rotAxis = Float3::UnitVForward.Cross(forward).Normalize();
1821  return CreateQuaternionFromAxisAngle(rotAxis, rotAngle);
1822  }
static const Float3 UnitVUp
Definition: Types.h:1245
DLLEXPORT Float3 Cross(const Float3 &val) const
Definition: Types.h:1143
static const Float3 UnitVForward
Definition: Types.h:1244
DLLEXPORT Float4 NormalizeSafe(const Float4 &safer=Float4(1, 0, 0, 0)) const noexcept
Definition: Types.h:1563
DLLEXPORT Float4() noexcept=default
DLLEXPORT Float3 Normalize() const
Definition: Types.h:1160
DLLEXPORT float Dot(const Float3 &val) const noexcept
Definition: Types.h:1137
static DLLEXPORT Float4 IdentityQuaternion() noexcept
Definition: Types.h:1798
static DLLEXPORT Float4 CreateQuaternionFromAxisAngle(const Float3 &axis, float angle) noexcept
Definition: Types.h:1828

◆ QuaternionMultiply()

DLLEXPORT Float4 Leviathan::Float4::QuaternionMultiply ( const Float4 other) const
inlinenoexcept

Definition at line 1784 of file Types.h.

1785  {
1786  return Float4(X * other.X + X * other.W + Y * other.Z - Z * other.Y,
1787  W * other.Y - X * other.Z + Y * other.W + Z * other.X,
1788  W * other.Z + X * other.Y - Y * other.X + Z * other.W,
1789  W * other.W - X * other.X - Y * other.Y - Z * other.Z);
1790  }
DLLEXPORT Float4() noexcept=default

◆ QuaternionReverse()

DLLEXPORT Float4 Leviathan::Float4::QuaternionReverse ( ) const
inlinenoexcept

Definition at line 1792 of file Types.h.

1793  {
1794  // reverse vector //
1795  return Float4(-X, -Y, -Z, W);
1796  }
DLLEXPORT Float4() noexcept=default

◆ QuaternionToEuler()

DLLEXPORT Float3 Leviathan::Float4::QuaternionToEuler ( ) const
inlinenoexcept
Note
This quaternion has to be normalized
See also
http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/

Definition at line 1762 of file Types.h.

1763  {
1764  const float test = X * Y + Z * W;
1765 
1766  if(test > 0.499) {
1767  // Singularity at north pole
1768  return Float3(2 * atan2(X, W), PI / 2, 0);
1769  }
1770 
1771  if(test < -0.499) {
1772  // Singularity at south pole
1773  return Float3(-2 * atan2(X, W), -PI / 2, 0);
1774  }
1775 
1776  const float sqx = X * X;
1777  const float sqy = Y * Y;
1778  const float sqz = Z * Z;
1779 
1780  return Float3(atan2(2 * Y * W - 2 * X * Z, 1 - 2 * sqy - 2 * sqz), asin(2 * test),
1781  atan2(2 * X * W - 2 * Y * Z, 1 - 2 * sqx - 2 * sqz));
1782  }
constexpr float PI
Definition: Define.h:59

◆ RotateVector()

DLLEXPORT Float3 Leviathan::Float4::RotateVector ( const Float3 vector) const
inline

Rotates a vector by this quaternion.

Definition at line 1657 of file Types.h.

1658  {
1659  // // Alternative from
1660  // //
1661  // https://gamedev.stackexchange.com/questions/28395/rotating-vector3-by-a-quaternion
1662  // const auto u = Float3(X, Y, Z);
1663 
1664  // // Complex math going on
1665  // return u * 2.0f * u.Dot(vector)
1666  // + vector * (W*W - u.Dot(u))
1667  // + u.Cross(vector) * 2.0f * W;
1668 
1669  // Math taken from Ogre::Quaternion
1670  Float3 qvec(X, Y, Z);
1671  const Float3 uv1 = qvec.Cross(vector);
1672  const Float3 uuv = qvec.Cross(uv1) * 2.0f;
1673  const Float3 uv2 = uv1 * 2.0f * W;
1674 
1675  return vector + uv2 + uuv;
1676  }

◆ SetW()

DLLEXPORT void Leviathan::Float4::SetW ( float  val)
inline

Definition at line 1493 of file Types.h.

1494  {
1495  W = val;
1496  DO_NAN_CHECK;
1497  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ SetX()

DLLEXPORT void Leviathan::Float4::SetX ( float  val)
inline

Definition at line 1475 of file Types.h.

1476  {
1477  X = val;
1478  DO_NAN_CHECK;
1479  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ SetY()

DLLEXPORT void Leviathan::Float4::SetY ( float  val)
inline

Definition at line 1481 of file Types.h.

1482  {
1483  Y = val;
1484  DO_NAN_CHECK;
1485  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ SetZ()

DLLEXPORT void Leviathan::Float4::SetZ ( float  val)
inline

Definition at line 1487 of file Types.h.

1488  {
1489  Z = val;
1490  DO_NAN_CHECK;
1491  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ Slerp()

DLLEXPORT Float4 Leviathan::Float4::Slerp ( const Float4 other,
float  f 
) const
inline

Definition at line 1590 of file Types.h.

1591  {
1592  // extra quaternion for calculations //
1593  Float4 quaternion3;
1594 
1595  // dot product of both //
1596  float dot = this->Dot(other);
1597 
1598  if(dot < 0) {
1599  dot = -dot;
1600  quaternion3 = -other;
1601  } else {
1602  quaternion3 = other;
1603  }
1604 
1605  if(dot < 0.95f) {
1606  const float angle = acosf(dot);
1607  return ((*this) * sinf(angle * (1 - f)) + quaternion3 * sinf(angle * f)) /
1608  sinf(angle);
1609 
1610  } else {
1611  // small angle, linear interpolation will be fine //
1612  return this->Lerp(quaternion3, f);
1613  }
1614  }
DLLEXPORT Float4() noexcept=default
DLLEXPORT Float4 Lerp(const Float4 &other, float f) const noexcept
Definition: Types.h:1583
DLLEXPORT float Dot(const Float4 &val) const noexcept
Definition: Types.h:1533

◆ ToAngle()

DLLEXPORT float Leviathan::Float4::ToAngle ( ) const
inlinenoexcept

Converts a quaternion to angle (and skips outputting the Axis)

Note
Must be normalized

Definition at line 1638 of file Types.h.

1639  {
1640  return 2 * std::acos(W);
1641  }

◆ ToAxis()

DLLEXPORT Float3 Leviathan::Float4::ToAxis ( ) const
inline

Converts a quaternion to Axis (and skips outputting the angle)

Note
Must be normalized

Definition at line 1625 of file Types.h.

1626  {
1627  const auto s = std::sqrt(1 - std::pow(W, 2));
1628  // Avoid division by zero (this small axis it can be basically converted directly)
1629  if(s > 0) {
1630  return Float3(X / s, Y / s, Z / s);
1631  } else {
1632  return Float3(X, Y, Z);
1633  }
1634  }

◆ VALUE_TYPE()

Leviathan::Float4::VALUE_TYPE ( Float4  )

Member Data Documentation

◆ ColourBlack

const Float4 Leviathan::Float4::ColourBlack = Float4(0, 0, 0, 1)
static

Definition at line 1851 of file Types.h.

◆ ColourTransparent

const Float4 Leviathan::Float4::ColourTransparent = Float4(0, 0, 0, 0)
static

Definition at line 1853 of file Types.h.

◆ ColourWhite

const Float4 Leviathan::Float4::ColourWhite = Float4(1, 1, 1, 1)
static

Definition at line 1852 of file Types.h.

◆ W

float Leviathan::Float4::W = 0

Definition at line 1848 of file Types.h.

◆ X

float Leviathan::Float4::X = 0

Definition at line 1845 of file Types.h.

◆ Y

float Leviathan::Float4::Y = 0

Definition at line 1846 of file Types.h.

◆ Z

float Leviathan::Float4::Z = 0

Definition at line 1847 of file Types.h.


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