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

Sphere-to-OBB


Checking if a Sphere and an Oriented Bounding Box (OBB) intersect is very similar to checking if a Sphere and an AABB intersect. First, we find the closest point on the OBB to the Sphere. Next, we must find the distance between the center of the Sphere and the closest point. Finally, we compare the distance against the radius of the sphere. If the distance is less than the radius, we have an intersection:

Getting ready

We are going to implement a function to test if a Sphere and an OBB are intersecting. We will also create a #define macro to test the opposite. This new macro just switches the function name and argument order.

How to do it…

Follow the given steps to implement sphere to OBB intersection testing:

  1. Declare SphereOBB in Geometry3D.h:

    bool SphereOBB(const Sphere& sphere, const OBB& obb);
  2. Declare OBBSphere in Geometry3D.h:

    #define OBBSphere(obb, sphere) \
    SphereOBB(sphere, obb)
  3. Implement SphereOBB in Geometry3D.h:

    bool SphereOBB(const Sphere& sphere, const OBB&...
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