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

Identity matrix


Multiplying a scalar number by 1 will result in the original scalar number. There is a matrix analogue to this, the identity matrix. The identity matrix is commonly written as I. If a matrix is multiplied by the identity matrix, the result is the original matrix .

In the identity matrix, all non-diagonal elements are 0, while all diagonal elements are one . The identity matrix looks like this:

Getting ready

Because the identity matrix has no effect on multiplication, by convention it is the default value for all matrices. We're going to add two constructors to every matrix struct. One of the constructors is going to take no arguments; this will create an identity matrix. The other constructor will take one float for every element of the matrix and assign every element inside the matrix. Both constructors are going to be inline.

How to do it…

Follow these steps to add both a default and overloaded constructors to matrices:

  1. Add the default inline constructor to the mat2 struct:

    inline...
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