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

Containing circle


One of the necessities for performing real-time collision detection is to simplify a given shape. For this reason, we need to make a function that, given a set of points, will return a circle containing all the points. This simplified bounding circle can then be used to approximate a collision area:

Getting ready

In order to avoid adding a dependency to std::vector in Geometry2D.h, we will implement this new function using an array. The ContainingCircle function will take two arguments, one is a Point2D array, and the other deals with the number of elements in the array. The ContainingCircle function will return a bounding circle that encapsulates all of the points.

How to do it…

Follow these steps to implement a function that will build a bounding circle from a set of points:

  1. Declare the ContainingCircle function in Geometry2D.h:

    Circle ContainingCircle(Point2D* pArray, int arrayCount);
  2. Implement ContainingCircle in Geometry2D.cpp:

    Circle ContainingCircle(Point2D* pArray, int...
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