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
![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);][2]
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?
UPDATE
after reading and changing the code over and over again i still can make the thing work as
i need the jonits are all missplaced still :
this is my fixed code as you can see it get the center of the car body buy way off the axle body:
b2BodyDef bodyDef;
bodyDef.position.Set((screenSize.width/2.0)/PTM_RATIO,(screenSize.height/2.0)/PTM_RATIO);
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=1.0;
axleContainerFixture->friction=1.0;
//axleContainerFixture->restitution=1.0;
axleContainerFixture->isSensor = false;
//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=body;
weldJointDef->bodyB=axlecontainerBody;
float x = axlecontainerBody->GetWorldCenter().x/PTM_RATIO;
float y = axlecontainerBody->GetWorldCenter().y/PTM_RATIO;
weldJointDef->Initialize(body,axlecontainerBody,body->GetWorldCenter());
world->CreateJoint(weldJointDef);