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 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
 
DLLEXPORT Float3 (const Ogre::Vector3 &vec)
 
DLLEXPORT operator Ogre::Vector3 () 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 Float3 other)
inline

Definition at line 658 of file Types.h.

659  {
660  // copy values //
661  X = other.X;
662  Y = other.Y;
663  Z = other.Z;
664 
665  DO_NAN_CHECK;
666  }
#define DO_NAN_CHECK
Definition: Types.h:18

◆ Float3() [6/6]

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

Definition at line 954 of file Types.h.

955  {
956  // copy values //
957  X = vec.x;
958  Y = vec.y;
959  Z = vec.z;
960  DO_NAN_CHECK;
961  }
#define DO_NAN_CHECK
Definition: Types.h:18

Member Function Documentation

◆ CheckForNans()

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

Definition at line 677 of file Types.h.

678  {
679  if(HasInvalidValues()) {
680  DEBUG_BREAK;
681  throw std::runtime_error("Float3 has NaNs (or infinites in it) in it!");
682  }
683  }
DLLEXPORT bool HasInvalidValues() const
Definition: Types.h:668

◆ Clamp()

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

Definition at line 846 of file Types.h.

847  {
848  const Float3 minval = this->MinElements(max);
849  return min.MaxElements(minval);
850  }
DLLEXPORT Float3 MinElements(const Float3 &other) const
Definition: Types.h:835
DLLEXPORT Float3()
Definition: Types.h:635

◆ Compare()

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

Definition at line 910 of file Types.h.

911  {
912  const Float3 difference = (*this) - other;
913  return difference.Dot(difference) < tolerance * tolerance;
914  }
DLLEXPORT Float3()
Definition: Types.h:635

◆ CreateVectorFromAngles()

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

Definition at line 916 of file Types.h.

917  {
918  return Float3(-sin(yaw * DEGREES_TO_RADIANS), sin(pitch * DEGREES_TO_RADIANS),
919  -cos(yaw * DEGREES_TO_RADIANS))
920  .NormalizeSafe(Zeroed);
921  }
static const Float3 Zeroed
Definition: Types.h:976
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 864 of file Types.h.

865  {
866  return Float3(Y * val.Z - val.Y * Z, Z * val.X - val.Z * X, X * val.Y - val.X * Y);
867  }
DLLEXPORT Float3()
Definition: Types.h:635

◆ DegreesToRadians()

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

Definition at line 852 of file Types.h.

853  {
854 
855  return Float3(X * DEGREES_TO_RADIANS, Y * DEGREES_TO_RADIANS, Z * DEGREES_TO_RADIANS);
856  }
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 860 of file Types.h.

861  {
862  return X * val.X + Y * val.Y + Z * val.Z;
863  }

◆ GetX()

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

Definition at line 796 of file Types.h.

797  {
798  return X;
799  };

◆ GetY()

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

Definition at line 800 of file Types.h.

801  {
802  return Y;
803  };

◆ GetZ()

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

Definition at line 804 of file Types.h.

805  {
806  return Z;
807  };

◆ HAdd()

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

Definition at line 825 of file Types.h.

826  {
827  return X + Y + Z;
828  }

◆ HAddAbs()

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

Definition at line 830 of file Types.h.

831  {
832  return std::abs(X) + std::abs(Y) + std::abs(Z);
833  }

◆ HasInvalidValues()

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

Definition at line 668 of file Types.h.

669  {
670  if(!std::isfinite(X) || !std::isfinite(Y) || !std::isfinite(Z)) {
671  return true;
672  }
673 
674  return false;
675  }

◆ IsNormalized()

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

Definition at line 898 of file Types.h.

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

◆ Length()

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

Definition at line 869 of file Types.h.

870  {
871  return sqrt(X * X + Y * Y + Z * Z);
872  }

◆ LengthSquared()

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

Definition at line 873 of file Types.h.

874  {
875  return X * X + Y * Y + Z * Z;
876  }

◆ Lerp()

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

Definition at line 905 of file Types.h.

906  {
907  return Float3((other.X - X) * f + X, (other.Y - Y) * f + Y, (other.Z - Z) * f + Z);
908  }
DLLEXPORT Float3()
Definition: Types.h:635

◆ MaxElements()

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

Definition at line 840 of file Types.h.

841  {
842  return Float3(
843  X > other.X ? X : other.X, Y > other.Y ? Y : other.Y, Z > other.Z ? Z : other.Z);
844  }
DLLEXPORT Float3()
Definition: Types.h:635

◆ MinElements()

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

Definition at line 835 of file Types.h.

836  {
837  return Float3(
838  X < other.X ? X : other.X, Y < other.Y ? Y : other.Y, Z < other.Z ? Z : other.Z);
839  }
DLLEXPORT Float3()
Definition: Types.h:635

◆ Normalize()

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

Definition at line 878 of file Types.h.

879  {
880  const float length = Length();
881  if(length == 0)
882  return Float3(0, 0, 0);
883  return Float3(X / length, Y / length, Z / length);
884  }
DLLEXPORT float Length() const
Definition: Types.h:869
DLLEXPORT Float3()
Definition: Types.h:635

◆ NormalizeSafe()

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

Definition at line 886 of file Types.h.

