【发布时间】:2013-09-14 17:45:49
【问题描述】:
编辑
哦,还有一件事,longtitute 效果很好,但是当 lattitute 达到大约 1.57 时,它会翻转......
编辑作品!
哦,只有转一圈才开始增加转速。猜测必须在每次旋转后重置 tempMouse。
private void mouseWheel(object sender, MouseWheelEventArgs e)
{
if (e.Delta < 0) { distance = distance - 0.5; } else { distance = distance + 0.5; }
Point3D position = new Point3D
(
Math.Cos(longitude) * Math.Cos(latitude) * distance,
Math.Sin(latitude) * distance,
Math.Sin(longitude) * Math.Cos(latitude) * distance
);
_perspectiveCamera.Position = position;
}
private void mouseMove(object sender, MouseEventArgs e)
{
if ( e.LeftButton == MouseButtonState.Pressed )
{
if (isLeftDown == false)
{
isLeftDown = true;
tempMouseX = this.PointToScreen(Mouse.GetPosition(this)).X;
tempMouseY = this.PointToScreen(Mouse.GetPosition(this)).Y;
}
else
{
double currentDelataX = tempMouseX - this.PointToScreen(Mouse.GetPosition(this)).X;
double currentDelataY = tempMouseY - this.PointToScreen(Mouse.GetPosition(this)).Y;
longitude = longitude - currentDelataX / 5000;
latitude = latitude - currentDelataY / 5000;
Point3D objectPosition = new Point3D(0, 0, 0);
Point3D position = new Point3D
(
Math.Cos(longitude) * Math.Cos(latitude) * distance,
Math.Sin(latitude) * distance,
Math.Sin(longitude) * Math.Cos(latitude) * distance
);
_perspectiveCamera.Position = position;
Vector3D lookDirection = objectPosition - position;
_perspectiveCamera.LookDirection = lookDirection;
}
}
/////////////////////////////////////////
if (e.LeftButton == MouseButtonState.Released)
{
isLeftDown = false;
}
}
【问题讨论】:
-
相机是什么
UpDirection? -
你希望上面的代码如何旋转任何东西?只是相机位置的平移。 Bzw,你应该更新
tempMouseY和tempMouseX。否则,deltas会变得很大。 -
UpDirection = new Vector3D(0, 1, 0);但就是这样吗?我假设相机会通过移动它的位置来旋转,并且仍然保持它指向世界的中心。
-
回复:编辑 - 看起来您忘记重新分配相机位置。也许某处有错误的标志。
-
尝试在您的
lookDirection中切换objectPosition和position。也许我把它弄反了。
标签: .net wpf perspectivecamera