Deformable terrain

No one would have believed in the first years of the twenty-first century, that this world was being simulated keenly and closely by intelligences greater than man’s and yet as mortal as his own – chipmunks.

In this project, I am trying to simulate a flexible and deformable terrain, using the outstanding physics engine Chipmunk Pro. That thing is a mighty powerful piece of software.

The basic idea is to do deformations to a bitmap image, and then scan the outline to make terrain.

The image is made with a CGBitmapContext, which allows very fast read and write access, while still having resonable render performance. The stuff we will be rendering to deform the terrain, are pretty simple anyways. First the context is filled with an image from file, represented the undistorted terrain. This image is then used by a ChipmunkContextSampler, to return he outline of the terrain for physics simulation. Various attributes can be applied  to the terrain, including smoothing. The sampler also supports sampling on blurred terrain, for real nice and smooth outputs.

Finally, a tile cache is added. It basically breaks the terrain down into smaller pieces, so that only parts of the terrain needs to be updated, when changes happen. Deformation is then made to the terrain, simply by drawing filled circles directly into the CGBitmapContext.

A demo project can be grabbed at Github.

The demo is provided as-is, but if you have questions, you can often find me in the cocos2D forum.


Advertisements

6 responses to “Deformable terrain

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: