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 B-spline interpolation for grenade action


In this section, we will introduce the left hand. The left hand will be used to throw the grenade. So, first we will need to create a linear animation of the left hand. However, this time, we will not interpolate over position but over rotation. Then, we will chain animations. When the animation of the left hand ends, we will start the animation of the grenade.

Using linear interpolation for left-hand rotation

We want to throw the grenade when the Enter key is pressed. Let's first go over the class to handle the animation of the left hand.

Open the LeftHand.js file from the primitive/game folder of the code bundle in your text editor.

The LeftHand class also inherits StageObject. We have defined some new properties (rotations, counter, and grenadeCallBack). The rotations array holds the angles that we need to interpolate on. The integer counter maintains number of times the update function has been invoked. The variable grenadeCallback, holds...