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

Constructor & Destructor Documentation

◆ Float4() [1/5]

DLLEXPORT Leviathan::Float4::Float4 ( )
inline

Definition at line 1003 of file Types.h.

1004  {
1005  X = Y = Z = W = 0;
1006  };

◆ Float4() [2/5]

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

Definition at line 1007 of file Types.h.

1008  {
1009  X = f1;
1010  Y = f2;
1011  Z = f3;
1012  W = f4;
1013  DO_NAN_CHECK;
1014  }
#define DO_NAN_CHECK
Definition: Types.h:18

◆ Float4() [3/5]

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

Definition at line 1015 of file Types.h.

1016  {
1017  X = floats.X;
1018  Y = floats.Y;
1019  Z = f3;
1020  W = f4;
1021  DO_NAN_CHECK;
1022  }
#define DO_NAN_CHECK
Definition: Types.h:18

◆ Float4() [4/5]

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

Definition at line 1023 of file Types.h.

1024  {
1025  X = floats.X;
1026  Y = floats.Y;
1027  Z = floats.Z;
1028  W = f4;
1029  DO_NAN_CHECK;
1030  }
#define DO_NAN_CHECK
Definition: Types.h:18

◆ Float4() [5/5]

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

Definition at line 1031 of file Types.h.

1032  {
1033  X = Y = Z = W = val;
1034  DO_NAN_CHECK;
1035  }
#define DO_NAN_CHECK
Definition: Types.h:18

Member Function Documentation

◆ CheckForNans()

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

Definition at line 1046 of file Types.h.

1047  {
1048  if(HasInvalidValues()) {
1049  DEBUG_BREAK;
1050  throw std::runtime_error("Float4 has NaNs (or infinites in it) in it!");
1051  }
1052  }
DLLEXPORT bool HasInvalidValues() const
Definition: Types.h:1037

◆ Clamp()

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

Definition at line 1189 of file Types.h.

1190  {
1191  const Float4 minval = this->MinElements(max);
1192  return min.MaxElements(minval);
1193  }
DLLEXPORT Float4 MinElements(const Float4 &other) const
Definition: Types.h:1178
DLLEXPORT Float4()
Definition: Types.h:1003

◆ Compare()

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

Definition at line 1276 of file Types.h.

1277  {
1278  const Float4 difference = (*this) - other;
1279  return difference.Dot(difference) < tolerance * tolerance;
1280  }
DLLEXPORT Float4()
Definition: Types.h:1003

◆ CreateAxisAngleFromEuler()

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

Definition at line 1542 of file Types.h.

1543  {
1544 
1545  throw std::exception();
1546  // return Float4();
1547  }

◆ CreateQuaternionFromAngles()

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

Definition at line 1432 of file Types.h.

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

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

1532  {
1533  const auto s = std::sin(angle / 2.0);
1534  const auto x = axis.X * s;
1535  const auto y = axis.Y * s;
1536  const auto z = axis.Z * s;
1537  const auto w = std::cos(angle / 2.0);
1538  return Float4(static_cast<float>(x), static_cast<float>(y), static_cast<float>(z),
1539  static_cast<float>(w));
1540  }
DLLEXPORT Float4()
Definition: Types.h:1003

◆ Dot()

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

Definition at line 1197 of file Types.h.

1198  {
1199  return X * val.X + Y * val.Y + Z * val.Z + W * val.W;
1200  }

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

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

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

◆ GetW()

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

Definition at line 1142 of file Types.h.

1143  {
1144  return W;
1145  };

◆ GetX()

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

Definition at line 1130 of file Types.h.

1131  {
1132  return X;
1133  };

◆ GetY()

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

Definition at line 1134 of file Types.h.

1135  {
1136  return Y;
1137  };

◆ GetZ()

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

Definition at line 1138 of file Types.h.

1139  {
1140  return Z;
1141  };

◆ HAdd()

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

Definition at line 1168 of file Types.h.

1169  {
1170  return X + Y + Z + W;
1171  }

◆ HAddAbs()

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

Definition at line 1173 of file Types.h.

1174  {
1175  return std::abs(X) + std::abs(Y) + std::abs(Z) + std::abs(W);
1176  }

◆ HasInvalidValues()

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

Definition at line 1037 of file Types.h.

1038  {
1039  if(!std::isfinite(X) || !std::isfinite(Y) || !std::isfinite(Z) || !std::isfinite(W)) {
1040  return true;
1041  }
1042 
1043  return false;
1044  }
#define isfinite
Definition: jsoncpp.cpp:4247

◆ IdentityQuaternion()

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

Definition at line 1500 of file Types.h.

1501  {
1502  return Float4(0, 0, 0, 1);
1503  }
DLLEXPORT Float4()
Definition: Types.h:1003

◆ Inverse()

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

Inverts a quaternion.

Definition at line 1305 of file Types.h.

1306  {
1307 
1308  const auto length = Length();
1309  if(length > 0.0f) {
1310 
1311  const auto inverted = 1.0f / length;
1312  return Float4(-X * inverted, -Y * inverted, -Z * inverted, W * inverted);
1313  } else {
1314  // Invalid inversing
1315  return Float4(0);
1316  }
1317  }
DLLEXPORT Float4()
Definition: Types.h:1003
DLLEXPORT float Length() const
Definition: Types.h:1203

◆ IsNormalized()

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

Definition at line 1233 of file Types.h.

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

◆ Length()

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

Definition at line 1203 of file Types.h.

1204  {
1205  return sqrt(X * X + Y * Y + Z * Z + W * W);
1206  }

◆ Lerp()

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

Definition at line 1240 of file Types.h.

1241  {
1242  return Float4((other.X - X) * f + X, (other.Y - Y) * f + Y, (other.Z - Z) * f + Z,
1243  (other.W - W) * f + W);
1244  }
DLLEXPORT Float4()
Definition: Types.h:1003

◆ MaxElements()

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

Definition at line 1183 of file Types.h.

1184  {
1185  return Float4(X > other.X ? X : other.X, Y > other.Y ? Y : other.Y,
1186  Z > other.Z ? Z : other.Z, W > other.W ? W : other.W);
1187  }
DLLEXPORT Float4()
Definition: Types.h:1003

◆ MinElements()

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

Definition at line 1178 of file Types.h.

1179  {
1180  return Float4(X < other.X ? X : other.X, Y < other.Y ? Y : other.Y,
1181  Z < other.Z ? Z : other.Z, W < other.W ? W : other.W);
1182  }
DLLEXPORT Float4()
Definition: Types.h:1003

◆ Normalize()

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

Definition at line 1209 of file Types.h.

1210  {
1211  const float length = Length();
1212 
1213  if(length == 0) {
1214  // Returns an identity quaternion
1215  return Float4(0, 0, 0, 1);
1216  }
1217 
1218  return Float4(X / length, Y / length, Z / length, W / length);
1219  }
DLLEXPORT Float4()
Definition: Types.h:1003
DLLEXPORT float Length() const
Definition: Types.h:1203

◆ NormalizeSafe()

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

Definition at line 1221 of file Types.h.

1222  {
1223  // security //
1224  const float len = X * X + Y * Y + Z * Z + W * W;
1225  if(len == 0) {
1226  return safer;
1227  }
1228 
1229  const float length = sqrt(len);
1230  return Float4(X / length, Y / length, Z / length, W / length);
1231  }
DLLEXPORT Float4()
Definition: Types.h:1003

◆ one()

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

Definition at line 1352 of file Types.h.

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

◆ operator float *()

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

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

Definition at line 1069 of file Types.h.

1070  {
1071  // this should be always confirmed to work //
1072  return &X;
1073  }

◆ operator!=()

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

Definition at line 1125 of file Types.h.

1126  {
1127  return X != other.X && Y != other.Y && Z != other.Z && W != other.W;
1128  };

◆ operator*() [1/2]

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

Definition at line 1092 of file Types.h.

1093  {
1094  return Float4(X * val.X, Y * val.Y, Z * val.Z, W * val.W);
1095  }
DLLEXPORT Float4()
Definition: Types.h:1003

◆ operator*() [2/2]

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

Definition at line 1097 of file Types.h.

1098  {
1099  return Float4(X * f, Y * f, Z * f, W * f);
1100  }
DLLEXPORT Float4()
Definition: Types.h:1003

◆ operator+()

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

Definition at line 1077 of file Types.h.

1078  {
1079  return Float4(X + val.X, Y + val.Y, Z + val.Z, W + val.W);
1080  }
DLLEXPORT Float4()
Definition: Types.h:1003

◆ operator-() [1/2]

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

Definition at line 1082 of file Types.h.

1083  {
1084  return Float4(X - val.X, Y - val.Y, Z - val.Z, W - val.W);
1085  }
DLLEXPORT Float4()
Definition: Types.h:1003

◆ operator-() [2/2]

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

Definition at line 1087 of file Types.h.

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

◆ operator/() [1/2]

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

Definition at line 1102 of file Types.h.

1103  {
1104  return Float4(X / val.X, Y / val.Y, Z / val.Z, W / val.W);
1105  }
DLLEXPORT Float4()
Definition: Types.h:1003

◆ operator/() [2/2]

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

Definition at line 1107 of file Types.h.

1108  {
1109  return Float4(X / f, Y / f, Z / f, W / f);
1110  }
DLLEXPORT Float4()
Definition: Types.h:1003

◆ operator<()

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

Definition at line 1113 of file Types.h.

1114  {
1115  return !(*this == other);
1116  };

◆ operator==()

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

Definition at line 1121 of file Types.h.

1122  {
1123  return X == other.X && Y == other.Y && Z == other.Z && W == other.W;
1124  };

◆ operator>()

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

Definition at line 1117 of file Types.h.

1118  {
1119  return !(*this == other);
1120  };

◆ operator[]()

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

Definition at line 1055 of file Types.h.

1056  {
1057  switch(nindex) {
1058  case 0: return X;
1059  case 1: return Y;
1060  case 2: return Z;
1061  case 3: return W;
1062  }
1063 
1064  LEVIATHAN_ASSERT(0, "invalid [] access");
1065  return X;
1066  }

◆ QuaternionLookAt()

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

Definition at line 1506 of file Types.h.

1508  {
1509  const auto forward = (target - sourcepoint).NormalizeSafe();
1510  const float dot = Float3::UnitVForward.Dot(forward);
1511 
1512  if(std::abs(dot - (-1.0f)) < 0.000001f) {
1513  // Assumes up is Float3(0, 1, 0)
1514  return Float4(
1515  Float3::UnitVUp.X, Float3::UnitVUp.Y, Float3::UnitVUp.Z, 3.1415926535897932f);
1516  }
1517  if(std::abs(dot - 1.0f) < 0.000001f) {
1518  return Float4::IdentityQuaternion();
1519  }
1520 
1521  const float rotAngle = std::acos(dot);
1522  const Float3 rotAxis = Float3::UnitVForward.Cross(forward).Normalize();
1523  return CreateQuaternionFromAxisAngle(rotAxis, rotAngle);
1524  }
static const Float3 UnitVUp
Definition: Types.h:997
DLLEXPORT Float3 Cross(const Float3 &val) const
Definition: Types.h:872
DLLEXPORT Float4 NormalizeSafe(const Float4 &safer=Float4(0, 0, 0, 1)) const
Definition: Types.h:1221
static const Float3 UnitVForward
Definition: Types.h:996
DLLEXPORT Float3 Normalize() const
Definition: Types.h:886
DLLEXPORT float Dot(const Float3 &val) const
Definition: Types.h:868
DLLEXPORT Float4()
Definition: Types.h:1003
static DLLEXPORT Float4 IdentityQuaternion()
Definition: Types.h:1500
static DLLEXPORT Float4 CreateQuaternionFromAxisAngle(const Float3 &axis, float angle)
Definition: Types.h:1530

◆ QuaternionMultiply()

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

Definition at line 1481 of file Types.h.

1482  {
1483 
1484  Float4 result;
1485 
1486  result.X = X * other.X + X * other.W + Y * other.Z - Z * other.Y;
1487  result.Y = W * other.Y - X * other.Z + Y * other.W + Z * other.X;
1488  result.Z = W * other.Z + X * other.Y - Y * other.X + Z * other.W;
1489  result.W = W * other.W - X * other.X - Y * other.Y - Z * other.Z;
1490 
1491  return result;
1492  }
DLLEXPORT Float4()
Definition: Types.h:1003

◆ QuaternionReverse()

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

Definition at line 1494 of file Types.h.

1495  {
1496  // reverse vector //
1497  return Float4(-X, -Y, -Z, W);
1498  }
DLLEXPORT Float4()
Definition: Types.h:1003

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

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

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

◆ SetW()

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

Definition at line 1161 of file Types.h.

1162  {
1163  W = val;
1164  DO_NAN_CHECK;
1165  };
#define DO_NAN_CHECK
Definition: Types.h:18

◆ SetX()

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

Definition at line 1146 of file Types.h.

1147  {
1148  X = val;
1149  DO_NAN_CHECK;
1150  };
#define DO_NAN_CHECK
Definition: Types.h:18

◆ SetY()

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

Definition at line 1151 of file Types.h.

1152  {
1153  Y = val;
1154  DO_NAN_CHECK;
1155  };
#define DO_NAN_CHECK
Definition: Types.h:18

◆ SetZ()

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

Definition at line 1156 of file Types.h.

1157  {
1158  Z = val;
1159  DO_NAN_CHECK;
1160  };
#define DO_NAN_CHECK
Definition: Types.h:18

◆ Slerp()

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

Definition at line 1247 of file Types.h.

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

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

1299  {
1300 
1301  return 2 * std::acos(W);
1302  }

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

1285  {
1286 
1287  const auto s = std::sqrt(1 - std::pow(W, 2));
1288  // Avoid division by zero (this small axis it can be basically converted directly)
1289  if(s > 0) {
1290  return Float3(X / s, Y / s, Z / s);
1291  } else {
1292  return Float3(X, Y, Z);
1293  }
1294  }

◆ VALUE_TYPE()

Leviathan::Float4::VALUE_TYPE ( Float4  )

◆ w_axis()

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

Definition at line 1373 of file Types.h.

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

◆ x_axis()

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

Definition at line 1358 of file Types.h.

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

◆ y_axis()

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

Definition at line 1363 of file Types.h.

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

◆ z_axis()

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

Definition at line 1368 of file Types.h.

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

◆ zero()

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

Definition at line 1346 of file Types.h.

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

Member Data Documentation

◆ ColourBlack

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

Definition at line 1559 of file Types.h.

◆ ColourTransparent

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

Definition at line 1561 of file Types.h.

◆ ColourWhite

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

Definition at line 1560 of file Types.h.

◆ W

float Leviathan::Float4::W

Definition at line 1555 of file Types.h.

◆ X

float Leviathan::Float4::X

Definition at line 1555 of file Types.h.

◆ Y

float Leviathan::Float4::Y

Definition at line 1555 of file Types.h.

◆ Z

float Leviathan::Float4::Z

Definition at line 1555 of file Types.h.


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