60 lines
2.1 KiB
C++
60 lines
2.1 KiB
C++
#ifndef DELTA_MATH
|
|
#define DELTA_MATH
|
|
|
|
class DeltaVector2 {
|
|
public:
|
|
float x, y;
|
|
DeltaVector2(float xval, float yval);
|
|
DeltaVector2();
|
|
DeltaVector2 operator+(const DeltaVector2& other) const;
|
|
DeltaVector2 operator-(const DeltaVector2& other) const;
|
|
DeltaVector2 operator*(float a) const;
|
|
DeltaVector2& operator+=(const DeltaVector2& other);
|
|
DeltaVector2& operator-=(const DeltaVector2& other);
|
|
float distanceToVector(const DeltaVector2& vec) const;
|
|
float distanceToPos(float x, float y) const;
|
|
float dotProduct(const DeltaVector2& vec) const;
|
|
float angleTo(const DeltaVector2& vec) const;
|
|
float length() const;
|
|
};
|
|
|
|
class DeltaVector3 {
|
|
public:
|
|
float x, y, z;
|
|
DeltaVector3(float xval, float yval, float zval);
|
|
DeltaVector3();
|
|
DeltaVector3 operator+(const DeltaVector3& other) const;
|
|
DeltaVector3 operator-(const DeltaVector3& other) const;
|
|
DeltaVector3 operator*(float a) const;
|
|
DeltaVector3& operator+=(const DeltaVector3& other);
|
|
DeltaVector3& operator-=(const DeltaVector3& other);
|
|
float distanceToVector(const DeltaVector3 &vec) const;
|
|
float distanceToPos(float x, float y) const;
|
|
float dotProduct(const DeltaVector3 &vec) const;
|
|
float angleTo(const DeltaVector3 &vec) const;
|
|
float length() const;
|
|
};
|
|
|
|
float getDeterminant(const DeltaVector2 &pointA, const DeltaVector2 &pointB, const DeltaVector2 &candidate);
|
|
DeltaVector2 barycentricToScreen(const DeltaVector3 &baryPoint, const DeltaVector2 &a, const DeltaVector2 &b, const DeltaVector2 &c);
|
|
DeltaVector3 intersect(DeltaVector3 a, DeltaVector3 b, float nearZ);
|
|
|
|
struct DeltaTriangle {
|
|
DeltaVector3 a, b, c;
|
|
};
|
|
|
|
struct DeltaTriangle2D {
|
|
DeltaVector2 a, b, c;
|
|
};
|
|
|
|
|
|
struct DeltaRenderTriangle {
|
|
DeltaVector3 a, b, c;
|
|
DeltaVector2 uva, uvb, uvc;
|
|
};
|
|
|
|
int clipTriangleAgainstNearPlane(float nearY, const DeltaRenderTriangle &in, DeltaRenderTriangle &out1, DeltaRenderTriangle &out2);
|
|
|
|
uint32_t SDLColorToUint32(SDL_Color color);
|
|
|
|
#endif |