在3D图形/ OpenGL的模型矩阵 [英] Model matrix in 3D graphics / OpenGL

查看:225
本文介绍了在3D图形/ OpenGL的模型矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下面的一些教程来学习openGL的(从www.opengl-tutorial.org如果它使任何区别),而且是一项工作,要求我画一个立方体,并在屏幕上一个三角形,它说作为暗示,我应该计算两个MVP矩阵,每个对象。 MVP矩阵由投影*查看*模型给出的,据我了解,在投影和视图矩阵是相同的屏幕上的所有对象(它们只受我所选择的照相机位置和设置)。然而,模型矩阵应该改变,因为它应该给我对象的坐标和旋转中的全局坐标。继教程,我的立方体模型矩阵仅仅是单位矩阵,因为它是位于原点,有没有旋转或缩放。然后,我画我的三角,其顶点是在(2,2,0),(2,3,0)和(3,2,0)。现在的问题是,什么是我的三角模型矩阵?

I'm following some tutorials to learn openGL (from www.opengl-tutorial.org if it makes any difference) and there is an exercise that asks me to draw a cube and a triangle on the screen and it says as a hint that I'm supposed to calculate two MVP-matrices, one for each object. MVP matrix is given by Projection*View*Model and as far as I understand, the projection and view matrices are the same for all the objects on the screen (they are only affected by my choice of "camera" location and settings). However, the model matrix should change since it's supposed to give me the coordinates and rotation of the object in the global coordinates. Following the tutorials, for my cube the model matrix is just the unit matrix since it is located at the origin and there's no rotation or scaling. Then I draw my triangle so that its vertices are at (2,2,0), (2,3,0) and (3,2,0). Now my question is, what is the model matrix for my triangle?

我自己的理由说,如果我不想旋转或缩放,模型矩阵应该只是平移矩阵。但是,是什么赋予了平移坐标吗?它应该包括的顶点中的一个的位置或三角形或什么的中心?还是我完全误解了模型矩阵是什么?

My own reasoning says that if I don't want to rotate or scale it, the model matrix should be just translation matrix. But what gives the translation coordinates here? Should it include the location of one of the vertices or the center of the triangle or what? Or have I completely misunderstood what the model matrix is?

推荐答案

模型矩阵像其他矩阵(投影视图)具有相同的布局一个4x4矩阵。根据您是否使用列或行向量的矩阵组成的X,Y,你的本地帧和Z轴T1,T2,T3矢量指定的翻译部分

The model matrix is like the other matrices (projection, view) a 4x4 matrix with the same layout. Depending on whether you're using column or row vectors the matrix consists of the x,y,z axis of your local frame and a t1,t2,t3 vector specifying the translation part

所以为列向量p中的变换矩阵(M)的样子

so for a column vector p the transformation matrix (M) looks like

x1, x2, x3, t1,
y1, y2, y3, t2,
z1, z2, z3, t3,
 0,  0,  0,  1 

P'= M * P

p' = M * p

所以对行向量,你可以尝试找出如何矩阵布局必须。还要注意的是,如果你有行向量P'= P * M。

so for row vectors you could try to find out how the matrix layout must be. Also note that if you have row vectors p' = p * M.

如果你没有旋转分量本地帧具有通常的x,y,z轴方向作为模型矩阵的3×3子矩阵的行..

If you have no rotational component your local frame has the usual x,y,z axis as the rows of the 3x3 submatrix of the model matrix..

1 0 0 t1 -> x axis 
0 1 0 t2 -> y axis 
0 0 1 t3 -> z axis 
0 0 0 1 

第四列指定平移向量(T1,T2,T3)。如果你有一个点p =

the forth column specifies the translation vector (t1,t2,t3). If you have a point p =

 1, 
 0,
 0,
 1 

在一个局部坐标系,你希望它翻译+1,Z方向将其放置在世界坐标系中的模型矩阵很简单:

in a local coordinate system and you want it to translate +1 in z direction to place it in the world coordinate system the model matrix is simply:

1 0 0 0  
0 1 0 0  
0 0 1 1  
0 0 0 1 

P'= M * P ... P'是世界上变换点坐标。

p' = M * p .. p' is the transformed point in world coordinates.

有关你上面的例子,你已经可以指定(2,2,0)在本地坐标系中的三角形,(2,3,0)和(3,2,0)。然后模型矩阵是微不足道的。否则,你必须找出你如何计算旋转等。我建议你阅读数学对3D游戏编程和计算机图形学的前几章。这是一个非常简单的3D数学书,但你应该让你需要处理的大多数3D图形运算的最低限度的信息。

For your example above you could already specify the triangle in (2,2,0), (2,3,0) and (3,2,0) in your local coordinate system. Then the model matrix is trivial. Otherwise you have to find out how you compute rotation etc.. I recommend reading the first few chapters of mathematics for 3d game programming and computer graphics. It's a very simple 3d math book, there you should get the minimal information you need to handle the most of the 3d graphics math.

这篇关于在3D图形/ OpenGL的模型矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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