Esempio n. 1
0
        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            Assets.updateTimer.Restart();


            #region Process Curtain Simulation

            //update point masses
            for (i = 0; i < PointMasses.Count; i++)
            {
                Functions_Simulate.Constrain(PointMasses[i]);
                Functions_Simulate.ApplyPhysics(PointMasses[i]);
                Functions_Simulate.RelaxPM(PointMasses[i]);
            }

            #endregion


            #region Pass input into curtain

            //get this frame of user input
            InputData.Update();
            //place cursor rec and draw game cursor
            MouseState currentMouseState = Mouse.GetState();
            cursorRec.X = (int)currentMouseState.X - (int)(cursorRec.Width / 2);
            cursorRec.Y = (int)currentMouseState.Y - (int)(cursorRec.Height / 2);


            //push cloth around upon collision with mouse
            for (i = 0; i < PointMasses.Count; i++)
            {   //do not allow input to be passed to pinned point masses
                if (cursorRec.Contains(PointMasses[i].X, PointMasses[i].Y))
                {
                    if (PointMasses[i].X > currentMouseState.X)
                    {
                        PointMasses[i].accX += 20.0f;
                    }
                    else
                    {
                        PointMasses[i].accX -= 20.0f;
                    }
                    PointMasses[i].accY -= 20.0f;

                    for (int g = 0; g < 4; g++)
                    {
                        if (PointMasses[i].neighbors[g] != null)
                        {
                            if (PointMasses[i].neighbors[g].X > currentMouseState.X)
                            {
                                PointMasses[i].neighbors[g].accX += 20.0f;
                            }
                            else
                            {
                                PointMasses[i].neighbors[g].accX -= 20.0f;
                            }
                            PointMasses[i].neighbors[g].accY -= 20.0f;
                        }
                    }
                }
            }


            /*
             * if (InputData.IsLeftMouseBtnPress())
             * {   //grab one PM colliding with cursor rec
             *  for (i = 0; i < PointMasses.Count; i++)
             *  {   //do not allow input to be passed to pinned point masses
             *      if (PointMasses[i].pinned == false)
             *      {
             *          if (cursorRec.Contains(PointMasses[i].X, PointMasses[i].Y))
             *          {   //grab PM, bail
             *              grabbedPM = PointMasses[i];
             *              grabbedPM.pinned = true;
             *              i = PointMasses.Count;
             *          }
             *      }
             *  }
             * }
             * if (currentMouseState.LeftButton == ButtonState.Pressed)
             * {   //handle dragging state (left mouse button down)
             *  if (grabbedPM != null)
             *  {   //drag the point until released
             *      grabbedPM.X = currentMouseState.X;
             *      grabbedPM.Y = currentMouseState.Y;
             *  }
             * }
             * else
             * {   //release grabbed pm
             *  if (grabbedPM != null)
             *  {
             *      grabbedPM.pinned = false;
             *      grabbedPM = null;
             *  }
             * }
             */

            #endregion


            //update how the lines connect to their pointMasses
            for (i = 0; i < Lines.Count; i++)
            {
                Functions_Simulate.UpdateLine(Lines[i]);
            }

            Assets.updateTimer.Stop();
            updateTimeRec.Width = (int)(Assets.updateTimer.ElapsedTicks / 1000 * 8);
            Debug.WriteLine("update ms: " + Assets.updateTimer.ElapsedMilliseconds);
        }
Esempio n. 2
0
        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            Assets.updateTimer.Restart();


            #region Process Curtain Simulation

            //update point masses
            for (i = 0; i < PointMasses.Count; i++)
            {
                Functions_Simulate.Constrain(PointMasses[i]);
                Functions_Simulate.ApplyPhysics(PointMasses[i]);
                Functions_Simulate.RelaxPM(PointMasses[i]);
            }

            #endregion


            #region Pass input into curtain

            //get this frame of user input
            InputData.Update();
            //place cursor rec and draw game cursor
            MouseState currentMouseState = Mouse.GetState();
            cursorRec.X = (int)currentMouseState.X - (int)(cursorRec.Width / 2);
            cursorRec.Y = (int)currentMouseState.Y - (int)(cursorRec.Height / 2);

            if (InputData.IsLeftMouseBtnPress())
            {     //grab one PM colliding with cursor rec
                for (i = 0; i < PointMasses.Count; i++)
                { //do not allow input to be passed to pinned point masses
                    if (PointMasses[i].pinned == false)
                    {
                        if (cursorRec.Contains(PointMasses[i].X, PointMasses[i].Y))
                        {   //grab PM, bail
                            grabbedPM        = PointMasses[i];
                            grabbedPM.pinned = true;
                            i = PointMasses.Count;
                        }
                    }
                }
            }
            if (currentMouseState.LeftButton == ButtonState.Pressed)
            {     //handle dragging state (left mouse button down)
                if (grabbedPM != null)
                { //drag the point until released
                    grabbedPM.X = currentMouseState.X;
                    grabbedPM.Y = currentMouseState.Y;
                }
            }
            else
            {   //release grabbed pm
                if (grabbedPM != null)
                {
                    grabbedPM.pinned = false;
                    grabbedPM        = null;
                }
            }

            #endregion


            //update how the lines connect to their pointMasses
            for (i = 0; i < Lines.Count; i++)
            {
                Functions_Simulate.UpdateLine(Lines[i]);
            }

            Assets.updateTimer.Stop();
            updateTimeRec.Width = (int)(Assets.updateTimer.ElapsedTicks / 1000 * 8);
        }