1
0
Fork 0

Add Length function to Vector

master
Austin Morlan 4 years ago
parent f1733b42a5
commit e29ad8b418
Signed by: austin
GPG Key ID: FD6B27654AF5E348
  1. 29
      include/vec.h

@ -12,10 +12,10 @@ struct Vector
inline void Normalize(void)
{
float length = sqrtf(x*x + y*y + z*z);
float length = Length();
// zero length
if (length < EPSILON_E3)
if (length == 0.0f)
{
x = 0.0f;
y = 0.0f;
@ -31,6 +31,19 @@ struct Vector
}
}
inline float Length(void)
{
float result = sqrtf(x*x + y*y + z*z);
// zero length
if (result < EPSILON_E3)
{
result = 0.0f;
}
return result;
}
inline static float Dot(Vector v1, Vector v2)
{
float result;
@ -96,6 +109,18 @@ inline Vector &operator+=(Vector &v1, Vector v2)
return v1;
}
// f * v
inline Vector operator*(float f, Vector &v)
{
Vector result;
result.x = v.x * f;
result.y = v.y * f;
result.z = v.z * f;
return result;
}
// v / f
inline Vector operator/(Vector v, float f)
{

Loading…
Cancel
Save