2018-03-22 23:01:55 +01:00
|
|
|
#ifndef _VEC3_H
|
|
|
|
#define _VEC3_H
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include "matrix4.h"
|
|
|
|
|
|
|
|
struct vec3
|
|
|
|
{
|
|
|
|
float x, y, z;
|
|
|
|
vec3()
|
|
|
|
{
|
|
|
|
x = 0.0f;
|
|
|
|
y = 0.0f;
|
|
|
|
z = 0.0f;
|
|
|
|
}
|
|
|
|
vec3(float x, float y, float z)
|
|
|
|
{
|
|
|
|
this->x = x;
|
|
|
|
this->y = y;
|
|
|
|
this->z = z;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
static vec3 operator *(const vec3& lhs, const matrix4& rhs)
|
|
|
|
{
|
|
|
|
vec3 ret;
|
|
|
|
ret.x = rhs(0, 0) * lhs.x + rhs(0, 1) * lhs.y + rhs(0, 2) * lhs.z;
|
|
|
|
ret.y = rhs(1, 0) * lhs.x + rhs(1, 1) * lhs.y + rhs(1, 2) * lhs.z;
|
|
|
|
ret.z = rhs(2, 0) * lhs.x + rhs(2, 1) * lhs.y + rhs(2, 2) * lhs.z;
|
|
|
|
return ret;
|
|
|
|
};
|
2018-07-26 19:11:08 +01:00
|
|
|
static vec3 operator *(const vec3& lhs, float scalar)
|
|
|
|
{
|
|
|
|
return {lhs.x * scalar, lhs.y * scalar, lhs.z * scalar};
|
|
|
|
}
|
|
|
|
static vec3 operator +(const vec3& lhs, const vec3& rhs)
|
|
|
|
{
|
|
|
|
return {lhs.x + rhs.x, lhs.y + rhs.y, lhs.z + rhs.z};
|
|
|
|
}
|
|
|
|
static vec3 operator -(const vec3& lhs, const vec3& rhs)
|
|
|
|
{
|
|
|
|
return {lhs.x - rhs.x, lhs.y - rhs.y, lhs.z - rhs.z};
|
|
|
|
}
|
|
|
|
static vec3 operator /(const vec3& lhs, const vec3& rhs)
|
|
|
|
{
|
|
|
|
return {lhs.x / rhs.x, lhs.y / rhs.y, lhs.z / rhs.z};
|
|
|
|
}
|
|
|
|
static vec3 operator /(const vec3& lhs, float scalar)
|
|
|
|
{
|
|
|
|
return {lhs.x / scalar, lhs.y / scalar, lhs.z / scalar};
|
|
|
|
}
|
2018-03-22 23:01:55 +01:00
|
|
|
#endif
|