我正在使用 Box2D distanceJoint 和 AndEngine 来保持形状。但是形状没有保持,碎片只是掉到了地板上。它应该保持圆形/椭圆形。你能告诉我我做错了什么吗?在这里,我与邻居保持距离。我应该与其他成员保持距离吗?
for (int i=1; i<nBodies; ++i) {
FIXTURE_DEF = PhysicsFactory.createFixtureDef(25f, 0.0f, 1f);
float angle = map(i, 0, nBodies, 0, 2*3.1415f);
float x = cx + rx * (float)Math.sin(angle);
float y = cy + ry * (float)Math.cos(angle);
// Add plate
float x1 = (x + 10) * 30;
float y1 = y * 20;
centers[i][0] = x1;
centers[i][1] = y1;
Vector2 v1 = new Vector2(x1,y1);
circle = new AnimatedSprite(x1, y1, this.mCircleFaceTextureRegion, this.getVertexBufferObjectManager());
circleBody[i] = PhysicsFactory.createCircleBody(this.mPhysicsWorld, circle, BodyType.DynamicBody, FIXTURE_DEF);
this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(circle, circleBody[i], true, true));
this.mScene.attachChild(circle);
}
for(int i= 1;i < nBodies -1; i++) {
Vector2 v1 = new Vector2(centers[i][0]/PIXEL_TO_METER_RATIO_DEFAULT,centers[i][1]/PIXEL_TO_METER_RATIO_DEFAULT);
Vector2 v2 = new Vector2(centers[i+1][0]/PIXEL_TO_METER_RATIO_DEFAULT,centers[i+1][1]/PIXEL_TO_METER_RATIO_DEFAULT);
Log.d("Vals","vals x:" + centers[i][0] + "y:" + centers[i][1] + "x:" +centers[i+1][0] + "y:" + centers[i+1%19][1]);
int j = i+1;
Log.d("i","i" + i + " " + j);
distanceJoint.initialize(circleBody[i], circleBody[(i+1)], v1, v2);
distanceJoint.collideConnected = true;
distanceJoint.dampingRatio = 10.0f;
distanceJoint.frequencyHz = 1.0f;
this.mPhysicsWorld.createJoint(distanceJoint);
}
Vector2 v1 = new Vector2(centers[1][0]/PIXEL_TO_METER_RATIO_DEFAULT,centers[1][1]/PIXEL_TO_METER_RATIO_DEFAULT);
Vector2 v2 = new Vector2(centers[19][0]/PIXEL_TO_METER_RATIO_DEFAULT,centers[19][1]/PIXEL_TO_METER_RATIO_DEFAULT);
distanceJoint.initialize(circleBody[1], circleBody[19], v1, v2);
distanceJoint.collideConnected = true;
distanceJoint.dampingRatio = 10.0f;
distanceJoint.frequencyHz = 1.0f;
this.mPhysicsWorld.createJoint(distanceJoint);
我错过了什么吗?请让我知道。