Leviathan  0.8.0.0
Leviathan game engine
Leviathan::Float4 Struct Reference

#include <Types.h>

Public Member Functions

DLLEXPORT Float4 ()
 
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 val)
 
DLLEXPORT bool HasInvalidValues () const
 
DLLEXPORT void CheckForNans ()
 
DLLEXPORT float & operator[] (const int &nindex)
 
DLLEXPORT operator float * ()
 return first value of {X, Y, Z, W} as a pointer More...
 
DLLEXPORT Float4 operator+ (const Float4 &val) const
 
DLLEXPORT Float4 operator- (const Float4 &val) const
 
DLLEXPORT Float4 operator- () const
 
DLLEXPORT Float4 operator* (const Float4 &val) const
 
DLLEXPORT Float4 operator* (float f) const
 
DLLEXPORT Float4 operator/ (const Float4 &val) const
 
DLLEXPORT Float4 operator/ (float f) const
 
DLLEXPORT bool operator< (const Float4 &other) const
 
DLLEXPORT bool operator> (const Float4 &other) const
 
DLLEXPORT bool operator== (const Float4 &other) const
 
DLLEXPORT bool operator!= (const Float4 &other) const
 
DLLEXPORT float GetX () const
 
DLLEXPORT float GetY () const
 
DLLEXPORT float GetZ () const
 
DLLEXPORT float GetW () const
 
DLLEXPORT void SetX (const float &val)
 
DLLEXPORT void SetY (const float &val)
 
DLLEXPORT void SetZ (const float &val)
 
DLLEXPORT void SetW (const float &val)
 
DLLEXPORT float HAdd () const
 
DLLEXPORT float HAddAbs () const
 
DLLEXPORT Float4 MinElements (const Float4 &other) const
 
DLLEXPORT Float4 MaxElements (const Float4 &other) const
 
DLLEXPORT Float4 Clamp (const Float4 &min, const Float4 &max)
 
DLLEXPORT float Dot (const Float4 &val) const
 
DLLEXPORT float Length () const
 
DLLEXPORT Float4 Normalize () const
 
DLLEXPORT Float4 NormalizeSafe (const Float4 &safer=Float4(0, 0, 0, 1)) const
 
DLLEXPORT bool IsNormalized () const
 
DLLEXPORT Float4 Lerp (const Float4 &other, float f) const
 
DLLEXPORT Float4 Slerp (const Float4 &other, float f) const
 
DLLEXPORT bool Compare (const Float4 &other, float tolerance) const
 
DLLEXPORT Float3 ToAxis () const
 
DLLEXPORT float ToAngle () const
 
DLLEXPORT Float4 Inverse () const
 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 Float3 QuaternionToEuler () const
 
DLLEXPORT Float4 QuaternionMultiply (const Float4 &other) const
 
DLLEXPORT Float4 QuaternionReverse () const
 
 VALUE_TYPE (Float4)
 

Static Public Member Functions

static DLLEXPORT Float4 zero ()
 
static DLLEXPORT Float4 one ()
 
static DLLEXPORT Float4 x_axis ()
 
static DLLEXPORT Float4 y_axis ()
 
static DLLEXPORT Float4 z_axis ()
 
static DLLEXPORT Float4 w_axis ()
 
static DLLEXPORT Float4 CreateQuaternionFromAngles (const Float3 &angles)
 
static DLLEXPORT Float4 IdentityQuaternion ()
 
static DLLEXPORT Float4 QuaternionLookAt (const Float3 &sourcepoint, const Float3 &target)
 
static DLLEXPORT Float4 CreateQuaternionFromAxisAngle (const Float3 &axis, float angle)
 
static DLLEXPORT Float4 CreateAxisAngleFromEuler (const Float3 &angles)
 
static DLLEXPORT const Float4GetColourBlack ()
 
static DLLEXPORT const Float4GetColourWhite ()
 
static DLLEXPORT const Float4GetColourTransparent ()
 

