Пример #1
0
        private void Window_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (!executed)
            {
                executed = true;
                new Thread(new ThreadStart(Execute)).Start();
            }
            else
            {
                BodyDef bodyDef = new BodyDef();
                bodyDef.position.Set(0, 7.0f, 0);
                bodyDef.bodyType = BodyType.eDynamicBody;
                Body body = scene.CreateBody(bodyDef);

                BoxDef boxDef = new BoxDef();
                boxes.Add(body.AddBox(boxDef));

                var c = new GeometryModel3D();
                c.Material  = SampleCube.Material;
                c.Geometry  = SampleCube.Geometry;
                c.Transform = new TranslateTransform3D(0, 0, 0);
                cubes.Add(c);
                SceneView.Children.Add(c);
            }
        }
Пример #2
0
        static Scene InitPhysics(List <Box> boxes)
        {
            var scene = new Scene(1 / 100.0, new Vec3(0, -9.8, 0), 10);
            //scene.SetAllowSleep(false);


            // Create the floor
            BodyDef bodyDef = new BodyDef();
            Body    body    = scene.CreateBody(bodyDef);

            BoxDef boxDef = new BoxDef();

            boxDef.SetRestitution(0.5);
            boxDef.SetFriction(0.7);
            Transform tx = Transform.Identity;

            boxDef.Set(tx, new Vec3(50.0, 1.0, 50.0));
            body.AddBox(boxDef);

            bodyDef.bodyType = BodyType.eDynamicBody;
            bodyDef.active   = true;
            bodyDef.awake    = true;
            boxDef.Set(tx, new Vec3(1.0f, 1.0f, 1.0f));

            var r = new Random();

            for (int i = 0; i < 8; ++i)
            {
                for (int j = 0; j < 8; ++j)
                {
                    bodyDef.position.Set(-5.0f + 1.25f * i, 5.0f, -5.0f + 1.25f * j);
                    bodyDef.axis  = new Vec3(0, 0, 1);
                    bodyDef.angle = r.NextDouble() * Math.PI;

                    body = scene.CreateBody(bodyDef);

                    boxes.Add(body.AddBox(boxDef));
                }
            }

            return(scene);
        }