Exemple #1
0
        /// <summary>
        /// Load content
        /// </summary>
        public void LoadContent()
        {
            uberShader = Content.Load <Ubershader>("render");
            factory    = new StateFactory(uberShader, typeof(RenderFlags), Primitive.TriangleList, VertexInputElement.FromStructure <CubeVertex>());
            texture    = Content.Load <Texture2D>(@"Scenes\lena");

            vb = new VertexBuffer(GraphicsDevice, typeof(CubeVertex), 24);
            ib = new IndexBuffer(GraphicsDevice, 36);

            // create a new space with physics
            space = new Space();

            // update gravity force
            space.ForceUpdater.Gravity = new Vector3BEPU(0, -9.81f, 0);

            // add ground, ground has infinite mass
            Box ground = new Box(new Vector3BEPU(0, 0, 0), 50, 1, 50);

            space.Add(ground);

            // create boxes with random position and add color as a tag, then add box to space
            for (int i = 0; i < numberOfBoxes; i++)
            {
                Vector3Fusion vector = RandomExt.NextVector3(random, new Vector3Fusion(-10, 20, -10), new Vector3Fusion(10, 80, 10));
                Box           box    = new Box(new Vector3BEPU(vector.X, vector.Y, vector.Z), 1, 1, 1, 1);

                box.Tag = RandomExt.NextColor(random);
                space.Add(box);
            }
        }
Exemple #2
0
        /// <summary>
        /// Handle keys for each demo
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void InputDevice_KeyDown(object sender, Fusion.Input.InputDevice.KeyEventArgs e)
        {
            if (e.Key == Keys.F1)
            {
                DevCon.Show(this);
            }

            if (e.Key == Keys.F2)
            {
                Parameters.ToggleVSync();
            }

            if (e.Key == Keys.F5)
            {
                Reload();
            }

            if (e.Key == Keys.F12)
            {
                GraphicsDevice.Screenshot();
            }

            if (e.Key == Keys.Escape)
            {
                Exit();
            }

            if (e.Key == Keys.T)
            {
                foreach (var box in space.Entities)
                {
                    box.AngularMomentum *= 10.1f;
                }
            }

            // pause physics
            if (e.Key == Keys.P)
            {
                if (flag)
                {
                    flag = false;
                }
                else
                {
                    flag = true;
                }
            }

            // shoot box from camera
            if (e.Key == Keys.LeftButton)
            {
                Vector3Fusion vector   = GetService <Camera>().FreeCamPosition;
                Box           box      = new Box(new Vector3BEPU(vector.X, vector.Y, vector.Z), 1, 1, 1, 1);
                Vector3Fusion velocity = 10 * GetService <Camera>().GetCameraMatrix(StereoEye.Mono).Forward;
                box.LinearVelocity = new Vector3BEPU(velocity.X, velocity.Y, velocity.Z);
                box.Tag            = RandomExt.NextColor(random);
                space.Add(box);
            }

            // add new box somewhere
            if (e.Key == Keys.O)
            {
                Vector3Fusion vector = RandomExt.NextVector3(random, new Vector3Fusion(-10, 20, -10), new Vector3Fusion(10, 30, 10));
                Box           box    = new Box(new Vector3BEPU(vector.X, vector.Y, vector.Z), 1, 1, 1, 1);
                box.Tag = RandomExt.NextColor(random);
                space.Add(box);
            }
        }