Example #1
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()
        {
            fixedBall = new Ball(1f);
            fixedBall.Texture = Content.Load<Texture2D>(@"basic_material");
            fixedBall.Position = new Vector3(0f, 0, 0f);

            ball = new Ball(0.3f);
            ball.Texture = Content.Load<Texture2D>(@"basic_material");
            ball.Position = new Vector3(0f, -2f, 0f);

            crate = new Crate(new Vector3(0.07f, 0.05f, 0.05f));
            crate.Position = new Vector3(0.3f, 5f, 0.20f);
            crate.Mass = 10;

            cg = new ContactGenerator();
            cg.AddBody(fixedBall);
            cg.AddBody(ball);
            cg.AddBody(crate);

            fixedBall.model = Content.Load<Model>(@"ball");
            ball.model = fixedBall.model;
            camera = new Camera(this, new Vector3(0, 0, 10f),
                Vector3.Zero, Vector3.Up);
            Components.Add(camera);
            g = new Gravity(new Vector3(0f, -10f, 0f));

            fixedBall.InverseMass = 0;
            fixedBall.InverseInertiaTensor = new Matrix();
            ball.Mass = 1f;
            sp = new Spring(fixedBall, ball, 3f, 2f, 0.995f, Vector3.Zero, new Vector3(0.5f, 0.5f, 0.5f));
            base.Initialize();
        }
        /// <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[numberOfballs];
            fixedBalls = new Ball[numberOfballs];
            Model mod = Content.Load<Model>(@"ball");
            Texture2D tex = Content.Load<Texture2D>(@"basic_material");

            g = new Gravity(Vector3.Down * 10);

            for (int i = 0; i < numberOfballs; i++)
            {
                balls[i] = new Ball(0.249f);
                fixedBalls[i] = new Ball(0.249f);

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

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

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

            balls[0].Position = new Vector3(-0.25f, 0, 0);
            balls[1].Position = new Vector3(0.50f, 0, 0);
            balls[2].Position = new Vector3(1.00f, 0, 0);
            balls[3].Position = new Vector3(1.50f, 0, 0);

            fixedBalls[0].Position = new Vector3(0, 1f, 0);
            fixedBalls[1].Position = new Vector3(0.50f, 1f, 0);
            fixedBalls[2].Position = new Vector3(1.00f, 1f, 0);
            fixedBalls[3].Position = new Vector3(1.50f, 1f, 0);

            cg = new ContactGenerator();

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

            }

            //cg.velocityIterations = numberOfballs + 2;
            //cg.friction = 0.0001f;
            //cg.restitution = 1;

            camera = new Camera(this, new Vector3(0, 0, 0.1f), Vector3.Zero, Vector3.Up);
            Components.Add(camera);

            base.Initialize();
        }
Example #3
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()
        {
            fixedBall = new Ball(1);
            fixedBall.model = Content.Load<Model>(@"ball");

            fixedBall.Texture = Content.Load<Texture2D>(@"basic_material");
            fixedBall.Position = new Vector3(0, 4, 0);

            ball = new Ball(1);
            ball.Texture = Content.Load<Texture2D>(@"basic_material");
            ball.Position = new Vector3(0, 0, 0);
            ball.model = fixedBall.model;

            ball.Mass = 10;

            cg = new ContactGenerator();
            cg.AddBody(fixedBall);
            cg.AddBody(ball);
            cg.AddConductor(new Cable(fixedBall, ball, 10, 0.7f));

            //////////////////////////////////////////////////
            fixedBall2 = new Ball(1);
            fixedBall2.model = Content.Load<Model>(@"ball");

            fixedBall2.Texture = Content.Load<Texture2D>(@"basic_material");
            fixedBall2.Position = new Vector3(-5, 4, 0);

            ball2 = new Ball(1);
            ball2.Texture = Content.Load<Texture2D>(@"basic_material");
            ball2.Position = new Vector3(-5, 0, 0);
            ball2.model = fixedBall.model;

            ball2.Mass = 10;

            cg.AddBody(fixedBall2);
            cg.AddBody(ball2);
            cg.AddConductor(new Rod(fixedBall2, ball2, 3));

            camera = new Camera(this, new Vector3(0, 0, 0.1f),
                Vector3.Zero, Vector3.Up);
            Components.Add(camera);
            g = new Gravity(new Vector3(0f, -10f, 0f));

            fixedBall.InverseMass = 0;
            fixedBall.InverseInertiaTensor = new Matrix();

            fixedBall2.InverseMass = 0;
            fixedBall2.InverseInertiaTensor = new Matrix();

            base.Initialize();
        }
