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 Float4 (const btQuaternion &colour)
 
DLLEXPORT operator btQuaternion () 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 1006 of file Types.h.

Constructor & Destructor Documentation

◆ Float4() [1/8]

DLLEXPORT Leviathan::Float4::Float4 ( )
inline

Definition at line 1009 of file Types.h.

1010  {
1011  X = Y = Z = W = 0;
1012  };

◆ Float4() [2/8]

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

Definition at line 1013 of file Types.h.

1014  {
1015  X = f1;
1016  Y = f2;
1017  Z = f3;
1018  W = f4;
1019  DO_NAN_CHECK;
1020  }
#define DO_NAN_CHECK
Definition: Types.h:21

◆ Float4() [3/8]

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

Definition at line 1021 of file Types.h.

1022  {
1023  X = floats.X;
1024  Y = floats.Y;
1025  Z = f3;
1026  W = f4;
1027  DO_NAN_CHECK;
1028  }
#define DO_NAN_CHECK
Definition: Types.h:21

◆ Float4() [4/8]

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

Definition at line 1029 of file Types.h.

1030  {
1031  X = floats.X;
1032  Y = floats.Y;
1033  Z = floats.Z;
1034  W = f4;
1035  DO_NAN_CHECK;
1036  }
#define DO_NAN_CHECK
Definition: Types.h:21

◆ Float4() [5/8]

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

Definition at line 1037 of file Types.h.

1038  {
1039  X = Y = Z = W = val;
1040  DO_NAN_CHECK;
1041  }
#define DO_NAN_CHECK
Definition: Types.h:21

◆ Float4() [6/8]

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

Definition at line 1385 of file Types.h.

1386  {
1387  // copy values //
1388  X = quat.x;
1389  Y = quat.y;
1390  Z = quat.z;
1391  W = quat.w;
1392  DO_NAN_CHECK;
1393  }
#define DO_NAN_CHECK
Definition: Types.h:21

◆ Float4() [7/8]

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

Definition at line 1395 of file Types.h.

1396  {
1397  // copy values //
1398  X = colour.r;
1399  Y = colour.g;
1400  Z = colour.b;
1401  W = colour.a;
1402  DO_NAN_CHECK;
1403  }
#define DO_NAN_CHECK
Definition: Types.h:21

◆ Float4() [8/8]

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

Definition at line 1421 of file Types.h.

1422  {
1423  // copy values //
1424  X = colour.x();
1425  Y = colour.y();
1426  Z = colour.z();
1427  W = colour.w();
1428  DO_NAN_CHECK;
1429  }
#define DO_NAN_CHECK
Definition: Types.h:21

Member Function Documentation

◆ CheckForNans()

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

Definition at line 1052 of file Types.h.

1053  {
1054  if(HasInvalidValues()) {
1055  DEBUG_BREAK;
1056  throw std::runtime_error("Float4 has NaNs (or infinites in it) in it!");
1057  }
1058  }
DLLEXPORT bool HasInvalidValues() const
Definition: Types.h:1043

◆ Clamp()

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

Definition at line 1195 of file Types.h.

1196  {
1197  const Float4 minval = this->MinElements(max);
1198  return min.MaxElements(minval);
1199  }
DLLEXPORT Float4 MinElements(const Float4 &other) const
Definition: Types.h:1184
DLLEXPORT Float4()
Definition: Types.h:1009

◆ Compare()

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

Definition at line 1282 of file Types.h.

1283  {
1284  const Float4 difference = (*this) - other;
1285  return difference.Dot(difference) < tolerance * tolerance;
1286  }
DLLEXPORT Float4()
Definition: Types.h:1009

◆ CreateAxisAngleFromEuler()

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

Definition at line 1548 of file Types.h.

1549  {
1550 
1551  throw std::exception();
1552  // return Float4();
1553  }

◆ CreateQuaternionFromAngles()

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

Definition at line 1438 of file Types.h.

