示例#1
0
    public override BulletBody CreateBodyWithDefaultMotionState( BulletShape pShape, uint pLocalID, Vector3 pRawPosition, Quaternion pRawOrientation)
    {

        IndexedMatrix mat =
            IndexedMatrix.CreateFromQuaternion(new IndexedQuaternion(pRawOrientation.X, pRawOrientation.Y,
                                                                     pRawOrientation.Z, pRawOrientation.W));
        mat._origin = new IndexedVector3(pRawPosition.X, pRawPosition.Y, pRawPosition.Z);

        CollisionShape shape = (pShape as BulletShapeXNA).shape;

        // TODO: Feed Update array into null
        RigidBody body = new RigidBody(0, new DefaultMotionState( mat, IndexedMatrix.Identity), shape, IndexedVector3.Zero);
        body.SetWorldTransform(mat);
        body.SetUserPointer(pLocalID);
        return new BulletBodyXNA(pLocalID, body);
    }
示例#2
0
    internal static object CreateBodyWithDefaultMotionState2( object pShape, uint pLocalID, Vector3 pRawPosition, Quaternion pRawOrientation)
    {

        IndexedMatrix mat =
            IndexedMatrix.CreateFromQuaternion(new IndexedQuaternion(pRawOrientation.X, pRawOrientation.Y,
                                                                     pRawOrientation.Z, pRawOrientation.W));
        mat._origin = new IndexedVector3(pRawPosition.X, pRawPosition.Y, pRawPosition.Z);

        CollisionShape shape = pShape as CollisionShape;

        // TODO: Feed Update array into null
        RigidBody body = new RigidBody(0, new DefaultMotionState( mat, IndexedMatrix.Identity), shape, IndexedVector3.Zero);
        body.SetWorldTransform(mat);
        body.SetUserPointer(pLocalID);
        return body;
    }
示例#3
0
        public void BuildCollisionData(Color[] map, int width, int height, Vector3 bottomLeft)
        {
            Vector2 dim   = Vector2.One;
            Vector3 scale = new Vector3(dim, 1);

            BoxShape collisionBoxShape = new BoxShape(new IndexedVector3(0.5f));

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    int currentIndex = x + y * width;
                    if (map[currentIndex] == Color.White)
                    {
                        float   yOffset  = -dim.Y;//0f;// -(dim.Y / 2f);
                        Vector3 position = new Vector3(x - bottomLeft.X, (bottomLeft.Y - y) + yOffset, bottomLeft.Z);
                        m_waterLocations.Add(position);
                    }

                    if (map[currentIndex] == Color.White)
                    {
                        // check the 4 ordinals , if we're surrounded by other solid blocks
                        // then we don't need a block here.
                        bool upSet    = false;
                        bool downSet  = false;
                        bool leftSet  = false;
                        bool rightSet = false;

                        if (x >= 1 && x < width - 1)
                        {
                            if (map[currentIndex - 1] == Color.White)
                            {
                                leftSet = true;
                            }
                            if (map[currentIndex + 1] == Color.White)
                            {
                                rightSet = true;
                            }
                        }

                        if (y >= 1 && y < height - 1)
                        {
                            if (map[currentIndex - height] == Color.White)
                            {
                                upSet = true;
                            }
                            if (map[currentIndex + height] == Color.White)
                            {
                                downSet = true;
                            }
                        }

                        // if we're not surrounded by blocks then add in.
                        if (!(upSet && downSet && leftSet && rightSet))
                        {
                            Object  rigifdBody;
                            float   yOffset  = -dim.Y;//0f;// -(dim.Y / 2f);
                            Vector3 position = new Vector3(x - bottomLeft.X, (bottomLeft.Y - y) + yOffset, bottomLeft.Z);

                            RigidBodyConstructionInfo constructionInfo = new BulletXNA.BulletDynamics.RigidBodyConstructionInfo(0f, null, (BulletXNA.BulletCollision.CollisionShape)collisionBoxShape);
                            RigidBody rigidBody = new BulletXNA.BulletDynamics.RigidBody(constructionInfo);
                            Matrix    bsm       = Matrix.CreateTranslation(position);
                            rigidBody.SetWorldTransform(bsm);
                            // FIXME MAN - setup some collision flags on these bodies...
                            BulletXNA.BulletCollision.CollisionFilterGroups flags = (BulletXNA.BulletCollision.CollisionFilterGroups)(1 << 8);
                            BulletXNA.BulletCollision.CollisionFilterGroups mask  = (BulletXNA.BulletCollision.CollisionFilterGroups)(1 << 9);
                            //rigidBody.CollisionFlags |= (BulletSharp.CollisionFlags)CollisionObjectType.Ground;
                            m_dynamicsWorld.AddRigidBody(rigidBody, flags, mask);
                        }
                    }

                    // Build water ghost objects.
                    foreach (Vector3 pos in m_waterLocations)
                    {
                        GhostObject ghostObject = new GhostObject();

                        ghostObject.SetCollisionShape((BulletXNA.BulletCollision.CollisionShape)collisionBoxShape);

                        CollisionFilterGroups flags = (CollisionFilterGroups)(1 << 10);
                        CollisionFilterGroups mask  = (CollisionFilterGroups)(1 << 9);

                        ghostObject.SetCollisionFlags(CollisionFlags.CF_NO_CONTACT_RESPONSE | CollisionFlags.CF_STATIC_OBJECT);         // We can choose to make it "solid" if we want...
                        ghostObject.SetWorldTransform(BulletXNA.LinearMath.IndexedMatrix.CreateTranslation(pos));
                        m_dynamicsWorld.AddCollisionObject(ghostObject, flags, mask);
                        break;
                    }
                }
            }
        }
