1

I am drawing line using bezier curve and i need to convert that bezier curve into box2d object. Which object can i use in box2d? any suggestions?

Chandan Shetty SP
  • 5,087
  • 6
  • 42
  • 63

1 Answers1

2

Try to understand it...

+(b2ChainShape)curveWithPoints:(CGPoint*)points Times:(int)times
{
    //points.count must be 3
    b2ChainShape shape;
    float step = 1/(float)times;
    float t = 0;
    b2Vec2 *p = new b2Vec2[times];
    b2Vec2 v1 = [CCMethod toMeter:points[0]];
    b2Vec2 v2 = [CCMethod toMeter:points[1]];
    b2Vec2 v3 = [CCMethod toMeter:points[2]];
    for(int i = 0;i < times;i++){
        b2Vec2 pa = v1;
        pa *= ( (t-1)*(t-1)*0.5 );
        b2Vec2 pb = v2;
        pb *= ( (-t)*t+t+0.5 );
        b2Vec2 pc = v3;
        pc *= ( t*t*0.5 );
        p[i] = pa+pb+pc;
        t+=step;
    }
    shape.CreateChain(p, times);
    return shape;
}

The only thing you need to do next is to create body and fixture with this shape. I hope it is hopeful to you ...

Ringo_D
  • 342
  • 1
  • 2
  • 12