1439  {
1440  // multiplied by 0.5 to get double the value //
1441  float cosx = cosf(0.5f * angles.X);
1442  float cosy = cosf(0.5f * angles.Y);
1443  float cosz = cosf(0.5f * angles.Z);
1444 
1445  float sinx = sinf(0.5f * angles.X);
1446  float siny = sinf(0.5f * angles.Y);
1447  float sinz = sinf(0.5f * angles.Z);
1448 
1449 
1450  Float4 quaternion((Float4)0);
1451  // compute quaternion //
1452  quaternion.X = cosz * cosy * sinx - sinz * siny * cosx;
1453  quaternion.Y = cosz * siny * cosx + sinz * cosy * sinx;
1454  quaternion.Z = sinz * cosy * cosx - cosz * siny * sinx;
1455  quaternion.W = cosz * cosy * cosx * sinz * siny * sinx;
1456 
1457  return quaternion;
1458  }
DLLEXPORT Float4()
Definition: Types.h:1009

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

1538  {
1539  const auto s = std::sin(angle / 2.0);
1540  const auto x = axis.X * s;
1541  const auto y = axis.Y * s;
1542  const auto z = axis.Z * s;
1543  const auto w = std::cos(angle / 2.0);
1544  return Float4(static_cast<float>(x), static_cast<float>(y), static_cast<float>(z),
1545  static_cast<float>(w));
1546  }
DLLEXPORT Float4()
Definition: Types.h:1009

◆ Dot()

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

Definition at line 1203 of file Types.h.

1204  {
1205  return X * val.X + Y * val.Y + Z * val.Z + W * val.W;
1206  }

◆ 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:1565

◆ 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:1567

◆ 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:1566

◆ GetW()

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

Definition at line 1148 of file Types.h.

1149  {
1150  return W;
1151  };

◆ GetX()

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

Definition at line 1136 of file Types.h.

1137  {
1138  return X;
1139  };

◆ GetY()

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

Definition at line 1140 of file Types.h.

1141  {
1142  return Y;
1143  };

◆ GetZ()

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

Definition at line 1144 of file Types.h.

1145  {
1146  return Z;
1147  };

◆ HAdd()

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

Definition at line 1174 of file Types.h.

1175  {
1176  return X + Y + Z + W;
1177  }

◆ HAddAbs()

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

Definition at line 1179 of file Types.h.

1180  {
1181  return std::abs(X) + std::abs(Y) + std::abs(Z) + std::abs(W);
1182  }

◆ HasInvalidValues()

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

Definition at line 1043 of file Types.h.

1044  {
1045  if(!std::isfinite(X) || !std::isfinite(Y) || !std::isfinite(Z) || !std::isfinite(W)) {
1046  return true;
1047  }
1048 
1049  return false;
1050  }
#define isfinite
Definition: jsoncpp.cpp:4247

◆ IdentityQuaternion()

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

Definition at line 1506 of file Types.h.

1507  {
1508  return Float4(0, 0, 0, 1);
1509  }
DLLEXPORT Float4()
Definition: Types.h:1009

◆ Inverse()

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

Inverts a quaternion.

Definition at line 1311 of file Types.h.

1312  {
1313 
1314  const auto length = Length();
1315  if(length > 0.0f) {
1316 
1317  const auto inverted = 1.0f / length;
1318  return Float4(-X * inverted, -Y * inverted, -Z * inverted, W * inverted);
1319  } else {
1320  // Invalid inversing
1321  return Float4(0);
1322  }
1323  }
DLLEXPORT Float4()
Definition: Types.h:1009
DLLEXPORT float Length() const
Definition: Types.h:1209

◆ IsNormalized()

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

Definition at line 1239 of file Types.h.

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

◆ Length()

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

Definition at line 1209 of file Types.h.

1210  {
1211  return sqrt(X * X + Y * Y + Z * Z + W * W);
1212  }

◆ Lerp()

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

Definition at line 1246 of file Types.h.

1247  {
1248  return Float4((other.X - X) * f + X, (other.Y - Y) * f + Y, (other.Z - Z) * f + Z,
1249  (other.W - W) * f + W);
1250  }
DLLEXPORT Float4()
Definition: Types.h:1009

◆ MaxElements()

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

Definition at line 1189 of file Types.h.

1190  {
1191  return Float4(X > other.X ? X : other.X, Y > other.Y ? Y : other.Y,
1192  Z > other.Z ? Z : other.Z, W > other.W ? W : other.W);
1193  }
DLLEXPORT Float4()
Definition: Types.h:1009

◆ MinElements()

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

Definition at line 1184 of file Types.h.

1185  {
1186  return Float4(X < other.X ? X : other.X, Y < other.Y ? Y : other.Y,
1187  Z < other.Z ? Z : other.Z, W < other.W ? W : other.W);
1188  }
DLLEXPORT Float4()
Definition: Types.h:1009

◆ Normalize()

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

Definition at line 1215 of file Types.h.

1216  {
1217  const float length = Length();
1218 
1219  if(length == 0) {
1220  // Returns an identity quaternion
1221  return Float4(0, 0, 0, 1);
1222  }
1223 
1224  return Float4(X / length, Y / length, Z / length, W / length);
1225  }
DLLEXPORT Float4()
Definition: Types.h:1009
DLLEXPORT float Length() const
Definition: Types.h:1209

◆ NormalizeSafe()

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

Definition at line 1227 of file Types.h.

1228  {
1229  // security //
1230  const float len = X * X + Y * Y + Z * Z + W * W;
1231  if(len == 0) {
1232  return safer;
1233  }
1234 
1235  const float length = sqrt(len);
1236  return Float4(X / length, Y / length, Z / length, W / length);
1237  }
DLLEXPORT Float4()
Definition: Types.h:1009

◆ one()

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

Definition at line 1358 of file Types.h.

1359  {
1360  return Float4(1.f, 1.f, 1.f, 1.f);
1361  }
DLLEXPORT Float4()
Definition: Types.h:1009

◆ operator btQuaternion()

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

Definition at line 1431 of file Types.h.

1432  {
1433  return btQuaternion(X, Y, Z, W);
1434  }

◆ operator float *()

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

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

Definition at line 1075 of file Types.h.

1076  {
1077  // this should be always confirmed to work //
1078  return &X;
1079  }

◆ operator Ogre::ColourValue()

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

Definition at line 1411 of file Types.h.

1412  {
1413  return Ogre::ColourValue(X, Y, Z, W);
1414  }

◆ operator Ogre::Quaternion()

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

Definition at line 1405 of file Types.h.

1406  {
1407  // Ogre has these in different order
1408  return Ogre::Quaternion(W, X, Y, Z);
1409  }

◆ operator Ogre::Vector4()

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

Definition at line 1416 of file Types.h.

1417  {
1418  return Ogre::Vector4(X, Y, Z, W);
1419  }

◆ operator!=()

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

Definition at line 1131 of file Types.h.

1132  {
1133  return X != other.X && Y != other.Y && Z != other.Z && W != other.W;
1134  };

◆ operator*() [1/2]

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

Definition at line 1098 of file Types.h.

1099  {
1100  return Float4(X * val.X, Y * val.Y, Z * val.Z, W * val.W);
1101  }
DLLEXPORT Float4()
Definition: Types.h:1009

◆ operator*() [2/2]

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

Definition at line 1103 of file Types.h.

1104  {
1105  return Float4(X * f, Y * f, Z * f, W * f);
1106  }
DLLEXPORT Float4()
Definition: Types.h:1009

◆ operator+()

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

Definition at line 1083 of file Types.h.

1084  {
1085  return Float4(X + val.X, Y + val.Y, Z + val.Z, W + val.W);
1086  }
DLLEXPORT Float4()
Definition: Types.h:1009

◆ operator-() [1/2]

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

Definition at line 1088 of file Types.h.

1089  {
1090  return Float4(X - val.X, Y - val.Y, Z - val.Z, W - val.W);
1091  }
DLLEXPORT Float4()
Definition: Types.h:1009

◆ operator-() [2/2]

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

Definition at line 1093 of file Types.h.

1094  {
1095  return Float4(-X, -Y, -Z, -W);
1096  }
DLLEXPORT Float4()
Definition: Types.h:1009

◆ operator/() [1/2]

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

Definition at line 1108 of file Types.h.

1109  {
1110  return Float4(X / val.X, Y / val.Y, Z / val.Z, W / val.W);
1111  }
DLLEXPORT Float4()
Definition: Types.h:1009

◆ operator/() [2/2]

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

Definition at line 1113 of file Types.h.

1114  {
1115  return Float4(X / f, Y / f, Z / f, W / f);
1116  }
DLLEXPORT Float4()
Definition: Types.h:1009

◆ operator<()

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

Definition at line 1119 of file Types.h.

1120  {
1121  return !(*this == other);
1122  };

◆ operator==()

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

Definition at line 1127 of file Types.h.

1128  {
1129  return X == other.X && Y == other.Y && Z == other.Z && W == other.W;
1130  };

◆ operator>()

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

Definition at line 1123 of file Types.h.

1124  {
1125  return !(*this == other);
1126  };

◆ operator[]()

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

