コード例 #1
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            // load models
            _footballModel = Content.Load<Model>("mdl/football");
            var pitchModel = Content.Load<Model>("mdl/pitch");

            // initialise physics simulation space
            _space = new Space();
            _space.ForceUpdater.Gravity = new Vector3(0, -9.81f, 0);

            Vector3[] vertices;
            int[] indices;
            TriangleMesh.GetVerticesAndIndicesFromModel(pitchModel, out vertices, out indices);
            var mesh = new StaticMesh(vertices, indices, new BEPUphysics.MathExtensions.AffineTransform(new Vector3(0, -40.0f, 0)));
            _space.Add(mesh);
            Components.Add(new StaticModel(pitchModel, mesh.WorldTransform.Matrix, this));

            var sphere = new Sphere(new Vector3(0, 4, 0), 1, 1);
            _space.Add(sphere);

            var scaling = Matrix.CreateScale(sphere.Radius);
            var model = new EntityModel(sphere, _footballModel, scaling, this);
            Components.Add(model);
            //sphere.Tag = model;
        }
コード例 #2
0
        private void ShootNewFootball(Player sender)
        {
            var origin = Camera.Position + new Vector3(0, -2.0f, 0);
            var sphere = new Sphere(origin, 1, 1);

            sphere.ApplyImpulse(sphere.Position, Camera.WorldMatrix.Forward * 100);
            _space.Add(sphere);

            var scaling = Matrix.CreateScale(sphere.Radius);
            var model = new EntityModel(sphere, _footballModel, scaling, this);
            Components.Add(model);
        }