You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.2 KiB
71 lines
1.2 KiB
#include "Vector3.h"
|
|
#include <math.h>
|
|
|
|
Vector3 Vector3::operator+(const Vector3 & v) const
|
|
{
|
|
return Vector3(x+v.x, y+v.y, z+v.z);
|
|
}
|
|
|
|
Vector3 Vector3::operator-(const Vector3 & v) const
|
|
{
|
|
return Vector3(x - v.x, y - v.y, z - v.z);
|
|
}
|
|
|
|
Vector3 Vector3::operator*(const Vector3 & v) const
|
|
{
|
|
return Vector3(x*v.x, y*v.y, z*v.z);
|
|
}
|
|
|
|
void Vector3::operator*=(float scale)
|
|
{
|
|
x *= scale;
|
|
y *= scale;
|
|
z *= scale;
|
|
}
|
|
|
|
Vector3 Vector3::operator/(float scale) const
|
|
{
|
|
return Vector3(x/scale, y/scale, z/scale);
|
|
}
|
|
|
|
void Vector3::operator/=(float scale)
|
|
{
|
|
x /= scale;
|
|
y /= scale;
|
|
z /= scale;
|
|
}
|
|
|
|
void Vector3::operator=(const Vector3 & v)
|
|
{
|
|
x = v.x;
|
|
y = v.y;
|
|
z = v.z;
|
|
}
|
|
|
|
void Vector3::Normalize()
|
|
{
|
|
float magnitude = Magnitude();
|
|
x /= magnitude;
|
|
y /= magnitude;
|
|
z /= magnitude;
|
|
}
|
|
|
|
float Vector3::Magnitude()
|
|
{
|
|
return sqrtf(x*x + y*y + z*z);
|
|
}
|
|
|
|
Vector3 operator*(float f, const Vector3 & v)
|
|
{
|
|
return Vector3(f*v.x, f*v.y, f*v.z);
|
|
}
|
|
|
|
float Dot(const Vector3 & l, const Vector3 & r)
|
|
{
|
|
return l.x * r.x + l.y * r.y + l.z * r.z;
|
|
}
|
|
|
|
Vector3 Cross(const Vector3 & l, const Vector3 & r)
|
|
{
|
|
return Vector3(l.y*r.z - l.z*r.y, l.z*r.x - l.x*r.z, l.x*r.y - l.y*r.x);
|
|
}
|