Public Attributes

float X
 
float Y
 
float Z
 
float W
 

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 978 of file Types.h.

Constructor & Destructor Documentation

◆ Float4() [1/7]

DLLEXPORT Leviathan::Float4::Float4 ( )
inline

Definition at line 981 of file Types.h.

982  {
983  X = Y = Z = W = 0;
984  };

◆ Float4() [2/7]

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

Definition at line 985 of file Types.h.

986  {
987  X = f1;
988  Y = f2;
989  Z = f3;
990  W = f4;
991  DO_NAN_CHECK;
992  }
#define DO_NAN_CHECK
Definition: Types.h:18

◆ Float4() [3/7]

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

Definition at line 993 of file Types.h.

994  {
995  X = floats.X;
996  Y = floats.Y;
997  Z = f3;
998  W = f4;
999  DO_NAN_CHECK;
1000  }
#define DO_NAN_CHECK
Definition: Types.h:18

◆ Float4() [4/7]

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

Definition at line 1001 of file Types.h.

1002  {
1003  X = floats.X;
1004  Y = floats.Y;
1005  Z = floats.Z;
1006  W = f4;
1007  DO_NAN_CHECK;
1008  }
#define DO_NAN_CHECK
Definition: Types.h:18

◆ Float4() [5/7]

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

Definition at line 1009 of file Types.h.

1010  {
1011  X = Y = Z = W = val;
1012  DO_NAN_CHECK;
1013  }
#define DO_NAN_CHECK
Definition: Types.h:18

◆ Float4() [6/7]

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

Definition at line 1357 of file Types.h.

1358  {
1359  // copy values //
1360  X = quat.x;
1361  Y = quat.y;
1362  Z = quat.z;
1363  W = quat.w;
1364  DO_NAN_CHECK;
1365  }
#define DO_NAN_CHECK
Definition: Types.h:18

◆ Float4() [7/7]

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

Definition at line 1367 of file Types.h.

1368  {
1369  // copy values //
1370  X = colour.r;
1371  Y = colour.g;
1372  Z = colour.b;
1373  W = colour.a;
1374  DO_NAN_CHECK;
1375  }
#define DO_NAN_CHECK
Definition: Types.h:18

Member Function Documentation

◆ CheckForNans()

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

Definition at line 1024 of file Types.h.

1025  {
1026  if(HasInvalidValues()) {
1027  DEBUG_BREAK;
1028  throw std::runtime_error("Float4 has NaNs (or infinites in it) in it!");
1029  }
1030  }
DLLEXPORT bool HasInvalidValues() const
Definition: Types.h:1015

◆ Clamp()

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

Definition at line 1167 of file Types.h.

1168  {
1169  const Float4 minval = this->MinElements(max);
1170  return min.MaxElements(minval);
1171  }
DLLEXPORT Float4 MinElements(const Float4 &other) const
Definition: Types.h:1156
DLLEXPORT Float4()
Definition: Types.h:981

◆ Compare()

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

Definition at line 1254 of file Types.h.

1255  {
1256  const Float4 difference = (*this) - other;
1257  return difference.Dot(difference) < tolerance * tolerance;
1258  }
DLLEXPORT Float4()
Definition: Types.h:981

◆ CreateAxisAngleFromEuler()

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

Definition at line 1506 of file Types.h.

1507  {
1508 
1509  throw std::exception();
1510  // return Float4();
1511  }

◆ CreateQuaternionFromAngles()

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

Definition at line 1396 of file Types.h.

