Ray

A ray is represented by a point in space and a direction. The ray extends from the point to infinity in the given direction. For our purposes, the direction of a ray is always assumed to be normalized:

Ray

Getting ready

We are going to declare a new Ray structure. This new structure will consist of a Point representing the origin of the ray and a vec3 representing the direction of the ray. It is assumed that the direction vector will always be normalized. We will also implement a helper function to create a ray given two points.

How to do it…

Follow these steps to implement a 3D ray:

  1. Declare the new Ray structure in Geometry3D.h:
    typedef struct Ray { ...

Get Game Physics Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.