protected void Add(PhyBody phyBody, Matrix m) { _AddPhyBody(phyBody); AddBulletPhysicsTransform(phyBody); m = m * Matrix.Translation(-phyBody.offset); phyBody.SetWorldTransform(m); if (phyBody.Constraint != null) { World.AddConstraint(phyBody.Constraint); } }
CollisionShape _AddFlipperCylinders(FlipperBehavior flipper) { float r1 = flipper.data.BaseRadius; float r2 = flipper.data.EndRadius; float h = flipper.data.Height; float l = flipper.data.FlipperRadius; var hh = h * 0.5f; // half height var cs = new BulletSharp.CompoundShape(); cs.AddChildShape( Matrix.Translation(0, 0, hh), new CylinderShapeZ(r1, r1, hh)); cs.AddChildShape( Matrix.Translation(0, -l, hh), new CylinderShapeZ(r2, r2, hh)); // we can't add Triangle Mesh Shape to Compound Shape. Add one or two boxes float hbl = new Vector2(l, r1 - r2).magnitude * 0.5f; Vector3 n = new Vector3(l, r1 - r2, 0); n.Normalize(); Vector3 beg = new Vector3(0, 0, hh) + n * (r1 - r2); Vector3 beg2 = new Vector3(-beg.X, beg.Y, beg.Z); Vector3 end = new Vector3(0, -l, hh); float angle = math.atan2(n.Y, n.X); bool onlyFront = true; bool rev = (flipper.data.StartAngle < 0 | flipper.data.StartAngle > 180); if (!onlyFront || rev) { cs.AddChildShape( Matrix.RotationZ(-angle) * Matrix.Translation((beg + end) * 0.5f), new BoxShape(Mathf.Min(r1, r2), hbl, hh)); } if (!onlyFront || !rev) { cs.AddChildShape( Matrix.RotationZ(angle) * Matrix.Translation((beg2 + end) * 0.5f), new BoxShape(Mathf.Min(r1, r2), hbl, hh)); } return(cs); }