code refactoring
This commit is contained in:
@@ -18,32 +18,33 @@ namespace OpenVulkano::Scene
|
||||
Math::Vector3f point;
|
||||
Math::Vector3f normal;
|
||||
float distance;
|
||||
bool operator==(const RayHit& other) const
|
||||
{
|
||||
return point == other.point && normal == other.normal && distance == other.distance;
|
||||
}
|
||||
bool operator!=(const RayHit& other) const { return !((*this) == other); }
|
||||
bool operator==(const RayHit& other) const = default;
|
||||
bool operator!=(const RayHit& other) const = default;
|
||||
};
|
||||
|
||||
class Ray
|
||||
{
|
||||
public:
|
||||
Ray() : m_origin(0), m_dir(0) {}
|
||||
Ray() = default;
|
||||
Ray(const Math::Vector3f& origin, const Math::Vector3f& dir)
|
||||
: m_origin(origin), m_dir(Math::Utils::normalize(dir))
|
||||
{
|
||||
}
|
||||
void SetPosition(const Math::Vector3f& origin) { m_origin = origin; }
|
||||
void SetDir(const Math::Vector3f& dir) { m_dir = dir; }
|
||||
std::optional<RayHit> IntersectSphere(const Math::Vector3f& center, float radius) const;
|
||||
[[nodiscard]] std::optional<RayHit> IntersectSphere(const Math::Vector3f& center, float radius) const;
|
||||
int IntersectSphere(const Math::Vector3f& center, float radius, RayHit& p1, RayHit& p2) const;
|
||||
std::optional<RayHit> IntersectTriangle(const Math::Vector3f& v0, const Math::Vector3f& v1,
|
||||
[[nodiscard]] std::optional<RayHit> IntersectTriangle(const Math::Vector3f& v0, const Math::Vector3f& v1,
|
||||
const Math::Vector3f& v2) const;
|
||||
std::optional<RayHit> IntersectQuad(const Math::Vector3f& v0, const Math::Vector3f& v1,
|
||||
[[nodiscard]] std::optional<RayHit> IntersectTriangle(const Math::Vector3f& v0, const Math::Vector3f& v1,
|
||||
const Math::Vector3f& v2, const Math::Vector3f& n0,
|
||||
const Math::Vector3f& n1, const Math::Vector3f& n2) const;
|
||||
[[nodiscard]] std::optional<RayHit> IntersectQuad(const Math::Vector3f& v0, const Math::Vector3f& v1,
|
||||
const Math::Vector3f& v2, const Math::Vector3f& v3) const;
|
||||
std::optional<RayHit> IntersectAABB(const Math::AABB& bbox) const;
|
||||
[[nodiscard]] std::optional<RayHit> IntersectAABB(const Math::AABB& bbox) const;
|
||||
int IntersectAABB(const Math::AABB& bbox, RayHit& p1, RayHit& p2) const;
|
||||
std::optional<RayHit> IntersectPlane(const Math::Vector3f& pOrigin, const Math::Vector3f& pNorm) const;
|
||||
[[nodiscard]] std::optional<RayHit> IntersectPlane(const Math::Vector3f& pOrigin,
|
||||
const Math::Vector3f& pNorm) const;
|
||||
[[nodiscard]] Math::Vector3f& GetOrigin() { return m_origin; }
|
||||
[[nodiscard]] Math::Vector3f& GetDir() { return m_dir; }
|
||||
[[nodiscard]] const Math::Vector3f& GetOrigin() const { return m_origin; }
|
||||
@@ -51,5 +52,6 @@ namespace OpenVulkano::Scene
|
||||
private:
|
||||
Math::Vector3f m_origin;
|
||||
Math::Vector3f m_dir;
|
||||
mutable Math::Vector2f m_baryPos;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user