Hey guys, I have a triangle which I create like so:
And a clip I attach to the triangle like so:
The problem is that the rotation from the clip and the box2d triangle (in debug draw) dont match. Also I was wondering if anybody would have any pointers on properly "skinning" triangles? As it stands now I just created a clip thats drawn close to the size of the shape I create in box2d and I dont know if that the best way to go about doing things.
My thanks in advance for any and all help.
Code: Select all
public function draw_tri():void
{
//draw_box(250,100,100,100,true);
var bodyDefP:b2BodyDef = new b2BodyDef();
bodyDefP.type = b2Body.b2_dynamicBody;
var polyShape:b2PolygonShape = new b2PolygonShape();
var vertices:Array = new Array();
var vertexCount:int;
vertexCount = 3;
for (var j:Number = 0; j < vertexCount; ++j)
{
vertices[j] = new b2Vec2();
}
/*vertices[0].Set(0, (17 +Math.random()*17) / scaleFactor);
vertices[1].Set((-12 -Math.random()*17) / scaleFactor, (-17 -Math.random()*17) / scaleFactor);
vertices[2].Set(( 12 +Math.random()*17) / scaleFactor, (-17 -Math.random()*17) / scaleFactor);*/
vertices[0].Set(0,-0.8);
vertices[1].Set(1,1);
vertices[2].Set(-1,1);
trace("firstSet = " + (17 +Math.random()*17) / scaleFactor);
trace("secSet = " + (-12 -Math.random()*17)+ " & " + (-17 -Math.random()*17));
trace("thirdSet = " + ( 12 +Math.random()*17)+ " & " + (-17 -Math.random()*17));
/*vertices[0].Set(0, (20 / scaleFactor));
vertices[1].Set((-20) / scaleFactor, (-17) / scaleFactor);
vertices[2].Set(( 20) / scaleFactor, (-20) / scaleFactor);*/
polyShape.SetAsArray( vertices, vertexCount );
var fixtureDef:b2FixtureDef = new b2FixtureDef();
fixtureDef.shape = polyShape;
fixtureDef.density = 0.1;
fixtureDef.friction = 0.1;
fixtureDef.restitution = 0.8;
//bodyDefP.position.Set((Math.random() * 400 + 120) / scaleFactor, (Math.random() * 150 + 50) / scaleFactor);
bodyDefP.position.Set(75/ scaleFactor, 75/ scaleFactor);
triBody = mainWorld.CreateBody(bodyDefP);
triBody.CreateFixture(fixtureDef);
}And a clip I attach to the triangle like so:
Code: Select all
private function onTick(a_event:TimerEvent):void
{
//scaleFactor:Number = 20;
graphics.clear();
graphics.lineStyle(3, 0xff0000);
//world.Step(0.025, 10, 10);//old
world.Step(1 / 30, 10, 10);
world.ClearForces();
world.DrawDebugData();
triClip.x = createShape.triBody.GetPosition().x*scaleFactor;
triClip.y = createShape.triBody.GetPosition().y*scaleFactor;
triClip.rotation = createShape.triBody.GetAngle()*scaleFactor;
trace("TRI -Angle = " + createShape.triBody.GetAngle());
trace("triClip -Angle = " + triClip.rotation);
}The problem is that the rotation from the clip and the box2d triangle (in debug draw) dont match. Also I was wondering if anybody would have any pointers on properly "skinning" triangles? As it stands now I just created a clip thats drawn close to the size of the shape I create in box2d and I dont know if that the best way to go about doing things.
My thanks in advance for any and all help.