用鼠标拖动算法的3D旋转摄像头控制拖动、算法、摄像头、用鼠标

2023-09-08 10:49:56 作者:孤山下

请帮忙,

我找不到这个是不具体,图书馆依赖语言,因为我想控制自己的数学出于某种原因,详细的解释。

I couldn't find detailed explanation about this which is not language specific and not library dependent, because I want to control the math myself for some reason.

如何建立轨道与鼠标摄像头控制,如单击鼠标拖动的谷歌的SketchUp

How to create orbiting camera control with mouse, like middle-click drag in Google SketchUp?

*在谷歌SketchUp中,相机可循环通过拖动鼠标移动飞机的中间轨道假想对象(不可以总是0,0,0)。它可以水平轨道,垂直,甚至是斜向,四面八方。

* In Google SketchUp, the camera can move circularly orbiting imaginary object in the middle of the plane (not always 0,0,0) by dragging the mouse. It can orbit horizontally, vertically, even diagonally, all directions.

推荐答案

最简单的解决方案是将X / Y方向的角度,并最终缩放级别。然后,修改一些MouseMove事件的角度,并利用它们来计算摄像机的方向。

The simplest solution is to store X/Y direction angles and eventually a zoom level. Then, you modify the angles in some MouseMove event, and use them to compute camera direction.

下面是一些伪$ C $下鼠标拖动:

Here's some pseudo-code for mouse drags:

OnMouseDown:
    mouseDragging = true;
    lastX = mouse.x;
    lastY = mouse.y;

OnMouseUp:
    mouseDragging = false;

OnMouseMove:
    if( mouseDragging ) {
        angleX += (mouse.x-lastX) * speedX;
        angleY += (mouse.y-lastY) * speedY;
    }

OnMouseWheel:
    zoom += mouse.wheelDelta;

鉴于这些数据,你可以建立一个摄像头的位置。你在使用这个我不知道,但这里有一个例子,从OpenGL的:

Given those data you can build a camera position. I don't know what are you using for this but here's an example from OpenGL:

glLoadIdentity();
glTranslatef( 0.0f, 0.0f, -zoom );
glRotatef( angleY, 1.0f, 0.0f, 0.0f );
glRotatef( angleX, 0.0f, 1.0f, 0.0f );
glTranslatef( -orbitCenterX, -orbitCenterY, -orbitCenterZ );
 
精彩推荐
图片推荐