2010-12-15 9 views
0

XNAの3Dレンダリングの仕組みを理解しようとしていますが、DirectXと非常によく似ているようです。XNA/WP7で2Dを3Dで描画すると、ぼんやりした3Dレンダリングが行われます

しかしスプライトバッチで描画するときに期待していない動作が1種類あります。 http://i.stack.imgur.com/DQAHg.png

しかし、私は次のように2Dスプライト(SpriteBatchから引き出された)の上に、それを描画しようとしている:私はこの結果を得る任意のスプライトなし

私はちょうど3Dキューブ、プリミティブを描画し、ファッション:明らかに間違っているhttp://imgur.com/7QZlj

 SpriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend); 
     base.Draw(gameTime); 
     SpriteBatch.End(); 

     shape.Draw(gameTime); 

これは私が得る結果です。私の最初の考えは、(何らかの理由で)正射投影を使用してレンダリングしていたのですが、わかりません。

は、ここで私は、キューブを描画するために使用するコードですが、それはほとんど1'S:1 XNAプリミティブサンプルから(私はゲームのための適切な3Dフレームワーク上で作業を開始していない)ので、

  GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise; 

      // Create camera matrices, making the object spin. 
      float time = (float)gameTime.TotalGameTime.TotalSeconds; 

      Vector3 cameraPosition = new Vector3(0, 0, 2.5f); 

      float aspect = GraphicsDevice.Viewport.AspectRatio; 

      float yaw = 3.05f; 
      float pitch = 5.34f; 
      float roll = 8.396f; 

      Matrix world = Matrix.CreateFromYawPitchRoll(yaw, pitch, roll); 
      Matrix view = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up); 
      Matrix projection = Matrix.CreatePerspectiveFieldOfView(1, aspect, 1, 10); 

      // currentPrimitive.Draw(world, view, projection, Color.Red); 

      // Reset the fill mode renderstate. 
      GraphicsDevice.RasterizerState = RasterizerState.CullClockwise; 


      Color color = Color.Red; 

      // Set BasicEffect parameters. 
      basicEffect.World = world; 
      basicEffect.View = view; 
      basicEffect.Projection = projection; 
      basicEffect.DiffuseColor = color.ToVector3(); 
      basicEffect.Alpha = 1.0f;// color.A/255.0f; 

      GraphicsDevice device = basicEffect.GraphicsDevice; 
      device.DepthStencilState = DepthStencilState.Default; 


      GraphicsDevice.RasterizerState = RasterizerState.CullClockwise; 

      GraphicsDevice graphicsDevice = basicEffect.GraphicsDevice; 

      // Set our vertex declaration, vertex buffer, and index buffer. 
      graphicsDevice.SetVertexBuffer(vertexBuffer); 

      graphicsDevice.Indices = indexBuffer; 


      foreach (EffectPass effectPass in basicEffect.CurrentTechnique.Passes) 
      { 
       effectPass.Apply(); 

       int primitiveCount = indices.Count/3; 

       graphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 
                vertices.Count, 0, primitiveCount); 

      } 
厄介かもしれません

私はまた、spritebatch.begin/spritebatch.endの結果ではないことを明確にする必要があります。私はちょうど/ endを開始し、何も描画しませんが、最終結果は問題ありませんが、フォントやスプライトを描画すると、キューブ。

誰もが考えている?

答えて

1

私の助言は、SpriteBatch.End()メソッド呼び出しの後にGraphicsDeviceの設定を確認することです。 SpriteBatchを使用すると、GraphicsDeviceの一部のレンダリング状態が変更されます。おそらくSpriteBatch.Begin()の前にGraphicsDeviceの値を格納しておき、SpriteBatch.End()メソッドの呼び出し後にそれらの値をリセットすることをお勧めします。

+0

これは問題を解決しました。 – tweetypi

+1

私は同じような問題(http://project-vanquish.co.cc)を持っていたため、多くの不満が生じました。 –

関連する問題