Laden...

XNA Terrain problem

Erstellt von chea77er vor 15 Jahren Letzter Beitrag vor 15 Jahren 685 Views
C
chea77er Themenstarter:in
74 Beiträge seit 2008
vor 15 Jahren
XNA Terrain problem

Guten tag,
Ich spiele derzeit mit Terrains mit XNA herrum und wollte wären der Runtime die render einstellungen umändern. Bin mir nicht ganz sich ob es Render heißt aber naja..
So sieht es aus am Start:
http://blog-dotnet.de/terrainprob1.jpg
Mit folgenden Code auschnitten:
Draw:


        protected override void Draw(GameTime gameTime)
        {
            device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0);

            device.RenderState.CullMode = CullMode.None;

            Vector3 rotAxis = new Vector3(3 * angle, angle, 2 * angle);
            rotAxis.Normalize();
            Matrix worldMatrix = Matrix.CreateTranslation(-terrainWidth / 2.0f, 0, terrainHeight / 2.0f) * Matrix.CreateRotationY(angle);
            effect.CurrentTechnique = effect.Techniques["Colored"];
            effect.Parameters["xView"].SetValue(viewMatrix);
            effect.Parameters["xProjection"].SetValue(projectionMatrix);
            effect.Parameters["xWorld"].SetValue(worldMatrix);

            effect.Begin();
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Begin();

                device.VertexDeclaration = myVertexDeclaration;
                device.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertices, 0, vertices.Length, indices, 0, indices.Length / 3);

                pass.End();
            }
            effect.End();

            base.Draw(gameTime);
        }

SetUpVertices():


        private void SetUpVertices()
        {

            float minHeight = float.MaxValue;
            float maxHeight = float.MinValue;
            for (int x = 0; x < terrainWidth; x++)
            {
                for (int y = 0; y < terrainHeight; y++)
                {
                    if (heightData[x, y] < minHeight)
                        minHeight = heightData[x, y];
                    if (heightData[x, y] > maxHeight)
                        maxHeight = heightData[x, y];
                }
            }

            vertices = new VertexPositionColor[terrainWidth * terrainHeight];
            for (int x = 0; x < terrainWidth; x++)
            {
                for (int y = 0; y < terrainHeight; y++)
                {
                    vertices[x + y * terrainWidth].Position = new Vector3(x, heightData[x, y], -y);

                    if (heightData[x, y] < minHeight + (maxHeight - minHeight) / 4)
                        vertices[x + y * terrainWidth].Color = Color.Blue;
                    else if (heightData[x, y] < minHeight + (maxHeight - minHeight) * 2 / 4)
                        vertices[x + y * terrainWidth].Color = Color.Green;
                    else if (heightData[x, y] < minHeight + (maxHeight - minHeight) * 3 / 4)
                        vertices[x + y * terrainWidth].Color = Color.Brown;
                    else
                        vertices[x + y * terrainWidth].Color = Color.White;
                }
            }

            myVertexDeclaration = new VertexDeclaration(device, VertexPositionColor.VertexElements);
        }

So nun will ich wärend der runtime diese Ansicht zu der wechseln:
http://blog-dotnet.de/terrainprob2.jpg
Hier der Code:
Draw:


public void DrawBasic(GameTime gameTime)
        {
            device.Clear(Color.DarkSlateBlue);

            effect.CurrentTechnique = effect.Techniques["Pretransformed"];
            device.RenderState.CullMode = CullMode.None;
            device.RenderState.FillMode = FillMode.WireFrame;

            Vector3 rotAxis = new Vector3(3 * angle, angle, 2 * angle);
            rotAxis.Normalize();
            Matrix worldMatrix = Matrix.CreateTranslation(-terrainWidth / 2.0f, 0, terrainHeight / 2.0f) * Matrix.CreateRotationY(angle);
            effect.CurrentTechnique = effect.Techniques["Colored"];
            effect.Parameters["xView"].SetValue(viewMatrix);
            effect.Parameters["xProjection"].SetValue(projectionMatrix);
            effect.Parameters["xWorld"].SetValue(worldMatrix);

            effect.Begin();
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Begin();

                device.VertexDeclaration = myVertexDeclaration;
                device.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertices, 0, vertices.Length, indices, 0, indices.Length / 3);

                pass.End();
            }
            effect.End();

            base.Draw(gameTime);
        }

SetUpVertices()


        private void SetUpVerticesBasic()
        {
            vertices = new VertexPositionColor[terrainWidth * terrainHeight];
            for (int x = 0; x < terrainWidth; x++)
            {
                for (int y = 0; y < terrainHeight; y++)
                {
                    vertices[x + y * terrainWidth].Position = new Vector3(x, heightData[x, y], -y);
                    vertices[x + y * terrainWidth].Color = Color.White;
                }
            }

            myVertexDeclaration = new VertexDeclaration(device, VertexPositionColor.VertexElements);
        }

So ok klappt alles nur nun will ich von dieser Ansicht wieder zur anderen nur wen folgendes ausführe:


        public void changeToColor()
        {
            SetUpVerticesColor();
            device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0);
            device.RenderState.CullMode = CullMode.None;            
        }

Kommt folgendes raus:
http://blog-dotnet.de/terrainprob3.jpg

So wo ist nun der Fehler!

MFG René

C
401 Beiträge seit 2007
vor 15 Jahren

So wie ich das sehe setzt du den FillMode nicht wieder zurück.