mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Implementa Ray
This commit is contained in:
parent
3abd8d50bf
commit
61fdf43488
@ -38,6 +38,24 @@ namespace xna {
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<float> Plane::Intersects(Ray const& ray) const {
|
||||||
|
const auto num1 = (Normal.X * ray.Direction.X + Normal.Y * ray.Direction.Y + Normal.Z * ray.Direction.Z);
|
||||||
|
|
||||||
|
if (std::abs(num1) < 9.9999997473787516E-06)
|
||||||
|
return {};
|
||||||
|
|
||||||
|
const auto num2 = (Normal.X * ray.Position.X + Normal.Y * ray.Position.Y + Normal.Z * ray.Position.Z);
|
||||||
|
auto num3 = (-D - num2) / num1;
|
||||||
|
|
||||||
|
if (num3 < 0.0)
|
||||||
|
{
|
||||||
|
if (num3 < -9.9999997473787516E-06)
|
||||||
|
return {};
|
||||||
|
num3 = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
return num3;
|
||||||
|
}
|
||||||
|
|
||||||
bool BoundingFrustum::Intersects(BoundingBox const& box) {
|
bool BoundingFrustum::Intersects(BoundingBox const& box) {
|
||||||
gjk.Reset();
|
gjk.Reset();
|
||||||
|
@ -41,6 +41,7 @@ namespace xna {
|
|||||||
constexpr PlaneIntersectionType Intersects(BoundingBox const& box) const;
|
constexpr PlaneIntersectionType Intersects(BoundingBox const& box) const;
|
||||||
constexpr PlaneIntersectionType Intersects(BoundingFrustum const& frustum) const;
|
constexpr PlaneIntersectionType Intersects(BoundingFrustum const& frustum) const;
|
||||||
constexpr PlaneIntersectionType Intersects(BoundingSphere const& sphere) const;
|
constexpr PlaneIntersectionType Intersects(BoundingSphere const& sphere) const;
|
||||||
|
std::optional<float> Intersects(Ray const& ray) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct BoundingFrustum {
|
struct BoundingFrustum {
|
||||||
@ -166,6 +167,30 @@ namespace xna {
|
|||||||
struct Ray {
|
struct Ray {
|
||||||
Vector3 Position{};
|
Vector3 Position{};
|
||||||
Vector3 Direction{};
|
Vector3 Direction{};
|
||||||
|
|
||||||
|
constexpr Ray() = default;
|
||||||
|
constexpr Ray(Vector3 const& position, Vector3 const& direction):
|
||||||
|
Position(position), Direction(direction){}
|
||||||
|
|
||||||
|
constexpr bool operator==(Ray const& other) const {
|
||||||
|
return Position == other.Position && Direction == other.Direction;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<float> Intersects(BoundingBox const& box) const {
|
||||||
|
return box.Intersects(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<float> Intersects(BoundingFrustum const& frustum) const {
|
||||||
|
return frustum.Intersects(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<float> Intersects(Plane const& plane) const {
|
||||||
|
return plane.Intersects(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<float> Sphere(BoundingSphere const& sphere) const {
|
||||||
|
return sphere.Intersects(*this);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------//
|
//---------------------------------------------------------------------------------//
|
||||||
@ -570,7 +595,7 @@ namespace xna {
|
|||||||
|
|
||||||
return num < -sphere.Radius
|
return num < -sphere.Radius
|
||||||
? PlaneIntersectionType::Back : PlaneIntersectionType::Intersecting;
|
? PlaneIntersectionType::Back : PlaneIntersectionType::Intersecting;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
x
Reference in New Issue
Block a user