2013-04-22 1 views
0

편집 : 대부분의 코드가 포함 된 pastebin을 추가했습니다. 이후이 게시물에 추가 할 수 없기 때문에 이러한 링크는 주석에서 찾을 수 있습니다.XNA 4.0 3D 구형 행성 관련 문제

Im는 XNA 4.0을 가지고 놀고 있습니다. 절차 상 생성 된 행성.

문제 1 : 당신이 볼 수 있듯이

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

, 행성의 가장자리에 보이는 삼각형이 있습니다. 나는 많은 것들을 시도했지만이 효과를 없애는 방법을 이해할 수 없다. 텍스처 자체는 괜찮지 만 구체는 가져온 모델입니다.

ps. 그래, 비슷한 문제에 대해 읽었지만 아무도 내 문제를 해결하지 못했습니다.

문제 2 :

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

이 내 카메라를 멀리 이동할 때 발생하는 것입니다. 나는 내 연구를 수행했고 비행기, 먼 비행기 및 다른 것들 근처에서 수정했다. 아무것도 도움이되지 않았습니다. 참고 : 구름 효과는 나에 의해 수행되지 않으며 어떻게 든 사라지지 않습니다.

경험이 많은 사람이 쉽게 대답 할 수 있다면 놀라지 않을 것입니다. 그러나 필요한 경우 여기에 필요한 코드를 붙여 넣을 수 있습니다.

미리 감사드립니다.

편집 : 나는 행성을 사라지 길 원합니다. 나는 카메라를 멀리 옮기고 도트 가더라도 여전히 그 행성을 볼 수 있기를 원합니다.

나는 더 자세한 설명을 할 것입니다. XNA 및 프로그래밍 전반에 초보자입니다. 이것이 나를 이해하기가 약간 어려울 수있는 이유입니다. < 1. 구형 모델을 가져 왔습니다.

  1. 텍스처가 생성되어 저장됩니다. 나는 그것들을 정사각형 텍스쳐 파일로 볼 수 있었고 문제가되지 않도록 잘 보였다.

  2. 이것은 인터넷에서 발견 된 코드의 일부를 이해하지 못하는 곳입니다. 제 견해로는 오류가있을 수있는 코드 조각을 첨부했습니다. 또한 주석 처리 된 행은 관련이 없습니다.

    개인 무효 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

도려내 기처럼 보이지만 꼭지점 중 하나가 컬링되어 전체 삼각형이 – Sayse

+0

입니다. @Sayse : 얼굴 당 후면 컬링이 수행됩니다. 하나의 정점이 추려지지도 컬링도되지 않습니다. TO, 적어도 행성을 그리는 개념을 설명 할 수 있습니까? (어떤 순서로 그려지며 어떤 상태가 설정되어 있습니까?) 두 번째 이미지는 무엇을 기대합니까? 행성을 사라지게하려면 렌더링 코드를 게시해야합니다. –

+0

문제를 해결하거나 적어도 실제 문제인지 확인하는 방법을 알고 있습니까? 이 문제를 해결하기로되어 있었지만 didnt은이 줄이 있습니다. GraphicsDevice.RasterizerState = RasterizerState.CullNone; – Szlose

답변

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 

기타 텍스처가 절차 적으로 생성되었습니다. 그 알고리즘은 아마 작동하지 않습니다. 나는 그들을 보았다.