1

编辑

哦,还有一件事,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;
        }


    }
4

1 回答 1

5

我认为您想在球体上移动相机,而不是像现在这样在平面上移动。

与其将相机的位置存储在欧几里得坐标中,不如将其存储在球坐标中。

double distance;
double latitude;
double longitude;

在鼠标滚轮处理程序中,只需增加/减少distance.

在鼠标移动处理程序中,latitude与 Y 增量成比例调整(您可能希望将其限制为 +/-pi/2,以免超出极点),并longitude与 X 增量成比例。

要计算您的位置,请使用以下内容:

Point3D position = new Point3D
(
    Math.Cos(longitude) * Math.Cos(latitude) * distance,
    Math.Sin(latitude) * distance,
    Math.Sin(longitude) * Math.Cos(latitude) * distance
);
// This line is just a simplified version of your LookDirection calculation
Vector3D lookDirection = objectPosition - position;
于 2013-09-14T18:19:18.703 回答