Raycast sphere
In order to solve collisions against constraints, we will need to determine some extra information about rays being cast into the world. In our current implementation, each raycast returns a floating point t-value. From this value we can infer if the ray hit anything and if it did at what point the intersection happened. We still need this t-value, but we also need to know the normal of the surface that the ray hit.
Getting ready
In this section, we will start modifying the Raycast
function to return more data. To achieve this, we first declare a new RaycastResult
data structure. We will also implement a helper method to reset the new RaycastResult
data structure.
How to do it…
Follow these steps to update the RaycastSphere function in a way that it returns more useful data:
- Declare the
RaycastResult
structure andResetRaycastResult
function inGeometry3D.h
:typedef struct RaycastResult { vec3 point; vec3 normal; float t; bool hit; } RaycastResult; void ResetRaycastResult...