hello, as usually I have a small problem.
I need to create 2 polygons and connect them using RevoluteJoint.
As you can see here http://uloz.to/xZdqCoXu/figure-bmp
the shape (polygons) represents a human foot. Every normal shape in Box2D is defind relatively at Fixation, but Polygon has no
special fixation point. How can I create such shape. How can I define coordinates of connection for revoIute joint? Is this correct ?
{ // POLYGON A, fingers - Left leg
// fingers at foot - body
BDX::BodyDef^ _bodyDef = gcnew BDX::BodyDef();
_bodyDef->type = BDX::BodyType::Dynamic;
_bodyDef->bullet = true;
_bodyDef->position = Vector2(0.0f, 0.0f);
_bodyList[0] = _world->CreateBody( _bodyDef );
// fingers at foot - polygonShape
array<MXF::Vector2,1>^ _shape = gcnew array<MXF::Vector2>(5);
_shape[0] = MXF::Vector2( 0.225f, 0.000f ); // point 0
_shape[1] = MXF::Vector2( 0.285f, 0.000f ); // point 1
_shape[2] = MXF::Vector2( 0.300f, 0.015f ); // point 2
_shape[3] = MXF::Vector2( 0.290f, 0.030f ); // point 3
_shape[4] = MXF::Vector2( 0.225f, 0.040f ); // point 4
BDX::PolygonShape^ _polygonShape_0 = gcnew BDX::PolygonShape();
_polygonShape_0->Set( _shape, 5 );
delete( _shape ); // delete array
_fixtureDef->shape = _polygonShape_0;
_fixtureDef->density = 1.0f;
_bodyList[0]->CreateFixture( _fixtureDef );
// K0, circle on the right
BDX::CircleShape^ _circleShape_0 = gcnew BDX::CircleShape();
_circleShape_0->_p = MXF::Vector2( 0.285f, 0.015f );
_circleShape_0->_radius = 0.015f;
_fixtureDef->shape = _circleShape_0;
_fixtureDef->density = 1.0f;
_bodyList[0]->CreateFixture( _fixtureDef );
// K1, circle on the left
BDX::CircleShape^ _circleShape_1 = gcnew BDX::CircleShape();
_circleShape_1->_p = MXF::Vector2( 0.225f, 0.020f );
_circleShape_1->_radius = 0.020f;
_fixtureDef->shape = _circleShape_1;
_fixtureDef->density = 1.0f;
_bodyList[0]->CreateFixture( _fixtureDef );
}
{
// vola pedis - left leg
BDX::BodyDef^ _bodyDef = gcnew BDX::BodyDef();
_bodyDef->type = BDX::BodyType::Dynamic;
_bodyDef->bullet = true;
_bodyDef->position = Vector2(0.0f, 0.0f);
_bodyList[1] = _world->CreateBody( _bodyDef );
array<MXF::Vector2,1>^ _shape = gcnew array<MXF::Vector2>(6);
_shape[0] = MXF::Vector2( 0.040f, 0.000f ); // 0
_shape[1] = MXF::Vector2( 0.225f, 0.000f ); // 1
_shape[2] = MXF::Vector2( 0.225f, 0.040f ); // 2
_shape[3] = MXF::Vector2( 0.130f, 0.100f ); // 3
_shape[4] = MXF::Vector2( 0.030f, 0.100f ); // 4
_shape[5] = MXF::Vector2( 0.010f, 0.030f ); // 5
BDX::PolygonShape^ _polygonShape_0 = gcnew BDX::PolygonShape();
_polygonShape_0->Set( _shape, 6 );
delete( _shape ); // delete array
_fixtureDef->shape = _polygonShape_0;
_fixtureDef->density = 1.0f;
_bodyList[1]->CreateFixture( _fixtureDef );
// K2, circle on the left
BDX::CircleShape^ _circleShape_0 = gcnew BDX::CircleShape();
_circleShape_0->_p = MXF::Vector2( 0.040f, 0.030f );
_circleShape_0->_radius = 0.030f;
_fixtureDef->shape = _circleShape_0;
_fixtureDef->density = 1.0f;
_bodyList[1]->CreateFixture( _fixtureDef );
}
{// common joint ( fingers + vola pedis ) on left leg
BDX::RevoluteJointDef^ _jointDef = gcnew BDX::RevoluteJointDef();
_jointDef->bodyA = _bodyList[0];
_jointDef->bodyB = _bodyList[1];
_jointDef->collideConnected = false;
_jointDef->localAnchorA = MXF::Vector2( +0.225f, +0.020f );
_jointDef->localAnchorB = MXF::Vector2( +0.225f, +0.020f );
_jointDef->referenceAngle = 0.0f;
_jointDef->enableLimit = true;
_jointDef->lowerAngle = (float)( (-1)*Math::PI*0.5 );
_jointDef->upperAngle = (float)( (+1)*Math::PI*0.5 );
_jointDef->enableMotor = false;
_jointList[0] = dynamic_cast<BDX::RevoluteJoint^>(_world->CreateJoint( _jointDef ));
}
As anyone can see I am using absolute coordinates of Joint. Is it correct ?
_jointDef->localAnchorA = MXF::Vector2( +0.225f, +0.020f );
_jointDef->localAnchorB = MXF::Vector2( +0.225f, +0.020f );
Both PolygonA and PolygonB have identical revolute joint.
So, it is terrible. Is there simething like detailed manual of theese problems ?
I need to create 2 polygons and connect them using RevoluteJoint.
As you can see here http://uloz.to/xZdqCoXu/figure-bmp
the shape (polygons) represents a human foot. Every normal shape in Box2D is defind relatively at Fixation, but Polygon has no
special fixation point. How can I create such shape. How can I define coordinates of connection for revoIute joint? Is this correct ?
{ // POLYGON A, fingers - Left leg
// fingers at foot - body
BDX::BodyDef^ _bodyDef = gcnew BDX::BodyDef();
_bodyDef->type = BDX::BodyType::Dynamic;
_bodyDef->bullet = true;
_bodyDef->position = Vector2(0.0f, 0.0f);
_bodyList[0] = _world->CreateBody( _bodyDef );
// fingers at foot - polygonShape
array<MXF::Vector2,1>^ _shape = gcnew array<MXF::Vector2>(5);
_shape[0] = MXF::Vector2( 0.225f, 0.000f ); // point 0
_shape[1] = MXF::Vector2( 0.285f, 0.000f ); // point 1
_shape[2] = MXF::Vector2( 0.300f, 0.015f ); // point 2
_shape[3] = MXF::Vector2( 0.290f, 0.030f ); // point 3
_shape[4] = MXF::Vector2( 0.225f, 0.040f ); // point 4
BDX::PolygonShape^ _polygonShape_0 = gcnew BDX::PolygonShape();
_polygonShape_0->Set( _shape, 5 );
delete( _shape ); // delete array
_fixtureDef->shape = _polygonShape_0;
_fixtureDef->density = 1.0f;
_bodyList[0]->CreateFixture( _fixtureDef );
// K0, circle on the right
BDX::CircleShape^ _circleShape_0 = gcnew BDX::CircleShape();
_circleShape_0->_p = MXF::Vector2( 0.285f, 0.015f );
_circleShape_0->_radius = 0.015f;
_fixtureDef->shape = _circleShape_0;
_fixtureDef->density = 1.0f;
_bodyList[0]->CreateFixture( _fixtureDef );
// K1, circle on the left
BDX::CircleShape^ _circleShape_1 = gcnew BDX::CircleShape();
_circleShape_1->_p = MXF::Vector2( 0.225f, 0.020f );
_circleShape_1->_radius = 0.020f;
_fixtureDef->shape = _circleShape_1;
_fixtureDef->density = 1.0f;
_bodyList[0]->CreateFixture( _fixtureDef );
}
{
// vola pedis - left leg
BDX::BodyDef^ _bodyDef = gcnew BDX::BodyDef();
_bodyDef->type = BDX::BodyType::Dynamic;
_bodyDef->bullet = true;
_bodyDef->position = Vector2(0.0f, 0.0f);
_bodyList[1] = _world->CreateBody( _bodyDef );
array<MXF::Vector2,1>^ _shape = gcnew array<MXF::Vector2>(6);
_shape[0] = MXF::Vector2( 0.040f, 0.000f ); // 0
_shape[1] = MXF::Vector2( 0.225f, 0.000f ); // 1
_shape[2] = MXF::Vector2( 0.225f, 0.040f ); // 2
_shape[3] = MXF::Vector2( 0.130f, 0.100f ); // 3
_shape[4] = MXF::Vector2( 0.030f, 0.100f ); // 4
_shape[5] = MXF::Vector2( 0.010f, 0.030f ); // 5
BDX::PolygonShape^ _polygonShape_0 = gcnew BDX::PolygonShape();
_polygonShape_0->Set( _shape, 6 );
delete( _shape ); // delete array
_fixtureDef->shape = _polygonShape_0;
_fixtureDef->density = 1.0f;
_bodyList[1]->CreateFixture( _fixtureDef );
// K2, circle on the left
BDX::CircleShape^ _circleShape_0 = gcnew BDX::CircleShape();
_circleShape_0->_p = MXF::Vector2( 0.040f, 0.030f );
_circleShape_0->_radius = 0.030f;
_fixtureDef->shape = _circleShape_0;
_fixtureDef->density = 1.0f;
_bodyList[1]->CreateFixture( _fixtureDef );
}
{// common joint ( fingers + vola pedis ) on left leg
BDX::RevoluteJointDef^ _jointDef = gcnew BDX::RevoluteJointDef();
_jointDef->bodyA = _bodyList[0];
_jointDef->bodyB = _bodyList[1];
_jointDef->collideConnected = false;
_jointDef->localAnchorA = MXF::Vector2( +0.225f, +0.020f );
_jointDef->localAnchorB = MXF::Vector2( +0.225f, +0.020f );
_jointDef->referenceAngle = 0.0f;
_jointDef->enableLimit = true;
_jointDef->lowerAngle = (float)( (-1)*Math::PI*0.5 );
_jointDef->upperAngle = (float)( (+1)*Math::PI*0.5 );
_jointDef->enableMotor = false;
_jointList[0] = dynamic_cast<BDX::RevoluteJoint^>(_world->CreateJoint( _jointDef ));
}
As anyone can see I am using absolute coordinates of Joint. Is it correct ?
_jointDef->localAnchorA = MXF::Vector2( +0.225f, +0.020f );
_jointDef->localAnchorB = MXF::Vector2( +0.225f, +0.020f );
Both PolygonA and PolygonB have identical revolute joint.
So, it is terrible. Is there simething like detailed manual of theese problems ?