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


A sphere is the 3D version of a circle. It is defined by a 3D point in space and a radius. Like a circle in 2D, in 3D the sphere is considered to be one of the simplest shapes we can implement. The simplicity of a sphere makes it very fast for collision detection:

Getting ready

We are going to declare a new Sphere structure in the Geometry3D.h header file. This structure will hold a position and a radius.

How to do it…

Follow these steps to implement a 3D sphere:

  1. Declare the Sphere structure in Geometry3D.h:

    typedef struct Sphere {
  2. Start by declaring the position and radius variables of the Sphere structure:

       Point position;
       float radius;
  3. Finish implementing the structure by adding a default constructor, and one which takes a point and radius to construct a sphere out of:

       inline Sphere() : radius(1.0f) { }
       inline Sphere(const Point& p, float r) :
           position(p), radius(r) { }
    } Sphere;

How it works…

The Sphere structure contains a position and a radius. It has two constructors...

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