Пример #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)
        {
            HandleInput(gameTime);
            fCamera.Update(gameTime);

            float seconds = (float)gameTime.ElapsedGameTime.TotalSeconds;

            if (!fHalted)
            {
                UpdatePoints(seconds);
                fPointsToCreate += (seconds * POINTS_PER_SECOND);
                if (fPointsToCreate > 1.0f)
                {
                    int newPoints = (int)fPointsToCreate;
                    fPointsToCreate -= newPoints;
                    AddNewPoints(newPoints);
                }
            }
            if (fIndexBuffer == null)
            {
                CalculateBuffers();
            }
            else if (!fHalted)
            {
                // I was previously using point sprites for this sample. With XNA 4.0 that function disappeared
                // and the framerate of this sample dropped as more data was needed from the CPU to the GPU
                // Simple trick to create a higher frame rate...
                //speedy=(speedy+1)%5;
                //if (speedy==0)
                CalculateBuffers();
            }
            base.Update(gameTime);
        }
Пример #2
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)
        {
            HandleInput(gameTime);
            fCamera.Update(gameTime);

            if (!fHalted)
            {
                float seconds = (float)gameTime.ElapsedGameTime.TotalSeconds;
                UpdatePoints(seconds);
            }
            if (fBillboards == null)
            {
                InitBillboard();
            }
            else if (!fHalted && fBillboardChanged)
            {
                // I was previously using point sprites for this sample. With XNA 4.0 that function disappeared
                // and the framerate of this sample dropped as more data was needed from the CPU to the GPU
                // Simple trick to create a higher frame rate...
                //speedy=(speedy+1)%5;
                //if (speedy==0)
                InitBillboard();
            }

            base.Update(gameTime);
        }
Пример #3
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)
        {
            HandleInput(gameTime);
            fCamera.Update(gameTime);

            double seconds = gameTime.TotalGameTime.TotalSeconds;


            base.Update(gameTime);
        }
Пример #4
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)
        {
            HandleInput(gameTime);
            fCamera.Update(gameTime);

            float seconds = (float)gameTime.ElapsedGameTime.TotalSeconds;

            if (fBillboard == null)
            {
                InitBillboard();
            }
            base.Update(gameTime);
        }
Пример #5
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)
        {
            HandleInput(gameTime);
            fCamera.Update(gameTime);

            double factor = gameTime.ElapsedGameTime.TotalMilliseconds / 1000.0f;

            if (factor > 0)
            {
                fCalculations = UpdateSpaceAndParticles(factor);
            }

            base.Update(gameTime);
        }
Пример #6
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.F))
            {
                fGenerateFractal = true;
            }
            else if (this.Manager.KeyPressed(Keys.W))
            {
                fAddZeroPlane = !fAddZeroPlane;
                fUpdatePlane  = true;
            }
            else if (this.Manager.KeyPressed(Keys.H))
            {
                fHalted = !fHalted;
            }

            fCamera.Update(gameTime);

            double seconds = gameTime.TotalGameTime.TotalSeconds;

            if (fGenerateFractal)
            {
                GenerateFractal();
            }
            if (fUpdatePlane)
            {
                UpdatePlane();
            }
            base.Update(gameTime);
        }
Пример #7
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)
        {
            fCamera.Update(gameTime);

            float seconds = (float)gameTime.ElapsedGameTime.TotalSeconds;

            if (fBillboard1 == null)
            {
                InitBillboard();
            }
            if (this.Manager.KeyPressed(Keys.V))
            {
                fUseVertexBuffer            = !fUseVertexBuffer;
                fBillboard1.UseVertexBuffer = fBillboard2.UseVertexBuffer = fBillboard3.UseVertexBuffer = fUseVertexBuffer;
            }
            else if (this.Manager.KeyPressed(Keys.H))
            {
                fHalted = !fHalted;
            }
            else if (this.Manager.KeyPressed(Keys.M))
            {
                if (fDrawMode == BillboardMode.PointList)
                {
                    fDrawMode = BillboardMode.Quad;
                }
                else
                {
                    fDrawMode = BillboardMode.PointList;
                }
                fBillboard1.Mode = fBillboard2.Mode = fBillboard3.Mode = fDrawMode;
                InitBillboard();
            }
            else if (this.Manager.KeyPressed(Keys.T))
            {
                if (fTextureMode == TextureMode.Faces)
                {
                    fTextureMode = TextureMode.Test;
                }
                else
                {
                    fTextureMode = TextureMode.Faces;
                }
            }

            base.Update(gameTime);
        }
Пример #8
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);
        }
Пример #9
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);
        }
Пример #10
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.F))
            {
                fGenerateFractal = true;
            }
            else if (this.Manager.KeyPressed(Keys.H))
            {
                fHalted = !fHalted;
            }

            else if (this.Manager.KeyPressed(Keys.D1))
            {
                fShowWater = !fShowWater;
            }
            else if (this.Manager.KeyPressed(Keys.D2))
            {
                fShowTerrain = !fShowTerrain;
            }
            else if (this.Manager.KeyPressed(Keys.D3))
            {
                fShowSkyBox = !fShowSkyBox;
            }
            else if (this.Manager.KeyPressed(Keys.D4))
            {
                fShowReflection = !fShowReflection;
            }
            else if (this.Manager.KeyPressed(Keys.D5))
            {
                fClipReflection = !fClipReflection;
            }
            else if (this.Manager.KeyPressed(Keys.D6))
            {
                fShowRefraction = !fShowRefraction;
            }
            else if (this.Manager.KeyPressed(Keys.D7))
            {
                fClipRefraction = !fClipRefraction;
            }
            else if (this.Manager.KeyPressed(Keys.D8))
            {
                fShowSkyBoxInReflection = !fShowSkyBoxInReflection;
            }
            else if (this.Manager.KeyPressed(Keys.D9))
            {
                fShowWaterBumpMap = !fShowWaterBumpMap;
            }

            fCamera.Update(gameTime);
            double seconds = gameTime.TotalGameTime.TotalSeconds;

            Vector3 cameraPosition = fCamera.Camera.Position;

            Quaternion quat = fCamera.Camera.Rotation;

            quat = Quaternion.Inverse(quat);
            Vector3 cameraForwardDirection = Vector3.Transform(Vector3.Forward, quat);
            Vector3 cameraUpDirection      = Vector3.Transform(Vector3.Up, quat);
            Vector3 cameraRightDirection   = Vector3.Transform(Vector3.Right, quat);
            Vector3 cameraTarget           = cameraForwardDirection + cameraPosition;

            fReflectionCameraPosition   = fCamera.Camera.Position;
            fReflectionCameraPosition.Y = -fCamera.Camera.Position.Y + WATER_HEIGHT * 2;
            Vector3 reflTargetPos = cameraTarget;

            reflTargetPos.Y = -cameraTarget.Y + WATER_HEIGHT * 2;
            Vector3 cameraRight = Vector3.Transform(Vector3.Right, quat);
            Vector3 invUpVector = Vector3.Cross(cameraRight, reflTargetPos - fReflectionCameraPosition);

            fReflectionViewMatrix = Matrix.CreateLookAt(fReflectionCameraPosition, reflTargetPos, invUpVector);


            if (fGenerateFractal)
            {
                GenerateFractal();
            }
            if (fUpdatePlane)
            {
                UpdatePlane();
            }
            base.Update(gameTime);
        }