26 #include <Eigen/Dense> 45 inline bool raySphereIntersection (
const Eigen::Vector3f& ray_direction,
const Eigen::Vector3f& ray_origin,
const Eigen::Vector3f& sphere_center,
float sphere_radius, Eigen::Vector3f& intersection)
48 Eigen::Vector3f dir = ray_origin - sphere_center;
49 float b = ray_direction.dot(dir);
50 float c = dir.dot(dir) - sphere_radius*sphere_radius;
53 intersection = Eigen::Vector3f::Zero();
58 float t = min(-b-e, -b+e);
66 intersection = ray_origin + ray_direction*t;
84 inline bool rayPlaneIntersection (
const Eigen::Vector3f& ray_direction,
const Eigen::Vector3f& ray_origin,
const Eigen::Vector3f& plane_point,
const Eigen::Vector3f& plane_normal, Eigen::Vector3f& intersection)
86 float t = (plane_point - ray_origin).dot(plane_normal) / ray_direction.dot(plane_normal);
91 intersection = ray_origin + ray_direction * t;
110 inline bool rayRingIntersection (
const Eigen::Vector3f& ray_direction,
const Eigen::Vector3f& ray_origin,
const Eigen::Vector3f& plane_point,
const Eigen::Vector3f& plane_normal,
float inner_radius,
float outer_radius, Eigen::Vector3f& intersection)
115 float dist = (p - plane_point).norm();
116 if (dist >= inner_radius && dist <= outer_radius)
136 inline Eigen::Vector3f
rayDirection(
const Eigen::Vector2f& pixel,
const Eigen::Vector2i& viewport_size,
const Eigen::Matrix4f& projection_matrix,
const Eigen::Affine3f& view_matrix)
140 Eigen::Vector4f screen_pos = Eigen::Vector4f(2.0* pixel[0] / (
float)viewport_size[0] - 1.0, 1.0 - 2.0*pixel[1] / (
float)viewport_size[1], -1.0, 1.0);
143 Eigen::Vector4f eye_ray = projection_matrix.inverse() * screen_pos;
148 eye_ray = view_matrix.inverse() * eye_ray;
151 Eigen::Vector3f ray = (eye_ray.head(3)).normalized();
bool raySphereIntersection(const Eigen::Vector3f &ray_direction, const Eigen::Vector3f &ray_origin, const Eigen::Vector3f &sphere_center, float sphere_radius, Eigen::Vector3f &intersection)
Computes the intersection point between a ray and a sphere.
Definition: math.hpp:45
Definition: bufferobject.hpp:34
bool rayPlaneIntersection(const Eigen::Vector3f &ray_direction, const Eigen::Vector3f &ray_origin, const Eigen::Vector3f &plane_point, const Eigen::Vector3f &plane_normal, Eigen::Vector3f &intersection)
Computes the intersection between a ray and a plane.
Definition: math.hpp:84
Eigen::Vector3f rayDirection(const Eigen::Vector2f &pixel, const Eigen::Vector2i &viewport_size, const Eigen::Matrix4f &projection_matrix, const Eigen::Affine3f &view_matrix)
Computes the ray direction given a pixel position and camera matrices.
Definition: math.hpp:136
bool rayRingIntersection(const Eigen::Vector3f &ray_direction, const Eigen::Vector3f &ray_origin, const Eigen::Vector3f &plane_point, const Eigen::Vector3f &plane_normal, float inner_radius, float outer_radius, Eigen::Vector3f &intersection)
Computes the intersection between a ray and a ring in 3D space.
Definition: math.hpp:110