计算机图形学:在世界中移动 [英] Computer Graphics: Moving in the world

查看:27
本文介绍了计算机图形学:在世界中移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了一个应用程序,该应用程序能够将多边形列表呈现到屏幕上,具有特定的静态相机设置(位置、观察和向上矢量),所有这些都在没有 OpenGL 的普通 Java AWT 中.

I have implemented an app which is able to render to the screen a list of polygons, with a specific static camera setting (position, look at and up vector), all in plain Java AWT without OpenGL.

我先应用模型-视图矩阵,然后应用投影到二维矩阵,然后应用视口矩阵.

I apply a model-view matrix first, then projection-to-2D matrix and then a viewport matrix.

我还在世界上实现了一些基本的变换矩阵,例如平移、X/Y/Z 轴围绕lookAt 点的旋转以及围绕lookAt 点的缩放.

I also implemented some basic transformation matrices on the world, such as translation, rotation of X/Y/Z axis around lookAt point and scaling around lookAt point.

我希望能够在世界上移动".具体来说,我想用键盘箭头向前、向后、向左和向右导航,并且能够用鼠标查看不同的点.就像在真实游戏中一样.

I want to be able to "move" in the world. Specifically, I want to navigate forward, backward, left and right with the keyboard arrows, and to be able to look at different points with the mouse. Just like in real games.

我想这是通过每次更改相机参数并再次渲染世界来完成的.

I guess this is done via changing the camera parameters each time and render the world again.

有那么简单吗?

在世界中移动只是将 x、y 值添加到相机位置并查看一个点?

Moving in the world is just adding x,y values to camera position and look at a point?

另外,移动鼠标只是在观察点上添加 x,y 吗?

In addition, is moving the mouse is just adding x,y to the look at a point?

在任何情况下我都必须触摸向上的向量吗?

Do I have to touch the up vector under any condition?

内容丰富的答案以及其他相关链接也确实会有所帮助.

Informative answers, with additional relevant links, would also really help.

推荐答案

您可以通过矩阵的结构化管理来实现此行为.尤其是视图矩阵.在大多数情况下,向 x/y 位置添加一些东西是不正确的,因为相机可能会旋转.

You can implement this behavior with a structured management of matrices. Especially the view matrix. Adding something to the x/y position is not correct in most cases because the camera may be rotated.

让我们用 V 表示当前的视图矩阵.如果你想移动相机,你必须计算一个新的视图变换:

Let's denote the current view matrix with V. If you want to move the camera, you have to calculate a new view transform:

V := Translate(-x, -y, -z) * V

,其中 Translate(a, b, c) 是一个平移矩阵.-x 表示左/右方向的移动.-y 代表向上/向下.-z 代表前进/后退.

, where Translate(a, b, c) is a translation matrix. -x represents the movement in the left/right direction. -y represents up/down. -z represents forward/backward.

如果你想旋转相机,可以用类似的方法来完成:

If you want to rotate the camera, this can be done similarly:

V := Rotate(-angle, axis) * V

,其中 Rotate(-angle,axis) 是一个旋转矩阵.使用绕 x 轴的旋转向上/向下看和绕 y 轴的旋转向左/向右看.通常不需要绕 z 轴旋转,因为它会给相机带来滚动.

, where Rotate(-angle, axis) is a rotation matrix. Use rotation about the x-axis to look up/down and rotation about the y-axis to look left/right. Rotation about the z-axis is usually not needed because it introduces a roll to the camera.

大多数参数被否定的原因是视图变换是逆变换.IE.它们不会定位相机对象,但会重新定位世界,就好像相机位于原点一样.

The reason why most parameters are negated is that view transforms are inverse transforms. I.e. they do not position the camera object, but they re-position the world as if the camera was at the origin.

这篇关于计算机图形学:在世界中移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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