1397  {
1398  // multiplied by 0.5 to get double the value //
1399  float cosx = cosf(0.5f * angles.X);
1400  float cosy = cosf(0.5f * angles.Y);
1401  float cosz = cosf(0.5f * angles.Z);
1402 
1403  float sinx = sinf(0.5f * angles.X);
1404  float siny = sinf(0.5f * angles.Y);
1405  float sinz = sinf(0.5f * angles.Z);
1406 
1407 
1408  Float4 quaternion((Float4)0);
1409  // compute quaternion //
1410  quaternion.X = cosz * cosy * sinx - sinz * siny * cosx;
1411  quaternion.Y = cosz * siny * cosx + sinz * cosy * sinx;
1412  quaternion.Z = sinz * cosy * cosx - cosz * siny * sinx;
1413  quaternion.W = cosz * cosy * cosx * sinz * siny * sinx;
1414 
1415  return quaternion;
1416  }
DLLEXPORT Float4()
Definition: Types.h:981

◆ CreateQuaternionFromAxisAngle()

static DLLEXPORT Float4 Leviathan::Float4::CreateQuaternionFromAxisAngle ( const Float3 axis,
float  angle 
)
inlinestatic
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 1494 of file Types.h.

1496  {
1497  const auto s = std::sin(angle / 2.0);
1498  const auto x = axis.X * s;
1499  const auto y = axis.Y * s;
1500  const auto z = axis.Z * s;
1501  const auto w = std::cos(angle / 2.0);
1502  return Float4(static_cast<float>(x), static_cast<float>(y), static_cast<float>(z),
1503  static_cast<float>(w));
1504  }
DLLEXPORT Float4()
Definition: Types.h:981

◆ Dot()

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

Definition at line 1175 of file Types.h.

1176  {
1177  return X * val.X + Y * val.Y + Z * val.Z + W * val.W;
1178  }

◆ GetColourBlack()

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

Definition at line 25 of file Types.cpp.

25  {
26  return ColourBlack;
27 }
static const Float4 ColourBlack
Definition: Types.h:1523

◆ GetColourTransparent()

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

Definition at line 33 of file Types.cpp.

33  {
34  return ColourTransparent;
35 }
static const Float4 ColourTransparent
Definition: Types.h:1525

◆ GetColourWhite()

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

Definition at line 29 of file Types.cpp.

29  {
30  return ColourWhite;
31 }
static const Float4 ColourWhite
Definition: Types.h:1524

◆ GetW()

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

Definition at line 1120 of file Types.h.

1121  {
1122  return W;
1123  };

◆ GetX()

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

Definition at line 1108 of file Types.h.

1109  {
1110  return X;
1111  };

◆ GetY()

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

Definition at line 1112 of file Types.h.

1113  {
1114  return Y;
1115  };

◆ GetZ()

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

Definition at line 1116 of file Types.h.

1117  {
1118  return Z;
1119  };

◆ HAdd()

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

Definition at line 1146 of file Types.h.

1147  {
1148  return X + Y + Z + W;
1149  }

◆ HAddAbs()

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

Definition at line 1151 of file Types.h.

1152  {
1153  return std::abs(X) + std::abs(Y) + std::abs(Z) + std::abs(W);
1154  }

◆ HasInvalidValues()

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

Definition at line 1015 of file Types.h.

1016  {
1017  if(!std::isfinite(X) || !std::isfinite(Y) || !std::isfinite(Z) || !std::isfinite(W)) {
1018  return true;
1019  }
1020 
1021  return false;
1022  }

◆ IdentityQuaternion()

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

Definition at line 1464 of file Types.h.

1465  {
1466  return Float4(0, 0, 0, 1);
1467  }
DLLEXPORT Float4()
Definition: Types.h:981

◆ Inverse()

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

Inverts a quaternion.

Definition at line 1283 of file Types.h.

1284  {
1285 
1286  const auto length = Length();
1287  if(length > 0.0f) {
1288 
1289  const auto inverted = 1.0f / length;
1290  return Float4(-X * inverted, -Y * inverted, -Z * inverted, W * inverted);
1291  } else {
1292  // Invalid inversing
1293  return Float4(0);
1294  }
1295  }
DLLEXPORT Float4()
Definition: Types.h:981
DLLEXPORT float Length() const
Definition: Types.h:1181

◆ IsNormalized()

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

Definition at line 1211 of file Types.h.

