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); }
public Line(PointMass p1, PointMass p2) { P1 = p1; P2 = p2; }
protected override void LoadContent() { Assets.graphicsDevice = GraphicsDevice; Assets.spriteBatch = new SpriteBatch(GraphicsDevice); Assets.Setup(); PointMasses = new List <PointMass>(); Lines = new List <Line>(); int counter; #region create the point masses for (int y = 0; y < Assets.curtainHeight; y++) { for (int x = 0; x < Assets.curtainWidth; x++) { //spread pms out PointMass pm = new PointMass(curPos.X + 64 + x * Assets.spacing, curPos.Y + y * Assets.spacing); if (y == 0) { //pm.pinned = true; //pin entire top row //pin some of top row curtain if (x == 0 || x == Assets.curtainWidth - 1) { pm.pinned = true; } if (x % Assets.pinNthTopPointMass == 0) { pm.pinned = true; } } PointMasses.Add(pm); //ad pm to game list } } #endregion #region setup point masses neighbors counter = 0; for (int y = 0; y < Assets.curtainHeight; y++) { for (int x = 0; x < Assets.curtainWidth; x++) { if (x < (Assets.curtainWidth - 1)) //connect left to right point, and vice versa { //neighbors ref ////0=up, 1=right, 2=down, 3=left PointMasses[counter].neighbors[1] = PointMasses[counter + 1]; PointMasses[counter + 1].neighbors[3] = PointMasses[counter]; } if (y < (Assets.curtainHeight - 1)) //connect top to bottom, and vice versa { PointMasses[counter].neighbors[2] = PointMasses[counter + Assets.curtainWidth]; PointMasses[counter + Assets.curtainWidth].neighbors[0] = PointMasses[counter]; } //track which pm index we are at counter++; } } #endregion #region assign point masses to lines counter = 0; for (int y = 0; y < Assets.curtainHeight; y++) { for (int x = 0; x < Assets.curtainWidth; x++) { if (x < (Assets.curtainWidth - 1)) //connect left to right point { Lines.Add(new Line(PointMasses[counter], PointMasses[counter + 1])); } if (y < (Assets.curtainHeight - 1)) //connect top to bottom { Lines.Add(new Line(PointMasses[counter], PointMasses[counter + Assets.curtainWidth])); } //track which pm index we are at counter++; } } #endregion }