Пример #1
0
        static public void AddBall()
        {
            Random R = new Random();
            Actor  B = Engine.AddBall(1, R.Next(1, 10), new Vector3(0, R.Next(10, 50), 0).ToPhx());

            Balls.Add(CGeometry.Ball(device));
            BallMatrices.Add(B, B.GlobalPose.As <Matrix>());
        }
Пример #2
0
        static public void MainWindow_KeyDown(object sender, KeyEventArgs e)
        {
            Random  R          = new Random();
            Vector3 moveVector = new Vector3(0, 0, 0);

            switch (e.KeyCode)
            {
            case Keys.D:  radius += deltar; moveVector.X += step; break;

            case Keys.A:  radius -= deltar; moveVector.X -= step; break;

            case Keys.Space:  phi -= deltaang; moveVector.Y += step; break;

            case Keys.ControlKey: phi += deltaang; moveVector.Y -= step; break;

            case Keys.W:  theta -= deltaang; moveVector.Z += step; break;

            case Keys.S:  theta += deltaang; moveVector.Z -= step; break;

            case Keys.F: cameraEnabled = false; break;

            case Keys.ShiftKey: step = (step == 0.6f) ? 2.2f : 0.6f; break;

            case Keys.C:
                Actor B1 = Engine.AddBox(0.5f, 0.5f, 0.5f, 5, new Vector3(0, 50, -1).ToPhx());
                Actor B2 = Engine.AddBox(0.5f, 0.5f, 0.5f, 5, new Vector3(0, 50, 1).ToPhx());
                Engine.AddJointActors(B1, B2, new Vector3(0, 50, -1).ToPhx(), new Vector3(0, 50, 1).ToPhx());
                Boxes.Add(CGeometry.Box(device));
                Boxes.Add(CGeometry.Box(device));
                BoxMatrices.Add(B1, B1.GlobalPose.As <Matrix>());
                BoxMatrices.Add(B2, B2.GlobalPose.As <Matrix>());
                break;

            case Keys.X:


                Cloth C = Engine.AddCloth(ClothGeometry, new Vector3(0, 50, 0).ToPhx());


                break;

            case Keys.B:
            {
                Actor B = Engine.AddBox(0.5f, 0.5f, 0.5f, R.Next(1, 10), new Vector3(0, R.Next(10, 50), 0).ToPhx());
                backbuffer.DebugName = "BOX " + Boxes.Count.ToString();
                Boxes.Add(CGeometry.Box(device));
                BoxMatrices.Add(B, B.GlobalPose.As <Matrix>());
            }
            break;

            case Keys.N:
            {
                Actor B = Engine.AddBall(1, R.Next(1, 10), new Vector3(0, R.Next(10, 50), 0).ToPhx());
                Balls.Add(CGeometry.Ball(device));
                BallMatrices.Add(B, B.GlobalPose.As <Matrix>());
            }
            break;

            case Keys.U:
            {
                foreach (Actor A in Engine.Actors)
                {
                    if (A.IsDynamic)
                    {
                        A.AddForce(new Vector3(0, R.Next(1, 10), 0).ToPhx(), ForceMode.Impulse);
                    }
                }
            }
            break;

            case Keys.J:
            {
                foreach (Actor A in Engine.Actors)
                {
                    if (A.IsDynamic)
                    {
                        A.AddForce(new Vector3(0, -R.Next(1, 10), 0).ToPhx(), ForceMode.Impulse);
                    }
                }
            }
            break;

            case Keys.I:
            {
                foreach (Actor A in Engine.Actors)
                {
                    if (A.IsDynamic)
                    {
                        A.AddForce(new Vector3(0, 0, R.Next(1, 10)).ToPhx(), ForceMode.Impulse);
                    }
                }
            }
            break;

            case Keys.O:
            {
                foreach (Actor A in Engine.Actors)
                {
                    if (A.IsDynamic)
                    {
                        A.AddForce(new Vector3(R.Next(1, 10), 0, 0).ToPhx(), ForceMode.Impulse);
                    }
                }
            }
            break;

            case Keys.L:
            {
                foreach (Actor A in Engine.Actors)
                {
                    if (A.IsDynamic)
                    {
                        A.AddForce(new Vector3(-R.Next(1, 10), 0, 0).ToPhx(), ForceMode.Impulse);
                    }
                }
            }
            break;

            case Keys.K:
            {
                foreach (Actor A in Engine.Actors)
                {
                    if (A.IsDynamic)
                    {
                        A.AddForce(new Vector3(0, 0, -R.Next(1, 10)).ToPhx(), ForceMode.Impulse);
                    }
                }
            }
            break;

            case Keys.R:
            {
                List <Actor> Actors = new List <Actor>();
                foreach (var m in BoxMatrices)
                {
                    Actors.Add(m.Key);
                }
                foreach (var m in BallMatrices)
                {
                    Actors.Add(m.Key);
                }
                for (int i = 0; i < Actors.Count; i++)
                {
                    Actors[i].Dispose();
                }
                Boxes.Clear();
                BoxMatrices.Clear();
                Balls.Clear();
                BallMatrices.Clear();
                List <Cloth> Clothes = new List <Cloth>();
                foreach (var c in Engine.Scene.Cloths)
                {
                    Clothes.Add(c);
                }
                foreach (var c in Clothes)
                {
                    c.Dispose();
                }

                List <Joint> Joints = new List <Joint>();
                foreach (var c in Engine.Scene.Joints)
                {
                    Joints.Add(c);
                }
                foreach (var c in Joints)
                {
                    c.Dispose();
                }
            }
            break;
            }
            Camera.SetPositionSpherical(phi, theta, radius);
            Matrix V  = Camera.CameraView;
            Matrix VI = Matrix.Invert(V);

            myCamera.AddToCameraPosition(moveVector);
            V  = myCamera.View;
            VI = Matrix.Invert(V);

            effect.GetVariableByName("mWVP").AsMatrix().SetMatrix(V * Projection);
            effect.GetVariableByName("mVI").AsMatrix().SetMatrix(VI);
        }