Esempio n. 1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            camera = new Camera(this, new Vector3(0, 0, 100),
                Vector3.Zero, Vector3.Up);
            Components.Add(camera);
            ball = new Ball(100f);
            dummy = new Ball(100f);
            crate = new Crate(new Vector3(1,1,1));
            crate.Position = new Vector3(20,20,20);
            //dummy.InverseMass = 0;
            //dummy.InverseInertiaTensor = new Matrix3();
            //spring = new Spring(ball, dummy, dummy.Position, 0.3f, 20.0f);
            //spring.AddBody(ball);
            g = new Gravity(Vector3.Down * 10f);
            g.AddBody(ball);
            //TODO determine which is down for the world
            //BoundingSphereRenderer.InitializeGraphics(GraphicsDevice, 10^100);

            base.Initialize();
        }
Esempio n. 2
0
        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        protected override void Initialize()
        {
            balls = new Ball[10];
            fixedBalls = new Ball[10];
            Model mod = Content.Load<Model>(@"ball");
            Texture2D tex = Content.Load<Texture2D>(@"basic_material");

            g = new Gravity(Vector3.Down );

            for (int i = 0; i < 10; i++)
            {
                balls[i] = new Ball(0.2f);
                fixedBalls[i] = new Ball(0.1f);

                balls[i].model = mod;
                fixedBalls[i].model = mod;

                balls[i].Mass = 2;
                fixedBalls[i].InverseMass = 0;
                fixedBalls[i].InverseInertiaTensor = new Matrix();
                balls[i].InverseInertiaTensor = new Matrix();
                g.AddBody(balls[i]);

                balls[i].Texture = tex;
                fixedBalls[i].Texture = tex;
            }

            balls[0].Position = new Vector3(0, 0, 0);
            balls[1].Position = new Vector3(1, 0, 0);
            balls[2].Position = new Vector3(2, 0, 0);
            balls[3].Position = new Vector3(3, 0, 0);
            balls[4].Position = new Vector3(4, 0, 0);
            balls[5].Position = new Vector3(0, 0, 3);
            balls[6].Position = new Vector3(1, 0, 3);
            balls[7].Position = new Vector3(2, 0, 3);
            balls[8].Position = new Vector3(3, 0, 3);
            balls[9].Position = new Vector3(4, 0, 3);

            fixedBalls[0].Position = new Vector3(0, 1.0f, 0);
            fixedBalls[1].Position = new Vector3(1, 1f, 0);
            fixedBalls[2].Position = new Vector3(2, 1f, 0);
            fixedBalls[3].Position = new Vector3(3, 1f, 0);
            fixedBalls[4].Position = new Vector3(4, 1f, 0);
            fixedBalls[5].Position = new Vector3(0, 1f, 3);
            fixedBalls[6].Position = new Vector3(1, 1f, 3);
            fixedBalls[7].Position = new Vector3(2, 1f, 3);
            fixedBalls[8].Position = new Vector3(3, 1f, 3);
            fixedBalls[9].Position = new Vector3(4, 1f, 3);

            cg = new ContactGenerator();

            for (int i = 0; i < 10; i++)
            {
                cg.AddBody(balls[i]);
                cg.AddBody(fixedBalls[i]);
                cg.AddConductor(new Cable(fixedBalls[i], balls[i], 2, 0.7f));

            }

            for (int i = 0; i < 5; i++)
            {
                cg.AddConductor(new Rod(balls[i], balls[i + 5], 3));

            }

            //cg.velocityIterations = 8;
            //cg.friction = 0;
            //cg.restitution = 0.5f;

            for (int i = 0; i < 4; i++)
            {
                cg.AddConductor(new Rod(balls[i], balls[i + 1], 1));
                cg.AddConductor(new Rod(balls[9 - i], balls[9 - i - 1], 1));
            }
                camera = new Camera(this, new Vector3(0, 0, 0.1f),Vector3.Zero, Vector3.Up);
            Components.Add(camera);

            base.Initialize();
        }