Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
OpenGL Game Development By Example

You're reading from   OpenGL Game Development By Example Design and code your own 2D and 3D games efficiently using OpenGL and C++

Arrow left icon
Product type Paperback
Published in Mar 2016
Publisher
ISBN-13 9781783288199
Length 340 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Robert Madsen Robert Madsen
Author Profile Icon Robert Madsen
Robert Madsen
Stephen Madsen Stephen Madsen
Author Profile Icon Stephen Madsen
Stephen Madsen
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

Asteroid slalom

It's now time to implement the final feature of this chapter. We are going to implement a slalom race with a twist. In a typical slalom, the point is to race around each obstacle without touching it. To keep things simple, we are going to race through each asteroid. If you successfully pass through each asteroid, you win the race.

Setting up collision detection

In order to determine whether you have passed through an asteroid, we have to implement some 3D collision detection. There are many types of collision detection, but we are going to keep it simple and implement spherical collision detection.

Spherical collision detection is a simple check to see whether the center of two 3D objects are within a certain distance of each other. As our asteroids are spheres, this will be a pretty accurate indication as to whether we have collided with one. The ship, however, is not a sphere, so this technique isn't perfect.

Let's start our collision detection coding by adding...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime