Hello all
in short my question is how to connect 2 polygons shapes that are complex and texture them .
here is info about my problem
i have problem with b2WeldJointDef that do attach 2 b2body's but when i start the debug with e_jointBit turns on.
this is my code and i have the image attached
now as you can see in the picture attached the weldjoint is not in the right position ,
what am i doing wrong ? or what do you thing about using weld joint for this ?
is it the right approach?
im sorry for the cross posting here and in stack over fllow
but the image can be seen here :
http://stackoverflow.com/questions/20727682/b2weldjointdef-not-showing-right-between-custom-polygones
in short my question is how to connect 2 polygons shapes that are complex and texture them .
here is info about my problem
i have problem with b2WeldJointDef that do attach 2 b2body's but when i start the debug with e_jointBit turns on.
this is my code and i have the image attached
Code:
b2BodyDef bodyDef;
bodyDef.position.Set((screenSize.width/2.0)/PTM_RATIO,(screenSize.height/2.0)/PTM_RATIO);
//CCLOGWARN("position:pX:%f pY:%f",pX,pY);
bodyDef.type=b2_dynamicBody;
bodyDef.userData = sprite;
bodyDef.linearDamping = 1.0;
bodyDef.angularDamping = 1.0;
b2FixtureDef* fixtureDef=new b2FixtureDef();
fixtureDef->density=3.0;
fixtureDef->restitution=0.0;
fixtureDef->friction=1.0;
fixtureDef->filter.groupIndex=-1;
b2Body* car_body = world->CreateBody(&bodyDef);
// here i build the custom polygons to form complex body
polygonShape = new b2PolygonShape();
b2Vec2 *vertices = new b2Vec2[10];
// setting the vertices all working great :
...
...
...
polygonShape->Set(vertices,10);
fixtureDef->shape = polygonShape;
car_body->CreateFixture(fd);
// -------- trying to attach the axle to the main car buy
b2BodyDef axlecontainerBodyDef;
axlecontainerBodyDef.userData = axlecontainerSprite;
axlecontainerBodyDef.type=b2_dynamicBody;
axlecontainerBodyDef.position.Set(((screenSize.width/2.0))/PTM_RATIO,(screenSize.height/2.0)/PTM_RATIO);
b2Body* axlecontainerBody = world->CreateBody(&axlecontainerBodyDef);
b2FixtureDef * axleContainerFixture = new b2FixtureDef();
axleContainerFixture->density=3.0;
axleContainerFixture->friction=0.0;
axleContainerFixture->restitution=1.0;
axleContainerFixture->filter.groupIndex=-1;
//LEFT AXLE CONTAINER
// here i build the custom polygons to form complex new body to be attached to the main car body
polygonShape = new b2PolygonShape();
b2Vec2 *vertices = new b2Vec2[10];
// setting the vertices all working great :
...
...
...
polygonShape->Set(vertices,10);
axleContainerFixture->shape = polygonShape;
axlecontainerBody->CreateFixture(fd);
b2WeldJointDef *weldJointDef = new b2WeldJointDef();
weldJointDef->bodyA=axlecontainerBody;
weldJointDef->bodyB=body;
float x = body->GetWorldCenter().x/PTM_RATIO;
float y = body->GetWorldCenter().y/PTM_RATIO;
weldJointDef->localAnchorA.Set(-0.5, -0.3);
weldJointDef->localAnchorB.Set(-0.5, -0.3);
weldJointDef->referenceAngle = 0* M_PI /3;
//weldJointDef->collideConnected = false;
world->CreateJoint(weldJointDef);
bodyDef.position.Set((screenSize.width/2.0)/PTM_RATIO,(screenSize.height/2.0)/PTM_RATIO);
//CCLOGWARN("position:pX:%f pY:%f",pX,pY);
bodyDef.type=b2_dynamicBody;
bodyDef.userData = sprite;
bodyDef.linearDamping = 1.0;
bodyDef.angularDamping = 1.0;
b2FixtureDef* fixtureDef=new b2FixtureDef();
fixtureDef->density=3.0;
fixtureDef->restitution=0.0;
fixtureDef->friction=1.0;
fixtureDef->filter.groupIndex=-1;
b2Body* car_body = world->CreateBody(&bodyDef);
// here i build the custom polygons to form complex body
polygonShape = new b2PolygonShape();
b2Vec2 *vertices = new b2Vec2[10];
// setting the vertices all working great :
...
...
...
polygonShape->Set(vertices,10);
fixtureDef->shape = polygonShape;
car_body->CreateFixture(fd);
// -------- trying to attach the axle to the main car buy
b2BodyDef axlecontainerBodyDef;
axlecontainerBodyDef.userData = axlecontainerSprite;
axlecontainerBodyDef.type=b2_dynamicBody;
axlecontainerBodyDef.position.Set(((screenSize.width/2.0))/PTM_RATIO,(screenSize.height/2.0)/PTM_RATIO);
b2Body* axlecontainerBody = world->CreateBody(&axlecontainerBodyDef);
b2FixtureDef * axleContainerFixture = new b2FixtureDef();
axleContainerFixture->density=3.0;
axleContainerFixture->friction=0.0;
axleContainerFixture->restitution=1.0;
axleContainerFixture->filter.groupIndex=-1;
//LEFT AXLE CONTAINER
// here i build the custom polygons to form complex new body to be attached to the main car body
polygonShape = new b2PolygonShape();
b2Vec2 *vertices = new b2Vec2[10];
// setting the vertices all working great :
...
...
...
polygonShape->Set(vertices,10);
axleContainerFixture->shape = polygonShape;
axlecontainerBody->CreateFixture(fd);
b2WeldJointDef *weldJointDef = new b2WeldJointDef();
weldJointDef->bodyA=axlecontainerBody;
weldJointDef->bodyB=body;
float x = body->GetWorldCenter().x/PTM_RATIO;
float y = body->GetWorldCenter().y/PTM_RATIO;
weldJointDef->localAnchorA.Set(-0.5, -0.3);
weldJointDef->localAnchorB.Set(-0.5, -0.3);
weldJointDef->referenceAngle = 0* M_PI /3;
//weldJointDef->collideConnected = false;
world->CreateJoint(weldJointDef);
now as you can see in the picture attached the weldjoint is not in the right position ,
what am i doing wrong ? or what do you thing about using weld joint for this ?
is it the right approach?
im sorry for the cross posting here and in stack over fllow
but the image can be seen here :
http://stackoverflow.com/questions/20727682/b2weldjointdef-not-showing-right-between-custom-polygones