I create a function that create a curve (cubic bezier). Its ok, and works fine to me.
But i cant to set Fixture to this body, the edges.
function CreateCurve()
{
var bd = new b2BodyDef;
bd.type = b2Body.b2_staticBody;
var bdFix = new b2FixtureDef;
bdFix.density = 1.0;
bdFix.friction = 0.0;
bdFix.restitution = 0.0;
//console.log("x1: " + x1 + " y1: " + y1)
var pontoA = new b2Vec2( 0.0 , 0.5 );
var pontoB = new b2Vec2( 2.35 , 4.7 );
var pontoC = new b2Vec2( 7.05 , 4.7 );
var pontoD = new b2Vec2( 9.4 , 0.5 );
var x1 = pontoA.x;
var y1 = pontoA.y
var x2, y2;
var t; /* 0 para 1 */
//console.log(pontoA);
//console.log(pontoB);
//console.log(pontoC);
//console.log(pontoD);
bd.position.Set(x1, y1);
var curve = world.CreateBody(bd);
for( t = 0 ; t < 1.01 ; t += 0.01)
{
//var ax = ( -pontoA.x + 3*pontoB.x - 3*pontoC.x + pontoD.x ) / 6;
//var ay = ( -pontoA.y + 3*pontoB.y - 3*pontoC.y + pontoD.y ) / 6;
var ax = Math.pow((1-t), 3)*pontoA.x;
var ay = Math.pow((1-t), 3)*pontoA.y;;
//var bx = ( pontoA.x - 2*pontoB.x + pontoC.x ) / 2;
//var by = ( pontoA.y - 2*pontoB.y + pontoC.y ) / 2;
var bx = 3 * t * Math.pow((1-t), 2) * pontoB.x;
var by = 3 * t * Math.pow((1-t), 2) * pontoB.y;
//var cx = ( -pontoA.x + pontoC.x ) / 2;
//var cy = ( -pontoA.y + pontoC.y ) / 2;
var cx = 3 * Math.pow(t, 2) * (1-t) * pontoC.x;
var cy = 3 * Math.pow(t, 2) * (1-t) * pontoC.y;
//var dx = ( pontoA.x + 4*pontoB.x + pontoC.x ) / 6;
//var dy = ( pontoA.y + 4*pontoB.y + pontoC.y ) / 6;
var dx = Math.pow(t, 3) * pontoD.x;
var dy = Math.pow(t, 3) * pontoD.y;
//x2 = ax*Math.pow(t, 3) + bx*Math.pow(t, 2) + cx*t + dx;
//y2 = ay*Math.pow(t, 3) + by*Math.pow(t, 2) + cy*t + dy;
x2 = ax+bx+cx+dx;
y2 = ay+by+cy+dy;
//console.log("x2: " + x2 + " y2: " + y2);
var edgeShape = new b2PolygonShape();
edgeShape.SetAsEdge( new b2Vec2(x1,y1) , new b2Vec2(x2,y2) );
curve.CreateFixture2(edgeShape);
x1 = x2;
y1 = y2;
}
}