1212  {
1213  // is absolute -1.f under normalization tolerance //
1214  return fabs(X * X + Y * Y + Z * Z + W * W - 1.0f) < NORMALIZATION_TOLERANCE;
1215  }
constexpr float NORMALIZATION_TOLERANCE
For checking vector normalization.
Definition: Define.h:43

◆ Length()

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

Definition at line 1181 of file Types.h.

1182  {
1183  return sqrt(X * X + Y * Y + Z * Z + W * W);
1184  }

◆ Lerp()

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

Definition at line 1218 of file Types.h.

1219  {
1220  return Float4((other.X - X) * f + X, (other.Y - Y) * f + Y, (other.Z - Z) * f + Z,
1221  (other.W - W) * f + W);
1222  }
DLLEXPORT Float4()
Definition: Types.h:981

◆ MaxElements()

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

Definition at line 1161 of file Types.h.

1162  {
1163  return Float4(X > other.X ? X : other.X, Y > other.Y ? Y : other.Y,
1164  Z > other.Z ? Z : other.Z, W > other.W ? W : other.W);
1165  }
DLLEXPORT Float4()
Definition: Types.h:981

◆ MinElements()

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

Definition at line 1156 of file Types.h.

1157  {
1158  return Float4(X < other.X ? X : other.X, Y < other.Y ? Y : other.Y,
1159  Z < other.Z ? Z : other.Z, W < other.W ? W : other.W);
1160  }
DLLEXPORT Float4()
Definition: Types.h:981

◆ Normalize()

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

Definition at line 1187 of file Types.h.

1188  {
1189  const float length = Length();
1190 
1191  if(length == 0) {
1192  // Returns an identity quaternion
1193  return Float4(0, 0, 0, 1);
1194  }
1195 
1196  return Float4(X / length, Y / length, Z / length, W / length);
1197  }
DLLEXPORT Float4()
Definition: Types.h:981
DLLEXPORT float Length() const
Definition: Types.h:1181

◆ NormalizeSafe()

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

Definition at line 1199 of file Types.h.

1200  {
1201  // security //
1202  const float len = X * X + Y * Y + Z * Z + W * W;
1203  if(len == 0) {
1204  return safer;
1205  }
1206 
1207  const float length = sqrt(len);
1208  return Float4(X / length, Y / length, Z / length, W / length);
1209  }
DLLEXPORT Float4()
Definition: Types.h:981

◆ one()

static DLLEXPORT Float4 Leviathan::Float4::one ( )
inlinestatic

Definition at line 1330 of file Types.h.

1331  {
1332  return Float4(1.f, 1.f, 1.f, 1.f);
1333  }
DLLEXPORT Float4()
Definition: Types.h:981

◆ operator float *()

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

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

Definition at line 1047 of file Types.h.

1048  {
1049  // this should be always confirmed to work //
1050  return &X;
1051  }

◆ operator Ogre::ColourValue()

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

Definition at line 1383 of file Types.h.

1384  {
1385 
1386  return Ogre::ColourValue(X, Y, Z, W);
1387  }

◆ operator Ogre::Quaternion()

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

Definition at line 1377 of file Types.h.

1378  {
1379 
1380  return Ogre::Quaternion(W, X, Y, Z);
1381  }

◆ operator Ogre::Vector4()

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

Definition at line 1388 of file Types.h.

1389  {
1390 
1391  return Ogre::Vector4(X, Y, Z, W);
1392  }

◆ operator!=()

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

Definition at line 1103 of file Types.h.

1104  {
1105  return X != other.X && Y != other.Y && Z != other.Z && W != other.W;
1106  };

◆ operator*() [1/2]

DLLEXPORT Float4 Leviathan::Float4::operator* ( const Float4 val) const
inline

Definition at line 1070 of file Types.h.

1071  {
1072  return Float4(X * val.X, Y * val.Y, Z * val.Z, W * val.W);
1073  }
DLLEXPORT Float4()
Definition: Types.h:981