Definition at line 1061 of file Types.h.

1062  {
1063  switch(nindex) {
1064  case 0: return X;
1065  case 1: return Y;
1066  case 2: return Z;
1067  case 3: return W;
1068  }
1069 
1070  LEVIATHAN_ASSERT(0, "invalid [] access");
1071  return X;
1072  }
#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 1512 of file Types.h.

1514  {
1515  const auto forward = (target - sourcepoint).NormalizeSafe();
1516  const float dot = Float3::UnitVForward.Dot(forward);
1517 
1518  if(std::abs(dot - (-1.0f)) < 0.000001f) {
1519  // Assumes up is Float3(0, 1, 0)
1520  return Float4(
1521  Float3::UnitVUp.X, Float3::UnitVUp.Y, Float3::UnitVUp.Z, 3.1415926535897932f);
1522  }
1523  if(std::abs(dot - 1.0f) < 0.000001f) {
1524  return Float4::IdentityQuaternion();
1525  }
1526 
1527  const float rotAngle = std::acos(dot);
1528  const Float3 rotAxis = Float3::UnitVForward.Cross(forward).Normalize();
1529  return CreateQuaternionFromAxisAngle(rotAxis, rotAngle);
1530  }
static const Float3 UnitVUp
Definition: Types.h:1003
DLLEXPORT Float3 Cross(const Float3 &val) const
Definition: Types.h:878
DLLEXPORT Float4 NormalizeSafe(const Float4 &safer=Float4(0, 0, 0, 1)) const
Definition: Types.h:1227
static const Float3 UnitVForward
Definition: Types.h:1002
DLLEXPORT Float3 Normalize() const
Definition: Types.h:892
DLLEXPORT float Dot(const Float3 &val) const
Definition: Types.h:874
DLLEXPORT Float4()
Definition: Types.h:1009
static DLLEXPORT Float4 IdentityQuaternion()
Definition: Types.h:1506
static DLLEXPORT Float4 CreateQuaternionFromAxisAngle(const Float3 &axis, float angle)
Definition: Types.h:1536

◆ QuaternionMultiply()

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

Definition at line 1487 of file Types.h.

1488  {
1489 
1490  Float4 result;
1491 
1492  result.X = X * other.X + X * other.W + Y * other.Z - Z * other.Y;
1493  result.Y = W * other.Y - X * other.Z + Y * other.W + Z * other.X;
1494  result.Z = W * other.Z + X * other.Y - Y * other.X + Z * other.W;
1495  result.W = W * other.W - X * other.X - Y * other.Y - Z * other.Z;
1496 
1497  return result;
1498  }
DLLEXPORT Float4()
Definition: Types.h:1009

◆ QuaternionReverse()

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

Definition at line 1500 of file Types.h.

1501  {
1502  // reverse vector //
1503  return Float4(-X, -Y, -Z, W);
1504  }
DLLEXPORT Float4()
Definition: Types.h:1009

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

1464  {
1465 
1466  float test = X * Y + Z * W;
1467 
1468  if(test > 0.499) {
1469  // Singularity at north pole
1470  return Float3(2 * atan2(X, W), PI / 2, 0);
1471  }
1472 
1473  if(test < -0.499) {
1474 
1475  // Singularity at south pole
1476  return Float3(-2 * atan2(X, W), -PI / 2, 0);
1477  }
1478 
1479  float sqx = X * X;
1480  float sqy = Y * Y;
1481  float sqz = Z * Z;
1482 
1483  return Float3(atan2(2 * Y * W - 2 * X * Z, 1 - 2 * sqy - 2 * sqz), asin(2 * test),
1484  atan2(2 * X * W - 2 * Y * Z, 1 - 2 * sqx - 2 * sqz));
1485  }
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 1326 of file Types.h.

1327  {
1328  // // Alternative from
1329  // //
1330  // https://gamedev.stackexchange.com/questions/28395/rotating-vector3-by-a-quaternion
1331  // const auto u = Float3(X, Y, Z);
1332 
1333  // // Complex math going on
1334  // return u * 2.0f * u.Dot(vector)
1335  // + vector * (W*W - u.Dot(u))
1336  // + u.Cross(vector) * 2.0f * W;
1337 
1338  // Math taken from Ogre::Quaternion
1339  Float3 uv;
1340  Float3 uuv;
1341  Float3 qvec(X, Y, Z);
1342  uv = qvec.Cross(vector);
1343  uuv = qvec.Cross(uv);
1344  uv *= 2.0f * W;
1345  uuv *= 2.0f;
1346 
1347  return vector + uv + uuv;
1348  }

