XNA에서 3D 렌더링이 어떻게 작동하는지 파악하려고하는 중입니다. DirectX와 매우 유사하여 상당히 직설적 인 것처럼 보입니다. .XNA/WP7에서 2D를 3D로 렌더링하면 나를 위해 멍청한 3D 렌더링이 생성됩니다.
하지만 스프라이트 배치를 사용하여 그리기를 기대하지 않은 행위가 한 가지 있습니다.
난 그냥 어떤 스프라이트없이 3D 큐브, 원시를 그릴 때 나는이 결과를 얻을 : http://i.stack.imgur.com/DQAHg.png
을하지만 2D 스프라이트의 상단에 그릴려고 할 때 다음에 (의 SpriteBatch에서 도출) 패션 : 분명히 잘못된 http://imgur.com/7QZlj
:
SpriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);
base.Draw(gameTime);
SpriteBatch.End();
shape.Draw(gameTime);
이것은 내가 얻을 결과입니다. 내 첫 번째 생각은 (어떤 이유로) 직교 투영을 사용하여 렌더링했지만 확실하지 않습니다. 여기
은 거의 1이다, 나는 큐브를 그리는 데 사용하는 코드입니다 : (I 게임에 대한 적절한 3D 프레임 워크 작업을 시작하지 않은)이 XNA 프리미티브 샘플에서 1 그래서 지저분 수 있습니다 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의 결과가 아니라는 것을 분명히해야합니다. 끝이 끝나고 무언가를 그려 내지 않아도되지만, 글꼴이나 스프라이트를 그릴 경우에는 입방체.
누구든지 아이디어가 있습니까?
이 문제가 해결되어 선별기 순서가 변경되었습니다. – tweetypi
나는 비슷한 문제 (http://project-vanquish.co.cc)로 많은 좌절감을 안겨 주었다. –