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

75 lines
974 B
C
Raw Normal View History

2018-09-05 02:50:27 +00:00
#ifndef POINT_H
#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;
};
};
};
// OPERATORS
2018-09-15 01:46:30 +00:00
// p / f
inline Point operator/(Point p, float f)
{
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;
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)
{
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;
return result;
}
2018-09-05 02:50:27 +00:00
#define POINT_H
#endif