Reader small image

You're reading from  Game Physics Cookbook

Product typeBook
Published inMar 2017
Reading LevelIntermediate
PublisherPackt
ISBN-139781787123663
Edition1st Edition
Languages
Tools
Concepts
Right arrow
Author (1)
Gabor Szauer
Gabor Szauer
author image
Gabor Szauer

Gabor Szauer has been making games since 2010. He graduated from Full Sail University in 2010 with a bachelor's degree in game development. Gabor maintains an active Twitter presence, and maintains a programming-oriented game development blog. Gabor's previously published books are Game Physics Programming Cookbook and Lua Quick Start Guide, both published by Packt.
Read more about Gabor Szauer

Right arrow

Raycast Bounding Box


Any box in 3D space, OBB, or AABB has six sides. This means the normal of a Raycast against a box will be the normal of one of the six sides. When doing a Raycast against a Bounding Box, we find the point of impact the same way we did for a Raycast against a Sphere. The normal, however, will be the same as the normal of the side which the ray hit.

Getting ready

Several of our existing functions use Raycast against AABB or OBB internally. When we change the API, we must be careful to update every spot where these functions are used. We must update the Linetest functions and the MeshRay function. In this section we are going to rewrite the Raycast function for AABB and OBB.

How to do it…

Follow these steps to update the Raycast functions of boxes in a way that they provide additional useful data:

  1. Update the declarations of Raycast against both OBB and AABB in Geometry3D.h:

    bool Raycast(const AABB& aabb, const Ray& ray, 
       RaycastResult* outResult);
    bool Raycast(const...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Game Physics Cookbook
Published in: Mar 2017Publisher: PacktISBN-13: 9781787123663

Author (1)

author image
Gabor Szauer

Gabor Szauer has been making games since 2010. He graduated from Full Sail University in 2010 with a bachelor's degree in game development. Gabor maintains an active Twitter presence, and maintains a programming-oriented game development blog. Gabor's previously published books are Game Physics Programming Cookbook and Lua Quick Start Guide, both published by Packt.
Read more about Gabor Szauer