Search code examples
iosobjective-copengl-esbox2dgame-physics

box2d spring mesh with texture map


I have an image of a lamp and I'd like to make the base elastic. If a user puts their finger on the base and pulls back, it stretches to a given range. When they let go it snaps back with a certain amount of elasticity.

This youtube video of box2d + springs + texture mapping seems very close to what I want:

http://www.youtube.com/watch?v=3cT6ZM3KkqY

I'm new to box2d ( iOS ) and was wondering if someone could point me in the right direction.


Solution

  • The video you posted uses soft body dynamics.

    The idea is that you create a soft body object made up of a matrix of points like this:

    0  0  0  0
    
    0  0  0  0
    
    0  0  0  0 
    

    To render the image, each point of the matrix will be a vertex. Calculating the indices is a trivial task.

    Here is a good tutorial for soft body dynamics on iOS using Box2d: http://www.uchidacoonga.com/2012/03/soft-body-physics-with-box2d-and-cocos2d-part-14/