计算机图形学:走向世界 [英] Computer Graphics: Moving in the world

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

问题描述

我已经实现了



我已经实现了一个应用程序,它能够在屏幕上呈现多边形列表,并具有特定的静态相机设置(位置,看看和向上的矢量),所有的在没有OpenGL的普通Java AWT中。



我首先应用模型视图矩阵,然后应用投影到2D矩阵,然后应用视口矩阵。

我还在世界上实现了一些基本的转换矩阵,例如平移,旋转X / Y / Z轴围绕lookAt点并缩放lookAt点。 / p>

我现在要达到的目标



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



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



这是简单的吗?



移动世界只是将x,y值添加到相机位置并观察一个点?



另外,移动鼠标只是加了x,y来看看一个点吗?

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



内容丰富的答案,以及其他相关链接,也可以帮助您。

解决方案

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



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

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

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



如果您想旋转摄像头,可以这样做: / p>

  V:=旋转(-angle,axis)* V 

,其中旋转(--angle,axis)是一个旋转矩阵。使用围绕x轴的旋转向上/向下查看以及围绕y轴旋转以向左/向右看。绕z轴旋转通常是不需要的,因为它向相机引入了一个卷。



大多数参数被否定的原因是视图变换是逆变换。即他们没有定位相机对象,但他们重新定位世界,就好像相机在原点一样。


What I have implemented already

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.

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.

What I want to achieve now

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.

Is it that simple, though?

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

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.

解决方案

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.

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

, 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

, 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.

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天全站免登陆