89 lines
1000 B
C++
89 lines
1000 B
C++
|
#pragma once
|
||
|
|
||
|
#include "Matrix.hpp"
|
||
|
#include "Vec.hpp"
|
||
|
|
||
|
|
||
|
class Point
|
||
|
{
|
||
|
public:
|
||
|
Point()
|
||
|
: x(0), y(0), z(0), w(1)
|
||
|
{}
|
||
|
|
||
|
Point(float x, float y, float z)
|
||
|
: x(x), y(y), z(z), w(1)
|
||
|
{}
|
||
|
|
||
|
Point operator-() const
|
||
|
{
|
||
|
return Point(
|
||
|
-x,
|
||
|
-y,
|
||
|
-z);
|
||
|
}
|
||
|
|
||
|
Vector operator-(Point const& rhs) const
|
||
|
{
|
||
|
return Vector(
|
||
|
x - rhs.x,
|
||
|
y - rhs.y,
|
||
|
z - rhs.z);
|
||
|
}
|
||
|
|
||
|
Point operator*(Matrix const& rhs)
|
||
|
{
|
||
|
Point result;
|
||
|
|
||
|
for (int col = 0; col < 4; ++col)
|
||
|
{
|
||
|
float sum = 0.0;
|
||
|
|
||
|
for (int row = 0; row < 4; ++row)
|
||
|
{
|
||
|
sum += e[row] * rhs.e[row][col];
|
||
|
}
|
||
|
|
||
|
result.e[col] = sum;
|
||
|
}
|
||
|
|
||
|
return result;
|
||
|
}
|
||
|
|
||
|
Point& operator*=(Matrix const& rhs)
|
||
|
{
|
||
|
*this = *this * rhs;
|
||
|
|
||
|
return *this;
|
||
|
}
|
||
|
|
||
|
Point operator/(float rhs) const
|
||
|
{
|
||
|
float inverse = 1.0f / rhs;
|
||
|
|
||
|
return Point(
|
||
|
x * inverse,
|
||
|
y * inverse,
|
||
|
z * inverse);
|
||
|
}
|
||
|
|
||
|
Point& operator/=(float rhs)
|
||
|
{
|
||
|
x /= rhs;
|
||
|
y /= rhs;
|
||
|
z /= rhs;
|
||
|
|
||
|
return *this;
|
||
|
}
|
||
|
|
||
|
union
|
||
|
{
|
||
|
float e[4];
|
||
|
|
||
|
struct
|
||
|
{
|
||
|
float x, y, z, w;
|
||
|
};
|
||
|
};
|
||
|
};
|