◆ operator*() [2/2]

DLLEXPORT Float4 Leviathan::Float4::operator* ( float  f) const
inline

Definition at line 1075 of file Types.h.

1076  {
1077  return Float4(X * f, Y * f, Z * f, W * f);
1078  }
DLLEXPORT Float4()
Definition: Types.h:981

◆ operator+()

DLLEXPORT Float4 Leviathan::Float4::operator+ ( const Float4 val) const
inline

Definition at line 1055 of file Types.h.

1056  {
1057  return Float4(X + val.X, Y + val.Y, Z + val.Z, W + val.W);
1058  }
DLLEXPORT Float4()
Definition: Types.h:981

◆ operator-() [1/2]

DLLEXPORT Float4 Leviathan::Float4::operator- ( const Float4 val) const
inline

Definition at line 1060 of file Types.h.

1061  {
1062  return Float4(X - val.X, Y - val.Y, Z - val.Z, W - val.W);
1063  }
DLLEXPORT Float4()
Definition: Types.h:981

◆ operator-() [2/2]

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

Definition at line 1065 of file Types.h.

1066  {
1067  return Float4(-X, -Y, -Z, -W);
1068  }
DLLEXPORT Float4()
Definition: Types.h:981

◆ operator/() [1/2]

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

Definition at line 1080 of file Types.h.

1081  {
1082  return Float4(X / val.X, Y / val.Y, Z / val.Z, W / val.W);
1083  }
DLLEXPORT Float4()
Definition: Types.h:981

◆ operator/() [2/2]

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

Definition at line 1085 of file Types.h.

1086  {
1087  return Float4(X / f, Y / f, Z / f, W / f);
1088  }
DLLEXPORT Float4()
Definition: Types.h:981

◆ operator<()

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

Definition at line 1091 of file Types.h.

1092  {
1093  return !(*this == other);
1094  };

◆ operator==()

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

Definition at line 1099 of file Types.h.

1100  {
1101  return X == other.X && Y == other.Y && Z == other.Z && W == other.W;
1102  };

◆ operator>()

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

Definition at line 1095 of file Types.h.

1096  {
1097  return !(*this == other);
1098  };

◆ operator[]()

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

Definition at line 1033 of file Types.h.

1034  {
1035  switch(nindex) {
1036  case 0: return X;
1037  case 1: return Y;
1038  case 2: return Z;
1039  case 3: return W;
1040  }
1041 
1042  LEVIATHAN_ASSERT(0, "invalid [] access");
1043  return X;
1044  }

◆ QuaternionLookAt()

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

Definition at line 1470 of file Types.h.

1472  {
1473  const auto forward = (target - sourcepoint).NormalizeSafe();
1474  const float dot = Float3::UnitVForward.Dot(forward);
1475 
1476  if(std::abs(dot - (-1.0f)) < 0.000001f) {
1477  // Assumes up is Float3(0, 1, 0)
1478  return Float4(
1479  Float3::UnitVUp.X, Float3::UnitVUp.Y, Float3::UnitVUp.Z, 3.1415926535897932f);
1480  }
1481  if(std::abs(dot - 1.0f) < 0.000001f) {
1482  return Float4::IdentityQuaternion();
1483  }
1484 
1485  const float rotAngle = std::acos(dot);
1486  const Float3 rotAxis = Float3::UnitVForward.Cross(forward).Normalize();
1487  return CreateQuaternionFromAxisAngle(rotAxis, rotAngle);
1488  }
static const Float3 UnitVUp
Definition: Types.h:975
DLLEXPORT Float3 Cross(const Float3 &val) const
Definition: Types.h:864
DLLEXPORT Float4 NormalizeSafe(const Float4 &safer=Float4(0, 0, 0, 1)) const
Definition: Types.h:1199
static const Float3 UnitVForward
Definition: Types.h:974
DLLEXPORT Float3 Normalize() const
Definition: Types.h:878
DLLEXPORT float Dot(const Float3 &val) const
Definition: Types.h:860
DLLEXPORT Float4()
Definition: Types.h:981
static DLLEXPORT Float4 IdentityQuaternion()
Definition: Types.h:1464
static DLLEXPORT Float4 CreateQuaternionFromAxisAngle(const Float3 &axis, float angle)
Definition: Types.h:1494

