我完全同意Coincoin,上下文代碼會有所幫助。
如果您只想繪製變換網格到屏幕上,則不需要以這種方式變換網格。您可以更改世界,視圖和投影矩陣之一。這產生了預期的結果。就像下面的示例代碼一樣。
// Clear the backbuffer to a Blue color.
device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Blue,
1.0f, 0);
// Begin the scene.
device.BeginScene();
device.Lights[0].Enabled = true;
// Setup the world, view, and projection matrices.
Matrix m = new Matrix();
if(destination.Y != 0)
y += DXUtil.Timer(DirectXTimer.GetElapsedTime) * (destination.Y
* 25);
if(destination.X != 0)
x += DXUtil.Timer(DirectXTimer.GetElapsedTime) * (destination.X
* 25);
m = Matrix.RotationY(y);
m *= Matrix.RotationX(x);
device.Transform.World = m;
device.Transform.View = Matrix.LookAtLH(
new Vector3(0.0f, 3.0f,-5.0f),
new Vector3(0.0f, 0.0f, 0.0f),
new Vector3(0.0f, 1.0f, 0.0f));
device.Transform.Projection = Matrix.PerspectiveFovLH(
(float)Math.PI/4, 1.0f, 1.0f, 100.0f);
// Render the teapot.
teapot.DrawSubset(0);
// End the scene.
device.EndScene();
此樣本取自here。
來源
2009-04-24 07:55:32
avp