ここのチュートリアルに従って、回転ジョイントを構築しようとしています。要するに腕。長方形の腕を正方形上の点に固定し、その周りを回転させる必要があります。力が加えられると、2 つの形状が 1 つのように動作し、アームがラグドールのようにボックスの周りを飛んでいる間、一緒に固定されると予想されます。
残念ながら、これはまったく機能していません。最初は腕がつながっていて、力を加えると 2 つの形が離れて、説明のつかない奇妙な動きをします。あたかもアンカーが不安定な位置にあるかのようです。
私は jbox2d とこのチュートリアルの多くのコードも使用しています。
(動作するかどうかを確認するために、最初のアンカーをセンターに設定しました)(openGlを使用しているため、奇妙な変換がいくつかあります)
要点は次のとおりです。
public class New_char
{
Vec2 torso_pos, arm_pos;
Body torso, arm;
PolygonShape torso_shape, arm_shape;
BodyDef torso_def, arm_def;
FixtureDef torso_fix, arm_fix;
RevoluteJointDef torsoArmDef;
RevoluteJoint torsoArmJoint;
//float[] torSize = {0.5f, 0.5f}, armSize={0.75f, 0.10f};
public New_char(World world, float[] pos)
{
//this.torso_pos = new Vec2(pos[0], pos[1]) ; this.arm_pos = new Vec2(pos[0]+10,pos[1]+10);
//out.println(this.arm_pos+" thepos "+this.torso_pos);
this.torso_def = new BodyDef() ; this.arm_def = new BodyDef();
torso_def.type = BodyType.DYNAMIC ; arm_def.type = BodyType.DYNAMIC;
torso_def.position.set(320 / 30 / 2, 240 / 30 / 2) ; arm_def.position.set(320 / 30 / 2, 240 / 30 / 2);
this.torso_shape = new PolygonShape() ; this.arm_shape = new PolygonShape();
this.torso_shape.setAsBox(0.50f, 0.50f) ; this.arm_shape.setAsBox(0.75f, 0.10f);
this.torso_fix = new FixtureDef() ; this.arm_fix = new FixtureDef();
this.torso_fix.density = 0.1f ; this.arm_fix.density = 0.5f;
this.torso_fix.shape = this.torso_shape ; this.arm_fix.shape = this.arm_shape;
this.torso = world.createBody(this.torso_def) ; this.arm = world.createBody(this.arm_def);
this.torso.createFixture(this.torso_fix) ; this.arm.createFixture(this.arm_fix);
this.torsoArmDef = new RevoluteJointDef();
this.torsoArmDef.bodyA = this.torso ; this.torsoArmDef.bodyB = this.arm;
this.torsoArmDef.collideConnected = false;
this.torsoArmDef.localAnchorA.set(this.torso.getWorldCenter());
//Vec2 armpin = new Vec2(1f, 1f);
this.torsoArmDef.localAnchorB.set(this.arm.getWorldCenter());
this.torsoArmJoint = (RevoluteJoint)world.createJoint(this.torsoArmDef);