◆ SetW()

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

Definition at line 1167 of file Types.h.

1168  {
1169  W = val;
1170  DO_NAN_CHECK;
1171  };
#define DO_NAN_CHECK
Definition: Types.h:21

◆ SetX()

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

Definition at line 1152 of file Types.h.

1153  {
1154  X = val;
1155  DO_NAN_CHECK;
1156  };
#define DO_NAN_CHECK
Definition: Types.h:21

◆ SetY()

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

Definition at line 1157 of file Types.h.

1158  {
1159  Y = val;
1160  DO_NAN_CHECK;
1161  };
#define DO_NAN_CHECK
Definition: Types.h:21

◆ SetZ()

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

Definition at line 1162 of file Types.h.

1163  {
1164  Z = val;
1165  DO_NAN_CHECK;
1166  };
#define DO_NAN_CHECK
Definition: Types.h:21

◆ Slerp()

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

Definition at line 1253 of file Types.h.

1254  {
1255  // extra quaternion for calculations //
1256  Float4 quaternion3;
1257 
1258  // dot product of both //
1259  float dot = this->Dot(other);
1260 
1261  if(dot < 0) {
1262 
1263  dot = -dot;
1264  quaternion3 = -other;
1265  } else {
1266  quaternion3 = other;
1267  }
1268 
1269  if(dot < 0.95f) {
1270 
1271  float angle = acosf(dot);
1272  return ((*this) * sinf(angle * (1 - f)) + quaternion3 * sinf(angle * f)) /
1273  sinf(angle);
1274 
1275  } else {
1276  // small angle, linear interpolation will be fine //
1277  return this->Lerp(quaternion3, f);
1278  }
1279  }
DLLEXPORT Float4 Lerp(const Float4 &other, float f) const
Definition: Types.h:1246
DLLEXPORT float Dot(const Float4 &val) const
Definition: Types.h:1203
DLLEXPORT Float4()
Definition: Types.h:1009

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

1305  {
1306 
1307  return 2 * std::acos(W);
1308  }

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

1291  {
1292 
1293  const auto s = std::sqrt(1 - std::pow(W, 2));
1294  // Avoid division by zero (this small axis it can be basically converted directly)
1295  if(s > 0) {
1296  return Float3(X / s, Y / s, Z / s);
1297  } else {
1298  return Float3(X, Y, Z);
1299  }
1300  }

◆ VALUE_TYPE()

Leviathan::Float4::VALUE_TYPE ( Float4  )

◆ w_axis()

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

Definition at line 1379 of file Types.h.

1380  {
1381  return Float4(0.f, 0.f, 0.f, 1.f);
1382  }
DLLEXPORT Float4()
Definition: Types.h:1009

◆ x_axis()

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

Definition at line 1364 of file Types.h.

1365  {
1366  return Float4(1.f, 0.f, 0.f, 0.f);
1367  }
DLLEXPORT Float4()
Definition: Types.h:1009

◆ y_axis()

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

Definition at line 1369 of file Types.h.

1370  {
1371  return Float4(0.f, 1.f, 0.f, 0.f);
1372  }
DLLEXPORT Float4()
Definition: Types.h:1009

◆ z_axis()

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

Definition at line 1374 of file Types.h.

1375  {
1376  return Float4(0.f, 0.f, 1.f, 0.f);
1377  }
DLLEXPORT Float4()
Definition: Types.h:1009

◆ zero()

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

Definition at line 1352 of file Types.h.

1353  {
1354  return Float4(0.f, 0.f, 0.f, 0.f);
1355  }
DLLEXPORT Float4()
Definition: Types.h:1009

Member Data Documentation

◆ ColourBlack

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

Definition at line 1565 of file Types.h.

◆ ColourTransparent

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

Definition at line 1567 of file Types.h.

◆ ColourWhite

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

Definition at line 1566 of file Types.h.

◆ W

float Leviathan::Float4::W

Definition at line 1561 of file Types.h.

◆ X

float Leviathan::Float4::X

Definition at line 1561 of file Types.h.

◆ Y

float Leviathan::Float4::Y

Definition at line 1561 of file Types.h.

◆ Z

float Leviathan::Float4::Z

Definition at line 1561 of file Types.h.


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