887  {
888  // security //
889  // assert(safer.IsNormalized() && "safer not normalized");
890  const float len = X * X + Y * Y + Z * Z;
891  if(len == 0) {
892  return safer;
893  }
894  const float length = sqrt(len);
895  return Float3(X / length, Y / length, Z / length);
896  }
DLLEXPORT Float3()
Definition: Types.h:635

◆ one()

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

Definition at line 930 of file Types.h.

931  {
932  return Float3(1.f, 1.f, 1.f);
933  }
DLLEXPORT Float3()
Definition: Types.h:635

◆ operator Ogre::Vector3()

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

Definition at line 963 of file Types.h.

964  {
965  return Ogre::Vector3(X, Y, Z);
966  }

◆ operator!=()

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

Definition at line 791 of file Types.h.

792  {
793  return !(*this == other);
794  };

◆ operator*() [1/2]

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

Definition at line 729 of file Types.h.

730  {
731  return Float3(X * val.X, Y * val.Y, Z * val.Z);
732  }
DLLEXPORT Float3()
Definition: Types.h:635

◆ operator*() [2/2]

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

Definition at line 747 of file Types.h.

748  {
749  return Float3(X * f, Y * f, Z * f);
750  }
DLLEXPORT Float3()
Definition: Types.h:635

◆ operator*=()

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

Definition at line 751 of file Types.h.

752  {
753  X *= f;
754  Y *= f;
755  Z *= f;
756  DO_NAN_CHECK;
757  return *this;
758  }
#define DO_NAN_CHECK
Definition: Types.h:18

◆ operator+()

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

Definition at line 699 of file Types.h.

700  {
701  return Float3(X + val.X, Y + val.Y, Z + val.Z);
702  }
DLLEXPORT Float3()
Definition: Types.h:635

◆ operator+=()

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

Definition at line 703 of file Types.h.

704  {
705  X += val.X;
706  Y += val.Y;
707  Z += val.Z;
708  return *this;
709  }

◆ operator-() [1/2]

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

Definition at line 719 of file Types.h.

720  {
721  return Float3(X - val.X, Y - val.Y, Z - val.Z);
722  }
DLLEXPORT Float3()
Definition: Types.h:635

◆ operator-() [2/2]

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

Definition at line 724 of file Types.h.

725  {
726  return Float3(-X, -Y, -Z);
727  }
DLLEXPORT Float3()
Definition: Types.h:635

◆ operator-=()

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

Definition at line 710 of file Types.h.

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

◆ operator/() [1/3]

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

Definition at line 734 of file Types.h.

735  {
736  return Float3(X / val, Y / val, Z / val);
737  }
DLLEXPORT Float3()
Definition: Types.h:635

◆ operator/() [2/3]

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

Definition at line 760 of file Types.h.

761  {
762  return Float3(X / val.X, Y / val.Y, Z / val.Z);
763  }
DLLEXPORT Float3()
Definition: Types.h:635

◆ operator/() [3/3]

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

Definition at line 765 of file Types.h.

766  {
767  return Float3(X / f, Y / f, Z / f);
768  }
DLLEXPORT Float3()
Definition: Types.h:635

◆ operator/=()

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

Definition at line 738 of file Types.h.

739  {
740  X /= val;
741  Y /= val;
742  Z /= val;
743  DO_NAN_CHECK;
744  return *this;
745  }
#define DO_NAN_CHECK
Definition: Types.h:18

◆ operator<()

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

Definition at line 771 of file Types.h.

772  {
773  return X < other.X && Y < other.Y && Z < other.Z;
774  };

◆ operator<=()

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

Definition at line 775 of file Types.h.

776  {
777  return X <= other.X && Y <= other.Y && Z <= other.Z;
778  };

◆ 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 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 float& Leviathan::Float3::operator[] ( const int &  nindex)
inline

Definition at line 686 of file Types.h.

687  {
688  switch(nindex) {
689  case 0: return X;
690  case 1: return Y;
691  case 2: return Z;
692  }
693  LEVIATHAN_ASSERT(0, "invalid [] access");
694  return X;
695  }

◆ SetX()

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

Definition at line 808 of file Types.h.

809  {
810  X = val;
811  DO_NAN_CHECK;
812  };
#define DO_NAN_CHECK
Definition: Types.h:18

◆ SetY()

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

Definition at line 813 of file Types.h.

814  {
815  Y = val;
816  DO_NAN_CHECK;
817  };
#define DO_NAN_CHECK
Definition: Types.h:18

◆ SetZ()

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

Definition at line 818 of file Types.h.

819  {
820  Z = val;
821  DO_NAN_CHECK;
822  };
#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 936 of file Types.h.

937  {
938  return Float3(1.f, 0.f, 0.f);
939  }
DLLEXPORT Float3()
Definition: Types.h:635

◆ y_axis()

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

Definition at line 942 of file Types.h.

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

◆ z_axis()

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

Definition at line 948 of file Types.h.

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

◆ zero()

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

Definition at line 925 of file Types.h.

926  {
927  return Float3(0.f, 0.f, 0.f);
928  }
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 974 of file Types.h.

◆ UnitVUp

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

Definition at line 975 of file Types.h.

◆ X

float Leviathan::Float3::X

Definition at line 972 of file Types.h.

◆ Y

float Leviathan::Float3::Y

Definition at line 972 of file Types.h.

◆ Z

float Leviathan::Float3::Z

Definition at line 972 of file Types.h.

◆ Zeroed

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

Definition at line 976 of file Types.h.


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