◆ QuaternionMultiply()

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

Definition at line 1445 of file Types.h.

1446  {
1447 
1448  Float4 result;
1449 
1450  result.X = X * other.X + X * other.W + Y * other.Z - Z * other.Y;
1451  result.Y = W * other.Y - X * other.Z + Y * other.W + Z * other.X;
1452  result.Z = W * other.Z + X * other.Y - Y * other.X + Z * other.W;
1453  result.W = W * other.W - X * other.X - Y * other.Y - Z * other.Z;
1454 
1455  return result;
1456  }
DLLEXPORT Float4()
Definition: Types.h:981

◆ QuaternionReverse()

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

Definition at line 1458 of file Types.h.

1459  {
1460  // reverse vector //
1461  return Float4(-X, -Y, -Z, W);
1462  }
DLLEXPORT Float4()
Definition: Types.h:981

◆ QuaternionToEuler()

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

Definition at line 1421 of file Types.h.

1422  {
1423 
1424  float test = X * Y + Z * W;
1425 
1426  if(test > 0.499) {
1427  // Singularity at north pole
1428  return Float3(2 * atan2(X, W), PI / 2, 0);
1429  }
1430 
1431  if(test < -0.499) {
1432 
1433  // Singularity at south pole
1434  return Float3(-2 * atan2(X, W), -PI / 2, 0);
1435  }
1436 
1437  float sqx = X * X;
1438  float sqy = Y * Y;
1439  float sqz = Z * Z;
1440 
1441  return Float3(atan2(2 * Y * W - 2 * X * Z, 1 - 2 * sqy - 2 * sqz), asin(2 * test),
1442  atan2(2 * X * W - 2 * Y * Z, 1 - 2 * sqx - 2 * sqz));
1443  }
constexpr float PI
Definition: Define.h:58

◆ RotateVector()

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

Rotates a vector by this quaternion.

Definition at line 1298 of file Types.h.

1299  {
1300  // // Alternative from
1301  // //
1302  // https://gamedev.stackexchange.com/questions/28395/rotating-vector3-by-a-quaternion
1303  // const auto u = Float3(X, Y, Z);
1304 
1305  // // Complex math going on
1306  // return u * 2.0f * u.Dot(vector)
1307  // + vector * (W*W - u.Dot(u))
1308  // + u.Cross(vector) * 2.0f * W;
1309 
1310  // Math taken from Ogre::Quaternion
1311  Float3 uv;
1312  Float3 uuv;
1313  Float3 qvec(X, Y, Z);
1314  uv = qvec.Cross(vector);
1315  uuv = qvec.Cross(uv);
1316  uv *= 2.0f * W;
1317  uuv *= 2.0f;
1318 
1319  return vector + uv + uuv;
1320  }

◆ SetW()

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

Definition at line 1139 of file Types.h.

1140  {
1141  W = val;
1142  DO_NAN_CHECK;
1143  };
#define DO_NAN_CHECK
Definition: Types.h:18

◆ SetX()

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

Definition at line 1124 of file Types.h.

1125  {
1126  X = val;
1127  DO_NAN_CHECK;
1128  };
#define DO_NAN_CHECK
Definition: Types.h:18

◆ SetY()

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

Definition at line 1129 of file Types.h.

1130  {
1131  Y = val;
1132  DO_NAN_CHECK;
1133  };
#define DO_NAN_CHECK
Definition: Types.h:18

◆ SetZ()

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

Definition at line 1134 of file Types.h.

1135  {
1136  Z = val;
1137  DO_NAN_CHECK;
1138  };
#define DO_NAN_CHECK
Definition: Types.h:18

