0

编辑:我添加了大部分代码的 pastebin。由于我无法将其添加到此帖子中,因此可以在评论中找到这些链接。

我在玩 XNA 4.0 程序生成的行星。

问题1:

http://i.stack.imgur.com/PofhL.png

如您所见,行星边缘有可见的三角形。我尝试了很多东西,但我不知道如何摆脱这种影响。纹理本身很好,球体是进口模型。

附言。是的,我读过类似的问题,但没有一个能帮助我解决我的问题。

问题2:

http://i.stack.imgur.com/KV28k.png

这就是当我移开相机时发生的事情。我做了研究,修改了近平面、远平面和其他一些东西。没有任何帮助。注意:云彩效果不是我做的,不知何故它不会消失。

我现在不附加任何代码,因为如果有经验的人回答很容易,我不会感到惊讶。但是,如果需要,我可以在此处粘贴所需的代码。

提前致谢。

编辑:我不希望行星永远消失。我希望能够将相机移到很远的地方,即使它们只是点,也能看到那些行星。

好的,我会证明更多的解释。我是 XNA 和一般编程的初学者。这就是为什么我可能有点难以理解的原因:< 1. 球体模型已导入。

  1. 生成并存储纹理。我能够将它们视为方形纹理文件,它们看起来很好,所以它们不是问题。

  2. 这是我不理解我在互联网上找到的某些部分代码的地方。我附上了我认为可能有错误的代码。注释掉的行也不是那么相关。

    private void UpdateCamera() { // 计算视图矩阵。

        Quaternion rotation = Quaternion.Identity;
        float heading = MathHelper.ToRadians(camera.rotation.Y);
        float pitch = MathHelper.ToRadians(camera.rotation.X);
    
        if (heading != 0.0f)
        {
            rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitY, heading);
            Quaternion.Concatenate(ref rotation, ref camera.orientation, out camera.orientation);
        }
    
        if (pitch != 0.0f)
        {
            rotation = Quaternion.CreateFromAxisAngle(Vector3.UnitX, pitch);
            Quaternion.Concatenate(ref camera.orientation, ref rotation, out camera.orientation);
        }
    
        Matrix.CreateFromQuaternion(ref camera.orientation, out camera.viewMatrix);
    
        Vector3 xAxis = new Vector3(camera.viewMatrix.M11, camera.viewMatrix.M21, camera.viewMatrix.M31);
        Vector3 yAxis = new Vector3(camera.viewMatrix.M12, camera.viewMatrix.M22, camera.viewMatrix.M32);
        Vector3 zAxis = new Vector3(camera.viewMatrix.M13, camera.viewMatrix.M23, camera.viewMatrix.M33);
    
        camera.target -= xAxis * camera.translate.X;
        camera.target -= yAxis * camera.translate.Y;
    
        camera.position = camera.target + zAxis * camera.offset;
    
        camera.viewMatrix.M41 = -Vector3.Dot(xAxis, camera.position);
        camera.viewMatrix.M42 = -Vector3.Dot(yAxis, camera.position);
        camera.viewMatrix.M43 = -Vector3.Dot(zAxis, camera.position);
    
        Vector3.Negate(ref zAxis, out camera.viewDir);
    
        // Calculate the projection matrix.
    
        camera.projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4,
            (float)windowWidth / (float)windowHeight, 0.1f, 30000.0f);
    }
    

第二段代码:

