Revolute Joint

hello

i am working on making a catapult using box2D and am using revolute joint to connect the base and arm of the catapult
here is the following code for it

#define PIXEL_TO_METRE 32

//Segment 1 poly 1
b2PolygonShape shSeg1;
shSeg1.SetAsBox(4.0f, 0.5f,b2Vec2(0,0),0);

//Segment 2 poly 2
b2PolygonShape shSeg2;
shSeg2.SetAsBox(0.5f, 1.5f, b2Vec2(-3.0f, 1.0f), 0.0f);

//body def 1
b2BodyDef boddef1;
boddef1.position.Set(340/PIXEL_TO_METRE,50/PIXEL_TO_METRE);
b2Body *bodsegment1 = world->CreateBody(&boddef1);

b2FixtureDef poly1, poly2;

poly1.shape = &shSeg1;
poly1.density = 1.0f;
poly1.friction = 0.2f;
poly1.restitution = 0.2f;

poly2.shape = &shSeg2;
poly2.density = 1.0f;
poly2.friction = 0.2f;
poly2.restitution = 0.2f;

bodsegment1->CreateFixture(&poly1);
bodsegment1->CreateFixture(&poly2);

//Segment 3 poly 3
b2PolygonShape shSeg3;
shSeg3.SetAsBox(0.2f, 4.0f, b2Vec2(-5.5f,1.6f),DEGREE_TO_RAD(100));

//segment 4 poly 4
b2PolygonShape shSeg4;
shSeg4.SetAsBox(0.2f, 0.7f, b2Vec2(-9.0f,1.5f),DEGREE_TO_RAD(10));

//body def 2
b2BodyDef boddef2;
boddef2.position.Set(340/PIXEL_TO_METRE,50/PIXEL_TO_METRE);
b2Body *bodsegment2 = world->CreateBody(&boddef2);

b2FixtureDef poly3, poly4;

poly3.shape = &shSeg3;
poly3.density = 1.0f;
poly3.friction = 0.2f;
poly3.restitution = 0.2f;

poly4.shape = &shSeg4;
poly4.density = 1.0f;
poly4.friction = 0.2f;
poly4.restitution = 0.2f;

bodsegment2->CreateFixture(&poly3);
bodsegment2->CreateFixture(&poly4);

//ball
b2BodyDef ball1;
ball1.position.Set(100/PIXEL_TO_METRE, 150/PIXEL_TO_METRE);
b2Body *ballBody1 = world->CreateBody(&ball1);

b2CircleShape shBall1;
shBall1.m_radius = 10.0f/PIXEL_TO_METRE;

b2FixtureDef ballShapeFix;
ballShapeFix.shape = &shBall1;
ballShapeFix.density = 1.0f;
ballShapeFix.friction = 0.2f;
ballShapeFix.restitution = 0.8f;
ballBody1->CreateFixture(&ballShapeFix);

b2RevoluteJointDef rjd;
rjd.Initialize(bodsegment1, bodsegment2, b2Vec2(7.0f,3.0f));
rjd.motorSpeed = 1.0f * b2_pi;
rjd.maxMotorTorque = 10000.0f;
rjd.enableMotor = false;
rjd.lowerAngle = DEGREE_TO_RAD(-45);
rjd.upperAngle = DEGREE_TO_RAD(90);
rjd.enableLimit = true;
rjd.collideConnected = false;// true;

b2RevoluteJoint *m_joint = (b2RevoluteJoint*)world->CreateJoint(&rjd);

but i am not getting joint connected properly to the arm as shown in the pic

Picture 1.png
Picture 1.png (39.73 KiB) Viewed 1905 times


we want the movement of the arm similar to the link below
http://www.emanueleferonato.com/2010/04/07/real-world-catapult-prototype-using-box2d/

please can someone suggest as to how can i connect the joint properly.
any suggestions on the same is highly appreciated.
The joint seems fine. The difference from the site you link is that you have a different body origin for the arm.

Original thread: https://box2d.org/forum/viewtopic.php?t=6491