Esempio n. 1
0
 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);
 }
Esempio n. 2
0
        /// <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, Vector3?offset = null, Quaternion?localrot = null)
        {
            Type = ColliderShapeTypes.Capsule;
            Is2D = is2D;

            Length      = length;
            Radius      = radius;
            Orientation = orientation;

            Matrix       rotation;
            CapsuleShape shape;

            cachedScaling = Is2D ? new Vector3(1, 1, 0) : Vector3.One;

            switch (orientation)
            {
            case ShapeOrientation.UpZ:
                shape = new CapsuleShapeZ(radius, length)
                {
                    LocalScaling = cachedScaling,
                };
                rotation = Matrix.RotationX((float)Math.PI / 2.0f);
                break;

            case ShapeOrientation.UpY:
                shape = new CapsuleShape(radius, length)
                {
                    LocalScaling = cachedScaling,
                };
                rotation = Matrix.Identity;
                break;

            case ShapeOrientation.UpX:
                shape = new CapsuleShapeX(radius, length)
                {
                    LocalScaling = cachedScaling,
                };
                rotation = Matrix.RotationZ((float)Math.PI / 2.0f);
                break;

            default:
                throw new ArgumentOutOfRangeException("orientation");
            }

            InternalShape = Is2D ? (CollisionShape) new Convex2DShape(shape)
            {
                LocalScaling = cachedScaling
            } : shape;

            DebugPrimitiveMatrix = Matrix.Scaling(new Vector3(DebugScaling)) * rotation;

            if (offset.HasValue || localrot.HasValue)
            {
                LocalOffset   = offset ?? Vector3.Zero;
                LocalRotation = localrot ?? Quaternion.Identity;
                UpdateLocalTransformations();
            }
        }
Esempio n. 3
0
        /// <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;
            shapeOrientation = orientation;

            Matrix       rotation;
            CapsuleShape shape;

            cachedScaling = Is2D ? new Vector3(1, 1, 0) : Vector3.One;

            switch (orientation)
            {
            case ShapeOrientation.UpZ:
                shape = new CapsuleShapeZ(radius, length)
                {
                    LocalScaling = cachedScaling,
                };
                rotation = Matrix.RotationX((float)Math.PI / 2.0f);
                break;

            case ShapeOrientation.UpY:
                shape = new CapsuleShape(radius, length)
                {
                    LocalScaling = cachedScaling,
                };
                rotation = Matrix.Identity;
                break;

            case ShapeOrientation.UpX:
                shape = new CapsuleShapeX(radius, length)
                {
                    LocalScaling = cachedScaling,
                };
                rotation = Matrix.RotationZ((float)Math.PI / 2.0f);
                break;

            default:
                throw new ArgumentOutOfRangeException("orientation");
            }

            InternalShape = Is2D ? (CollisionShape) new Convex2DShape(shape)
            {
                LocalScaling = cachedScaling
            } : shape;

            DebugPrimitiveMatrix = Matrix.Scaling(new Vector3(DebugScaling)) * rotation;
        }
Esempio n. 4
0
        CapsuleShape _CreateCapsuleShape()
        {
            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
            {
                Log.Warning("invalid axis value");
            }
            cs.LocalScaling = m_localScaling.ToBullet();
            return(cs);
        }
Esempio n. 5
0
        private CapsuleShape _CreateCapsuleShape()
        {
            CapsuleShape cs = null;

            switch (upAxis)
            {
            default:
            case CapsuleAxis.x:
                cs = new CapsuleShapeX(radius, height);
                break;

            case CapsuleAxis.y:
                cs = new CapsuleShape(radius, height);
                break;

            case CapsuleAxis.z:
                cs = new CapsuleShapeZ(radius, height);
                break;
            }

            cs.LocalScaling = m_localScaling.ToBullet();

            return(cs);
        }
Esempio n. 6
0
        CapsuleShape _CreateCapsuleShape()
        {
            CapsuleShape cs = null;

            if (upAxis == Axis.x)
            {
                cs = new CapsuleShapeX(radius, height);
            }
            else if (upAxis == Axis.y)
            {
                cs = new CapsuleShape(radius, height);
            }
            else if (upAxis == Axis.z)
            {
                cs = new CapsuleShapeZ(radius, height);
            }
            else
            {
                Debug.LogError("invalid axis value");
            }
            cs.LocalScaling = m_localScaling.ToBullet();
            cs.Margin       = m_Margin;
            return(cs);
        }
