简体   繁体   English

GlOrtho矩阵的开罗矩阵等价物?

[英]Cairo Matrix equivillant of GlOrtho Matrix?

Given that I do something like this: 鉴于我做这样的事情:

void glOrtho(   GLdouble    left, 
    GLdouble    right, 
    GLdouble    bottom, 
    GLdouble    top, 
    GLdouble    nearVal, 
    GLdouble    farVal);

and the result is: http://www.opengl.org/sdk/docs/man/xhtml/glOrtho.xml w could I achieve a matrix like this: 结果是: http : //www.opengl.org/sdk/docs/man/xhtml/glOrtho.xml w我可以实现如下矩阵:

http://cairographics.org/manual/cairo-matrix.html http://cairographics.org/manual/cairo-matrix.html

I tried this: 我尝试了这个:

cairo_matrix_t mat;
            mat.xx = 2 / (right - left);
            mat.yx = 0;
            mat.xy =  2 / (top - bottom);
            mat.yy = 0;
            mat.x0 = 0;
            mat.y0 = 0;

cairo_set_matrix(cr,&mat);

But it did not work. 但这没有用。 How could I acheive the same matrix that GlOrtho makes in Cairo? 我如何才能达到GlOrtho在开罗制作的矩阵? Thanks 谢谢

I don't know Cairo so I'll delete my answer if a better one comes. 我不知道开罗,所以如果有更好的答案,我会删除答案。

According to the docs of Cairo: 根据开罗的文档:

x_new = xx * x + xy * y + x0;
y_new = yx * x + yy * y + y0;

When you use OpenGL, the formula is like: ( m being the matrix) 当您使用OpenGL时,公式类似于:( m为矩阵)

x_new = m(1,1) * x + m(1,2) * y + m(1,3) * z + m(1,4)
y_new = m(2,1) * x + m(2,2) * y + m(2,3) * z + m(2,4)
z_new = m(3,1) * x + m(3,2) * y + m(3,3) * z + m(3,4)

(note that for the sake of simplicity I did not mention the fourth coordinate) (请注意,为简单起见,我没有提及第四坐标)

So what you have to do is simply match the two formulas: 因此,您要做的就是简单地匹配两个公式:

mat.xx = 2 / (right - left);
mat.yy = 2 / (top - bottom);
mat.xy = 0;
mat.yx = 0;
mat.x0 = -(right + left) / (right - left);
mat.y0 = -(top + bottom) / (top - bottom);

Please try this 请尝试这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM