Leviathan  0.8.0.0
Leviathan game engine
Leviathan::Float3 Struct Reference

#include <Types.h>

Public Member Functions

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

Static Public Member Functions

static DLLEXPORT Float3 CreateVectorFromAngles (const float &yaw, const float &pitch)
 
static DLLEXPORT Float3 zero ()
 
static DLLEXPORT Float3 one ()
 
static DLLEXPORT Float3 x_axis ()
 
static DLLEXPORT Float3 y_axis ()
 
static DLLEXPORT Float3 z_axis ()
 

Public Attributes

float X
 
float Y
 
float Z
 

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::zero()
 

Detailed Description

Definition at line 632 of file Types.h.

Constructor & Destructor Documentation

◆ Float3() [1/6]

DLLEXPORT Leviathan::Float3::Float3 ( )
inline

Definition at line 635 of file Types.h.

636  {
637  X = Y = Z = 0;
638  };

◆ Float3() [2/6]

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

Definition at line 639 of file Types.h.

640  {
641  X = x;
642  Y = y;
643  Z = z;
644  DO_NAN_CHECK;
645  }
#define DO_NAN_CHECK
Definition: Types.h:18

◆ Float3() [3/6]

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

Definition at line 646 of file Types.h.

647  {
648  X = floats.X;
649  Y = floats.Y;
650  Z = z;
651  DO_NAN_CHECK;
652  }
#define DO_NAN_CHECK
Definition: Types.h:18

◆ Float3() [4/6]

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

Definition at line 653 of file Types.h.

654  {
655  X = Y = Z = data;
656  DO_NAN_CHECK;
657  }
#define DO_NAN_CHECK
Definition: Types.h:18

◆ Float3() [5/6]

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

Definition at line 658 of file Types.h.

659  {
660  X = static_cast<float>(values.X);
661  Y = static_cast<float>(values.Y);
662  Z = static_cast<float>(values.Z);
663 
664  DO_NAN_CHECK;
665  }
#define DO_NAN_CHECK
Definition: Types.h:18

◆ Float3() [6/6]

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

Definition at line 666 of file Types.h.

667  {
668  // copy values //
669  X = other.X;
670  Y = other.Y;
671  Z = other.Z;
672 
673  DO_NAN_CHECK;
674  }
#define DO_NAN_CHECK
Definition: Types.h:18

Member Function Documentation

◆ CheckForNans()

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

Definition at line 685 of file Types.h.

686  {
687  if(HasInvalidValues()) {
688  DEBUG_BREAK;
689  throw std::runtime_error("Float3 has NaNs (or infinites in it) in it!");
690  }
691  }
DLLEXPORT bool HasInvalidValues() const
Definition: Types.h:676

◆ Clamp()

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

Definition at line 854 of file Types.h.

855  {
856  const Float3 minval = this->MinElements(max);
857  return min.MaxElements(minval);
858  }
DLLEXPORT Float3 MinElements(const Float3 &other) const
Definition: Types.h:843
DLLEXPORT Float3()
Definition: Types.h:635

◆ Compare()

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

Definition at line 918 of file Types.h.

919  {
920  const Float3 difference = (*this) - other;
921  return difference.Dot(difference) < tolerance * tolerance;
922  }
DLLEXPORT Float3()
Definition: Types.h:635

◆ CreateVectorFromAngles()

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

Definition at line 924 of file Types.h.

925  {
926  return Float3(-sin(yaw * DEGREES_TO_RADIANS), sin(pitch * DEGREES_TO_RADIANS),
927  -cos(yaw * DEGREES_TO_RADIANS))
928  .NormalizeSafe(Zeroed);
929  }
static const Float3 Zeroed
Definition: Types.h:998
DLLEXPORT Float3()
Definition: Types.h:635
constexpr float DEGREES_TO_RADIANS
Definition: Define.h:60

◆ Cross()

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

Definition at line 872 of file Types.h.

873  {
874  return Float3(Y * val.Z - val.Y * Z, Z * val.X - val.Z * X, X * val.Y - val.X * Y);
875  }
DLLEXPORT Float3()
Definition: Types.h:635

◆ DegreesToRadians()

DLLEXPORT Float3 Leviathan::Float3::DegreesToRadians ( )
inline

Definition at line 860 of file Types.h.

861  {
862 
864  }
DLLEXPORT Float3()
Definition: Types.h:635
constexpr float DEGREES_TO_RADIANS
Definition: Define.h:60

◆ Dot()

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

Definition at line 868 of file Types.h.

869  {
870  return X * val.X + Y * val.Y + Z * val.Z;
871  }

◆ GetX()

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

Definition at line 804 of file Types.h.

805  {
806  return X;
807  };

◆ GetY()

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

Definition at line 808 of file Types.h.

809  {
810  return Y;
811  };

◆ GetZ()

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

Definition at line 812 of file Types.h.

813  {
814  return Z;
815  };

◆ HAdd()

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

Definition at line 833 of file Types.h.

834  {
835  return X + Y + Z;
836  }

◆ HAddAbs()

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

Definition at line 838 of file Types.h.

839  {
840  return std::abs(X) + std::abs(Y) + std::abs(Z);
841  }

◆ HasInvalidValues()

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

Definition at line 676 of file Types.h.

677  {
678  if(!std::isfinite(X) || !std::isfinite(Y) || !std::isfinite(Z)) {
679  return true;
680  }
681 
682  return false;
683  }
#define isfinite
Definition: jsoncpp.cpp:4247

◆ IsNormalized()

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

Definition at line 906 of file Types.h.

907  {
908  // is absolute -1.f under normalization tolerance //
909  return fabs(X * X + Y * Y + Z * Z - 1.0f) < NORMALIZATION_TOLERANCE;
910  }
constexpr float NORMALIZATION_TOLERANCE
For checking vector normalization.
Definition: Define.h:43

◆ Length()

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

Definition at line 877 of file Types.h.

878  {
879  return sqrt(X * X + Y * Y + Z * Z);
880  }

◆ LengthSquared()

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

Definition at line 881 of file Types.h.

882  {
883  return X * X + Y * Y + Z * Z;
884  }

◆ Lerp()

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

Definition at line 913 of file Types.h.

914  {
915  return Float3((other.X - X) * f + X, (other.Y - Y) * f + Y, (other.Z - Z) * f + Z);
916  }
DLLEXPORT Float3()
Definition: Types.h:635

◆ MaxElements()

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

Definition at line 848 of file Types.h.

849  {
850  return Float3(
851  X > other.X ? X : other.X, Y > other.Y ? Y : other.Y, Z > other.Z ? Z : other.Z);
852  }
DLLEXPORT Float3()
Definition: Types.h:635

◆ MinElements()

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

Definition at line 843 of file Types.h.

844  {
845  return Float3(
846  X < other.X ? X : other.X, Y < other.Y ? Y : other.Y, Z < other.Z ? Z : other.Z);
847  }
DLLEXPORT Float3()
Definition: Types.h:635

◆ Normalize()

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

Definition at line 886 of file Types.h.

887  {
888  const float length = Length();
889  if(length == 0)
890  return Float3(0, 0, 0);
891  return Float3(X / length, Y / length, Z / length);
892  }
DLLEXPORT float Length() const
Definition: Types.h:877
DLLEXPORT Float3()
Definition: Types.h:635

◆ NormalizeSafe()

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

Definition at line 894 of file Types.h.

895  {
896  // security //
897  // assert(safer.IsNormalized() && "safer not normalized");
898  const float len = X * X + Y * Y + Z * Z;
899  if(len == 0) {
900  return safer;
901  }
902  const float length = sqrt(len);
903  return Float3(X / length, Y / length, Z / length);
904  }
DLLEXPORT Float3()
Definition: Types.h:635

◆ one()

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

Definition at line 938 of file Types.h.

939  {
940  return Float3(1.f, 1.f, 1.f);
941  }
DLLEXPORT Float3()
Definition: Types.h:635

◆ operator!=()

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

Definition at line 799 of file Types.h.

800  {
801  return !(*this == other);
802  };

◆ operator*() [1/2]

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

Definition at line 737 of file Types.h.

738  {
739  return Float3(X * val.X, Y * val.Y, Z * val.Z);
740  }
DLLEXPORT Float3()
Definition: Types.h:635

◆ operator*() [2/2]

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

Definition at line 755 of file Types.h.

756  {
757  return Float3(X * f, Y * f, Z * f);
758  }
DLLEXPORT Float3()
Definition: Types.h:635

◆ operator*=()

DLLEXPORT Float3& Leviathan::Float3::operator*= ( float  f)
inline

Definition at line 759 of file Types.h.

760  {
761  X *= f;
762  Y *= f;
763  Z *= f;
764  DO_NAN_CHECK;
765  return *this;
766  }
#define DO_NAN_CHECK
Definition: Types.h:18

◆ operator+()

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

Definition at line 707 of file Types.h.

708  {
709  return Float3(X + val.X, Y + val.Y, Z + val.Z);
710  }
DLLEXPORT Float3()
Definition: Types.h:635

◆ operator+=()

DLLEXPORT Float3& Leviathan::Float3::operator+= ( const Float3 val)
inline

Definition at line 711 of file Types.h.

712  {
713  X += val.X;
714  Y += val.Y;
715  Z += val.Z;
716  return *this;
717  }

◆ operator-() [1/2]

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

Definition at line 727 of file Types.h.

728  {
729  return Float3(X - val.X, Y - val.Y, Z - val.Z);
730  }
DLLEXPORT Float3()
Definition: Types.h:635

◆ operator-() [2/2]

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

Definition at line 732 of file Types.h.

733  {
734  return Float3(-X, -Y, -Z);
735  }
DLLEXPORT Float3()
Definition: Types.h:635

◆ operator-=()

DLLEXPORT Float3& Leviathan::Float3::operator-= ( const Float3 val)
inline

Definition at line 718 of file Types.h.

719  {
720  X -= val.X;
721  Y -= val.Y;
722  Z -= val.Z;
723  return *this;
724  }

◆ operator/() [1/3]

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

Definition at line 742 of file Types.h.

743  {
744  return Float3(X / val, Y / val, Z / val);
745  }
DLLEXPORT Float3()
Definition: Types.h:635

◆ operator/() [2/3]

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

Definition at line 768 of file Types.h.

769  {
770  return Float3(X / val.X, Y / val.Y, Z / val.Z);
771  }
DLLEXPORT Float3()
Definition: Types.h:635

◆ operator/() [3/3]

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

Definition at line 773 of file Types.h.

774  {
775  return Float3(X / f, Y / f, Z / f);
776  }
DLLEXPORT Float3()
Definition: Types.h:635

◆ operator/=()

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

Definition at line 746 of file Types.h.

747  {
748  X /= val;
749  Y /= val;
750  Z /= val;
751  DO_NAN_CHECK;
752  return *this;
753  }
#define DO_NAN_CHECK
Definition: Types.h:18

◆ operator<()

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

Definition at line 779 of file Types.h.

780  {
781  return X < other.X && Y < other.Y && Z < other.Z;
782  };

◆ operator<=()

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

Definition at line 783 of file Types.h.

784  {
785  return X <= other.X && Y <= other.Y && Z <= other.Z;
786  };

◆ operator==()

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

Definition at line 795 of file Types.h.

796  {
797  return X == other.X && Y == other.Y && Z == other.Z;
798  };

◆ operator>()

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

Definition at line 787 of file Types.h.

788  {
789  return X > other.X && Y > other.Y && Z > other.Z;
790  };

◆ operator>=()

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

Definition at line 791 of file Types.h.

792  {
793  return X >= other.X && Y >= other.Y && Z > other.Z;
794  };

◆ operator[]()

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

Definition at line 694 of file Types.h.

695  {
696  switch(nindex) {
697  case 0: return X;
698  case 1: return Y;
699  case 2: return Z;
700  }
701  LEVIATHAN_ASSERT(0, "invalid [] access");
702  return X;
703  }

◆ SetX()

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

Definition at line 816 of file Types.h.

817  {
818  X = val;
819  DO_NAN_CHECK;
820  };
#define DO_NAN_CHECK
Definition: Types.h:18

◆ SetY()

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

Definition at line 821 of file Types.h.

822  {
823  Y = val;
824  DO_NAN_CHECK;
825  };
#define DO_NAN_CHECK
Definition: Types.h:18

◆ SetZ()

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

Definition at line 826 of file Types.h.

827  {
828  Z = val;
829  DO_NAN_CHECK;
830  };
#define DO_NAN_CHECK
Definition: Types.h:18

◆ VALUE_TYPE()

Leviathan::Float3::VALUE_TYPE ( Float3  )

◆ x_axis()

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

Definition at line 944 of file Types.h.

945  {
946  return Float3(1.f, 0.f, 0.f);
947  }
DLLEXPORT Float3()
Definition: Types.h:635

◆ y_axis()

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

Definition at line 950 of file Types.h.

951  {
952  return Float3(0.f, 1.f, 0.f);
953  }
DLLEXPORT Float3()
Definition: Types.h:635

◆ z_axis()

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

Definition at line 956 of file Types.h.

957  {
958  return Float3(0.f, 0.f, 1.f);
959  }
DLLEXPORT Float3()
Definition: Types.h:635

◆ zero()

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

Definition at line 933 of file Types.h.

934  {
935  return Float3(0.f, 0.f, 0.f);
936  }
DLLEXPORT Float3()
Definition: Types.h:635

Member Data Documentation

◆ UnitVForward

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

Definition at line 996 of file Types.h.

◆ UnitVUp

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

Definition at line 997 of file Types.h.

◆ X

float Leviathan::Float3::X

Definition at line 994 of file Types.h.

◆ Y

float Leviathan::Float3::Y

Definition at line 994 of file Types.h.

◆ Z

float Leviathan::Float3::Z

Definition at line 994 of file Types.h.

◆ Zeroed

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

Definition at line 998 of file Types.h.


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