Esempio n. 7
0
        private void BuildBoard()
        {
            float width  = 40;
            float height = 40;

            IndexedVector3 boardBackExtents = new IndexedVector3(width, height, 2) / 2f;
            IndexedVector3 boardSideExtents = new IndexedVector3(1, height, 2) / 2f;
            IndexedVector3 boardBarExtents  = new IndexedVector3(width, 1, 2) / 2f;
            IndexedVector3 pinExtent        = new IndexedVector3(0.5f, 1f, 2f);


            IndexedVector3 boardCenter = new IndexedVector3(0, 0, 0);

            // build frame.objects

            BoxShape         boardBack  = new BoxShape(boardBackExtents);
            BoxShape         boardSide  = new BoxShape(boardSideExtents);
            BoxShape         boardBar   = new BoxShape(boardBarExtents);
            StaticPlaneShape boardFront = new StaticPlaneShape(new IndexedVector3(0, 0, -1), -(boardBackExtents.Z + boardSideExtents.Z));

            CollisionShape pinShape = new CapsuleShapeZ(pinExtent.Y, pinExtent.Z);

            //pinShape = new BoxShape(pinExtent);

            //pinShape = new SphereShape(pinExtent.Y);

            m_cameraUp = Vector3.Up;

            // now RB's
            Matrix        m     = Matrix.Identity;
            IndexedMatrix trans = m;

            trans._origin = boardCenter;

            float mass = 0f;

            //LocalCreateRigidBody(mass,trans,boardBack);
            //LocalCreateRigidBody(mass, trans, boardFront);


            IndexedVector3 leftSide  = new IndexedVector3(boardCenter.X - boardBackExtents.X + boardSideExtents.X, boardCenter.Y, boardCenter.Z + boardSideExtents.Z);
            IndexedVector3 rightSide = new IndexedVector3(boardCenter.X + boardBackExtents.X - boardSideExtents.X, boardCenter.Y, boardCenter.Z + boardSideExtents.Z);

            IndexedVector3 topBar    = new IndexedVector3(boardCenter.X, boardCenter.Y + boardBackExtents.Y - boardBarExtents.Y, boardCenter.Z + boardSideExtents.Z);
            IndexedVector3 bottomBar = new IndexedVector3(boardCenter.X, boardCenter.Y - boardBackExtents.Y + boardBarExtents.Y, boardCenter.Z + boardSideExtents.Z);


            trans._origin = leftSide;
            LocalCreateRigidBody(mass, trans, boardSide);
            trans._origin = rightSide;
            LocalCreateRigidBody(mass, trans, boardSide);
            trans._origin = topBar;
            LocalCreateRigidBody(mass, trans, boardBar);
            trans._origin = bottomBar;
            LocalCreateRigidBody(mass, trans, boardBar);



            // now place the pins? (simple offset grid to start)

            int numPinsX = 8;
            int numPinsY = 8;

            // fixme
            IndexedVector3 pinTopLeft = new IndexedVector3(-boardBackExtents.X + 4, boardBackExtents.Y - 5, boardCenter.Z + boardSideExtents.Z);
            IndexedVector3 pinSpacer  = new IndexedVector3(pinExtent.Y * 4f, -pinExtent.Y * 4f, 0);



            float ballRadius = 0.9f;
            float fudge      = 3f;

            m_dropSphereShape = new SphereShape(ballRadius);

            m_ballDropSpot = new Vector3(1f, pinTopLeft.Y + 1, boardCenter.Z + boardBackExtents.Z + ballRadius);
            //new SphereShape(0.95f);


            m_debugDraw.SetDebugMode(m_debugDraw.GetDebugMode() | DebugDrawModes.DBG_DrawAabb);

            trans._origin = pinTopLeft;

            LocalCreateRigidBody(mass, trans, pinShape);


            for (int i = 0; i < numPinsX; ++i)
            {
                for (int j = 0; j < numPinsY; ++j)
                {
                    IndexedVector3 pos = new IndexedVector3(pinSpacer.X * i, (pinSpacer.Y * j), pinSpacer.Z);
                    // stagger rows.
                    if (j % 2 == 1)
                    {
                        pos.X += pinSpacer.X / 2f;
                    }

                    trans._origin = pinTopLeft + pos;
                    LocalCreateRigidBody(mass, trans, pinShape);
                }
            }
        }