views:

1782

answers:

2

I'm working on an iPhone game that takes place on the ocean surface. Can someone recommend some sample code or tutorials for implementing waves or ripples in OpenGL?

iPhone supports OpenGL ES 1.1, so there is no support for shaders or other fancy effects.

I don't need anything too fancy. I don't need reflections, for example. I don't want to overtax the device. I just need something that sorta looks like an ocean. (But it would be nice if it looked as nice as Koi Pond.)

+3  A: 

iPhone is pretty much like a GPU from 1999 in capabilities (e.g. NVIDIA Riva TNT 2). So your most realistic options are just blending several scrolling textures.

E.g. have one texture with some "wave pattern". Set it up into two texture stages, and scroll both in different directions/speeds (via a texture matrix). The setup texture combiners to add the textures together for the final result (or do some other operation; tons of possibilities here).

NeARAZ
+2  A: 

Add together terms of the form:

a * sin(b * x + c * y + d * t)

Each such term produces a boring set of straight waves this way: a is the amplitude (height) contributed by these waves, b and c control the relative direction and frequency (spacing) of the waves, and d shifts the waves along in that direction as t (the simulated time) changes.

Experiment with a few terms of that form, holding t constant, to get an undulating surface. You can then "tune" the coefficients to get the degree of roughness you like. Once you've found a few sets of coefficients that you're happy with, let t vary to put it in motion.

joel.neely
Where would you put that formula into code? What's the result of it? An image or what?
Thanks
For fixed a, b, c, and d, that formula gives height at a specific time t and place (the x and y coordinates). A set of such formulas (with different a, b, c, and d values for each) gives heights of moving wave components; adding them gives total height. Converting heights to image depends on perspective. For a straight-down-from-overhead view, just map the range of heights to a range of blue-green colors. Perspective-based rendering requires matrix operations (too complex for this comment field! ;-)
joel.neely