3d 为什么我的相机不能跟踪它的目标?(XNA 4.0)
这是我的代码,它让对象用鼠标移动,但它不会使屏幕(相机)随之移动。我不明白为什么它会这样做。有人知道为什么吗3d 为什么我的相机不能跟踪它的目标?(XNA 4.0),3d,xna,camera,3d,Xna,Camera,这是我的代码,它让对象用鼠标移动,但它不会使屏幕(相机)随之移动。我不明白为什么它会这样做。有人知道为什么吗 void UpdateCamera() { currentmousestate = Mouse.GetState(); // Calculate the camera's current position. Vector3 cameraPosition = avatarPosition; Matrix rotati
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;
}
您应该使用调试器来监视变量获取的值。。。虚拟位置值是否在变化 我不明白你拿老鼠做什么。。。你应该在世界坐标中获得鼠标射线,以便进行有意义的计算。。。您可以使用Viewport.UnProject获取它 我想你想实现一个arcball鼠标摄像头。。。但是,如果您要查找“xna arcball”,则有几个示例