◆ Slerp()

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

Definition at line 1225 of file Types.h.

1226  {
1227  // extra quaternion for calculations //
1228  Float4 quaternion3;
1229 
1230  // dot product of both //
1231  float dot = this->Dot(other);
1232 
1233  if(dot < 0) {
1234 
1235  dot = -dot;
1236  quaternion3 = -other;
1237  } else {
1238  quaternion3 = other;
1239  }
1240 
1241  if(dot < 0.95f) {
1242 
1243  float angle = acosf(dot);
1244  return ((*this) * sinf(angle * (1 - f)) + quaternion3 * sinf(angle * f)) /
1245  sinf(angle);
1246 
1247  } else {
1248  // small angle, linear interpolation will be fine //
1249  return this->Lerp(quaternion3, f);
1250  }
1251  }
DLLEXPORT Float4 Lerp(const Float4 &other, float f) const
Definition: Types.h:1218
DLLEXPORT float Dot(const Float4 &val) const
Definition: Types.h:1175
DLLEXPORT Float4()
Definition: Types.h:981

◆ ToAngle()

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

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

Note
Must be normalized

Definition at line 1276 of file Types.h.

1277  {
1278 
1279  return 2 * std::acos(W);
1280  }

◆ 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 1262 of file Types.h.

1263  {
1264 
1265  const auto s = std::sqrt(1 - std::pow(W, 2));
1266  // Avoid division by zero (this small axis it can be basically converted directly)
1267  if(s > 0) {
1268  return Float3(X / s, Y / s, Z / s);
1269  } else {
1270  return Float3(X, Y, Z);
1271  }
1272  }

◆ VALUE_TYPE()

Leviathan::Float4::VALUE_TYPE ( Float4  )

◆ w_axis()

static DLLEXPORT Float4 Leviathan::Float4::w_axis ( )
inlinestatic

Definition at line 1351 of file Types.h.

1352  {
1353  return Float4(0.f, 0.f, 0.f, 1.f);
1354  }
DLLEXPORT Float4()
Definition: Types.h:981

◆ x_axis()

static DLLEXPORT Float4 Leviathan::Float4::x_axis ( )
inlinestatic

Definition at line 1336 of file Types.h.

1337  {
1338  return Float4(1.f, 0.f, 0.f, 0.f);
1339  }
DLLEXPORT Float4()
Definition: Types.h:981

◆ y_axis()

static DLLEXPORT Float4 Leviathan::Float4::y_axis ( )
inlinestatic

Definition at line 1341 of file Types.h.

1342  {
1343  return Float4(0.f, 1.f, 0.f, 0.f);
1344  }
DLLEXPORT Float4()
Definition: Types.h:981

◆ z_axis()

static DLLEXPORT Float4 Leviathan::Float4::z_axis ( )
inlinestatic

Definition at line 1346 of file Types.h.

1347  {
1348  return Float4(0.f, 0.f, 1.f, 0.f);
1349  }
DLLEXPORT Float4()
Definition: Types.h:981

◆ zero()

static DLLEXPORT Float4 Leviathan::Float4::zero ( )
inlinestatic

Definition at line 1324 of file Types.h.

1325  {
1326  return Float4(0.f, 0.f, 0.f, 0.f);
1327  }
DLLEXPORT Float4()
Definition: Types.h:981

Member Data Documentation

◆ ColourBlack

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

Definition at line 1523 of file Types.h.

◆ ColourTransparent

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

Definition at line 1525 of file Types.h.

◆ ColourWhite

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

Definition at line 1524 of file Types.h.

◆ W

float Leviathan::Float4::W

Definition at line 1519 of file Types.h.

◆ X

float Leviathan::Float4::X

Definition at line 1519 of file Types.h.

◆ Y

float Leviathan::Float4::Y

Definition at line 1519 of file Types.h.

◆ Z

float Leviathan::Float4::Z

Definition at line 1519 of file Types.h.


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