用鼠标拖动算法的3D旋转摄像头控制 [英] Algorithm 3d orbiting camera control with mouse drag

查看:302
本文介绍了用鼠标拖动算法的3D旋转摄像头控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮忙,

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

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 );

这篇关于用鼠标拖动算法的3D旋转摄像头控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