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?
Asked
Active
Viewed 1,666 times
1 Answers
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
-
Can u please explain me what is pa,pb and pc – Chandan Shetty SP May 07 '12 at 08:39
-
They're just temporary variables...It is a formula about Quadratic Bezier... You can learn more from Computer Graphic... – Ringo_D May 07 '12 at 10:22