
Game Physics Cookbook
By :

To Raycast against a plane we must find a point which is on the plane being cast against and also along the normal of the ray. We know a point is on the surface of a plane if it satisfies the plane equation. If no point along the ray satisfies the plane equation, the ray and plane do not intersect:
We are going to implement a function that performs a Raycast against a plane. This function will return t, the time along the ray at which it intersects the plane. If there is no intersection, the value of t will be negative.
Follow these steps to implement raycasting against a plane:
Declare the Raycast
function in Geometry3D.h
:
float Raycast(const Plane& plane, const Ray& ray);
Implement the Raycast
function in Geometry3D.cpp
:
float Raycast(const Plane& plane, const Ray& ray) { float nd = Dot(ray.direction, plane.normal); float pn = Dot(ray.origin, plane.normal);
The nd
variable must be less than zero for the ray to intersect the plane....