OpenBarnyard
 
Loading...
Searching...
No Matches
TVector2 Class Reference

#include <TVector2.h>

Public Member Functions

constexpr TVector2 ()=default
 
constexpr TVector2 (TFLOAT x, TFLOAT y)
 
constexpr TVector2 (TFLOAT coords[2])
 
constexpr TVector2 (const TVector2 &other)
 
constexpr void Set (TFLOAT x, TFLOAT y)
 
constexpr void Set (TFLOAT coords[2])
 
constexpr void Set (const TVector2 &other)
 
constexpr void Add (const TVector2 &vec)
 
constexpr void Add (const TVector2 &a, const TVector2 &b)
 
constexpr void Divide (const TVector2 &vec)
 
constexpr void Divide (TFLOAT scalar)
 
constexpr void Divide (const TVector2 &vec1, const TVector2 &vec2)
 
constexpr void Divide (const TVector2 &vec, TFLOAT scalar)
 
constexpr void Multiply (const TVector2 &vec)
 
constexpr void Multiply (TFLOAT scalar)
 
constexpr void Multiply (const TVector2 &vec1, const TVector2 &vec2)
 
constexpr void Multiply (const TVector2 &vec, TFLOAT scalar)
 
constexpr void Negate ()
 
void Normalize ()
 
void Abs (const TVector2 &vec3)
 
void Abs ()
 
TFLOAT Magnitude () const
 
constexpr TFLOAT MagnitudeSq () const
 
TBOOL IsEqual (const TVector2 &vec)
 
constexpr TVector2 operator+ (const TVector2 &other) const
 
constexpr TVector2 operator- (const TVector2 &other) const
 
constexpr TVector2 operator* (const TVector2 &other) const
 
constexpr TVector2 operator/ (const TVector2 &other) const
 
constexpr void operator= (const TVector2 &other)
 
constexpr void operator+= (const TVector2 &other)
 
constexpr void operator/= (const TVector2 &other)
 

Static Public Member Functions

static TFLOAT Distance (const TVector2 &vec1, const TVector2 &vec2)
 
static constexpr TFLOAT DistanceSq (const TVector2 &vec1, const TVector2 &vec2)
 
static constexpr TFLOAT DotProduct (const TVector2 &vec1, const TVector2 &vec2)
 

Public Attributes

TFLOAT x
 
TFLOAT y
 

Static Public Attributes

constinit static const TVector2 VEC_ZERO = TVector2( 0, 0 )
 
constinit static const TVector2 VEC_POSX = TVector2( 1, 0 )
 
constinit static const TVector2 VEC_POSY = TVector2( 0, 1 )
 
constinit static const TVector2 VEC_NEGX = TVector2( -1, 0 )
 
constinit static const TVector2 VEC_NEGY = TVector2( 0, -1 )
 

Detailed Description

Definition at line 5 of file TVector2.h.

Constructor & Destructor Documentation

◆ TVector2() [1/4]

TVector2::TVector2 ( )
constexprdefault

◆ TVector2() [2/4]

TVector2::TVector2 ( TFLOAT x,
TFLOAT y )
inlineconstexpr

Definition at line 9 of file TVector2.h.

9{ Set( x, y ); }
TFLOAT y
Definition TVector2.h:139
constexpr void Set(TFLOAT x, TFLOAT y)
Definition TVector2.h:13
TFLOAT x
Definition TVector2.h:139

◆ TVector2() [3/4]

TVector2::TVector2 ( TFLOAT coords[2])
inlineconstexpr

Definition at line 10 of file TVector2.h.

10{ Set( coords[ 0 ], coords[ 1 ] ); }

◆ TVector2() [4/4]

TVector2::TVector2 ( const TVector2 & other)
inlineconstexpr

Definition at line 11 of file TVector2.h.

11{ Set( other ); }

Member Function Documentation

◆ Abs() [1/2]

void TVector2::Abs ( )
inline

Definition at line 109 of file TVector2.h.

109{ Set( TMath::Abs( x ), TMath::Abs( y ) ); }
TFORCEINLINE TFLOAT Abs(TFLOAT fVal)
Definition TMathInline.h:63

◆ Abs() [2/2]

void TVector2::Abs ( const TVector2 & vec3)
inline

