Hi guys,
I am fairly new at this, but I have found an issue that needs help. When using shape.SetBox or edge, things work fine. But when I use just the ::Set() method giving it number of vertices, my revolute joint gets messed with...the connection points are not in the center of the body anymore. What am I doing wrong here? You can see what I am doing below:
The joint starts at body[1] lower left corner, goes to pivot point and then does back to 0,0 coordinate. When i set a position of a body, then the joint is fine, but the body is drawn at wrong coordinate.
I looked into the debug drawing code and i can see that a transform is being used (set by bodyDef.position) to determine joint points (so missing transform means, joint ends up at 0,0). But the transform is also being used to figure out where the body should go. So setting it means, the body ends up somewhere else.
Any help is appreciated.
I am fairly new at this, but I have found an issue that needs help. When using shape.SetBox or edge, things work fine. But when I use just the ::Set() method giving it number of vertices, my revolute joint gets messed with...the connection points are not in the center of the body anymore. What am I doing wrong here? You can see what I am doing below:
Code:
b2PolygonShape shape;
b2BodyDef bd;
bd.type = b2_dynamicBody;
b2Vec2* array = new b2Vec2[4];
array[0].x = 0.0;
array[0].y = 0.0;
array[1].x = 4.0;
array[1].y = 0.0;
array[2].x = 4.0;
array[2].y = 4.0;
array[3].x = 0.0;
array[3].y = 4.0;
shape.Set(array, 4);
m_bodies[1] = m_world->CreateBody(&bd);
m_bodies[1]->CreateFixture(&shape, 5.0f);
array[0].x = 0.0;
array[0].y = 6.0;
array[1].x = 4.0;
array[1].y = 6.0;
array[2].x = 4.0;
array[2].y = 10.0;
array[3].x = 0.0;
array[3].y = 10.0;
shape.Set(array, 4);
m_bodies[2] = m_world->CreateBody(&bd);
m_bodies[2]->CreateFixture(&shape, 5.0f);
b2RevoluteJointDef oj;
oj.collideConnected = true;
oj.Initialize(m_bodies[1], m_bodies[2], b2Vec2(2.0, 5.0));
m_world->CreateJoint(&oj);
b2BodyDef bd;
bd.type = b2_dynamicBody;
b2Vec2* array = new b2Vec2[4];
array[0].x = 0.0;
array[0].y = 0.0;
array[1].x = 4.0;
array[1].y = 0.0;
array[2].x = 4.0;
array[2].y = 4.0;
array[3].x = 0.0;
array[3].y = 4.0;
shape.Set(array, 4);
m_bodies[1] = m_world->CreateBody(&bd);
m_bodies[1]->CreateFixture(&shape, 5.0f);
array[0].x = 0.0;
array[0].y = 6.0;
array[1].x = 4.0;
array[1].y = 6.0;
array[2].x = 4.0;
array[2].y = 10.0;
array[3].x = 0.0;
array[3].y = 10.0;
shape.Set(array, 4);
m_bodies[2] = m_world->CreateBody(&bd);
m_bodies[2]->CreateFixture(&shape, 5.0f);
b2RevoluteJointDef oj;
oj.collideConnected = true;
oj.Initialize(m_bodies[1], m_bodies[2], b2Vec2(2.0, 5.0));
m_world->CreateJoint(&oj);
The joint starts at body[1] lower left corner, goes to pivot point and then does back to 0,0 coordinate. When i set a position of a body, then the joint is fine, but the body is drawn at wrong coordinate.
I looked into the debug drawing code and i can see that a transform is being used (set by bodyDef.position) to determine joint points (so missing transform means, joint ends up at 0,0). But the transform is also being used to figure out where the body should go. So setting it means, the body ends up somewhere else.
Any help is appreciated.