/// <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="height">The height.</param> /// <param name="upAxis">Up axis.</param> public CapsuleColliderShape(bool is2D, float radius, float height, Vector3 upAxis) { Type = ColliderShapeTypes.Capsule; Is2D = is2D; Radius = radius; Height = height; UpAxis = upAxis; BulletSharp.CapsuleShape shape; Matrix rotation; //http://en.wikipedia.org/wiki/Capsule_(geometry) var h = radius * 2 + height; if (upAxis == Vector3.UnitX) { shape = new BulletSharp.CapsuleShapeX(radius, height); rotation = Matrix.RotationZ((float)Math.PI / 2.0f); } else if (upAxis == Vector3.UnitZ) { shape = new BulletSharp.CapsuleShapeZ(radius, height); rotation = Matrix.RotationX((float)Math.PI / 2.0f); } else //default to Y { UpAxis = Vector3.UnitY; shape = new BulletSharp.CapsuleShape(radius, height); rotation = Matrix.Identity; } if (Is2D) { InternalShape = new BulletSharp.Convex2DShape(shape) { LocalScaling = new Vector3(1, 1, 0) }; } else { InternalShape = shape; } if (!PhysicsEngine.Singleton.CreateDebugPrimitives) { return; } DebugPrimitive = GeometricPrimitive.Capsule.New(PhysicsEngine.Singleton.DebugGraphicsDevice); DebugPrimitiveScaling = Matrix.Scaling(new Vector3(radius * 2, h / 2, radius * 2) * 1.01f) * rotation; }
/// <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="height">The height.</param> /// <param name="upAxis">Up axis.</param> public CapsuleColliderShape(bool is2D, float radius, float height, Vector3 upAxis) { Type = ColliderShapeTypes.Capsule; Is2D = is2D; BulletSharp.CapsuleShape shape; Matrix rotation; //http://en.wikipedia.org/wiki/Capsule_(geometry) var h = radius * 2 + height; if (upAxis == Vector3.UnitX) { shape = new BulletSharp.CapsuleShapeX(radius, height); rotation = Matrix.RotationZ((float)Math.PI / 2.0f); } else if (upAxis == Vector3.UnitZ) { shape = new BulletSharp.CapsuleShapeZ(radius, height); rotation = Matrix.RotationX((float)Math.PI / 2.0f); } else //default to Y { shape = new BulletSharp.CapsuleShape(radius, height); rotation = Matrix.Identity; } if (Is2D) { InternalShape = new BulletSharp.Convex2DShape(shape) { LocalScaling = new Vector3(1, 1, 0) }; } else { InternalShape = shape; } DebugPrimitiveMatrix = Matrix.Scaling(new Vector3(radius * 2, h / 2, Is2D ? 1.0f : radius * 2) * 1.01f) * rotation; }
/// <summary> /// Create the collision capsule. /// </summary> /// <param name="radius">Capsule radius.</param> /// <param name="height">Capsule height.</param> /// <param name="axis">Capsule axis direction.</param> public CollisionCapsule(float radius = 1f, float height = 1f, CapsuleDirectionAxis axis = CapsuleDirectionAxis.Y) { _axisType = axis; switch (_axisType) { case CapsuleDirectionAxis.X: _shape = new BulletSharp.CapsuleShapeX(radius, height); break; case CapsuleDirectionAxis.Y: _shape = new BulletSharp.CapsuleShape(radius, height); break; case CapsuleDirectionAxis.Z: _shape = new BulletSharp.CapsuleShapeZ(radius, height); break; } }