开罗矩阵与 GlOrtho 矩阵等效?

发布于 2024-09-16 08:04:30 字数 842 浏览 1 评论 0原文

鉴于我做了这样的事情:

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://cairgraphics.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 在开罗制作的相同的矩阵? 谢谢

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.xmlw could I achieve a matrix like this:

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?
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

近箐 2024-09-23 08:04:30

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

根据开罗的文档:

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

请尝试这个

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)

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文