2018-09-05 02:50:27 +00:00
|
|
|
#ifndef POINT_H
|
|
|
|
|
2018-09-06 02:26:54 +00:00
|
|
|
#include "vec.h"
|
|
|
|
|
2018-09-05 02:50:27 +00:00
|
|
|
|
|
|
|
// STRUCTURE
|
|
|
|
struct Point
|
|
|
|
{
|
|
|
|
inline Point(void) : x(0), y(0), z(0), w(1) {}
|
|
|
|
inline Point(float x, float y, float z) : x(x), y(y), z(z), w(1) {}
|
|
|
|
|
|
|
|
union
|
|
|
|
{
|
|
|
|
float e[4];
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
float x, y, z, w;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-09-06 01:48:27 +00:00
|
|
|
// OPERATORS
|
2018-09-15 01:46:30 +00:00
|
|
|
// p / f
|
|
|
|
inline Point operator/(Point p, float f)
|
2018-09-06 01:48:27 +00:00
|
|
|
{
|
|
|
|
Point result;
|
|
|
|
|
|
|
|
float inverse = 1.0f / f;
|
|
|
|
|
2018-09-15 01:46:30 +00:00
|
|
|
result.x = p.x * inverse;
|
|
|
|
result.y = p.y * inverse;
|
|
|
|
result.z = p.z * inverse;
|
2018-09-06 01:48:27 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-09-07 01:32:15 +00:00
|
|
|
// v /= f
|
2018-09-15 01:46:30 +00:00
|
|
|
inline Point &operator/=(Point &p, float f)
|
2018-09-07 01:32:15 +00:00
|
|
|
{
|
2018-09-15 01:46:30 +00:00
|
|
|
p = p / f;
|
2018-09-07 01:32:15 +00:00
|
|
|
|
2018-09-15 01:46:30 +00:00
|
|
|
return p;
|
2018-09-07 01:32:15 +00:00
|
|
|
}
|
|
|
|
|
2018-09-15 01:46:30 +00:00
|
|
|
// p1 - p2
|
|
|
|
inline Vector operator-(Point p1, Point p2)
|
2018-09-06 02:26:54 +00:00
|
|
|
{
|
|
|
|
Vector result;
|
|
|
|
|
2018-09-15 01:46:30 +00:00
|
|
|
result.x = p1.x - p2.x;
|
|
|
|
result.y = p1.y - p2.y;
|
|
|
|
result.z = p1.z - p2.z;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -p
|
|
|
|
inline Point operator-(Point p)
|
|
|
|
{
|
|
|
|
Point result;
|
|
|
|
|
|
|
|
result.x = -p.x;
|
|
|
|
result.y = -p.y;
|
|
|
|
result.z = -p.z;
|
2018-09-06 02:26:54 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-09-06 01:48:27 +00:00
|
|
|
|
2018-09-05 02:50:27 +00:00
|
|
|
#define POINT_H
|
|
|
|
#endif
|
|
|
|
|