编辑:我添加了大部分代码的pastebin。由于我无法将其添加到此帖子中,因此可以在评论中找到这些链接。
我正在玩XNA 4.0程序生成的行星。
问题1:
http://i.stack.imgur.com/PofhL.png
如您所见,行星边缘有可见的三角形。我尝试了很多东西,但我无法弄清楚如何摆脱这种影响。纹理本身很好,球体是导入的模型。
PS。是的,我读过类似的问题,但没有人帮助我解决我的问题。
问题2:
http://i.stack.imgur.com/KV28k.png
当我移开相机时会发生这种情况。我做了我的研究,并修改了近飞机,远飞机和其他一些东西。什么都没有帮助。注意:云效果不是由我完成的,并且它不会消失。
此刻我没有附加任何代码,因为如果有经验的人很容易回答这个问题,我不会感到惊讶。但是,如果需要,我可以在这里粘贴所需的代码。
提前致谢。
编辑: 我不希望行星永远消失。我希望能够远离相机并仍然可以看到那些行星,即使它们只是点。
好的,我会证明更多的解释。我是XNA的一员,也是一般的编程。这就是为什么我可能有点难以理解:< 1.导入球体模型。
生成并存储纹理。我能够将它们视为方形纹理文件,它们看起来很好,所以它们不是问题。
这是我不理解我在互联网上找到的代码部分的地方。我附上了我认为可能有错误的代码片段。注释掉的行也不相关。
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();
}
答案 0 :(得分: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
其他纹理是程序生成的。那些算法可能不起作用。我虽然没有看过他们。