Chapter 10. Math

This chapter covers some basic math functions that will improve the support library within the game engine. First we will look at linear velocity, then we’ll examine a more advanced technique for calculating the angle between two points (which is helpful when targeting an enemy in a game or for moving a sprite along a path set by waypoints). Note that this chapter is not about the theory behind any of these math functions, nor does this text attempt to derive any of the math functions—we are simply coding some of the more common math functions into our game engine.

The versatile Vector3 class, introduced in Chapter 3, already has many commonly used math functions built in. You may want to review the Vector3 class because it provides the following:

  • Distance between two vectors

  • Length of a vector

  • Dot product

  • Cross product

  • Normalized vector

Because this assortment of math functions is already very useful as contained within Vector3, you may use them when convenient, but I believe it is helpful to provide, in the engine, more generic versions of these and the new math functions we develop this chapter. More specifically, we need a Math class embedded in the game engine (like g_engine->audio for the audio system).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset