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.
February 11th, 2012 at 23:16
Very nice! I’m starting to believe that NSArrays are not the bloated nightmares I initially took them to be :) Hoping to have a peek through the code when Github stops showing 404’s
February 12th, 2012 at 10:51
[…] to make deformable terrain effect:LINK Tweet « iUridium Source Christmas Sale – Price drop to […]
February 14th, 2012 at 17:49
Thanks for this demo !
You mentioned about using Chipmunk Pro version. Is free version of Chipmunk included in cocos2d can achieve this outcome as well.
February 14th, 2012 at 21:26
Yes. The only limitation to chipmunk pro, is a nag screen on devices, otherwise they are 100% identical.
February 15th, 2012 at 12:05
[…] Blog link | Forum Post Did you enjoy this article? Share it! […]
July 3rd, 2012 at 20:46
[…] explains his drawing technique used in the above video on his blog. But he’s also got an explanation and a example project for a simpler […]