0
這是我的代碼,讓對象隨鼠標移動,但它不會使屏幕(相機)隨之移動。我無法弄清楚爲什麼這樣做。任何人都可以弄清楚爲什麼?爲什麼我的相機無法實現其目標? (XNA 4.0)
void UpdateCamera()
{
currentmousestate = Mouse.GetState();
// Calculate the camera's current position.
Vector3 cameraPosition = avatarPosition;
Matrix rotationMatrix = Matrix.CreateRotationY(avatarYaw);
// Create a vector pointing the direction the camera is facing.
// Compare the original mouse position with the new one,
// and divide that by a float of -80.
cameraReference = new Vector3((currentmousestate.X - originalstate.X)/-80f, (currentmousestate.Y - originalstate.Y)/-80f, 1);
avatarYaw = (float)(currentmousestate.X - originalstate.X)/-160f;
Vector3 transformedReference = Vector3.Transform(cameraReference, rotationMatrix);
// Calculate the position the camera is looking at.
Vector3 cameraLookat = cameraPosition + transformedReference;
// Set up the view matrix and projection matrix.
view = Matrix.CreateLookAt(cameraPosition, cameraLookat, new Vector3(0.0f, 1.0f, 0.0f));
Viewport viewport = graphics.GraphicsDevice.Viewport;
float aspectRatio = (float)viewport.Width/(float)viewport.Height;
proj = Matrix.CreatePerspectiveFieldOfView(viewAngle, aspectRatio, nearClip, farClip);
//originalstate = currentmousestate;
}