Example #4
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()
        {
            b1 = new Ball(10f);
            b1.Texture = Content.Load<Texture2D>(@"basic_material");
            b1.Position = new Vector3(100,0,0);
            b1.model = Content.Load<Model>(@"ball");

            p1 = new Border(new Plane(new Vector3(50, 50, 50), 10));
            p1.model = Content.Load<Model>(@"plane");

            cg = new ContactGenerator();
            cg.AddBody(b1);
            cg.AddPlane(p1);

            camera = new Camera(this, new Vector3(0, 0, 100),
                Vector3.Zero, Vector3.Up);
            Components.Add(camera);
            base.Initialize();
        }
Example #5
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()
        {
            fixedBall = new Ball(0.1f);
            fixedBall.model = Content.Load<Model>(@"ball");
            fixedBall.Texture = Content.Load<Texture2D>(@"basic_material");
            fixedBall.Position = new Vector3(0, 4, 0);

            fixedBall.InverseMass = 0;
            fixedBall.InverseInertiaTensor = new Matrix();

            ball = new Ball(0.1f);
            ball.model = Content.Load<Model>(@"ball");

            ball.Texture = Content.Load<Texture2D>(@"basic_material");
            ball.Position = new Vector3(0, -4, 0);

            ball.Mass = 1;
            ball.InverseInertiaTensor = new Matrix();

            cg = new ContactGenerator();

            g = new Gravity(new Vector3(0f, -5f, 0f));

            rope = new Rope(4, cg, this, g);
            rope.AddUpperBody(fixedBall);
            rope.AddBottomBody(ball);

            cg.AddBody(fixedBall);
            cg.AddBody(ball);

            camera = new Camera(this, new Vector3(0, 0, 0.1f),
                Vector3.Zero, Vector3.Up);
            Components.Add(camera);

            base.Initialize();
        }
Example #6
0
        public Rope(float length,ContactGenerator cg,Game game,Gravity gravity)
        {
            Balls = new List<Ball>();
            uint n = (uint)length * 6;

            this.g = gravity;
            this.cg=cg;
            this.game = game;

            Model model=game.Content.Load<Model>(@"ball");
            Texture2D texture=game.Content.Load<Texture2D>(@"basic_material");

            for (int i = 0; i < n; i++)
            {
                Balls.Add(new Ball(0.02f));

                Balls[i].model = model;
                Balls[i].Texture = texture;
                Balls[i].Position = new Vector3(0,-i*0.1f,0.0f);
                Balls[i].InverseMass = 1f;
                //g.AddBody(Balls[i]);
                Balls[i].InverseInertiaTensor = new Matrix();
                //cg.AddBody(Balls[i]);
            }

            //Balls[Balls.Count - 1].Position = new Vector3(2, 0, 3);
            //Balls[(Balls.Count - 1) / 2].Position = new Vector3(1, 0, 3);
            //Balls[0].Position = new Vector3(0, 0, 3);
            Ball b = new Ball(0.02f);
            b.Position = Balls[(Balls.Count - 1) / 2].Position+new Vector3(0,-0.1f,3);
            b.Mass = 1;
            //g.AddBody(b);
            b.InverseInertiaTensor = new Matrix();
            //cg.AddConductor(new Rod(Balls[(Balls.Count - 1)/2], b, 0.1f));
            //cg.AddConductor(new Rod(b,Balls[(Balls.Count - 1) / 2], 0.1f));

            //cg.velocityIterations = n*10;
            //cg.positionIterations = n * 10;
            //cg.friction = 0;
            //cg.restitution = 0.1f;

            for (int i = 0; i < n-1; i++)
            {
                //if (i == (Balls.Count) / 2)//|| i == (Balls.Count - 1) / 2)
                //{
                //    cg.AddConductor(new Rod(Balls[i], b, 0.1f));//,0.6f));
                //    cg.AddConductor(new Rod(b, Balls[i+1], 0.1f));//,0.6f));
                //    continue;
                //}
                //if (i == ((Balls.Count - 1) / 2)+1)
                //{
                //    cg.AddConductor(new Rod(b, Balls[i], 0.1f));//,0.6f));
                //    continue;
                //}

                //if (i % 2 == 0)
                  //  cg.AddConductor(new Cable(Balls[i], Balls[i + 1], 0.1f, 0.3f));//,0.6f));
                //else
                    cg.AddConductor(new Rod(Balls[i], Balls[i + 1], 0.12f));//,0.6f));
            }
        }
