You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

147 lines
2.6 KiB

1 year ago
#pragma once
#ifdef MY_LIB_SHARED_BUILD
#ifdef _WIN32
#ifdef MY_LIB_EXPORTS
#define LIB_API __declspec(dllexport)
#else
#define LIB_API __declspec(dllimport)
#endif // MY_LIB_EXPORTS
#else
#define LIB_API
#endif // _WIN32
#else
#define LIB_API
#endif // MY_LIB_SHARED_BUILD
1 year ago
#include <numeric>
#include <limits>
#include <cmath>
#include <vector>
template <typename T>
class Vec3
{
1 year ago
public:
T a, b, c;
Vec3(T x = T(), T y = T(), T z = T()) : a(x), b(y), c(z) {} // �޸ĺ�����
1 year ago
T operator[](int i) const
{
if (i == 0)
{
1 year ago
return a;
}
else if (i == 1)
{
1 year ago
return b;
}
else if (i == 2)
{
1 year ago
return c;
}
return a;
}
T &operator[](int i)
{
if (i == 0)
{
1 year ago
return a;
}
else if (i == 1)
{
1 year ago
return b;
}
else if (i == 2)
{
1 year ago
return c;
}
return a;
}
Vec3 operator+(const Vec3 &other) const
{
1 year ago
return Vec3(a + other.a, b + other.b, c + other.c);
}
Vec3 operator/(const float w) const
{
return Vec3(a / w, b / w, c / w);
}
Vec3 operator-(const Vec3 &other) const
{
return Vec3(a - other.a, b - other.b, c - other.c);
}
Vec3 operator*(const float &w) const
{
1 year ago
return Vec3(a * w, b * w, c * w);
}
1 year ago
float length() const
{
1 year ago
return sqrt(a * a + b * b + c * c);
}
Vec3 norm() const
{
1 year ago
return *this / length();
}
Vec3 cross(const Vec3 &other) const
{
return Vec3(b * other.c - c * other.b, c * other.a - a * other.c, a * other.b - b * other.a);
1 year ago
}
float dot(const Vec3 &other) const
{
1 year ago
return a * other.a + b * other.b + c * other.c;
}
};
typedef Vec3<float> Vec3f;
typedef Vec3<unsigned int> Vec3u;
extern "C" class LIB_API Mesh
{
1 year ago
public:
std::vector<Vec3f> vertices;
1 year ago
std::vector<Vec3u> indices;
};
extern "C" class LIB_API AABB
{
1 year ago
public:
Vec3f min, max;
AABB();
1 year ago
};
extern "C" class LIB_API LineSegment
{
1 year ago
public:
Vec3f start;
Vec3f end;
float length;
Vec3f dir;
1 year ago
LineSegment(const Vec3f &s, const Vec3f &e);
1 year ago
float getLength() const;
1 year ago
Vec3f getDir() const;
1 year ago
void calculate();
1 year ago
};
extern "C" struct LIB_API FaceCenterComparator
{
const std::vector<Vec3f> &faceCenters; // �滻 YourVectorType Ϊ������������
int longAxis;
FaceCenterComparator(const std::vector<Vec3f> &centers, int axis);
bool operator()(const size_t &a, const size_t &b) const;
1 year ago
};