Assignment 5

Ray-Sphere Intersection

Your browser does not support HTML5
// Compute the ray-sphere intersection. // In case of intersection, overwrite the ray's origin with the intersection point AND set the // Arguments: // ray - object with attributes: // [in, out] origin - origin of the ray (vec3) // [in] direction - direction of the ray (vec3) // [in] center - center of the sphere (vec3) // [in] radius - radius of the sphere (float) // Returns: // boolean - true if the ray intersects the sphere, false otherwise ray_sphere_intersect = function(ray, sphere_center, sphere_radius){ // [TODO] Compute the coefficients of the quadratic equation // [TODO] Compute the discriminant // [TODO] Compute the solutions t0 and t1 // [TODO] If t0 is behind the ray, swap t0 and t1 // [TODO] If t0 is negative, let's use t1 instead // [TODO] If both t0 and t1 are negative, the sphere is behind the ray // Set output variables ray.back = false; ray.origin = vec3.create(); return true; };