CSEngine
Loading...
Searching...
No Matches
CSE::Vector3< T > Class Template Reference

Public Member Functions

 Vector3 (T x, T y, T z)
 
void Set (T x, T y, T z)
 
void Normalize ()
 
Vector3 Normalized () const
 
Vector3 Cross (const Vector3 &v) const
 
Dot (const Vector3 &v) const
 
Vector3 operator+ (const Vector3 &v) const
 
void operator+= (const Vector3 &v)
 
void operator-= (const Vector3 &v)
 
void operator/= (T s)
 
Vector3 operator- (const Vector3 &v) const
 
Vector3 operator- () const
 
Vector3 operator* (T s) const
 
Vector3 operator/ (T s) const
 
bool operator== (const Vector3 &v) const
 
Vector3 Lerp (float t, const Vector3 &v) const
 
const T * Pointer () const
 
template<typename P >
P * Write (P *pData)
 

Static Public Member Functions

static Vector3 Lerp (float t, const Vector3 &a, Vector3 &b)
 
static float Distance (const Vector3 &a, const Vector3 &b)
 

Public Attributes

x
 
y
 
z
 

Static Public Attributes

static Vector3< T > Zero = Vector3<T>{0, 0, 0}
 

Detailed Description

template<typename T>
class CSE::Vector3< T >

Definition at line 118 of file Vector.h.

Constructor & Destructor Documentation

◆ Vector3() [1/2]

template<typename T >
CSE::Vector3< T >::Vector3 ( )
inline

Definition at line 123 of file Vector.h.

123: x(0.0f), y(0.0f), z(0.0f) {}

◆ Vector3() [2/2]

template<typename T >
CSE::Vector3< T >::Vector3 ( T x,
T y,
T z )
inline

Definition at line 125 of file Vector.h.

125: x(x), y(y), z(z) {}

◆ ~Vector3()

template<typename T >
CSE::Vector3< T >::~Vector3 ( )
inline

Definition at line 127 of file Vector.h.

127{}

Member Function Documentation

◆ Cross()

template<typename T >
Vector3 CSE::Vector3< T >::Cross ( const Vector3< T > & v) const
inline

Definition at line 148 of file Vector.h.

148 {
149 return Vector3(y * v.z - z * v.y,
150 z * v.x - x * v.z,
151 x * v.y - y * v.x);
152 }

◆ Distance()

template<typename T >
static float CSE::Vector3< T >::Distance ( const Vector3< T > & a,
const Vector3< T > & b )
inlinestatic

Definition at line 212 of file Vector.h.

212 {
213 return sqrtf(powf(a.x - b.x, 2) + powf(a.y - b.y, 2) + powf(a.z - b.z, 2));
214 }

◆ Dot()

template<typename T >
T CSE::Vector3< T >::Dot ( const Vector3< T > & v) const
inline

Definition at line 154 of file Vector.h.

154 {
155 return x * v.x + y * v.y + z * v.z;
156 }

◆ Lerp() [1/2]

template<typename T >
static Vector3 CSE::Vector3< T >::Lerp ( float t,
const Vector3< T > & a,
Vector3< T > & b )
inlinestatic

Definition at line 206 of file Vector.h.

206 {
207 return Vector3(a.x * (1 - t) + b.x * t,
208 a.y * (1 - t) + b.y * t,
209 a.z * (1 - t) + b.z * t);
210 }

◆ Lerp() [2/2]

template<typename T >
Vector3 CSE::Vector3< T >::Lerp ( float t,
const Vector3< T > & v ) const
inline

Definition at line 200 of file Vector.h.

200 {
201 return Vector3(x * (1 - t) + v.x * t,
202 y * (1 - t) + v.y * t,
203 z * (1 - t) + v.z * t);
204 }

◆ Normalize()

template<typename T >
void CSE::Vector3< T >::Normalize ( )
inline

Definition at line 135 of file Vector.h.

135 {
136 float s = 1.0f / std::sqrt(x * x + y * y + z * z);
137 x *= s;
138 y *= s;
139 z *= s;
140 }

◆ Normalized()

template<typename T >
Vector3 CSE::Vector3< T >::Normalized ( ) const
inline

Definition at line 142 of file Vector.h.

142 {
143 Vector3 v = *this;
144 v.Normalize();
145 return v;
146 }

◆ operator*()

template<typename T >
Vector3 CSE::Vector3< T >::operator* ( T s) const
inline

Definition at line 188 of file Vector.h.

188 {
189 return Vector3(x * s, y * s, z * s);
190 }

◆ operator+()

template<typename T >
Vector3 CSE::Vector3< T >::operator+ ( const Vector3< T > & v) const
inline

Definition at line 158 of file Vector.h.

158 {
159 return Vector3(x + v.x, y + v.y, z + v.z);
160 }

◆ operator+=()

template<typename T >
void CSE::Vector3< T >::operator+= ( const Vector3< T > & v)
inline

Definition at line 162 of file Vector.h.

162 {
163 x += v.x;
164 y += v.y;
165 z += v.z;
166 }

◆ operator-() [1/2]

template<typename T >
Vector3 CSE::Vector3< T >::operator- ( ) const
inline

Definition at line 184 of file Vector.h.

184 {
185 return Vector3(-x, -y, -z);
186 }

◆ operator-() [2/2]

template<typename T >
Vector3 CSE::Vector3< T >::operator- ( const Vector3< T > & v) const
inline

Definition at line 180 of file Vector.h.

180 {
181 return Vector3(x - v.x, y - v.y, z - v.z);
182 }

◆ operator-=()

template<typename T >
void CSE::Vector3< T >::operator-= ( const Vector3< T > & v)
inline

Definition at line 168 of file Vector.h.

168 {
169 x -= v.x;
170 y -= v.y;
171 z -= v.z;
172 }

◆ operator/()

template<typename T >
Vector3 CSE::Vector3< T >::operator/ ( T s) const
inline

Definition at line 192 of file Vector.h.

192 {
193 return Vector3(x / s, y / s, z / s);
194 }

◆ operator/=()

template<typename T >
void CSE::Vector3< T >::operator/= ( T s)
inline

Definition at line 174 of file Vector.h.

174 {
175 x /= s;
176 y /= s;
177 z /= s;
178 }

◆ operator==()

template<typename T >
bool CSE::Vector3< T >::operator== ( const Vector3< T > & v) const
inline

Definition at line 196 of file Vector.h.

196 {
197 return x == v.x && y == v.y && z == v.z;
198 }

◆ Pointer()

template<typename T >
const T * CSE::Vector3< T >::Pointer ( ) const
inline

Definition at line 216 of file Vector.h.

216 {
217 return &x;
218 }

◆ Set()

template<typename T >
void CSE::Vector3< T >::Set ( T x,
T y,
T z )
inline

Definition at line 129 of file Vector.h.

129 {
130 this->x = x;
131 this->y = y;
132 this->z = z;
133 }

◆ Write()

template<typename T >
template<typename P >
P * CSE::Vector3< T >::Write ( P * pData)
inline

Definition at line 221 of file Vector.h.

221 {
222 Vector3<T>* pVector = (Vector3<T>*) pData;
223 *pVector++ = *this;
224 return (P*) pVector;
225 }

Member Data Documentation

◆ x

template<typename T >
T CSE::Vector3< T >::x

Definition at line 227 of file Vector.h.

◆ y

template<typename T >
T CSE::Vector3< T >::y

Definition at line 228 of file Vector.h.

◆ z

template<typename T >
T CSE::Vector3< T >::z

Definition at line 229 of file Vector.h.

◆ Zero

template<class T >
Vector3< T > CSE::Vector3< T >::Zero = Vector3<T>{0, 0, 0}
static

Definition at line 120 of file Vector.h.


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