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

Triangle


Triangles are one of the most important primitive shapes for 3D graphics. A triangle can be represented by three non linear points. Triangles are special because they are co-planar. This means that the three points of a triangle always lie on the same plane:

Getting ready

We are going to implement a triangle that is defined by three points. To make this structure more convenient to use, we can declare an anonymous union. This union will let us access the members of the Triangle struct in different ways.

How to do it

Follow these steps to implement a 3D triangle:

  1. Declare the Triangle structure in Geometry3D.h:

    typedef struct Triangle {
       union {
  2. The points of a triangle should be accessible as three separate points: a, b and c:

           struct {
               Point a;
               Point b;
               Point c;
           };
  3. One of the alternate methods to access the points of a triangle is as an array of points:

           Point points[3];
  4. The final way of accessing the points of a triangle is as a linear...

lock icon
The rest of the page is locked
Previous PageNext Chapter
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