查看管道和3D转换 [英] Viewing pipeline and 3D Transformations

查看:143
本文介绍了查看管道和3D转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题在计算机图形学领域非常基础,但不知何故我找不到答案。

序言:



我想编写一个在画布上打印多边形的程序,我希望允许用户玩这个多边形 - 缩放,平移和旋转(在x / y / z轴)。

我应该只使用java AWT;而不是JOGL(用于openGL的java库)。




我通过输入文件将多边形作为3d世界坐标接收到程序中,以及相机属性,如相机的坐标,看点,向上矢量和窗口大小(用于从3d到2d的投影中)。




第一个问题:

我的第一个问题是写观看管道,因此三维世界协调员将转换为查看坐标(摄像机坐标),然后将其投影到2d坐标上并执行裁剪以创建透视图。我已经看到了无数的视频和方法,但我无法决定最终的矩阵。




第二个问题:



我的第二个问题是,在哪里应用3D变换矩阵。
应该在原始世界坐标上应用变换(然后当然继续使用查看管道)或直接查看坐标(并从此点开始继续)?

为了便于说明,让我们将观看管道表示为A-> B-> C-> D,它是在每次用户转换时重新计算的,并且用户启动的转换(可以是上述任何一种)为T.



我担心的是是否要做T - em> A-> B-> C-> D或A-> T B-> C-> D。



感谢您的帮助。

解决方案

从顶点坐标到屏幕坐标由

 (1)顶点 - > (2)模型 - > (3)世界 - > (4)查看 - > (5)屏幕

举例来说:


  1. 最初指定的多边形坐标

  2. 也许您缩放/旋转/剪切点以创建模型

  3. 将您的模型放置在世界中

  4. 将相机放在世界中(或者说,您将世界移动到适合您​​的相机位置)。这是您要放置 lookAt 矩阵的地方。

  5. 您将它投影到屏幕上

当我们向右扩展时,我们需要在程序中写入时切换顺序。最后一条语句如下所示:

  outPosition = screenProjection * worldToView * modelToWorld * polygonToModel * inPosition 


$ b 所以你会看到,是否使用 TA-> B-> C-> D A-> TB-> C-> D 会产生两种不同的效果:第一种与上述例子类似(即T可以作为 polygonToModel ),否则它将用作 modelToWorld 转换。两者都有效,它们只是产生不同的结果。



请注意,这里所有的转换都是4乘4矩阵。步骤2 - 4中的转换都可以是标识矩阵(即无缩放/剪切/旋转或任何其他),但对于投影,您需要创建一个平截头体。你可以通过使用这里这样的东西来创建这一个,但它可能会更容易使用Java的3D数学库。


My question is quite basic in computer graphics field, but somehow I couldn't find an answer.

Prolog:

I want to write a program which prints polygons on a canvas, and I'd like to allow users to play with the polygons - scale, translate and rotate (around x/y/z axis).

I ought to use java AWT only; not JOGL (java's library for openGL).


I recieve the polygons as 3d world coordinates as via input file to the program, as well as "camera" properties such as coordinates of camera, look at point, up vector and a window size (used in the projection from 3d to 2d).


First question:

My first problem is to write the viewing pipeline, so the 3d world coordinats would convert to viewing coordinates (camera coordinates), then project it onto 2d coordinates and perform a clipping to create the perspective. I've seen countless videos and methods but I can't decide on the final matrices.


Second question:

My second problem is, where to apply the 3D transformation matrices. Should the transformations be applied on the original world coordinates (and then of course continue with the viewing pipeline) or directly to view coordinates (and continue the pipeline from that point)?

For clarification, let's denote viewing pipeline as A->B->C->D, which is re-calculated on each user transformation, and a user initiated transformation (could be any of the above) as T.

My concern is whether to do TA->B->C->D or A->TB->C->D.

Thanks for helpers.

解决方案

The way you usually go from vertex coordinates to screen coordinates is by

(1) vertex -> (2) model -> (3) world -> (4) view -> (5) screen

So to exemplify:

  1. The polygon coordinates you specify initially
  2. Maybe you scale/rotate/shear the points to create your model
  3. You place your model in the world
  4. You place your camera in the world (or rather, you move the world to fit your camera position). This is where you would put a lookAt matrix.
  5. You project it on the screen

As we multiply to the right, we need to switch the order when we write it in a program. The final statement would look like this:

outPosition = screenProjection*worldToView*modelToWorld*polygonToModel*inPosition

So you see, whether you would use TA->B->C->D or A->TB->C->D would generate two different effects: the first would be similar to the one I exemplified above (i.e. T would work as polygonToModel), or else it would work as the modelToWorld transformation. Both works, they just yield different results.

Note that all transformations here are 4 by 4 matrices. Transformations in steps 2 - 4 can all be identity matrices (i.e. no scaling/shearing/rotation or anything), however for the projection you need to create a frustum. You could create this one yourself by using something like is being stated here, but it might be easier to just use a 3D math library for java.

这篇关于查看管道和3D转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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