我使用贝塞尔曲线画线,我需要将贝塞尔曲线转换为box2d对象。我可以在box2d中使用哪个对象?有什么建议吗?
答案 0 :(得分:2)
尝试理解它......
+(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;
}
接下来你唯一需要做的就是用这种形状创造身体和夹具。 我希望你有希望...