Exemplo n.º 1
0
        protected override void LoadContent()
        {
            _spriteBatch = new SpriteBatch(GraphicsDevice);
            _font        = Content.Load <SpriteFont>("MgGenFont");
            _dot         = CreateDotTexture(GraphicsDevice, Color.White);
            DrawHelpers.Initialize(GraphicsDevice, _spriteBatch, null);

            mesh = new Mesh_BwtPrimitive(meshPoints, cpWidth, cpHeight, numOfPoints, isCurveClosed, isUniformedUsed, numOfIntegrationSteps);
        }
Exemplo n.º 2
0
        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, 10f);


            // show extra position and tangent lines.
            if (IsPressedWithDelay(Keys.F1, gameTime))
            {
                showGeneratedTangentsPositions = !showGeneratedTangentsPositions;
                //curve._showTangents = showGeneratedTangentsPositions;
            }

            // switch to a uniformed or non uniformed curve.
            if (IsPressedWithDelay(Keys.Space, gameTime))
            {
                isUniformedUsed = !isUniformedUsed;
                redoCurve       = true;
            }

            // switch curve open or closed.
            if (IsPressedWithDelay(Keys.Tab, gameTime))
            {
                isCurveClosed = !isCurveClosed;
                redoCurve     = true;
            }

            // adjust weight
            if (IsPressedWithDelay(Keys.Up, gameTime) || ms.ScrollWheelValue > currentScrollWheelvalueForWeight)
            {
                selectedWeight += .05f;
                if (selectedWeight > maxSelectableWeight)
                {
                    selectedWeight = -1f;
                }
                meshPoints[selectedCp].W         = selectedWeight;
                currentScrollWheelvalueForWeight = ms.ScrollWheelValue;
                redoCurve = true;
            }

            // adjust weight
            if (IsPressedWithDelay(Keys.Down, gameTime) || ms.ScrollWheelValue < currentScrollWheelvalueForWeight)
            {
                selectedWeight -= .05f;
                if (selectedWeight < -1f)
                {
                    selectedWeight = maxSelectableWeight;
                }
                meshPoints[selectedCp].W         = selectedWeight;
                currentScrollWheelvalueForWeight = ms.ScrollWheelValue;
                redoCurve = true;
            }

            if (GraphicsDevice.Viewport.Bounds.Contains(ms.Position))
            {
                // adjust control point position.
                if (ms.LeftButton == ButtonState.Pressed)
                {
                    meshPoints[selectedCp] = new Vector4(ms.Position.X, ms.Position.Y, 0, meshPoints[selectedCp].W);
                    redoCurve = true;
                }

                // select a control point.
                if (ms.RightButton == ButtonState.Pressed)
                {
                    CheckPointSelected();
                }
            }


            if (redoCurve)
            {
                mesh = new Mesh_BwtPrimitive(meshPoints, cpWidth, cpHeight, numOfPoints, isCurveClosed, isUniformedUsed, numOfIntegrationSteps);
            }

            string msg2 = "Open";

            if (isCurveClosed)
            {
                msg2 = "Closed";
            }
            string msg3 = "NonUniform";

            if (isUniformedUsed)
            {
                msg3 = "Uniform";
            }
            msg =
                $"GameTime In Seconds {gameTimeInSeconds.ToString("#########0.00")}  Cycle time over curve: {cycledTime.ToString("###0.00")}" +
                $"\n" + $"Bezier Mesh" +
                $"\n" + $"Press Tab ....... Curve is {msg2}" +
                $"\n" + $"Press Space .. Curve is {msg3}" +
                $"\n" + $"Left Click ........ Move selectedCp " +
                $"\n" + $"Right Click ...... Selected Cp " + selectedCp +
                $"\n" + $"Mouse Scroll ... Alter Weight " + selectedWeight
            ;

            base.Update(gameTime);
        }