gpt4 book ai didi

c++ - 开罗矩阵与 GlOrtho 矩阵等效?

转载 作者:行者123 更新时间:2023-11-30 18:08:18 24 4
gpt4 key购买 nike

鉴于我做了这样的事情:

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

结果是:http://www.opengl.org/sdk/docs/man/xhtml/glOrtho.xml我可以实现这样的矩阵吗:

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

我尝试过这个:

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);

但是没有成功。我怎样才能获得与 GlOrtho 在开罗制作的相同的矩阵?谢谢

最佳答案

我不了解开罗,所以如果有更好的答案,我会删除我的答案。

根据开罗的文档:

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

当您使用 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)

(请注意,为了简单起见,我没有提及第四个坐标)

所以你要做的就是简单地匹配两个公式:

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);

请尝试这个

关于c++ - 开罗矩阵与 GlOrtho 矩阵等效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3589517/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com