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

Simple bullet action – linear animation


In this section, we will add another object to our scene, the bullet (Bullet.json), and we will move our bullet in a straight line, unlike Angelina Jolie's movie Wanted, where the guys curve bullets. We can do that by applying B-spline interpolation but we are still medieval and we will save it for our grenade.

The equation to move the bullet is simple: f(x)=z. We will simply change the z value to move the bullet. However, this is awful because if we rotate ourselves (the camera and subsequently, our arm), the bullet should go in the arm's direction. To achieve this, we need to apply the camera transformation to the bullet. Each bullet will have the same defined set of points, let's say (0,0,1),(0,0,2)...(0,0,200), but when we apply these translations to the clone of the camera matrix, then each time we fire the bullet from a different angle or position, we will get different trajectories. Actually, these defined positions are with respect to the camera...