Hey,
I am having some difficulty drawing my lines correctly using flash.Box2D. The fault isnt with box2D, rather with my math.
I attached a swf with the basic engine as well as some angles drawn on it.
Why doesnt the lines want to draw correctly for anything greater than +-40 degrees?
Here is the code used to draw the line, from the mouse events till the actual drawing.
public function beginDraw(e:Event):void{
if (!drawing){
beginX = mouseX;
beginY = mouseY;
drawing = true;
}
}
public function endDraw(e:Event):void{
if (!drawing){
}
else{
endX = mouseX;
endY = mouseY;
drawLine(beginX,beginY,endX,endY);
drawing = false;
}
}
public function drawLine(bX:Number,bY:Number,eX:Number,eY:Number):void{
var line:b2PolygonShape= new b2PolygonShape();
var lineBd:b2BodyDef = new b2BodyDef();
var lineB:b2Body;
var distancevar:Number = distance(bX,bY,eX,eY);
lineBd.position.Set( (bX+eX)/2 / pixelsPerMeter, (bY+eY)/2 / pixelsPerMeter);//Line is drawn from middle hence /2
line.SetAsBox((distancevar/2)/pixelsPerMeter, 4/pixelsPerMeter/2);
lineB = world.CreateBody(lineBd); // Box2D handles the creation of a new b2Body for us.
lineB.CreateFixture2(line);
lineB.SetAngle((eY / pixelsPerMeter-bY / pixelsPerMeter)/(eX / pixelsPerMeter-bX / pixelsPerMeter));
}
Thanks alot