/// <summary> /// Initializes a new instance of the <see cref="CapsuleColliderShape"/> class. /// </summary> /// <param name="is2D">if set to <c>true</c> [is2 d].</param> /// <param name="radius">The radius.</param> /// <param name="length">The length of the capsule.</param> /// <param name="orientation">Up axis.</param> public CapsuleColliderShape(bool is2D, float radius, float length, ShapeOrientation orientation) { Type = ColliderShapeTypes.Capsule; Is2D = is2D; capsuleLength = length; capsuleRadius = radius; Matrix rotation; CapsuleShape shape; switch (orientation) { case ShapeOrientation.UpX: shape = new CapsuleShapeZ(radius, length); rotation = Matrix.RotationX((float)Math.PI / 2.0f); break; case ShapeOrientation.UpY: shape = new CapsuleShape(radius, length); rotation = Matrix.Identity; break; case ShapeOrientation.UpZ: shape = new CapsuleShapeX(radius, length); rotation = Matrix.RotationZ((float)Math.PI / 2.0f); break; default: throw new ArgumentOutOfRangeException("orientation"); } InternalShape = Is2D ? (CollisionShape)new Convex2DShape(shape) { LocalScaling = new Vector3(1, 1, 0) }: shape; DebugPrimitiveMatrix = Matrix.Scaling(new Vector3(1.01f)) * rotation; }
void Init_CapsuleCollision() { float s = 4; float h = 6; int r = 20; Matrix startTransform = Matrix.Translation(0, h - 2, 0); CollisionShape capsuleShape = new CapsuleShapeX(1, 5); capsuleShape.Margin = 0.5f; //capsuleShape.LocalScaling = new Vector3(5, 1, 1); //RigidBody body = LocalCreateRigidBody(20, startTransform, capsuleShape); RigidBody body = LocalCreateRigidBody(0, startTransform, capsuleShape); body.Friction = 0.8f; const int fixeds = 0; //4+8; SoftBody psb = SoftBodyHelpers.CreatePatch(softBodyWorldInfo, new Vector3(-s, h, -s), new Vector3(+s, h, -s), new Vector3(-s, h, +s), new Vector3(+s, h, +s), r, r, fixeds, true); SoftWorld.AddSoftBody(psb); psb.TotalMass = 0.1f; psb.Cfg.PIterations = 10; psb.Cfg.CIterations = 10; psb.Cfg.DIterations = 10; //psb.Cfg.VIterations = 10; //psb.AppendAnchor(0, body); //psb.AppendAnchor(r-1, body); //cutting = true; CullingEnabled = false; }
public override CollisionShape GetCollisionShape() { if (collisionShapePtr == null) { CapsuleShape cs = null; if (upAxis == CapsuleAxis.x) { cs = new CapsuleShapeX(radius, height); } else if (upAxis == CapsuleAxis.y) { cs = new CapsuleShape(radius, height); } else if (upAxis == CapsuleAxis.z) { cs = new CapsuleShapeZ(radius, height); } else { Debug.LogError("invalid axis value"); } cs.LocalScaling = m_localScaling.ToBullet(); collisionShapePtr = cs; } return collisionShapePtr; }
public CollisionShape CreateCapsuleShapeX(float radius, float height) { CapsuleShapeX shape = new CapsuleShapeX(radius, height); _allocatedCollisionShapes.Add(shape); return shape; }