Exemplo n.º 1
0
        public void CreatePhysicsObjectJitter()
        {
            Color[] md = new Color[verts.Length];
            heightMap.GetData <Color>(md);
            float[,] heightMapData = new float[width, height];

            float maxHeight = 30f;

            int counter = 0;

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    heightMapData[x, y] = (md[counter++].R / 256f) * maxHeight;
                }
            }

            indices = new int[(width - 1) * (height - 1) * 6];
            for (int x = 0; x < width - 1; x++)
            {
                for (int y = 0; y < height - 1; y++)
                {
                    indices[(x + y * (width - 1)) * 6]     = ((x + 1) + (y + 1) * width);
                    indices[(x + y * (width - 1)) * 6 + 1] = ((x + 1) + y * width);
                    indices[(x + y * (width - 1)) * 6 + 2] = (x + y * width);

                    indices[(x + y * (width - 1)) * 6 + 3] = ((x + 1) + (y + 1) * width);
                    indices[(x + y * (width - 1)) * 6 + 4] = (x + y * width);
                    indices[(x + y * (width - 1)) * 6 + 5] = (x + (y + 1) * width);
                }
            }

            Jitter.Collision.Shapes.TerrainShape terrainShape    = new Jitter.Collision.Shapes.TerrainShape(heightMapData, 1f, 1f);
            Jitter.Dynamics.RigidBody            jitterRigidBody = new Jitter.Dynamics.RigidBody(terrainShape);
            //Position.Y += maxHeight / 2f;

            Vector3 heightAdjustedPosition = Position;

            //heightAdjustedPosition.Y -= maxHeight / 2f;

            jitterRigidBody.Position = JitterObject.ToJitterVector(heightAdjustedPosition);


            RigidBody = jitterRigidBody;
        }
Exemplo n.º 2
0
        public void InitializePhysicsJitter()
        {
#if JITTER
            if (jitterPhysics == null)
            {
                JitterPhysicsComponent jitterPhysics2 = new JitterPhysicsComponent(this);
            }


            JitterObject ball = new JitterObject(this, "Models/Sphere");
            ball.Shape = new Jitter.Collision.Shapes.SphereShape(1f);
            ball.SetUpBulletPhysicsBody();
            ball.TranslateAA(camera.Position + new Vector3(0, 10, -5));
            ball.TextureMaterials.Add("Textures/core1");
            ball.NormalMaterials.Add("Textures/core1Normal");
            Components.Add(ball);

            // create a few dynamic rigidbodies
            float mass = 1.0f;

            Jitter.Collision.Shapes.BoxShape colShape = new Jitter.Collision.Shapes.BoxShape(Jitter.LinearMath.JVector.One);


            float start_x = StartPosX - ArraySizeX / 2;
            float start_y = StartPosY;
            float start_z = StartPosZ - ArraySizeZ / 2;

            start_z -= 8;
            Random rnd = new Random();

            int k, i, j;
            for (k = 0; k < ArraySizeY; k++)
            {
                for (i = 0; i < ArraySizeX; i++)
                {
                    for (j = 0; j < ArraySizeZ; j++)
                    {
                        Matrix startTransform = Matrix.CreateTranslation(
                            2 * i + start_x,
                            2 * k + start_y,
                            2 * j + start_z
                            );

                        // using motionstate is recommended, it provides interpolation capabilities
                        // and only synchronizes 'active' objects
                        JitterObject box = new JitterObject(this, "Models/Box");
                        box.Shape = new Jitter.Collision.Shapes.BoxShape(Jitter.LinearMath.JVector.One);
                        box.SetUpBulletPhysicsBody();
                        box.Position = startTransform.Translation;

                        box.TextureMaterials.Add("Textures/BoxColor");
                        box.NormalMaterials.Add("Textures/BoxNormal");

                        box.TranslateAA(new Vector3(0, 7, 0));
                        Components.Add(box);
                    }
                }
            }

            start_x -= 8;

            for (k = 0; k < 2; k++)
            {
                for (i = 0; i < 2; i++)
                {
                    for (j = 0; j < 2; j++)
                    {
                        Matrix startTransform = Matrix.CreateTranslation(
                            2 * i + start_x,
                            2 * k + start_y,
                            2 * j + start_z
                            );

                        // using motionstate is recommended, it provides interpolation capabilities
                        // and only synchronizes 'active' objects
                        JitterObject box = new JitterObject(this, "Models/Box");
                        box.Shape = new Jitter.Collision.Shapes.BoxShape(Jitter.LinearMath.JVector.One);
                        box.SetUpBulletPhysicsBody();
                        box.Position = startTransform.Translation;
                        box.TextureMaterials.Add("Textures/BoxColor01");
                        box.NormalMaterials.Add("Textures/BoxNormal01");

                        box.TranslateAA(new Vector3(0, 7, 0));
                        Components.Add(box);
                    }
                }
            }
            IsPhysicsEnabled = false;
#endif
        }