Esempio n. 1
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)
        {
            if (this.Manager.KeyPressed(Keys.M))
            {
                switch (fDrawMode)
                {
                case DrawMode.Grid:
                    CurrentDrawMode = DrawMode.Solid;
                    break;

                case DrawMode.Solid:
                    CurrentDrawMode = DrawMode.WireFrame;
                    break;

                case DrawMode.WireFrame:
                    CurrentDrawMode = DrawMode.Grid;
                    break;
                }
            }
            else if (this.Manager.KeyPressed(Keys.C))
            {
                switch (fColorMode)
                {
                case ColorMode.Points:
                    CurrentColorMode = ColorMode.SkyBlue;
                    break;

                case ColorMode.SkyBlue:
                    CurrentColorMode = ColorMode.Points;
                    break;
                }
            }
            else if (this.Manager.KeyPressed(Keys.N))
            {
                switch (fNormalMode)
                {
                case NormalMode.Crazy:
                    CurrentNormalMode = NormalMode.Standard;
                    break;

                case NormalMode.Standard:
                    CurrentNormalMode = NormalMode.Crazy;
                    break;
                }
            }

            fCamera.Update(gameTime);

            double seconds = gameTime.TotalGameTime.TotalSeconds;

            if (!fHalted)
            {
                fUpdateDiagram = true;
            }

            fUpdateDiagram = fUpdateDiagram || fUpdatePlane;
            fUpdateColors  = fUpdateColors || fUpdateDiagram;
            fUpdateNormals = fUpdateNormals || fUpdateDiagram;

            if (fUpdatePlane)
            {
                SetPlane();
            }
            int max = fPlane.Segments;

            if (fUpdateDiagram)
            {
                fUpdateDiagram = false;
                for (int x = 0; x <= max; x++)
                {
                    float nX = 2.0f * (float)x / max - 1.0f;// -1 to +1
                    for (int z = 0; z <= max; z++)
                    {
                        float  nZ = 2.0f * (float)z / max - 1.0f;
                        double r  = Math.Sqrt(nX * nX + nZ * nZ);
                        // function
                        double y = nX * Math.Cos(r * 7.0f - seconds * 4.2f) +
                                   nZ * Math.Sin((r - 0.5) * 10.0f - seconds * 1.9f);

                        float height = 200.0f * (float)y;
                        fPlane.SetHeight(x, z, height);
                    }
                }
            }
            if (fUpdateColors)
            {
                SetColors();
            }
            if (fUpdateNormals)
            {
                switch (fNormalMode)
                {
                case NormalMode.Crazy:
                    for (int x = 0; x <= max; x++)
                    {
                        float nX = 2.0f * (float)x / max - 1.0f;    // -1 to +1
                        for (int z = 0; z <= max; z++)
                        {
                            float nZ = 2.0f * (float)z / max - 1.0f;
                            // function
                            double r = Math.Sqrt(nX * nX + nZ * nZ);
                            VertexPositionNormalColor p = fPlane.GetPoint(x, z);
                            p.Normal = Vector3.Normalize(new Vector3(
                                                             Convert.ToSingle(Math.Cos(r * 1.0f + 0.5f - seconds * 0.1f)),
                                                             Convert.ToSingle(Math.Cos(r * 2.0f + 2.1f - seconds * 0.2f)),
                                                             Convert.ToSingle(Math.Cos(r * 5.1f * seconds))));
                            fPlane.SetPoint(x, z, p);
                        }
                    }
                    break;

                case NormalMode.Standard:
                    fPlane.GenerateNormals();
                    break;
                }
            }

            base.Update(gameTime);
        }
Esempio n. 2
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)
        {
            fCamera.Update(gameTime);

            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            if (fEngine.InputManager.KeyPressed(Keys.P))
            {
                fEngine.UpdatePaused = !fEngine.UpdatePaused;
            }

            if (fEngine.InputManager.KeyPressed(Keys.M))
            {
                fEngine.ToggleFullscreen();
            }

            fLabelDisplayMode.Text = $"Mode={fEngine.DisplayMode}";
            fAdapterSize.Text      = $"Adapter={fEngine.AdapterSize.Width}x{fEngine.AdapterSize.Height}";
            fWindowSize.Text       = $"Window={fEngine.WindowSize.Width}x{fEngine.WindowSize.Height}";
            fAspectRatio.Text      = $"AspectRatio={fEngine.AspectRatio}";
            fFPS.Text = $"FPS={fEngine.FPS.FrameRate}";
            int count = fPlane.NumberOfTriangles;

            foreach (var plane in fPlanes)
            {
                count += plane.NumberOfTriangles;
            }
            count += fObject1.NumberOfTriangles;

            fInfo.Text            = $"#Triangles={count}";
            lblDrawMode.Text      = $"Draw Mode = {fDrawMode}";
            lblShaderMode.Text    = $"Shader Mode = {fShaderMode}";
            lblRenderObjects.Text = $"Render Objects = {fRenderObjects}";
            if (fEngine.MouseOverElement == null)
            {
                fCurrentElement.Text = "...";
            }
            else
            {
                GuiElement element = fEngine.MouseOverElement;
                string     name    = String.Empty;
                bool       isFirst = true;

                while (element != null)
                {
                    if (!isFirst)
                    {
                        name = name + "/";
                    }
                    isFirst = false;
                    string n = element.GetType().Name;
                    if (n.StartsWith("Gui"))
                    {
                        name = name + n.Substring(3);
                    }
                    else
                    {
                        name = name + n;
                    }
                    element = element.Parent;
                }
                fCurrentElement.Text = name;
            }


            if (fUpdatePlane)
            {
                SetPlane();
            }
            int    max     = fPlane.Segments;
            double seconds = gameTime.TotalGameTime.TotalSeconds;

            for (int x = 0; x <= max; x++)
            {
                float nX = 2.0f * (float)x / max - 1.0f;// -1 to +1
                for (int z = 0; z <= max; z++)
                {
                    float  nZ = 2.0f * (float)z / max - 1.0f;
                    double r  = Math.Sqrt(nX * nX + nZ * nZ);
                    //double y = nX * Math.Cos(r * 12.0f - seconds * 4.2f) + nZ * Math.Sin((r - 0.5) * 3.1f - seconds * 1.9f);
                    double y      = Math.Cos(r * 10.0f - seconds * 2.0f) + Math.Sin(r * 10.0f - seconds * 2.1f);
                    float  height = 200.0f * (float)y;
                    fPlane.SetHeight(x, z, height);
                }
            }
            fPlane.GenerateNormals();

            base.Update(gameTime);
        }