Definition at line 108 of file TVector2.h.

108{ Set( TMath::Abs( vec3.x ), TMath::Abs( vec3.y ) ); }

◆ Add() [1/2]

void TVector2::Add ( const TVector2 & a,
const TVector2 & b )
inlineconstexpr

Definition at line 37 of file TVector2.h.

38 {
39 Set( a + b );
40 }

◆ Add() [2/2]

void TVector2::Add ( const TVector2 & vec)
inlineconstexpr

Definition at line 31 of file TVector2.h.

32 {
33 x += vec.x;
34 y += vec.y;
35 }

◆ Distance()

static TFLOAT TVector2::Distance ( const TVector2 & vec1,
const TVector2 & vec2 )
inlinestatic

Definition at line 127 of file TVector2.h.

127{ return ( vec2 - vec1 ).Magnitude(); }

◆ DistanceSq()

static constexpr TFLOAT TVector2::DistanceSq ( const TVector2 & vec1,
const TVector2 & vec2 )
inlinestaticconstexpr

Definition at line 128 of file TVector2.h.

128{ return ( vec2 - vec1 ).MagnitudeSq(); }

◆ Divide() [1/4]

void TVector2::Divide ( const TVector2 & vec)
inlineconstexpr

Definition at line 42 of file TVector2.h.

43 {
44 x /= vec.x;
45 y /= vec.y;
46 }

◆ Divide() [2/4]

void TVector2::Divide ( const TVector2 & vec,
TFLOAT scalar )
inlineconstexpr

Definition at line 60 of file TVector2.h.

61 {
62 Set( vec );
63 Divide( scalar );
64 }
constexpr void Divide(const TVector2 &vec)
Definition TVector2.h:42

◆ Divide() [3/4]

void TVector2::Divide ( const TVector2 & vec1,
const TVector2 & vec2 )
inlineconstexpr

Definition at line 55 of file TVector2.h.

56 {
57 Set( vec1 / vec2 );
58 }

◆ Divide() [4/4]

void TVector2::Divide ( TFLOAT scalar)
inlineconstexpr

Definition at line 48 of file TVector2.h.

49 {
50 TFLOAT ratio = 1.0f / scalar;
51 x *= ratio;
52 y *= ratio;
53 }
float TFLOAT
Definition Typedefs.h:4

◆ DotProduct()

static constexpr TFLOAT TVector2::DotProduct ( const TVector2 & vec1,
const TVector2 & vec2 )
inlinestaticconstexpr

Definition at line 129 of file TVector2.h.

129{ return vec1.x * vec2.x + vec1.y * vec2.y; }

◆ IsEqual()

TBOOL TVector2::IsEqual ( const TVector2 & vec)
inline

Definition at line 115 of file TVector2.h.

115{ return TMath::Abs( x - vec.x ) < 0.00001f && TMath::Abs( y - vec.y ) < 0.00001f; }

◆ Magnitude()

TFLOAT TVector2::Magnitude ( ) const
inline

Definition at line 112 of file TVector2.h.

112{ return TMath::Sqrt( x * x + y * y ); }
TFORCEINLINE TFLOAT Sqrt(TFLOAT a_fX)
Definition TMathInline.h:84

◆ MagnitudeSq()

TFLOAT TVector2::MagnitudeSq ( ) const
inlineconstexpr

Definition at line 113 of file TVector2.h.

113{ return x * x + y * y; }

◆ Multiply() [1/4]

void TVector2::Multiply ( const TVector2 & vec)
inlineconstexpr

Definition at line 66 of file TVector2.h.

67 {
68 x *= vec.x;
69 y *= vec.y;
70 }

◆ Multiply() [2/4]

void TVector2::Multiply ( const TVector2 & vec,
TFLOAT scalar )
inlineconstexpr

Definition at line 83 of file TVector2.h.

84 {
85 Set( vec );
86 Multiply( scalar );
87 }
constexpr void Multiply(const TVector2 &vec)
Definition TVector2.h:66

◆ Multiply() [3/4]

void TVector2::Multiply ( const TVector2 & vec1,
const TVector2 & vec2 )
inlineconstexpr

Definition at line 78 of file TVector2.h.

79 {
80 Set( vec1 * vec2 );
81 }

◆ Multiply() [4/4]

