2012-02-23 80 views

回答

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; 
} 

你下一步需要做的唯一的事情就是創建身體和夾具與這種形狀。 我希望對你有所盼望......

+0

可以請你解釋一下什麼是pa,pb和pc – 2012-05-07 08:39:54

+0

它們只是臨時變量......這是一個關於二次貝塞爾的公式......你可以從計算機圖形學中瞭解更多...... – 2012-05-07 10:22:29