/// <summary> /// Initializes a new instance of the <see cref="CylinderColliderShape"/> class. /// </summary> /// <param name="halfExtents">The half extents.</param> /// <param name="upAxis">Up axis.</param> public CylinderColliderShape(Vector3 halfExtents, Vector3 upAxis) { Type = ColliderShapeTypes.Cylinder; Is2D = false; //always false for cylinders Matrix rotation; Vector3 scaling; if (upAxis == Vector3.UnitX) { InternalShape = new BulletSharp.CylinderShapeX(halfExtents); rotation = Matrix.RotationZ((float)Math.PI / 2.0f); scaling = new Vector3(halfExtents.Y * 2.0f, halfExtents.X * 2.0f, halfExtents.Z * 2.0f); } else if (upAxis == Vector3.UnitZ) { InternalShape = new BulletSharp.CylinderShapeZ(halfExtents); rotation = Matrix.RotationX((float)Math.PI / 2.0f); scaling = new Vector3(halfExtents.X * 2.0f, halfExtents.Z * 2.0f, halfExtents.Y * 2.0f); } else //default to Y { InternalShape = new BulletSharp.CylinderShape(halfExtents); rotation = Matrix.Identity; scaling = halfExtents * 2.0f; } DebugPrimitiveMatrix = Matrix.Scaling(scaling * 1.01f) * rotation; }
/// <summary> /// Initializes a new instance of the <see cref="CylinderColliderShape"/> class. /// </summary> /// <param name="orientation">Up axis.</param> /// <param name="radius">The radius of the cylinder</param> /// <param name="height">The height of the cylinder</param> public CylinderColliderShape(float height, float radius, ShapeOrientation orientation) { Type = ColliderShapeTypes.Cylinder; Is2D = false; //always false for cylinders Matrix rotation; switch (orientation) { case ShapeOrientation.UpX: InternalShape = new BulletSharp.CylinderShapeX(new Vector3(height / 2, radius, 0)); rotation = Matrix.RotationZ((float)Math.PI / 2.0f); break; case ShapeOrientation.UpY: InternalShape = new BulletSharp.CylinderShape(new Vector3(radius, height / 2, 0)); rotation = Matrix.Identity; break; case ShapeOrientation.UpZ: InternalShape = new BulletSharp.CylinderShapeZ(new Vector3(radius, 0, height / 2)); rotation = Matrix.RotationX((float)Math.PI / 2.0f); break; default: throw new ArgumentOutOfRangeException("orientation"); } DebugPrimitiveMatrix = Matrix.Scaling(new Vector3(2 * radius, height, 2 * radius) * 1.01f) * rotation; }
/// <summary> /// Initializes a new instance of the <see cref="CylinderColliderShape"/> class. /// </summary> /// <param name="orientation">Up axis.</param> /// <param name="radius">The radius of the cylinder</param> /// <param name="height">The height of the cylinder</param> public CylinderColliderShape(float height, float radius, ShapeOrientation orientation) { Type = ColliderShapeTypes.Cylinder; Is2D = false; //always false for cylinders Matrix rotation; switch (orientation) { case ShapeOrientation.UpX: InternalShape = new BulletSharp.CylinderShapeX(new Vector3(height/2, radius, 0)); rotation = Matrix.RotationZ((float)Math.PI / 2.0f); break; case ShapeOrientation.UpY: InternalShape = new BulletSharp.CylinderShape(new Vector3(radius, height/2, 0)); rotation = Matrix.Identity; break; case ShapeOrientation.UpZ: InternalShape = new BulletSharp.CylinderShapeZ(new Vector3(radius, 0, height/2)); rotation = Matrix.RotationX((float)Math.PI / 2.0f); break; default: throw new ArgumentOutOfRangeException("orientation"); } DebugPrimitiveMatrix = Matrix.Scaling(new Vector3(2*radius, height, 2*radius) * 1.01f) * rotation; }
/// <summary> /// Initializes a new instance of the <see cref="CylinderColliderShape"/> class. /// </summary> /// <param name="orientation">Up axis.</param> /// <param name="radius">The radius of the cylinder</param> /// <param name="height">The height of the cylinder</param> public CylinderColliderShape(float heightParam, float radiusParam, ShapeOrientation orientationParam, Vector3?offset = null, Quaternion?localrot = null) { Type = ColliderShapeTypes.Cylinder; Is2D = false; //always false for cylinders Height = heightParam; Radius = radiusParam; Matrix rotation; cachedScaling = Vector3.One; Orientation = orientationParam; switch (Orientation) { case ShapeOrientation.UpX: InternalShape = new BulletSharp.CylinderShapeX(new Vector3(Height / 2, Radius, Radius)) { LocalScaling = cachedScaling, }; rotation = Matrix.RotationZ((float)Math.PI / 2.0f); break; case ShapeOrientation.UpY: InternalShape = new BulletSharp.CylinderShape(new Vector3(Radius, Height / 2, Radius)) { LocalScaling = cachedScaling, }; rotation = Matrix.Identity; break; case ShapeOrientation.UpZ: InternalShape = new BulletSharp.CylinderShapeZ(new Vector3(Radius, Radius, Height / 2)) { LocalScaling = cachedScaling, }; rotation = Matrix.RotationX((float)Math.PI / 2.0f); break; default: throw new ArgumentOutOfRangeException(nameof(Orientation)); } DebugPrimitiveMatrix = Matrix.Scaling(new Vector3(Radius * 2, Height, Radius * 2) * DebugScaling) * rotation; if (offset.HasValue || localrot.HasValue) { LocalOffset = offset ?? Vector3.Zero; LocalRotation = localrot ?? Quaternion.Identity; UpdateLocalTransformations(); } }
/// <summary> /// Create the collision cylinder. /// </summary> /// <param name="halfExtent">Half extent on X, Y and Z of the cylinder.</param> /// <param name="axis">Cylinder axis direction.</param> public CollisionCylinder(Vector3 halfExtent, CylinderDirectionAxis axis = CylinderDirectionAxis.Y) { _axisType = axis; switch (_axisType) { case CylinderDirectionAxis.X: _shape = new BulletSharp.CylinderShapeX(halfExtent.X, halfExtent.Y, halfExtent.Z); break; case CylinderDirectionAxis.Y: _shape = new BulletSharp.CylinderShape(halfExtent.X, halfExtent.Y, halfExtent.Z); break; case CylinderDirectionAxis.Z: _shape = new BulletSharp.CylinderShapeZ(halfExtent.X, halfExtent.Y, halfExtent.Z); break; } }
/// <summary> /// Initializes a new instance of the <see cref="CylinderColliderShape"/> class. /// </summary> /// <param name="orientation">Up axis.</param> /// <param name="radius">The radius of the cylinder</param> /// <param name="height">The height of the cylinder</param> public CylinderColliderShape(float heightParam, float radiusParam, ShapeOrientation orientationParam) { Type = ColliderShapeTypes.Cylinder; Is2D = false; //always false for cylinders Height = heightParam; Radius = radiusParam; Matrix rotation; cachedScaling = Vector3.One; Orientation = orientationParam; switch (Orientation) { case ShapeOrientation.UpX: InternalShape = new BulletSharp.CylinderShapeX(new Vector3(Height / 2, Radius, Radius)) { LocalScaling = cachedScaling, }; rotation = Matrix.RotationZ(MathF.PI / 2.0f); break; case ShapeOrientation.UpY: InternalShape = new BulletSharp.CylinderShape(new Vector3(Radius, Height / 2, Radius)) { LocalScaling = cachedScaling, }; rotation = Matrix.Identity; break; case ShapeOrientation.UpZ: InternalShape = new BulletSharp.CylinderShapeZ(new Vector3(Radius, Radius, Height / 2)) { LocalScaling = cachedScaling, }; rotation = Matrix.RotationX(MathF.PI / 2.0f); break; default: throw new ArgumentOutOfRangeException(nameof(Orientation)); } DebugPrimitiveMatrix = Matrix.Scaling(new Vector3(Radius * 2, Height, Radius * 2) * DebugScaling) * rotation; }
/// <summary> /// Initializes a new instance of the <see cref="CylinderColliderShape"/> class. /// </summary> /// <param name="orientation">Up axis.</param> /// <param name="radius">The radius of the cylinder</param> /// <param name="height">The height of the cylinder</param> public CylinderColliderShape(float height, float radius, ShapeOrientation orientation) { Type = ColliderShapeTypes.Cylinder; Is2D = false; //always false for cylinders Matrix rotation; CachedScaling = Vector3.One; shapeOrientation = orientation; switch (orientation) { case ShapeOrientation.UpX: InternalShape = new BulletSharp.CylinderShapeX(new Vector3(height / 2, radius, radius)) { LocalScaling = CachedScaling }; rotation = Matrix.RotationZ((float)Math.PI / 2.0f); break; case ShapeOrientation.UpY: InternalShape = new BulletSharp.CylinderShape(new Vector3(radius, height / 2, radius)) { LocalScaling = CachedScaling }; rotation = Matrix.Identity; break; case ShapeOrientation.UpZ: InternalShape = new BulletSharp.CylinderShapeZ(new Vector3(radius, radius, height / 2)) { LocalScaling = CachedScaling }; rotation = Matrix.RotationX((float)Math.PI / 2.0f); break; default: throw new ArgumentOutOfRangeException(nameof(orientation)); } DebugPrimitiveMatrix = Matrix.Scaling(new Vector3(radius * 2, height, radius * 2) * DebugScaling) * rotation; }
/// <summary> /// Initializes a new instance of the <see cref="CylinderColliderShape"/> class. /// </summary> /// <param name="halfExtents">The half extents.</param> /// <param name="upAxis">Up axis.</param> public CylinderColliderShape(Vector3 halfExtents, Vector3 upAxis) { Type = ColliderShapeTypes.Cylinder; Is2D = false; //always false for cylinders HalfExtents = halfExtents; UpAxis = upAxis; Matrix rotation; Vector3 scaling; if (upAxis == Vector3.UnitX) { InternalShape = new BulletSharp.CylinderShapeX(halfExtents); rotation = Matrix.RotationZ((float)Math.PI / 2.0f); scaling = new Vector3(halfExtents.Y * 2.0f, halfExtents.X * 2.0f, halfExtents.Z * 2.0f); } else if (upAxis == Vector3.UnitZ) { InternalShape = new BulletSharp.CylinderShapeZ(halfExtents); rotation = Matrix.RotationX((float)Math.PI / 2.0f); scaling = new Vector3(halfExtents.X * 2.0f, halfExtents.Z * 2.0f, halfExtents.Y * 2.0f); } else //default to Y { UpAxis = Vector3.UnitY; InternalShape = new BulletSharp.CylinderShape(halfExtents); rotation = Matrix.Identity; scaling = halfExtents * 2.0f; } if (!PhysicsEngine.Singleton.CreateDebugPrimitives) { return; } DebugPrimitive = GeometricPrimitive.Cylinder.New(PhysicsEngine.Singleton.DebugGraphicsDevice); DebugPrimitiveScaling = Matrix.Scaling(scaling * 1.01f) * rotation; }
/// <summary> /// Initializes a new instance of the <see cref="CylinderColliderShape"/> class. /// </summary> /// <param name="orientation">Up axis.</param> /// <param name="radius">The radius of the cylinder</param> /// <param name="height">The height of the cylinder</param> public CylinderColliderShape(float height, float radius, ShapeOrientation orientation) { Type = ColliderShapeTypes.Cylinder; Is2D = false; //always false for cylinders Matrix rotation; CachedScaling = Vector3.One; shapeOrientation = orientation; switch (orientation) { case ShapeOrientation.UpX: InternalShape = new BulletSharp.CylinderShapeX(new Vector3(height/2, radius, radius)) { LocalScaling = CachedScaling }; rotation = Matrix.RotationZ((float)Math.PI / 2.0f); break; case ShapeOrientation.UpY: InternalShape = new BulletSharp.CylinderShape(new Vector3(radius, height/2, radius)) { LocalScaling = CachedScaling }; rotation = Matrix.Identity; break; case ShapeOrientation.UpZ: InternalShape = new BulletSharp.CylinderShapeZ(new Vector3(radius, radius, height/2)) { LocalScaling = CachedScaling }; rotation = Matrix.RotationX((float)Math.PI / 2.0f); break; default: throw new ArgumentOutOfRangeException(nameof(orientation)); } DebugPrimitiveMatrix = Matrix.Scaling(new Vector3(radius * 2, height, radius * 2) * DebugScaling) * rotation; }