예제 #1
0
        private PhysicObject SpawnPrimitive(Vector3 pos,Matrix ori)
        {
            int prim = random.Next(3);
            PhysicObject physicObj;

            float a = 1.0f + (float)random.NextDouble() * 1.0f;
            float b = a + (float)random.NextDouble() * 0.5f;
            float c = 2.0f / a / b;

            switch (prim)
            {
                case 0:
                    physicObj = new BoxObject(this, boxModel, new Vector3(a, b, c), ori, pos);
                    break;
                case 1:
                    physicObj = new SphereObject(this, sphereModel, 0.5f, ori, pos);
                    break;
                case 2:
                    physicObj = new CapsuleObject(this, capsuleModel, 0.5f,1f, ori, pos);
                    break;
                default:
                    physicObj = new SphereObject(this, sphereModel, (float)random.Next(5, 15), ori, pos);
                    break;
            }
            return physicObj;
        }
예제 #2
0
        private void CreateScene7()
        {
            Matrix rotM = Matrix.CreateRotationY(0.5f);

            for (int i = 0; i < 15; i += 2)
            {
                BoxObject boxObj0 = new BoxObject(this, boxModel, new Vector3(1, 1, 4),rotM, new Vector3(0, i - 10, 25));
                BoxObject boxObj2 = new BoxObject(this, boxModel, new Vector3(1, 1, 4), rotM, new Vector3(2, i - 10, 25));
                this.Components.Add(boxObj0); this.Components.Add(boxObj2);

                BoxObject boxObj3 = new BoxObject(this, boxModel, new Vector3(4, 1, 1), rotM, new Vector3(1, i + 1 - 10, 24));
                BoxObject boxObj5 = new BoxObject(this, boxModel, new Vector3(4, 1, 1), rotM, new Vector3(1, i + 1 - 10, 26));
                this.Components.Add(boxObj3); this.Components.Add(boxObj5);
            }
        }
예제 #3
0
        private void CreateScene6()
        {
            for (int i = 0; i < 10; i += 2)
            {
                BoxObject boxObj0 = new BoxObject(this, boxModel, new Vector3(1, 1f, 3), Matrix.Identity, new Vector3(0, i * 1f - 14, 1));
                BoxObject boxObj1 = new BoxObject(this, boxModel, new Vector3(1, 1f, 3), Matrix.Identity, new Vector3(1, i * 1f - 14, 1));
                BoxObject boxObj2 = new BoxObject(this, boxModel, new Vector3(1, 1f, 3), Matrix.Identity, new Vector3(2, i * 1f - 14, 1));
                this.Components.Add(boxObj0); this.Components.Add(boxObj1); this.Components.Add(boxObj2);

                BoxObject boxObj3 = new BoxObject(this, boxModel, new Vector3(3, 1f, 1), Matrix.Identity, new Vector3(1, i * 1f + 1f - 14, 0));
                BoxObject boxObj4 = new BoxObject(this, boxModel, new Vector3(3, 1f, 1), Matrix.Identity, new Vector3(1, i * 1f + 1f - 14, 1));
                BoxObject boxObj5 = new BoxObject(this, boxModel, new Vector3(3, 1f, 1), Matrix.Identity, new Vector3(1, i * 1f + 1f - 14, 2));
                this.Components.Add(boxObj3); this.Components.Add(boxObj4); this.Components.Add(boxObj5);
            }

            for (int i = 0; i < 10; i++)
            {
                CylinderObject cyl = new CylinderObject(this, 0.5f, 1.0f, new Vector3(5, i * 1.01f - 14.2f, 0), cylinderModel);
                this.Components.Add(cyl);
            }

            RagdollObject rgd;

            // professional stuntmen, noone gets hurt!

            for (int e = 0; e < 2; e++)
            {
                for (int i = 0; i < 2; i++)
                {
                    rgd = new RagdollObject(this, capsuleModel, sphereModel, boxModel, RagdollObject.RagdollType.Simple, 1.0f);
                    rgd.Position = new Vector3(e * 2, -14, 10 + i * 2);
                    rgd.PutToSleep();
                }
            }

            for (int x = 0; x < 8; x++)
            {
                for (int y = 0; y < 3; y++)
                    if (y % 2 == 0)
                        this.Components.Add(new BoxObject(this, boxModel, new Vector3(1, 1, 1), Matrix.Identity, new Vector3(x * 1.01f - 10.0f, y * 1.01f - 14.5f, 0)));
                    else
                        this.Components.Add(new BoxObject(this, boxModel, new Vector3(1, 1, 1), Matrix.Identity, new Vector3(x * 1.01f - 10.5f, y * 1.01f - 14.5f, 0)));
            }
        }
예제 #4
0
 private void CreateScene4(int dim)
 {
     for (int x = 0; x < dim; x++)
     {
         BoxObject obj = new BoxObject(this, boxModel, Vector3.One, Matrix.Identity, new Vector3(0, x * 1.01f-14.0f, 25));
         this.Components.Add(obj);
     }
 }
예제 #5
0
        private void CreateScene3()
        {
            // add a chain
            List<BoxObject> chainBoxes = new List<BoxObject>();

            for (int i = 0; i < 25; i++)
            {
                BoxObject boxObject = new BoxObject(this, boxModel, Vector3.One, Matrix.Identity, new Vector3(i, 25 - i, 0));
                if (i == 0) boxObject.PhysicsBody.Immovable = true;
                chainBoxes.Add(boxObject);
            }

            for (int i = 1; i < 25; i++)
            {
                HingeJoint hingeJoint = new HingeJoint();
                hingeJoint.Initialise(chainBoxes[i - 1].PhysicsBody, chainBoxes[i].PhysicsBody, Vector3.Backward,
                    new Vector3(0.5f, -0.5f, 0.0f), 0.5f, 90.0f, 90.0f, 0.0f, 0.2f);
                hingeJoint.EnableController();
                hingeJoint.EnableHinge();
            }

            foreach (BoxObject obj in chainBoxes)
            {
                this.Components.Add(obj);
            }
        }
예제 #6
0
        private void CreateScene0()
        {
            // Newton was here

            BoxObject holder = new BoxObject(this, boxModel, new Vector3(5, 1, 1), Matrix.Identity, new Vector3(-10, -5, 5));
            holder.PhysicsBody.Immovable = true;
            this.Components.Add(holder);

            for (int i = 0; i < 5; i++)
            {
                SphereObject obj = new SphereObject(this, sphereModel, 0.5f, Matrix.Identity, new Vector3(-12 + i, -8, 5));
                obj.PhysicsBody.CollisionSkin.SetMaterialProperties(0, new MaterialProperties(1.0f, 0.2f, 0.2f));
                obj.PhysicsBody.AllowFreezing = false;

                ConstraintMaxDistance maxDist1 = new ConstraintMaxDistance(holder.PhysicsBody, new Vector3(-2 + i, -0.5f, 0.5f), obj.PhysicsBody, Vector3.Up * 0.5f, 3f);
                ConstraintMaxDistance maxDist2 = new ConstraintMaxDistance(holder.PhysicsBody, new Vector3(-2 + i, -0.5f, -0.5f), obj.PhysicsBody, Vector3.Up * 0.5f, 3f);
                maxDist1.EnableConstraint();
                maxDist2.EnableConstraint();

                this.Components.Add(obj);

                if (i == 4)
                    obj.PhysicsBody.MoveTo(new Vector3(-6, -6, 5), Matrix.Identity);
                if (i == 3)
                    obj.PhysicsBody.MoveTo(new Vector3(-7, -6, 5), Matrix.Identity);

            }
        }