欢迎访问:常州市武进区嘉泽中心小学网站 !今天是:
栏目列表
您现在的位置是:首页>>教师>>计算机技术>>程序设计>>游戏开发>>文章内容
OpenGL中的矩阵存储方式
发布时间:2008-11-20   点击:   来源:本站原创   录入者:佚名
 

在OpenGL中,矩阵是以列优先的方式(column-major order)存储的,而一般的数学书上是以行优先的方式(row-major order)存储的。

列优先:

m0     m4     m8     m12

m1     m5     m9     m13

m2     m6     m10   m14

m3     m7     m11   m15

行优先:

 m0     m1     m2     m3

 m4     m5     m6     m7

 m8     m9     m10    m11

 m12   m13   m14   m15

  在OpenGL中,矩阵是用一维数组来保存的:m[16]。

可以用ARB_transpose_matrix来实现2者的转换:

    New functions and tokens are added allowing application matrices
    stored in row major order rather than column major order to be
    transferred to the OpenGL implementation.  This allows an application
    to use standard C-language 2-dimensional arrays (m[row][col]) and
    have the array indices match the expected matrix row and column indexes.
    These arrays are referred to as transpose matrices since they are
    the transpose of the standard matrices passed to OpenGL.

    This extension adds an interface for transfering data to and from the
    OpenGL pipeline, it does not change any OpenGL processing or imply any
    changes in state representation.
提供的函数:

    void LoadTransposeMatrix{fd}ARB(T m[16]);
    void MultTransposeMatrix{fd}ARB(T m[16]);

提供的标记(对GetBooleanv, GetIntegerv, GetFloatv, GetDoublev函数):

 TRANSPOSE_MODELVIEW_MATRIX_ARB   
TRANSPOSE_PROJECTION_MATRIX_ARB   
TRANSPOSE_TEXTURE_MATRIX_ARB   
TRANSPOSE_COLOR_MATRIX_ARB  

LoadTransposeMatrixARB(m)相当于:

 float n[16];
transpose(m,n)
LoadMatrix(n);

MultTransposeMatrixARB(m)相当于:

 float n[16];
transpose(m,n);
MultMatrix(n);

GetFloatv(TRANSPOSE_MODELVIEW_MATRIX_ARB,m)相当于:

 float n[16];
GetFloatv(MODELVIEW_MATRIX_ARB,n);
transpose(n,m);

TRANSPOSE_PROJECTION_MATRIX_ARB,TRANSPOSE_TEXTURE_MATRIX_ARB和 TRANSPOSE_COLOR_MATRIX_ARB类似。


附件:
    关闭窗口
    打印文档
    账号登录
    保持登录 忘记密码?
    账号与武进教师培训平台同步