【发布时间】:2018-10-18 17:36:54
【问题描述】:
我有一个问题 - 我说问题,它更像是一种极端的不便,让玩起来很烦人。
我正在使用 XNA Monogame 制作一个 3D 游戏(这是一项痛苦的工作,在统一中会更容易,但由于我懒得进入的原因,它不是。)我的相机是用来设置玩家的将鼠标移到窗口/视口的中心,然后在该帧和下一帧之间获取鼠标移动的变化,这将用于旋转相机......它正在工作......有点。但是现在我已经将这个项目转移到了个人电脑上,而不是我正在使用的笔记本电脑上,相机在移动时变得非常不稳定。我不太确定如何修复它,我一直在弄乱我将发布的代码 sn-p 中的一些值,但它不再流畅了。如果这可能是一个问题,这台电脑是使用 3 个屏幕设置的吗?
if (moveVector != Vector3.Zero)
{
//Normalise the vector - to stop us moving faster diagonally
moveVector.Normalize();
//Add smooth and speed
moveVector *= deltaTime * cameraSpeed;
//Move camera
Move(moveVector);
}
//Handle mouse movement
float deltaX;
float deltaY;
if (currentMouseState != previousMouseState)
{
//Save mouse location
deltaX = currentMouseState.X - (Game.GraphicsDevice.PresentationParameters.BackBufferWidth / 2);
deltaY = currentMouseState.Y - (Game.GraphicsDevice.PresentationParameters.BackBufferHeight / 2);
//Determines the speed of the rotation 0.1 is pretty quick and looks just about right
mouseRotationBuffer.X -= 0.1f * deltaX * deltaTime;
mouseRotationBuffer.Y -= 0.1f * deltaY * deltaTime;
if (mouseRotationBuffer.Y < MathHelper.ToRadians(-75.0f))
{
mouseRotationBuffer.Y = mouseRotationBuffer.Y - (mouseRotationBuffer.Y - MathHelper.ToRadians(-75.0f));
}
if (mouseRotationBuffer.Y > MathHelper.ToRadians(75.0f))
{
mouseRotationBuffer.Y = mouseRotationBuffer.Y - (mouseRotationBuffer.Y - MathHelper.ToRadians(75.0f));
}
Rotation = new Vector3(-MathHelper.Clamp(mouseRotationBuffer.Y, MathHelper.ToRadians(-75.0f), MathHelper.ToRadians(75.0f)),
MathHelper.WrapAngle(mouseRotationBuffer.X), 0);
deltaX = 0;
deltaY = 0;
}
Mouse.SetPosition(Game.GraphicsDevice.Viewport.Width / 2, Game.GraphicsDevice.Viewport.Height / 2);
在任何人说之前,我也将这个发布到 gamedev,但我想我也会在这里尝试一下,以防有人知道一些事情。
【问题讨论】:
标签: 3d rotation xna monogame xna-4.0