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

Understanding ModelView transformations


In all our previous chapters, we used model transformations. We used glMatrix (http://glmatrix.net/) functions to calculate translation and rotation. Let's look at what we are talking about here:

// Create an identity matrix
var mvMatrix=mat4.create();

// Translate the matrix by objects location and replace the matrix with the result(mat4.translate(out,in,vec3))
  mat4.translate(mvMatrix, mvMatrix, stage.stageObjects[i].location);
// Rotate the matrix by objects rotation X and replace the matrix with the result(mat4.rotateX(out,in,vec3))
  mat4.rotateX(mvMatrix, mvMatrix, stage.stageObjects[i].rotationX);
  mat4.rotateY(mvMatrix, mvMatrix, stage.stageObjects[i].rotationY);
  mat4.rotateZ(mvMatrix, mvMatrix, stage.stageObjects[i].rotationZ);

In the preceding code, we created a ModelView matrix, mvMatrix, which stores the translation and rotation of the object. We passed this matrix to our fragment shader using our own function, setMatrixUniforms. When...