Leviathan  0.8.0.0
Leviathan game engine
Leviathan::Float3 Struct Reference

#include <Types.h>

Public Member Functions

DLLEXPORT Float3 () noexcept=default
 
DLLEXPORT Float3 (float x, float y, float z)
 
DLLEXPORT Float3 (Float2 floats, float z)
 
DLLEXPORT Float3 (float data)
 
DLLEXPORT Float3 (const Int3 &values) noexcept
 
DLLEXPORT bool HasInvalidValues () const noexcept
 
DLLEXPORT void CheckForNans () const
 
DLLEXPORT float & operator[] (int nindex)
 
DLLEXPORT Float3 operator+ (const Float3 &other) const noexcept
 
DLLEXPORT Float3operator+= (const Float3 &other) noexcept
 
DLLEXPORT Float3 operator- (const Float3 &other) const noexcept
 
DLLEXPORT Float3operator-= (const Float3 &other) noexcept
 
DLLEXPORT Float3 operator- () const noexcept
 
DLLEXPORT Float3 operator+ () const noexcept
 
DLLEXPORT Float3 operator* (const Float3 &other) const noexcept
 
DLLEXPORT Float3operator*= (const Float3 &other) noexcept
 
DLLEXPORT Float3 operator/ (float val) const
 
DLLEXPORT Float3operator/= (float val)
 
DLLEXPORT Float3 operator* (float val) const noexcept
 
DLLEXPORT Float3operator*= (float val) noexcept
 
DLLEXPORT Float3 operator/ (const Float3 &other) const
 
DLLEXPORT Float3operator/= (const Float3 &other)
 
DLLEXPORT bool operator< (const Float3 &other) const noexcept
 
DLLEXPORT bool operator<= (const Float3 &other) const noexcept
 
DLLEXPORT bool operator> (const Float3 &other) const noexcept
 
DLLEXPORT bool operator>= (const Float3 &other) const noexcept
 
DLLEXPORT bool operator== (const Float3 &other) const noexcept
 
DLLEXPORT bool operator!= (const Float3 &other) const noexcept
 
DLLEXPORT float GetX () const noexcept
 
DLLEXPORT float GetY () const noexcept
 
DLLEXPORT float GetZ () const noexcept
 
DLLEXPORT void SetX (float val)
 
DLLEXPORT void SetY (float val)
 
DLLEXPORT void SetZ (float val)
 
DLLEXPORT float HAdd () const noexcept
 
DLLEXPORT float HAddAbs () const noexcept
 
DLLEXPORT Float3 MinElements (const Float3 &other) const noexcept
 
DLLEXPORT Float3 MaxElements (const Float3 &other) const noexcept
 
DLLEXPORT Float3 Clamp (const Float3 &min, const Float3 &max) const noexcept
 
DLLEXPORT Float3 DegreesToRadians () const noexcept
 
DLLEXPORT float Dot (const Float3 &val) const noexcept
 
DLLEXPORT Float3 Cross (const Float3 &val) const
 
DLLEXPORT float Length () const noexcept
 
DLLEXPORT float LengthSquared () const noexcept
 
DLLEXPORT Float3 Normalize () const
 
DLLEXPORT Float3 NormalizeSafe (const Float3 &safer=Float3(1, 0, 0)) const noexcept
 
DLLEXPORT bool IsNormalized () const noexcept
 
DLLEXPORT Float3 Lerp (const Float3 &other, float f) const noexcept
 
DLLEXPORT bool Compare (const Float3 &other, float tolerance) const noexcept
 
DLLEXPORT Float3 (const Ogre::Vector3 &vec)
 
DLLEXPORT operator Ogre::Vector3 () const
 
DLLEXPORT Float3 (const btVector3 &vec)
 
DLLEXPORT operator btVector3 () const
 
 VALUE_TYPE (Float3)
 

Static Public Member Functions

static DLLEXPORT Float3 CreateVectorFromAngles (const float &yaw, const float &pitch) noexcept
 

Public Attributes

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

Static Public Attributes

static const Float3 UnitVForward = Float3(0.f, 0.f, -1.f)
 
static const Float3 UnitVUp = Float3(0.f, 1.f, 0.f)
 
static const Float3 Zeroed = Float3()
 

Detailed Description

Definition at line 877 of file Types.h.

Constructor & Destructor Documentation

◆ Float3() [1/7]

DLLEXPORT Leviathan::Float3::Float3 ( )
inlinedefaultnoexcept

◆ Float3() [2/7]

DLLEXPORT Leviathan::Float3::Float3 ( float  x,
float  y,
float  z 
)
inline

Definition at line 881 of file Types.h.

881  : X(x), Y(y), Z(z)
882  {
883  DO_NAN_CHECK;
884  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ Float3() [3/7]

DLLEXPORT Leviathan::Float3::Float3 ( Float2  floats,
float  z 
)
inline

Definition at line 886 of file Types.h.

886  : X(floats.X), Y(floats.Y), Z(z)
887  {
888  DO_NAN_CHECK;
889  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ Float3() [4/7]

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

Definition at line 891 of file Types.h.

891  : X(data), Y(data), Z(data)
892  {
893  DO_NAN_CHECK;
894  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ Float3() [5/7]

DLLEXPORT Leviathan::Float3::Float3 ( const Int3 values)
inlinenoexcept

Definition at line 896 of file Types.h.

896  :
897  X(static_cast<float>(values.X)), Y(static_cast<float>(values.Y)),
898  Z(static_cast<float>(values.Z))
899  {
900  DO_NAN_CHECK;
901  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ Float3() [6/7]

DLLEXPORT Leviathan::Float3::Float3 ( const Ogre::Vector3 &  vec)
inline

Definition at line 1211 of file Types.h.

1211  :
1212  // copy values //
1213  X(vec.x), Y(vec.y), Z(vec.z)
1214  {
1215  DO_NAN_CHECK;
1216  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ Float3() [7/7]

DLLEXPORT Leviathan::Float3::Float3 ( const btVector3 &  vec)
inline

Definition at line 1223 of file Types.h.

1223  :
1224  // copy values //
1225  X(vec.x()), Y(vec.y()), Z(vec.z())
1226  {
1227  DO_NAN_CHECK;
1228  }
#define DO_NAN_CHECK
Definition: Types.h:20

Member Function Documentation

◆ CheckForNans()

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

Definition at line 908 of file Types.h.

909  {
910  if(HasInvalidValues()) {
911  DEBUG_BREAK;
912  throw std::runtime_error("Float3 has NaNs (or infinites in it) in it!");
913  }
914  }
DLLEXPORT bool HasInvalidValues() const noexcept
Definition: Types.h:903

◆ Clamp()

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

Definition at line 1124 of file Types.h.

1125  {
1126  const Float3 minval = this->MinElements(max);
1127  return min.MaxElements(minval);
1128  }
DLLEXPORT Float3() noexcept=default
DLLEXPORT Float3 MinElements(const Float3 &other) const noexcept
Definition: Types.h:1111

◆ Compare()

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

Definition at line 1194 of file Types.h.

1195  {
1196  const Float3 difference = (*this) - other;
1197  return difference.Dot(difference) < tolerance * tolerance;
1198  }
DLLEXPORT Float3() noexcept=default

◆ CreateVectorFromAngles()

static DLLEXPORT Float3 Leviathan::Float3::CreateVectorFromAngles ( const float &  yaw,
const float &  pitch 
)
inlinestaticnoexcept

Definition at line 1200 of file Types.h.

1202  {
1203  return Float3(-sin(yaw * DEGREES_TO_RADIANS), sin(pitch * DEGREES_TO_RADIANS),
1204  -cos(yaw * DEGREES_TO_RADIANS))
1205  .NormalizeSafe(Zeroed);
1206  }
static const Float3 Zeroed
Definition: Types.h:1246
DLLEXPORT Float3() noexcept=default
constexpr float DEGREES_TO_RADIANS
Definition: Define.h:61

◆ Cross()

DLLEXPORT Float3 Leviathan::Float3::Cross ( const Float3 val) const
inline

Definition at line 1143 of file Types.h.

1144  {
1145  return Float3(Y * val.Z - val.Y * Z, Z * val.X - val.Z * X, X * val.Y - val.X * Y);
1146  }
DLLEXPORT Float3() noexcept=default

◆ DegreesToRadians()

DLLEXPORT Float3 Leviathan::Float3::DegreesToRadians ( ) const
inlinenoexcept

Definition at line 1130 of file Types.h.

1131  {
1133  }
DLLEXPORT Float3() noexcept=default
constexpr float DEGREES_TO_RADIANS
Definition: Define.h:61

◆ Dot()

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

Definition at line 1137 of file Types.h.

1138  {
1139  return X * val.X + Y * val.Y + Z * val.Z;
1140  }

◆ GetX()

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

Definition at line 1064 of file Types.h.

1065  {
1066  return X;
1067  }

◆ GetY()

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

Definition at line 1069 of file Types.h.

1070  {
1071  return Y;
1072  }

◆ GetZ()

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

Definition at line 1074 of file Types.h.

1075  {
1076  return Z;
1077  }

◆ HAdd()

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

Definition at line 1099 of file Types.h.

1100  {
1101  return X + Y + Z;
1102  }

◆ HAddAbs()

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

Definition at line 1105 of file Types.h.

1106  {
1107  return std::abs(X) + std::abs(Y) + std::abs(Z);
1108  }

◆ HasInvalidValues()

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

Definition at line 903 of file Types.h.

904  {
905  return !std::isfinite(X) || !std::isfinite(Y) || !std::isfinite(Z);
906  }
#define isfinite
Definition: jsoncpp.cpp:4247

◆ IsNormalized()

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

Definition at line 1180 of file Types.h.

1181  {
1182  // is absolute -1.f under normalization tolerance //
1183  return fabs(X * X + Y * Y + Z * Z - 1.0f) < NORMALIZATION_TOLERANCE;
1184  }
constexpr float NORMALIZATION_TOLERANCE
For checking vector normalization.
Definition: Define.h:44

◆ Length()

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

Definition at line 1149 of file Types.h.

1150  {
1151  return std::sqrt(LengthSquared());
1152  }
DLLEXPORT float LengthSquared() const noexcept
Definition: Types.h:1154

◆ LengthSquared()

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

Definition at line 1154 of file Types.h.

1155  {
1156  return X * X + Y * Y + Z * Z;
1157  }

◆ Lerp()

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

Definition at line 1188 of file Types.h.

1189  {
1190  return Float3((other.X - X) * f + X, (other.Y - Y) * f + Y, (other.Z - Z) * f + Z);
1191  }
DLLEXPORT Float3() noexcept=default

◆ MaxElements()

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

Definition at line 1117 of file Types.h.

1118  {
1119  return Float3(
1120  X > other.X ? X : other.X, Y > other.Y ? Y : other.Y, Z > other.Z ? Z : other.Z);
1121  }
DLLEXPORT Float3() noexcept=default

◆ MinElements()

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

Definition at line 1111 of file Types.h.

1112  {
1113  return Float3(
1114  X < other.X ? X : other.X, Y < other.Y ? Y : other.Y, Z < other.Z ? Z : other.Z);
1115  }
DLLEXPORT Float3() noexcept=default

◆ Normalize()

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

Definition at line 1160 of file Types.h.

1161  {
1162  const float length = Length();
1163  if(length == 0)
1164  return Float3(0, 0, 0);
1165  return (*this) / length;
1166  }
DLLEXPORT float Length() const noexcept
Definition: Types.h:1149
DLLEXPORT Float3() noexcept=default

◆ NormalizeSafe()

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

Definition at line 1169 of file Types.h.

1170  {
1171  // security //
1172  LEVIATHAN_ASSERT(safer.IsNormalized(), "safer not normalized");
1173  if(LengthSquared() == 0)
1174  return safer;
1175  const float length = Length();
1176  return (*this) / length;
1177  }
DLLEXPORT float Length() const noexcept
Definition: Types.h:1149
#define LEVIATHAN_ASSERT(x, msg)
Definition: Define.h:92
DLLEXPORT float LengthSquared() const noexcept
Definition: Types.h:1154

◆ operator btVector3()

DLLEXPORT Leviathan::Float3::operator btVector3 ( ) const
inline

Definition at line 1230 of file Types.h.

1231  {
1232  return btVector3(X, Y, Z);
1233  }

◆ operator Ogre::Vector3()

DLLEXPORT Leviathan::Float3::operator Ogre::Vector3 ( ) const
inline

Definition at line 1218 of file Types.h.

1219  {
1220  return Ogre::Vector3(X, Y, Z);
1221  }

◆ operator!=()

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

Definition at line 1057 of file Types.h.

1058  {
1059  return X != other.X || Y != other.Y || Z != other.Z;
1060  }

◆ operator*() [1/2]

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

Definition at line 971 of file Types.h.

972  {
973  return Float3(X * other.X, Y * other.Y, Z * other.Z);
974  }
DLLEXPORT Float3() noexcept=default

◆ operator*() [2/2]

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

Definition at line 1001 of file Types.h.

1002  {
1003  return Float3(X * val, Y * val, Z * val);
1004  }
DLLEXPORT Float3() noexcept=default

◆ operator*=() [1/2]

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

Definition at line 976 of file Types.h.

977  {
978  X *= other.X;
979  Y *= other.Y;
980  Z *= other.Z;
981  DO_NAN_CHECK;
982  return *this;
983  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ operator*=() [2/2]

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

Definition at line 1006 of file Types.h.

1007  {
1008  X *= val;
1009  Y *= val;
1010  Z *= val;
1011  DO_NAN_CHECK;
1012  return *this;
1013  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ operator+() [1/2]

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

Definition at line 931 of file Types.h.

932  {
933  return Float3(X + other.X, Y + other.Y, Z + other.Z);
934  }
DLLEXPORT Float3() noexcept=default

◆ operator+() [2/2]

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

Definition at line 965 of file Types.h.

966  {
967  return Float3(*this);
968  }
DLLEXPORT Float3() noexcept=default

◆ operator+=()

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

Definition at line 936 of file Types.h.

937  {
938  X += other.X;
939  Y += other.Y;
940  Z += other.Z;
941  return *this;
942  }

◆ operator-() [1/2]

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

Definition at line 945 of file Types.h.

946  {
947  return Float3(X - other.X, Y - other.Y, Z - other.Z);
948  }
DLLEXPORT Float3() noexcept=default

◆ operator-() [2/2]

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

Definition at line 959 of file Types.h.

960  {
961  return Float3(-X, -Y, -Z);
962  }
DLLEXPORT Float3() noexcept=default

◆ operator-=()

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

Definition at line 950 of file Types.h.

951  {
952  X -= other.X;
953  Y -= other.Y;
954  Z -= other.Z;
955  return *this;
956  }

◆ operator/() [1/2]

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

Definition at line 986 of file Types.h.

987  {
988  return Float3(X / val, Y / val, Z / val);
989  }
DLLEXPORT Float3() noexcept=default

◆ operator/() [2/2]

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

Definition at line 1016 of file Types.h.

1017  {
1018  return Float3(X / other.X, Y / other.Y, Z / other.Z);
1019  }
DLLEXPORT Float3() noexcept=default

◆ operator/=() [1/2]

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

Definition at line 991 of file Types.h.

992  {
993  X /= val;
994  Y /= val;
995  Z /= val;
996  DO_NAN_CHECK;
997  return *this;
998  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ operator/=() [2/2]

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

Definition at line 1021 of file Types.h.

1022  {
1023  X /= other.X;
1024  Y /= other.Y;
1025  Z /= other.Z;
1026  DO_NAN_CHECK;
1027  return *this;
1028  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ operator<()

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

Definition at line 1032 of file Types.h.

1033  {
1034  return std::tie(X, Y, Z) < std::tie(other.X, other.Y, other.Z);
1035  }

◆ operator<=()

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

Definition at line 1037 of file Types.h.

1038  {
1039  return std::tie(X, Y, Z) <= std::tie(other.X, other.Y, other.Z);
1040  }

◆ operator==()

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

Definition at line 1052 of file Types.h.

1053  {
1054  return X == other.X && Y == other.Y && Z == other.Z;
1055  }

◆ operator>()

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

Definition at line 1042 of file Types.h.

1043  {
1044  return std::tie(X, Y, Z) > std::tie(other.X, other.Y, other.Z);
1045  }

◆ operator>=()

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

Definition at line 1047 of file Types.h.

1048  {
1049  return std::tie(X, Y, Z) >= std::tie(other.X, other.Y, other.Z);
1050  }

◆ operator[]()

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

Definition at line 917 of file Types.h.

918  {
919  switch(nindex) {
920  case 0: return X;
921  case 1: return Y;
922  case 2: return Z;
923  default: break;
924  }
925  LEVIATHAN_ASSERT(0, "invalid [] access");
926  return X;
927  }
#define LEVIATHAN_ASSERT(x, msg)
Definition: Define.h:92

◆ SetX()

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

Definition at line 1080 of file Types.h.

1081  {
1082  X = val;
1083  DO_NAN_CHECK;
1084  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ SetY()

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

Definition at line 1086 of file Types.h.

1087  {
1088  Y = val;
1089  DO_NAN_CHECK;
1090  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ SetZ()

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

Definition at line 1092 of file Types.h.

1093  {
1094  Z = val;
1095  DO_NAN_CHECK;
1096  }
#define DO_NAN_CHECK
Definition: Types.h:20

◆ VALUE_TYPE()

Leviathan::Float3::VALUE_TYPE ( Float3  )

Member Data Documentation

◆ UnitVForward

const Float3 Leviathan::Float3::UnitVForward = Float3(0.f, 0.f, -1.f)
static

Definition at line 1244 of file Types.h.

◆ UnitVUp

const Float3 Leviathan::Float3::UnitVUp = Float3(0.f, 1.f, 0.f)
static

Definition at line 1245 of file Types.h.

◆ X

float Leviathan::Float3::X = 0

Definition at line 1240 of file Types.h.

◆ Y

float Leviathan::Float3::Y = 0

Definition at line 1241 of file Types.h.

◆ Z

float Leviathan::Float3::Z = 0

Definition at line 1242 of file Types.h.

◆ Zeroed

const Float3 Leviathan::Float3::Zeroed = Float3()
static

Definition at line 1246 of file Types.h.


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