Пример #1
0
 public ConeShape(float radius, float height)
 {
     Radius                 = radius;
     Height                 = height;
     BulletShape            = new BulletSharp.ConeShape(radius, height);
     BulletShape.UserObject = this;
 }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ConeColliderShape"/> class.
        /// </summary>
        /// <param name="orientation">Up axis.</param>
        /// <param name="radius">The radius of the cone</param>
        /// <param name="height">The height of the cone</param>
        public ConeColliderShape(float heightParam, float radiusParam, ShapeOrientation orientationParam, Vector3?offset = null, Quaternion?localrot = null)
        {
            Type        = ColliderShapeTypes.Cone;
            Is2D        = false; //always false for cone
            Height      = heightParam;
            Radius      = radiusParam;
            Orientation = orientationParam;

            Matrix rotation;

            cachedScaling = Vector3.One;

            switch (Orientation)
            {
            case ShapeOrientation.UpX:
                InternalShape = new BulletSharp.ConeShapeX(Radius, Height)
                {
                    LocalScaling = cachedScaling,
                };
                rotation = Matrix.RotationZ((float)Math.PI / 2.0f);
                break;

            case ShapeOrientation.UpY:
                InternalShape = new BulletSharp.ConeShape(Radius, Height)
                {
                    LocalScaling = cachedScaling,
                };
                rotation = Matrix.Identity;
                break;

            case ShapeOrientation.UpZ:
                InternalShape = new BulletSharp.ConeShapeZ(Radius, Height)
                {
                    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();
            }
        }
Пример #3
0
        /// <summary>
        /// Create the collision cone.
        /// </summary>
        /// <param name="radius">Cone radius.</param>
        /// <param name="height">Cone height.</param>
        /// <param name="axis">Cone axis direction.</param>
        public CollisionCone(float radius = 1f, float height = 1f, ConeDirectionAxis axis = ConeDirectionAxis.Y)
        {
            _axisType = axis;
            switch (_axisType)
            {
            case ConeDirectionAxis.X:
                _shape = new BulletSharp.ConeShapeX(radius, height);
                break;

            case ConeDirectionAxis.Y:
                _shape = new BulletSharp.ConeShape(radius, height);
                break;

            case ConeDirectionAxis.Z:
                _shape = new BulletSharp.ConeShapeZ(radius, height);
                break;
            }
        }
Пример #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ConeColliderShape"/> class.
        /// </summary>
        /// <param name="orientation">Up axis.</param>
        /// <param name="radius">The radius of the cone</param>
        /// <param name="height">The height of the cone</param>
        public ConeColliderShape(float heightParam, float radiusParam, ShapeOrientation orientationParam)
        {
            Type        = ColliderShapeTypes.Cone;
            Is2D        = false; //always false for cone
            Height      = heightParam;
            Radius      = radiusParam;
            Orientation = orientationParam;

            Matrix rotation;

            cachedScaling = Vector3.One;

            switch (Orientation)
            {
            case ShapeOrientation.UpX:
                InternalShape = new BulletSharp.ConeShapeX(Radius, Height)
                {
                    LocalScaling = cachedScaling,
                };
                rotation = Matrix.RotationZ((float)Math.PI / 2.0f);
                break;

            case ShapeOrientation.UpY:
                InternalShape = new BulletSharp.ConeShape(Radius, Height)
                {
                    LocalScaling = cachedScaling,
                };
                rotation = Matrix.Identity;
                break;

            case ShapeOrientation.UpZ:
                InternalShape = new BulletSharp.ConeShapeZ(Radius, Height)
                {
                    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="ConeColliderShape"/> class.
        /// </summary>
        /// <param name="orientation">Up axis.</param>
        /// <param name="radius">The radius of the cone</param>
        /// <param name="height">The height of the cone</param>
        public ConeColliderShape(float height, float radius, ShapeOrientation orientation)
        {
            Type = ColliderShapeTypes.Cone;
            Is2D = false; //always false for cone

            Matrix rotation;

            CachedScaling = Vector3.One;

            switch (orientation)
            {
                case ShapeOrientation.UpX:
                    InternalShape = new BulletSharp.ConeShapeX(radius, height)
                    {
                        LocalScaling = CachedScaling
                    };
                    rotation = Matrix.RotationZ((float)Math.PI / 2.0f);
                    break;
                case ShapeOrientation.UpY:
                    InternalShape = new BulletSharp.ConeShape(radius, height)
                    {
                        LocalScaling = CachedScaling
                    };
                    rotation = Matrix.Identity;
                    break;
                case ShapeOrientation.UpZ:
                    InternalShape = new BulletSharp.ConeShapeZ(radius, height)
                    {
                        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;
        }