Example #7
0
        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            float duration = gameTime.ElapsedGameTime.Milliseconds / 1000f;
            if (Keyboard.GetState().IsKeyDown(Keys.Space))
                spaceClicked = true;
            if (Keyboard.GetState().IsKeyUp(Keys.Space) && spaceClicked)
            {
                spaceClicked = false;
                Ball b = new Ball(10f);
                b.model = b1.model;
                balls.AddLast(b);
                cg.AddBody(b);
                b.AddForce(new Vector3(400, 20, 0));
            }
            cg.Update(duration);
            b1.Update(duration);
            foreach (Ball b in balls)
                b.Update(duration);

            base.Update(gameTime);
        }
Example #8
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()
        {
            //crates = new Crate[NUM_CRATES];

            Ball b = new Ball(2);
            b.Position = Vector3.Up * 1000;

            cg = new ContactGenerator();
            cg.AddBody(b);

            joints = new Joint[NUM_JOINTS];
            balls = new Ball[NUM_BALLS];
            fixedBalls = new Ball[4];
            ground = new Crate(new Vector3(10, 1, 10));

            #region oldcode
            /*
            //Arms
            crates[0] = new Crate(new Vector3(0.3f, 1f, 0.2f));
            crates[1] = new Crate(new Vector3(0.3f, 1f, 0.2f));
            crates[2] = new Crate(new Vector3(0.3f, 1f, 0.2f));
            crates[3] = new Crate(new Vector3(0.3f, 1f, 0.2f));

            crates[4] = new Crate(new Vector3(0.4f, 0.3f, 0.6f));

            crates[5] = new Crate(new Vector3(0.3f, 0.3f, 0.6f));
            crates[6] = new Crate(new Vector3(0.4f, 0.3f, 0.7f));
            crates[7] = new Crate(new Vector3(0.4f, 0.5f, 0.4f));

            //Legs
            crates[8] = new Crate(new Vector3(0.2f, 0.8f, 0.2f));
            crates[9] = new Crate(new Vector3(0.2f, 0.8f, 0.2f));
            crates[10] = new Crate(new Vector3(0.2f, 0.8f, 0.2f));
            crates[11] = new Crate(new Vector3(0.2f, 0.8f, 0.2f));

            crates[0].Position=new Vector3(0,0.9f,-0.5f);
            crates[1].Position = new Vector3(0, 3.159f, -0.56f);
            crates[2].Position = new Vector3(0, 0.993f, 0.5f);
            crates[3].Position = new Vector3(0, 3.15f, 0.56f);
            crates[4].Position = new Vector3(-0.054f, 4.683f, 0.013f);
            crates[5].Position = new Vector3(0.043f, 5.603f, 0.013f);
            crates[6].Position = new Vector3(0, 6.485f, 0.013f);
            crates[7].Position = new Vector3(0, 7.759f, 0.013f);
            crates[8].Position = new Vector3(0, 5.946f, -1.066f);
            crates[9].Position = new Vector3(0, 4.024f, -1.066f);
            crates[10].Position = new Vector3(0, 5.946f, 1.066f);
            crates[11].Position = new Vector3(0, 4.024f, 1.066f);

            for (int i = 0; i < NUM_CRATES; i++)
            {
                crates[i].Mass = 1;
                crates[i].Position = Vector3.Zero;
            }

            //right leg
            joints[0]=new Joint(crates[0],crates[1],new Vector3(0,1,0),new Vector3(0,-1,0),0.15f);

            //Left leg
            joints[1]=new Joint(crates[2],crates[3],new Vector3(0,1,0),new Vector3(0,-1,0),0.15f);

            //right arm
            joints[2]=new Joint(crates[9],crates[8],new Vector3(0,1,0),new Vector3(0,-1,0),0.15f);

            //left arm
            joints[3]=new Joint(crates[8],crates[1],new Vector3(0,1,0),new Vector3(0,-1,0),0.15f);

            //stomach to waist
            joints[4]=new Joint(crates[4],crates[5],new Vector3(0.05f,0.5f,0),new Vector3(-0.04f,-0.45f,0),0.15f);

            //
            joints[5]=new Joint(crates[5],crates[6],new Vector3(-0.04f,0.4f,0),new Vector3(0,-4,0),0.15f);

            joints[6]=new Joint(crates[6],crates[7],new Vector3(0,0.5f,0),new Vector3(0,-0.7f,0),0.15f);

            joints[7]=new Joint(crates[1],crates[4],new Vector3(0,1,0),new Vector3(0,-0.45f,-.5f),0.15f);

            joints[8]=new Joint(crates[3],crates[4],new Vector3(0,1,0),new Vector3(0,-0.45f,0.5f),0.15f);

            joints[9]=new Joint(crates[6],crates[8],new Vector3(0,0.3f,-.8f),new Vector3(0,0.8f,.3f),0.15f);

            joints[10]=new Joint(crates[6],crates[10],new Vector3(0,0.3f,0.8f),new Vector3(0,0.8f,-0.3f),0.15f);
            */
            #endregion

            #region
            ////Head
            //crates[0] = new Crate(new Vector3(0.1f / 2f, 0.1f / 2f, 0.1f / 2f));

            ////Arms
            //crates[1] = new Crate(new Vector3(0.1f / 2f, 0.2f / 2f, 0.1f / 2f));
            //crates[2] = new Crate(new Vector3(0.1f / 2f, 0.3f / 2f, 0.1f / 2f));
            //crates[3] = new Crate(new Vector3(0.1f / 2f, 0.2f / 2f, 0.1f / 2f));
            //crates[4] = new Crate(new Vector3(0.1f / 2f, 0.3f / 2f, 0.1f / 2f));

            ////Shoulder
            //crates[5] = new Crate(new Vector3(0.5f / 2f, 0.1f / 2f, 0.1f / 2f));

            ////chest
            //crates[6] = new Crate(new Vector3(0.4f / 2f, 0.1f / 2f, 0.1f / 2f));

            ////Stomach
            //crates[7] = new Crate(new Vector3(0.4f / 2f, 0.1f / 2f, 0.1f / 2f));

            ////Legs
            //crates[8] = new Crate(new Vector3(0.1f / 2f, 0.2f / 2f, 0.1f / 2f));
            //crates[9] = new Crate(new Vector3(0.1f / 2f, 0.2f / 2f, 0.1f / 2f));
            //crates[10] = new Crate(new Vector3(0.1f / 2f, 0.2f / 2f, 0.1f / 2f));
            //crates[11] = new Crate(new Vector3(0.1f / 2f, 0.2f / 2f, 0.1f / 2f));

            ////Head
            //crates[0].Position = new Vector3(0, 0.45f, 0);

            ////Arms
            //crates[1].Position = new Vector3(0.35f, 0.25f, 0);
            //crates[2].Position = new Vector3(0.35f, -.05f, 0);
            //crates[3].Position = new Vector3(-0.35f, .25f, 0);
            //crates[4].Position = new Vector3(-0.35f, -0.05f, 0);

            ////Shoulder
            //crates[5].Position = new Vector3(0, 0.3f, -.05f);

            ////chest
            //crates[6].Position = new Vector3(0, 0.15f, 0);

            ////Center Stomach
            //crates[7].Position = new Vector3(0, 0f, 0.05f);

            ////legs
            //crates[8].Position = new Vector3(0.15f, -0.2f, 0);
            //crates[9].Position = new Vector3(0.15f, -0.45f, 0);
            //crates[10].Position = new Vector3(-0.15f, -0.2f, 0);
            //crates[11].Position = new Vector3(-0.15f, -0.45f, 0);

            ////Head and shoulders :)
            //joints[0] = new Joint(crates[0], crates[5], new Vector3(0, -0.05f, -0.05f), new Vector3(0, 0.05f, 0), 0.05f);

            ////right arm
            //joints[1] = new Joint(crates[1], crates[2], new Vector3(0, -0.1f, 0.05f), new Vector3(0, 0.15f, 0), 0.05f);

            ////left arm
            //joints[2] = new Joint(crates[3], crates[4], new Vector3(0, -0.1f, 0.05f), new Vector3(0, 0.15f, 0), 0.05f);

            ////right leg
            //joints[3] = new Joint(crates[8], crates[9], new Vector3(0, -0.1f, 0.05f), new Vector3(0, 0.1f, 0), 0.05f);

            ////left leg
            //joints[4] = new Joint(crates[10], crates[11], new Vector3(0, -0.1f, 0.05f), new Vector3(0, 0.1f, 0), 0.05f);

            ////right arm with shoulders
            //joints[5] = new Joint(crates[5], crates[1], new Vector3(.25f, 0.05f, 0), new Vector3(-0.05f, 0.1f, 0), 0.05f);

            ////left arm with shoulders
            //joints[6] = new Joint(crates[5], crates[3], new Vector3(-.25f, 0.05f, 0), new Vector3(0.05f, 0.1f, 0), 0.05f);

            //joints[7] = new Joint(crates[5], crates[6], new Vector3(0, -0.05f, 0.05f), new Vector3(0, 0.05f, 0), 0.05f);

            //joints[8] = new Joint(crates[6], crates[7], new Vector3(0, -0.05f, 0), new Vector3(0, 0.05f, -.05f), 0.05f);

            //joints[9] = new Joint(crates[7], crates[8], new Vector3(.15f, -0.05f, 0), new Vector3(0, 0.1f, 0), 0.05f);

            //joints[10] = new Joint(crates[7], crates[10], new Vector3(-.15f, -0.05f, 0), new Vector3(0, 0.1f, 0), 0.05f);
            #endregion

            #region newBall
            balls[0] = new Ball(0.1f);
            balls[1] = new Ball(0.15f);
            balls[2] = new Ball(0.15f);
            balls[3] = new Ball(0.05f);
            balls[4] = new Ball(0.05f);
            balls[5] = new Ball(0.05f);
            balls[6] = new Ball(0.05f);
            balls[7] = new Ball(0.05f);
            balls[8] = new Ball(0.05f);
            balls[9] = new Ball(0.05f);
            balls[10] = new Ball(0.05f);
            balls[11] = new Ball(0.05f);
            balls[12] = new Ball(0.05f);
            balls[13] = new Ball(0.05f);
            balls[14] = new Ball(0.05f);
            fixedBalls[0] = new Ball(0.05f);
            fixedBalls[1] = new Ball(0.05f);
            fixedBalls[2] = new Ball(0.05f);
            fixedBalls[3] = new Ball(0.05f);
            #endregion

            #region position
            balls[0].Position = new Vector3(0, 0.6f, 0);
            balls[1].Position = new Vector3(0, 0.3f, 0);
            balls[2].Position = new Vector3(0, -0.05f, 0);

            balls[3].Position = new Vector3(0.25f, 0.3f, 0);
            balls[4].Position = new Vector3(0.25f, 0.15f, 0);
            balls[5].Position = new Vector3(0.25f, 0, 0);
            balls[6].Position = new Vector3(-0.25f, 0.3f, 0);
            balls[7].Position = new Vector3(-0.25f, 0.15f, 0);
            balls[8].Position = new Vector3(-0.25f, 0, 0);

            balls[9].Position = new Vector3(0.1f, -.25f, 0);
            balls[10].Position = new Vector3(0.1f, -.4f, 0);
            balls[11].Position = new Vector3(0.1f, -.55f, 0);
            balls[12].Position = new Vector3(-0.1f, -.25f, 0);
            balls[13].Position = new Vector3(-0.1f, -.4f, 0);
            balls[14].Position = new Vector3(-0.1f, -.55f, 0);

            fixedBalls[0].Position = new Vector3(0.7f, 0.6f, 0);
            fixedBalls[1].Position = new Vector3(-0.7f, 0.6f, 0);
            fixedBalls[2].Position = new Vector3(0.7f, -1, 0);
            fixedBalls[3].Position = new Vector3(-0.7f, -1, 0);

            ground.Position = new Vector3(0, -3, 0);
            #endregion
            #region Masses
            balls[0].Mass = 5;
            balls[1].Mass = 5;
            balls[2].Mass = 5;
            balls[3].Mass = 1;
            balls[4].Mass = 1;
            balls[5].Mass = 1;
            balls[6].Mass = 1;
            balls[7].Mass = 1;
            balls[8].Mass = 1;
            balls[9].Mass = 1;
            balls[10].Mass = 1;
            balls[11].Mass = 1;
            balls[12].Mass = 1;
            balls[13].Mass = 1;
            balls[14].Mass = 1;
            #endregion

            //head and shoulder :)
            joints[0] = new Joint(balls[0], balls[1], new Vector3(0, -0.1f,0f), new Vector3(0, 0.15f, 0), 0.05f);

            joints[1] = new Joint(balls[1], balls[2], new Vector3(0, -0.15f, 0), new Vector3(0, 0.15f, 0), 0.05f);

            //right arm with shoulders
            joints[2] = new Joint(balls[1], balls[3], new Vector3(0.1f, 0.1f, 0), new Vector3(-0.04f, 0.03f, 0), 0.05f);

            //left arm with shoulders
            joints[3] = new Joint(balls[1], balls[6], new Vector3(-0.1f, 0.1f, 0), new Vector3(0.04f, 0.03f, 0), 0.05f);

            //right arm
            joints[4] = new Joint(balls[3], balls[4], new Vector3(0, -0.05f, 0), new Vector3(0, 0.05f, 0), 0.05f);
            joints[5] = new Joint(balls[4], balls[5], new Vector3(0, -0.05f, 0), new Vector3(0, 0.05f, 0), 0.05f);

            //left arm
            joints[6] = new Joint(balls[6], balls[7], new Vector3(0, -0.05f, 0), new Vector3(0, 0.05f, 0), 0.05f);
            joints[7] = new Joint(balls[7], balls[8], new Vector3(0, -0.05f, 0), new Vector3(0, 0.05f, 0), 0.05f);

            //Stomach with right leg
            joints[8] = new Joint(balls[2], balls[9], new Vector3(0.1f, -0.15f, 0), new Vector3(0, 0.05f, 0), 0.05f);

            //Stomach with left leg
            joints[9] = new Joint(balls[2], balls[12], new Vector3(-.1f, -0.15f, 0), new Vector3(0, 0.05f, 0), 0.05f);

            //right leg
            joints[10] = new Joint(balls[9], balls[10], new Vector3(0, -0.05f, 0), new Vector3(0, 0.05f, 0), 0.05f);
            joints[11] = new Joint(balls[10], balls[11], new Vector3(0, -0.05f, 0), new Vector3(0, 0.05f, 0), 0.05f);

            joints[12] = new Joint(balls[12], balls[13], new Vector3(0, -0.05f, 0), new Vector3(0, 0.05f, 0), 0.05f);
            joints[13] = new Joint(balls[13], balls[14], new Vector3(0, -0.05f, 0), new Vector3(0, 0.05f, 0), 0.05f);

            Model model = this.Content.Load<Model>(@"ball");
            Texture2D texture = this.Content.Load<Texture2D>(@"basic_material");

            for (int i = 0; i < NUM_BALLS; i++)
            {
                balls[i].model = model;
                balls[i].Texture = texture;
                cg.AddBody(balls[i]);
                //balls[i].Mass = 1;
            }

            for (int i = 0; i < 4; i++)
            {
                fixedBalls[i].Lock();
                fixedBalls[i].model = model;
                fixedBalls[i].Texture = texture;
            }

            cg.AddConductor(new Cable(balls[5], fixedBalls[0], (balls[5].Position - fixedBalls[0].Position).Length(), 0.5f));
            cg.AddConductor(new Cable(balls[8], fixedBalls[1], (balls[8].Position - fixedBalls[1].Position).Length(), 0.5f));
            cg.AddConductor(new Cable(balls[11], fixedBalls[2], (balls[11].Position - fixedBalls[2].Position).Length(), 0.5f));
            cg.AddConductor(new Cable(balls[14], fixedBalls[3], (balls[14].Position - fixedBalls[3].Position).Length(), 0.5f));

            ground.Lock();

            for (int i = 0; i < NUM_JOINTS; i++)
                cg.AddJoint(joints[i]);
            cg.AddBody(ground);
                camera = new Camera(this, new Vector3(0, 0, 0.1f),
                    Vector3.Zero, Vector3.Up);
            Components.Add(camera);
            g = new Gravity(new Vector3(0f, -1f, 0f));

            base.Initialize();
        }
