O'Reilly logo

OpenGL ES 2 for Android by Kevin Brothaler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding Gravity

What goes up must come down. Isaac Newton became famous because he observed the effects of gravity on apples falling from a tree; our particles will look better if we add some gravity to them as well.

On earth, everyone feels an acceleration of 9.8 meters per second squared, and if we ignore the effects of wind resistance, then the longer something falls, the faster it goes. We can easily reproduce this effect in our code by adding a gravity adjustment to our vertex shader. Let’s open up particle_vertex_shader.glsl and add the following line of code after the assignment to v_ElapsedTime:

Particles/res/raw/particle_vertex_shader.glsl
 
float​ gravityFactor = v_ElapsedTime * v_ElapsedTime / 8.0;

This will calculate an accelerating ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required