void TVector2::Multiply ( TFLOAT scalar)
inlineconstexpr

Definition at line 72 of file TVector2.h.

73 {
74 x *= scalar;
75 y *= scalar;
76 }

◆ Negate()

void TVector2::Negate ( )
inlineconstexpr

Definition at line 89 of file TVector2.h.

90 {
91 Set( -x, -y );
92 }

◆ Normalize()

void TVector2::Normalize ( )
inline

Definition at line 95 of file TVector2.h.

96 {
97 if ( MagnitudeSq() != 0.0f )
98 {
99 TFLOAT magnitude = TMath::OneOverSqrt( MagnitudeSq() );
100 Set( x * magnitude, y * magnitude );
101 }
102 else
103 {
104 Set( 1.0f, 0.0f );
105 }
106 }
TFORCEINLINE TFLOAT OneOverSqrt(TFLOAT a_fX)
Definition TMathInline.h:92
constexpr TFLOAT MagnitudeSq() const
Definition TVector2.h:113

◆ operator*()

TVector2 TVector2::operator* ( const TVector2 & other) const
inlineconstexpr

Definition at line 119 of file TVector2.h.

119{ return { x * other.x, y * other.y }; }

◆ operator+()

TVector2 TVector2::operator+ ( const TVector2 & other) const
inlineconstexpr

Definition at line 117 of file TVector2.h.

117{ return { x + other.x, y + other.y }; }

◆ operator+=()

void TVector2::operator+= ( const TVector2 & other)
inlineconstexpr

Definition at line 123 of file TVector2.h.

123{ Add( other ); }
constexpr void Add(const TVector2 &vec)
Definition TVector2.h:31

◆ operator-()

TVector2 TVector2::operator- ( const TVector2 & other) const
inlineconstexpr

Definition at line 118 of file TVector2.h.

118{ return { x - other.x, y - other.y }; }

◆ operator/()

TVector2 TVector2::operator/ ( const TVector2 & other) const
inlineconstexpr

Definition at line 120 of file TVector2.h.

120{ return { x / other.x, y / other.y }; }

◆ operator/=()

void TVector2::operator/= ( const TVector2 & other)
inlineconstexpr

Definition at line 124 of file TVector2.h.

124{ Divide( other ); }

◆ operator=()

void TVector2::operator= ( const TVector2 & other)
inlineconstexpr

Definition at line 122 of file TVector2.h.

122{ Set( other ); }

◆ Set() [1/3]

void TVector2::Set ( const TVector2 & other)
inlineconstexpr

Definition at line 25 of file TVector2.h.

26 {
27 TVector2::x = other.x;
28 TVector2::y = other.y;
29 }

◆ Set() [2/3]

void TVector2::Set ( TFLOAT coords[2])
inlineconstexpr

Definition at line 19 of file TVector2.h.

20 {
21 TVector2::x = coords[ 0 ];
22 TVector2::y = coords[ 1 ];
23 }

◆ Set() [3/3]

void TVector2::Set ( TFLOAT x,
TFLOAT y )
inlineconstexpr

Definition at line 13 of file TVector2.h.

14 {
15 TVector2::x = x;
16 TVector2::y = y;
17 }

Member Data Documentation

◆ VEC_NEGX

const TVector2 TVector2::VEC_NEGX = TVector2( -1, 0 )
staticconstinit

Definition at line 135 of file TVector2.h.

◆ VEC_NEGY

const TVector2 TVector2::VEC_NEGY = TVector2( 0, -1 )
staticconstinit

Definition at line 136 of file TVector2.h.

◆ VEC_POSX

const TVector2 TVector2::VEC_POSX = TVector2( 1, 0 )
staticconstinit

Definition at line 133 of file TVector2.h.

◆ VEC_POSY

const TVector2 TVector2::VEC_POSY = TVector2( 0, 1 )
staticconstinit

Definition at line 134 of file TVector2.h.

◆ VEC_ZERO

const TVector2 TVector2::VEC_ZERO = TVector2( 0, 0 )
staticconstinit

Definition at line 132 of file TVector2.h.

◆ x

TFLOAT TVector2::x

Definition at line 139 of file TVector2.h.

◆ y

TFLOAT TVector2::y

Definition at line 139 of file TVector2.h.


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