protected override void LoadContent() { _spriteBatch = new SpriteBatch(GraphicsDevice); _font = Content.Load <SpriteFont>("MgGenFont"); _dot = CreateDotTexture(GraphicsDevice, Color.White); curve = new Curve_BezierSplineWeighted(_wayPoints, 0.5f, isCurveClosed); DrawHelpers.Initialize(GraphicsDevice, _spriteBatch, null); }
protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } ms = Mouse.GetState(); bool redoCurve = false; CurveIterationTimer(gameTime); // next control point if (IsPressedWithDelay(Keys.Space, gameTime)) { selectedCp += 1; if (selectedCp > _wayPoints.Length - 1) { selectedCp = 0; } } // switch curve open or closed. if (IsPressedWithDelay(Keys.Tab, gameTime)) { isCurveClosed = !isCurveClosed; redoCurve = true; } // adjust weight if (IsPressedWithDelay(Keys.Up, gameTime) || ms.ScrollWheelValue > currentScrollWheelvalue) { selectedWeight += .05f; if (selectedWeight > maxSelectableWeight) { selectedWeight = -1f; } _wayPoints[selectedCp].W = selectedWeight; currentScrollWheelvalue = ms.ScrollWheelValue; redoCurve = true; } // adjust weight if (IsPressedWithDelay(Keys.Down, gameTime) || ms.ScrollWheelValue < currentScrollWheelvalue) { selectedWeight -= .05f; if (selectedWeight < -1f) { selectedWeight = maxSelectableWeight; } _wayPoints[selectedCp].W = selectedWeight; currentScrollWheelvalue = ms.ScrollWheelValue; redoCurve = true; } // adjust control point position. if (ms.LeftButton == ButtonState.Pressed) { _wayPoints[selectedCp] = new Vector4(ms.Position.X, ms.Position.Y, 0, _wayPoints[selectedCp].W); redoCurve = true; } // select a control point. if (ms.RightButton == ButtonState.Pressed) { CheckPointSelected(); } if (redoCurve) { curve = new Curve_BezierSplineWeighted(_wayPoints, isCurveClosed); } string msg2 = "Open"; if (isCurveClosed) { msg2 = "Closed"; } msg = $"Bezier " + $"\n" + $"Press Tab ....... Curve is {msg2}" + $"\n" + $"Left Click ........ Move selectedCp " + $"\n" + $"Right Click ...... Selected Cp " + selectedCp + $"\n" + $"Mouse Scroll ... Alter Weight " + selectedWeight ; base.Update(gameTime); }