Example #9
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();
        }
Example #10
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            float duration = gameTime.ElapsedGameTime.Milliseconds / 1000f;
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();
            if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.P))
                paused = !paused;
            if (!paused)
            {

                if (Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.Space))
                {
                    spaceDown = true;
                }
                if (spaceDown && (Keyboard.GetState(PlayerIndex.One).IsKeyUp(Keys.Space)))
                {
                    spaceDown = false;
                    Ball b = new Ball(100f);
                    b.model = ball.model;
                    //g.AddBody(b);
                    balls.AddLast(b);
                    b.Position = new Vector3(0, -100f, 0);
                    //b.AddForce(new Vector3(10f, 5f, 0));
                    //spring.AddBody(b);
                    //spring = new Spring(b, dummy, dummy.Position, 0.3f, 20f, 0.995f);
                    //crate.AddForce(new Vector3(12,32,3),new Vector3(2,2,3));
                    crate.AngularAcceleration = new Vector3(0.001f,0f,0f);
                }
                g.Update(duration);
                if (spring != null)
                    spring.Update(duration);
                // TODO: Add your update logic here
                ball.Update(duration);
                dummy.Update(duration);
                crate.Update(duration);
                foreach (Ball b in balls)
                    b.Update(duration);
            }
            base.Update(gameTime);
        }
