Ray.pkg 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. $#include "Ray.h"
  2. /// Infinite straight line in three-dimensional space.
  3. class Ray
  4. {
  5. public:
  6. /// Construct undefined.
  7. Ray();
  8. /// Construct from origin and direction. The direction must be normalized.
  9. Ray(const Vector3& origin, const Vector3& direction);
  10. /// Copy-construct from another ray.
  11. Ray(const Ray& ray);
  12. /// Check for equality with another ray.
  13. bool operator == (const Ray& rhs) const;
  14. /// Define from origin and direction. The direction will be normalized.
  15. void Define(const Vector3& origin, const Vector3& direction);
  16. /// Project a point on the ray.
  17. Vector3 Project(const Vector3& point) const;
  18. /// Return distance of a point from the ray
  19. float Distance(const Vector3& point) const;
  20. /// Return closest point to another ray.
  21. Vector3 ClosestPoint(const Ray& ray) const;
  22. /// Return hit distance to a plane, or infinity if no hit.
  23. float HitDistance(const Plane& plane) const;
  24. /// Return hit distance to a bounding box, or infinity if no hit.
  25. float HitDistance(const BoundingBox& box) const;
  26. /// Return hit distance to a frustum, or infinity if no hit. If solidInside parameter is true (default) rays originating from inside return zero distance, otherwise the distance to the closest plane.
  27. float HitDistance(const Frustum& frustum, bool solidInside = true) const;
  28. /// Return hit distance to a sphere, or infinity if no hit.
  29. float HitDistance(const Sphere& sphere) const;
  30. /// Return hit distance to a triangle, or infinity if no hit.
  31. float HitDistance(const Vector3& v0, const Vector3& v1, const Vector3& v2) const;
  32. /// Return hit distance to non-indexed geometry data, or infinity if no hit.
  33. float HitDistance(const void* vertexData, unsigned vertexSize, unsigned vertexStart, unsigned vertexCount) const;
  34. /// Return hit distance to indexed geometry data, or infinity if no hit.
  35. float HitDistance(const void* vertexData, unsigned vertexSize, const void* indexData, unsigned indexSize, unsigned indexStart, unsigned indexCount) const;
  36. /// Return whether ray is inside non-indexed geometry.
  37. bool InsideGeometry(const void* vertexData, unsigned vertexSize, unsigned vertexStart, unsigned vertexCount) const;
  38. /// Return whether ray is inside indexed geometry.
  39. bool InsideGeometry(const void* vertexData, unsigned vertexSize, const void* indexData, unsigned indexSize, unsigned indexStart, unsigned indexCount) const;
  40. /// Ray origin.
  41. Vector3 origin_ @ origin;
  42. /// Ray direction.
  43. Vector3 direction_ @ direction;
  44. };