protected override void LoadContent()
    {
        spriteBatch = new SpriteBatch(GraphicsDevice);
        spriteFont = Content.Load<SpriteFont>(@"Fonts\DemoFont");

        GenerateTextures(2);

        // Load the assets for the Earth.
        earth.model = Content.Load<Model>(@"Models\earth");
        earth.effect = Content.Load<Effect>(@"Effects\earth");
        //earth.dayTexture = Content.Load<Texture2D>(@"Textures\earth_day_color_spec");
        earth.dayTexture = colorTexture_;

        //earth.nightTexture = Content.Load<Texture2D>(@"Textures\earth_night_color");
        //earth.nightTexture = heightTexture_;

        earth.cloudTexture = Content.Load<Texture2D>(@"Textures\earth_clouds_alpha");

        //earth.normalMapTexture = Content.Load<Texture2D>(@"Textures\earth_nrm");
        earth.normalMapTexture = normalTexture_;

        // Setup material settings for the Earth.
        earth.ambient = new Vector4(0.3f, 0.3f, 0.3f, 1.0f);
        earth.diffuse = new Vector4(0.7f, 0.7f, 0.7f, 1.0f);
        earth.specular = new Vector4(0.7f, 0.7f, 0.7f, 1.0f);
        earth.shininess = 20.0f;
        earth.cloudStrength = 1.15f;

        // Calculate the bounding sphere of the Earth model and bind the
        // custom Earth effect file to the model.
        foreach (ModelMesh mesh in earth.model.Meshes)
        {
            earth.bounds = BoundingSphere.CreateMerged(earth.bounds, mesh.BoundingSphere);

            foreach (ModelMeshPart part in mesh.MeshParts)
                part.Effect = earth.effect;
        }

        // Position the camera based on the Earth model's size.
        camera.target = earth.bounds.Center;
        camera.offset = earth.bounds.Radius * 3.0f;
        camera.orientation = Quaternion.Identity;

        // Setup starfield.
        starfieldComponent.Generate(5000, earth.bounds.Radius * 45.0f);



    }

最后:

private void DrawEarth()
    {
        Matrix rotation = Matrix.CreateScale(0.2f) * Matrix.CreateRotationY(earth.rotation) *
                           Matrix.CreateRotationZ(MathHelper.ToRadians(-23.4f));

        foreach (ModelMesh m in earth.model.Meshes)
        {
            foreach (Effect e in m.Effects)
            {
                if (hideClouds)
                {
                    e.CurrentTechnique = e.Techniques["EarthWithoutClouds"];
                }
                else
                {
                    e.CurrentTechnique = e.Techniques["EarthWithClouds"];
                    e.Parameters["cloudStrength"].SetValue(earth.cloudStrength);
                }

                e.Parameters["world"].SetValue(rotation);
                e.Parameters["view"].SetValue(camera.viewMatrix);
                e.Parameters["projection"].SetValue(camera.projectionMatrix);
                e.Parameters["cameraPos"].SetValue(new Vector4(camera.position, 1.0f));
                e.Parameters["globalAmbient"].SetValue(globalAmbient);
                e.Parameters["lightDir"].SetValue(sunlight.direction);
                e.Parameters["lightColor"].SetValue(sunlight.color);
                e.Parameters["materialAmbient"].SetValue(earth.ambient);
                e.Parameters["materialDiffuse"].SetValue(earth.diffuse);
                e.Parameters["materialSpecular"].SetValue(earth.specular);
                e.Parameters["materialShininess"].SetValue(earth.shininess);
                e.Parameters["landOceanColorGlossMap"].SetValue(earth.dayTexture);
                e.Parameters["cloudColorMap"].SetValue(earth.cloudTexture);
                e.Parameters["nightColorMap"].SetValue(earth.nightTexture);
                e.Parameters["normalMap"].SetValue(earth.normalMapTexture);

            }

            m.Draw();
        }
4

1 回答 1

0

问题确实是由纹理引起的。

我猜你(或其他人)在LoadContent. 以下是正确的:

earth.dayTexture =
    Content.Load<Texture2D>(@"Textures\earth_day_color_spec"); // <-- correct
//earth.dayTexture = colorTexture_; <-- wrong

earth.nightTexture = 
    Content.Load<Texture2D>(@"Textures\earth_night_color"); // <-- correct
//earth.nightTexture = heightTexture_; <-- wrong

earth.normalMapTexture = 
    Content.Load<Texture2D>(@"Textures\earth_nrm"); // <-- correct
//earth.normalMapTexture = normalTexture_; <-- wrong

其他纹理是程序生成的。这些算法可能不起作用。不过我还没有看过他们。

于 2013-04-23T18:46:46.063 回答