Example #11
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()
        {
            crates = new Crate[NUM_CRATES];

            Ball b = new Ball(2);
            b.Position = Vector3.Up * 1000;

            cg = new ContactGenerator();
            cg.AddBody(b);

            joints = new Joint[NUM_JOINTS];

            #region oldcode
            /*
            //Arms
            crates[0] = new Crate(new Vector3(0.3f, 1f, 0.2f));
            crates[1] = new Crate(new Vector3(0.3f, 1f, 0.2f));
            crates[2] = new Crate(new Vector3(0.3f, 1f, 0.2f));
            crates[3] = new Crate(new Vector3(0.3f, 1f, 0.2f));

            crates[4] = new Crate(new Vector3(0.4f, 0.3f, 0.6f));

            crates[5] = new Crate(new Vector3(0.3f, 0.3f, 0.6f));
            crates[6] = new Crate(new Vector3(0.4f, 0.3f, 0.7f));
            crates[7] = new Crate(new Vector3(0.4f, 0.5f, 0.4f));

            //Legs
            crates[8] = new Crate(new Vector3(0.2f, 0.8f, 0.2f));
            crates[9] = new Crate(new Vector3(0.2f, 0.8f, 0.2f));
            crates[10] = new Crate(new Vector3(0.2f, 0.8f, 0.2f));
            crates[11] = new Crate(new Vector3(0.2f, 0.8f, 0.2f));

            crates[0].Position=new Vector3(0,0.9f,-0.5f);
            crates[1].Position = new Vector3(0, 3.159f, -0.56f);
            crates[2].Position = new Vector3(0, 0.993f, 0.5f);
            crates[3].Position = new Vector3(0, 3.15f, 0.56f);
            crates[4].Position = new Vector3(-0.054f, 4.683f, 0.013f);
            crates[5].Position = new Vector3(0.043f, 5.603f, 0.013f);
            crates[6].Position = new Vector3(0, 6.485f, 0.013f);
            crates[7].Position = new Vector3(0, 7.759f, 0.013f);
            crates[8].Position = new Vector3(0, 5.946f, -1.066f);
            crates[9].Position = new Vector3(0, 4.024f, -1.066f);
            crates[10].Position = new Vector3(0, 5.946f, 1.066f);
            crates[11].Position = new Vector3(0, 4.024f, 1.066f);

            for (int i = 0; i < NUM_CRATES; i++)
            {
                crates[i].Mass = 1;
                crates[i].Position = Vector3.Zero;
            }

            //right leg
            joints[0]=new Joint(crates[0],crates[1],new Vector3(0,1,0),new Vector3(0,-1,0),0.15f);

            //Left leg
            joints[1]=new Joint(crates[2],crates[3],new Vector3(0,1,0),new Vector3(0,-1,0),0.15f);

            //right arm
            joints[2]=new Joint(crates[9],crates[8],new Vector3(0,1,0),new Vector3(0,-1,0),0.15f);

            //left arm
            joints[3]=new Joint(crates[8],crates[1],new Vector3(0,1,0),new Vector3(0,-1,0),0.15f);

            //stomach to waist
            joints[4]=new Joint(crates[4],crates[5],new Vector3(0.05f,0.5f,0),new Vector3(-0.04f,-0.45f,0),0.15f);

            //
            joints[5]=new Joint(crates[5],crates[6],new Vector3(-0.04f,0.4f,0),new Vector3(0,-4,0),0.15f);

            joints[6]=new Joint(crates[6],crates[7],new Vector3(0,0.5f,0),new Vector3(0,-0.7f,0),0.15f);

            joints[7]=new Joint(crates[1],crates[4],new Vector3(0,1,0),new Vector3(0,-0.45f,-.5f),0.15f);

            joints[8]=new Joint(crates[3],crates[4],new Vector3(0,1,0),new Vector3(0,-0.45f,0.5f),0.15f);

            joints[9]=new Joint(crates[6],crates[8],new Vector3(0,0.3f,-.8f),new Vector3(0,0.8f,.3f),0.15f);

            joints[10]=new Joint(crates[6],crates[10],new Vector3(0,0.3f,0.8f),new Vector3(0,0.8f,-0.3f),0.15f);
            */
            #endregion

            //Head
            crates[0] = new Crate(new Vector3(0.1f / 2f, 0.1f / 2f, 0.1f / 2f));

            //Arms
            crates[1] = new Crate(new Vector3(0.1f / 2f, 0.2f / 2f, 0.1f / 2f));
            crates[2] = new Crate(new Vector3(0.1f / 2f, 0.3f / 2f, 0.1f / 2f));
            crates[3] = new Crate(new Vector3(0.1f / 2f, 0.2f / 2f, 0.1f / 2f));
            crates[4] = new Crate(new Vector3(0.1f / 2f, 0.3f / 2f, 0.1f / 2f));

            //Shoulder
            crates[5] = new Crate(new Vector3(0.5f / 2f, 0.1f / 2f, 0.1f / 2f));

            //chest
            crates[6] = new Crate(new Vector3(0.4f / 2f, 0.1f / 2f, 0.1f / 2f));

            //Stomach
            crates[7] = new Crate(new Vector3(0.4f / 2f, 0.1f / 2f, 0.1f / 2f));

            //Legs
            crates[8] = new Crate(new Vector3(0.1f / 2f, 0.2f / 2f, 0.1f / 2f));
            crates[9] = new Crate(new Vector3(0.1f / 2f, 0.2f / 2f, 0.1f / 2f));
            crates[10] = new Crate(new Vector3(0.1f / 2f, 0.2f / 2f, 0.1f / 2f));
            crates[11] = new Crate(new Vector3(0.1f / 2f, 0.2f / 2f, 0.1f / 2f));

            //Head
            crates[0].Position = new Vector3(0, 0.45f, 0);

            //Arms
            crates[1].Position = new Vector3(0.35f, 0.25f, 0);
            crates[2].Position = new Vector3(0.35f, -.05f, 0);
            crates[3].Position = new Vector3(-0.35f, .25f, 0);
            crates[4].Position = new Vector3(-0.35f, -0.05f, 0);

            //Shoulder
            crates[5].Position = new Vector3(0, 0.3f, -.05f);

            //chest
            crates[6].Position = new Vector3(0, 0.15f, 0);

            //Center Stomach
            crates[7].Position = new Vector3(0, 0f, 0.05f);

            //legs
            crates[8].Position = new Vector3(0.15f, -0.2f, 0);
            crates[9].Position = new Vector3(0.15f, -0.45f, 0);
            crates[10].Position = new Vector3(-0.15f, -0.2f, 0);
            crates[11].Position = new Vector3(-0.15f, -0.45f, 0);

            //Head and shoulders :)
            joints[0] = new Joint(crates[0], crates[5], new Vector3(0, -0.05f, -0.05f), new Vector3(0, 0.05f, 0), 0.05f);

            //right arm
            joints[1] = new Joint(crates[1], crates[2], new Vector3(0, -0.1f, 0.05f), new Vector3(0, 0.15f, 0), 0.05f);

            //left arm
            joints[2] = new Joint(crates[3], crates[4], new Vector3(0, -0.1f, 0.05f), new Vector3(0, 0.15f, 0), 0.05f);

            //right leg
            joints[3] = new Joint(crates[8], crates[9], new Vector3(0, -0.1f, 0.05f), new Vector3(0, 0.1f, 0), 0.05f);

            //left leg
            joints[4] = new Joint(crates[10], crates[11], new Vector3(0, -0.1f, 0.05f), new Vector3(0, 0.1f, 0), 0.05f);

            //right arm with shoulders
            joints[5] = new Joint(crates[5], crates[1], new Vector3(.25f, 0.05f, 0), new Vector3(-0.05f, 0.1f, 0), 0.05f);

            //left arm with shoulders
            joints[6] = new Joint(crates[5], crates[3], new Vector3(-.25f, 0.05f, 0), new Vector3(0.05f, 0.1f, 0), 0.05f);

            joints[7] = new Joint(crates[5], crates[6], new Vector3(0, -0.05f, 0.05f), new Vector3(0, 0.05f, 0), 0.05f);

            joints[8] = new Joint(crates[6], crates[7], new Vector3(0, -0.05f, 0), new Vector3(0, 0.05f, -.05f), 0.05f);

            joints[9] = new Joint(crates[7], crates[8], new Vector3(.15f, -0.05f, 0), new Vector3(0, 0.1f, 0), 0.05f);

            joints[10] = new Joint(crates[7], crates[10], new Vector3(-.15f, -0.05f, 0), new Vector3(0, 0.1f, 0), 0.05f);

            for (int i = 0; i < NUM_CRATES; i++)
            {
                crates[i].InverseMass = 1;
                //cg.AddBody(crates[i]);
                //crates[i].InverseInertiaTensor = new Matrix();
            }

            for (int i = 0; i < NUM_JOINTS; i++)
                cg.AddJoint(joints[i]);

            camera = new Camera(this, new Vector3(0, 0, 0.1f),
                Vector3.Zero, Vector3.Up);
            Components.Add(camera);
            g = new Gravity(new Vector3(0f, -1f, 0f));

            //crates[0].InverseMass = 0;
            //crates[7].InverseMass = 0;
            //crates[6].InverseInertiaTensor = new Matrix();

            base.Initialize();
        }
Example #12
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();
        }