示例#4
0
        public void BuildCollisionData(Color[] map, int width, int height, Vector3 bottomLeft)
        {
            Vector2 dim = Vector2.One;
            Vector3 scale = new Vector3(dim, 1);

            BoxShape collisionBoxShape = new BoxShape(new IndexedVector3(0.5f));

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    int currentIndex = x + y * width;
                    if (map[currentIndex] == Color.White)
                    {
                        float yOffset = -dim.Y;//0f;// -(dim.Y / 2f);
                        Vector3 position = new Vector3(x - bottomLeft.X, (bottomLeft.Y - y) + yOffset, bottomLeft.Z);
                        m_waterLocations.Add(position);
                    }

                    if (map[currentIndex] == Color.White)
                    {
                        // check the 4 ordinals , if we're surrounded by other solid blocks
                        // then we don't need a block here.
                        bool upSet = false;
                        bool downSet = false;
                        bool leftSet = false;
                        bool rightSet = false;

                        if (x >= 1 && x < width - 1)
                        {
                            if (map[currentIndex - 1] == Color.White)
                            {
                                leftSet = true;
                            }
                            if (map[currentIndex + 1] == Color.White)
                            {
                                rightSet = true;

                            }
                        }

                        if (y >= 1 && y < height - 1)
                        {
                            if (map[currentIndex - height] == Color.White)
                            {
                                upSet = true;
                            }
                            if (map[currentIndex + height] == Color.White)
                            {
                                downSet = true;
                            }

                        }

                        // if we're not surrounded by blocks then add in.
                        if (!(upSet && downSet && leftSet && rightSet))
                        {
                            Object rigifdBody;
                            float yOffset = -dim.Y;//0f;// -(dim.Y / 2f);
                            Vector3 position = new Vector3(x - bottomLeft.X, (bottomLeft.Y - y) + yOffset, bottomLeft.Z);

                            RigidBodyConstructionInfo constructionInfo = new BulletXNA.BulletDynamics.RigidBodyConstructionInfo(0f, null, (BulletXNA.BulletCollision.CollisionShape)collisionBoxShape);
                            RigidBody rigidBody = new BulletXNA.BulletDynamics.RigidBody(constructionInfo);
                            Matrix bsm = Matrix.CreateTranslation(position);
                            rigidBody.SetWorldTransform(bsm);
                            // FIXME MAN - setup some collision flags on these bodies...
                            BulletXNA.BulletCollision.CollisionFilterGroups flags = (BulletXNA.BulletCollision.CollisionFilterGroups)(1 << 8);
                            BulletXNA.BulletCollision.CollisionFilterGroups mask = (BulletXNA.BulletCollision.CollisionFilterGroups)(1 << 9);
                            //rigidBody.CollisionFlags |= (BulletSharp.CollisionFlags)CollisionObjectType.Ground;
                            m_dynamicsWorld.AddRigidBody(rigidBody, flags, mask);

                        }
                    }

                    // Build water ghost objects.
                    foreach (Vector3 pos in m_waterLocations)
                    {
                        GhostObject ghostObject = new GhostObject();
                        
                        ghostObject.SetCollisionShape((BulletXNA.BulletCollision.CollisionShape)collisionBoxShape);

                        CollisionFilterGroups flags = (CollisionFilterGroups)(1 << 10);
                        CollisionFilterGroups mask = (CollisionFilterGroups)(1<<9);

                        ghostObject.SetCollisionFlags(CollisionFlags.CF_NO_CONTACT_RESPONSE | CollisionFlags.CF_STATIC_OBJECT);		// We can choose to make it "solid" if we want...
                        ghostObject.SetWorldTransform(BulletXNA.LinearMath.IndexedMatrix.CreateTranslation(pos));
                        m_dynamicsWorld.AddCollisionObject(ghostObject, flags, mask);
                        break;
                    }


                }
            }



        }