private void SpawnRandomPrimitive(JVector position, JVector velocity)
        {
            RigidBody body = null;
            int       rndn = rndn = random.Next(1); //7

            // less of the more advanced objects
            if (rndn == 5 || rndn == 6)
            {
                rndn = random.Next(7);
            }

            switch (rndn)
            {
            /*case 0:
             *  body = new RigidBody(new ConeShape((float)random.Next(5, 50) / 20.0f, (float)random.Next(10, 20) / 20.0f));
             *  break;
             * case 1:
             *  body = new RigidBody(new BoxShape((float)random.Next(10, 30) / 20.0f, (float)random.Next(10, 30) / 20.0f, (float)random.Next(10, 30) / 20.0f));
             *  break;
             * case 2:
             *  body = new RigidBody(new SphereShape(0.4f));
             *  break;
             * case 3:
             *  body = new RigidBody(new CylinderShape(1.0f, 0.5f));
             *  break;
             * case 4:
             *  body = new RigidBody(new CapsuleShape(1.0f, 0.5f));
             *  break;*/
            /*case 0:
             *  Shape b1 = new BoxShape(new JVector(3, 1, 1));
             *  Shape b2 = new BoxShape(new JVector(1, 1, 3));
             *  Shape b3 = new CylinderShape(3.0f, 0.5f);
             *
             *  CompoundShape.TransformedShape t1 = new CompoundShape.TransformedShape(b1, JMatrix.Identity, JVector.Zero);
             *  CompoundShape.TransformedShape t2 = new CompoundShape.TransformedShape(b2, JMatrix.Identity, JVector.Zero);
             *  CompoundShape.TransformedShape t3 = new CompoundShape.TransformedShape(b3, JMatrix.Identity, new JVector(0, 0, 0));
             *
             *  CompoundShape ms = new CompoundShape(new CompoundShape.TransformedShape[3] { t1, t2, t3 });
             *
             *  body = new RigidBody(ms);
             *  break;*/
            case 0:
                ConvexHullObject obj2 = new ConvexHullObject(this);
                Components.Add(obj2);
                body = obj2.body;
                body.Material.Restitution    = 0.2f;
                body.Material.StaticFriction = 0.8f;
                convexObj.Add(obj2);
                break;
            }

            World.AddBody(body);
            //body.IsParticle = true;
            // body.EnableSpeculativeContacts = true;
            body.Position       = position;
            body.LinearVelocity = velocity;
            lastBody            = body;
        }
示例#2
0
        private void SpawnRandomPrimitive(JVector position, JVector velocity)
        {
            RigidBody body = null;
            int       rndn = rndn = random.Next(7);

            if (rndn == 5 || rndn == 6)
            {
                rndn = random.Next(7);
            }

            switch (rndn)
            {
            case 0:
                body = new RigidBody(new ConeShape(random.Next(5, 50) / 20.0f, random.Next(10, 20) / 20.0f));
                break;

            case 1:
                body = new RigidBody(new BoxShape(random.Next(10, 30) / 20.0f, random.Next(10, 30) / 20.0f, random.Next(10, 30) / 20.0f));
                break;

            case 2:
                body = new RigidBody(new SphereShape(0.4f));
                break;

            case 3:
                body = new RigidBody(new CylinderShape(1.0f, 0.5f));
                break;

            case 4:
                body = new RigidBody(new CapsuleShape(1.0f, 0.5f));
                break;

            case 5:
                Shape b1 = new BoxShape(new JVector(3, 1, 1));
                Shape b2 = new BoxShape(new JVector(1, 1, 3));
                Shape b3 = new CylinderShape(3.0f, 0.5f);

                var t1 = new CompoundShape.TransformedShape(b1, JMatrix.Identity, JVector.Zero);
                var t2 = new CompoundShape.TransformedShape(b2, JMatrix.Identity, JVector.Zero);
                var t3 = new CompoundShape.TransformedShape(b3, JMatrix.Identity, new JVector(0, 0, 0));

                var ms = new CompoundShape(new CompoundShape.TransformedShape[3] {
                    t1, t2, t3
                });

                body = new RigidBody(ms);
                break;

            case 6:
                var obj2 = new ConvexHullObject(this);
                Components.Add(obj2);
                body = obj2.body;
                body.Material.Restitution    = 0.2f;
                body.Material.StaticFriction = 0.8f;
                break;
            }

            World.AddBody(body);
            body.Position       = position;
            body.LinearVelocity = velocity;
            lastBody            = body;
        }
示例#3
0
文件: JitterDemo.cs 项目: tpb3d/TPB3D
        private void SpawnRandomPrimitive(JVector position, JVector velocity)
        {
            RigidBody body = null;
            int rndn = random.Next(7);

            // less of the more advanced objects
            if (rndn == 5 || rndn == 6) rndn = random.Next(7);

            switch (rndn)
            {
                case 0:
                    body = new RigidBody(new ConeShape((float)random.Next(5, 50) / 20.0f, (float)random.Next(10, 20) / 20.0f));
                    break;
                case 1:
                    body = new RigidBody(new BoxShape((float)random.Next(10, 30) / 20.0f, (float)random.Next(10, 30) / 20.0f, (float)random.Next(10, 30) / 20.0f));
                    break;
                case 2:
                    body = new RigidBody(new SphereShape(1.0f));
                    break;
                case 3:
                    body = new RigidBody(new CylinderShape(1.0f, 0.5f));
                    break;
                case 4:
                    body = new RigidBody(new CapsuleShape(1.0f, 0.5f));
                    break;
                case 5:
                    Shape b1 = new BoxShape(new JVector(3, 1, 1));
                    Shape b2 = new BoxShape(new JVector(1, 1, 3));
                    Shape b3 = new CylinderShape(3.0f, 0.5f);

                    CompoundShape.TransformedShape t1 = new CompoundShape.TransformedShape(b1, JMatrix.Identity, JVector.Zero);
                    CompoundShape.TransformedShape t2 = new CompoundShape.TransformedShape(b2, JMatrix.Identity, JVector.Zero);
                    CompoundShape.TransformedShape t3 = new CompoundShape.TransformedShape(b3, JMatrix.Identity, new JVector(0, 0, 0));

                    CompoundShape ms = new CompoundShape(new CompoundShape.TransformedShape[3] { t1, t2, t3 });

                    body = new RigidBody(ms);
                    break;
                case 6:
                    ConvexHullObject obj2 = new ConvexHullObject(this);
                    Components.Add(obj2);
                    body = obj2.body;
                    body.Material.Restitution = 0.2f;
                    body.Material.StaticFriction = 0.8f;
                    break;
            }

            World.AddBody(body);

            body.Position = position;
            body.LinearVelocity = velocity;
            //body.EnableDebugDraw = true;

            lastBody = body;
        }