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 rectangle


A containing rectangle is very similar to a containing circle. We will find the minimum non-oriented rectangle that contains a set of points. Depending on the shape being contained, a rectangle might be a tighter fit than a circle:

Getting ready

The ContainingRectangle function is going to be very similar to the ContainingCircle function. Just like ContainingCircle, this function will take an array of points, and a count of the number of points in the array. Given this set of input points, ContainingRectangle will return the minimum non-oriented rectangle that encompasses every point.

How to do it…

Follow these steps to create a function that will create a bounding rectangle from a set of points:

  1. Declare the ContainingRectangle function in Geometry2D.h:

    Rectangle2D ContainingRectangle(Point2D* pointArray, 
       int arrayCount);
  2. Implement the ContainingRectangle function in Geometry2D.cpp:

    Rectangle2D ContainingRectangle(Point2D* pointArray, 
       int arrayCount) {
       vec2 min =...
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