1
0
Fork 0
2018-soft-3d-renderer/include/point.h

75 lines
974 B
C

#ifndef POINT_H
#include "vec.h"
// 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;
};
};
};
// OPERATORS
// p / f
inline Point operator/(Point p, float f)
{
Point result;
float inverse = 1.0f / f;
result.x = p.x * inverse;
result.y = p.y * inverse;
result.z = p.z * inverse;
return result;
}
// v /= f
inline Point &operator/=(Point &p, float f)
{
p = p / f;
return p;
}
// p1 - p2
inline Vector operator-(Point p1, Point p2)
{
Vector result;
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;
return result;
}
#define POINT_H
#endif