不久之前,我决定从XNA切换到SharpDX Toolkit,因为它得到了积极支持,与XNA非常相似。虽然我在制作2D游戏时没有遇到任何麻烦,但我决定尝试一款基本的3D游戏。我可以同时获得模型和它的纹理,但是当它渲染时它只显示远离相机的一侧的纹理在它们之间根本没有显示任何东西。
这是我用来设置环境的代码。
Vector3 cameraPosition = new Vector3(0, 0, -10f * 2.5f);
Vector3 cameraTarget = Vector3.Zero;
BoundingSphere modelBounds = model.CalculateBounds();
float fovAngle = MathUtil.DegreesToRadians(45);
float aspectRatio = (float)GraphicsDevice.BackBuffer.Width / GraphicsDevice.BackBuffer.Height;
float near = 0.01f;
float far = 100f;
float scaling = 10f / modelBounds.Radius;
Matrix translation = Matrix.Scaling(scaling) * Matrix.RotationY((float)gameTime.TotalGameTime.TotalSeconds) * Matrix.Translation(0, -modelBounds.Center.Y * scaling, 0);
Matrix lookAt = Matrix.LookAtLH(cameraPosition, cameraTarget, Vector3.Up);
Matrix projection = Matrix.PerspectiveFovLH(.9f, aspectRatio, near, far);
这是呈现它的代码。
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
model.Draw(GraphicsDevice, translation, lookAt, projection);
base.Draw(gameTime);
}
感谢任何帮助。