I’m using the GLCameraRipple example to have ripples over a static image, which I load with glTexImage2D.
I use my own shaders since those in the example are for getting images from video feed.
It responds to touches and generates ripples on the touch location.
It works ok, but I need it to pause drawing, for battery preservation reasons, when the ripple animation has finished. In this example from Apple, I don’t see anywhere how I can check this state. GLKView or GLKViewController don’t have any delegate method for this.
It uses a -runSimulation method that is called in every -update of my GLKViewController, which does all the magic, but I still don’t see where I can check if the ripples have finished animating, or even compare the initial state with the state where ripples are running all over.
I am currently counting myself how much time the ripple animation takes to finish at most, until what we see is a static image again and I’ve set it to pause after this amount of seconds and unpause it again when a touch event occurs, but it doesn’t feel right at all.
(The animation duration is different on larger screens (e.g. on iPad) and may vary depending on the pool size, mesh factor, touch radius etc.)
I was hoping there would be a way to check if the view’s contents are different than the initial state (when I have just loaded the image) and know the ripple animation is done playing?
As requested, I’m converting my comment to an answer so that the question can be closed out.
The GLCameraRipple example calculates the displacement for the texture coordinates in the image using an internal array called
rippleTexCoords. This array is updated in the-runSimulationmethod on each frame, which is what causes the ripples to propagate.If you observe the values of this array as they change, you can determine the point at which the ripples die down below a certain threshold. You can then use this as the time to pause the ongoing simulation.