Book Image

WebGL Game Development

By : Sumeet Arora
Book Image

WebGL Game Development

By: Sumeet Arora

Overview of this book

<p>WebGL, the web implementation of Open GL, is a JavaScript API used to render interactive 3D graphics within any compatible web browser, without the need for plugins. It helps you create detailed, high-quality graphical 3D objects easily. WebGL elements can be mixed with other HTML elements and composites to create high-quality, interactive, creative, innovative graphical 3D objects.</p> <p>This book begins with collecting coins in Super Mario, killing soldiers in Contra, and then quickly evolves to working out strategies in World of Warcraft. You will be guided through creating animated characters, image processing, and adding effects as part of the web page canvas to the 2D/3D graphics. Pour life into your gaming characters and learn how to create special effects seen in the most powerful 3D games. Each chapter begins by showing you the underlying mathematics and its programmatic implementation, ending with the creation of a complete game scene to build a wonderful virtual world.</p>
Table of Contents (17 chapters)
WebGL Game Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using the basic camera


Let's now write our class for the basic camera. What have we learned so far? There are two transformation matrices: the view matrix and the projection matrix. To calculate the view matrix, we need four parameters: up, direction, left, and position. These parameters define the camera's orientation and position in space.

To compute the projection matrix, we need four parameters as well: field of view (radians), aspect ratio of the 2D screen, and the near and far clip planes.

Hence, in our basic camera class, we will need getters/setters for our four parameters and a function to calculate the view and projection matrices. Although the camera class in games would need more functions such as pitch and yaw, we will first create a base class.

Implementing the basic camera

Our base camera class has variables and basic functionality defined, which will be used in all our different camera implementations. In different types of 3D games, we generally require three types of cameras...