Book Image

OpenGL ES 3.0 Cookbook

By : Parminder Singh
Book Image

OpenGL ES 3.0 Cookbook

By: Parminder Singh

Overview of this book

<p>"Write once, use anywhere" is truly the power behind OpenGL ES and has made it an embedded industry standard. The library provides cutting-edge, easy-to-use features to build a wide range of applications in the gaming, simulation, augmented-reality, image-processing, and geospatial domains.</p> <p>The book starts by providing you with all the necessary OpenGL ES 3.0 setup guidelines on iOS and Android platforms. You'll go on to master the fundamentals of modern 3D graphics, such as drawing APIs, transformations, buffer objects, the model-view-project analogy, and much more. The book goes on to deal with advanced topics and offers a wide range of recipes on the light shading, real-time rendering techniques with static and procedure textures to create stunning visualizations and runtime effects.</p>
Table of Contents (21 chapters)
OpenGL ES 3.0 Cookbook
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Calculating cosine between two vectors


This is an illustration of how to calculate the cosine angle between two vectors formed by the 0, 20, and 0 points on a flat x-z plane surface and the light source situated at 20, 20, and 40, as shown in the following figure:

Calculate ON and OL vectors, as shown in the following code:

   OL = L – O = (20, 20, 40) – (0, 0, 0) => (20-0), (20-0), (40-0) => (20, 20, 40)
ON = N – O = (0, 20, 0) – (0, 0, 0) => (0, 20, 0) 

The dot product between OL and ON is as follows:

OL . ON = |OL| * |ON| * cos(θ)

Using Equation 1:

OL .ON = (20*0) + (20*20) + (40*0) = 400

Using Equation 2:

|OL|*|ON| = [√ (20*20) + (20*20) + (40*40)] * [ √ (0*0) +(20*20)+(0*0)] = 979.79

Equating both equations, the result is shown in the following code:

400 = 979.79 * cos(θ);

Here, cos(θ) = 0.40 implies that the θ is 65.90 degrees.