【问题标题】:Cairo Matrix equivillant of GlOrtho Matrix?Cairo Matrix 等同于 GlOrtho Matrix?
【发布时间】:2010-08-28 04:54:17
【问题描述】:

鉴于我做了这样的事情:

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

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

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

【问题讨论】:

  • 我不知道 Cairo,但看起来 cairo_matrix_t 是一个 3x3 矩阵,而不是像 OpenGL 那样的 4x4。如果您的观点类似于 ( x y 1 )(我也不知道 Cairo),您必须删除 GL 矩阵的第三行和第三列,而不是第四行
  • 那我应该怎么做才能让它适用于 3x3?
  • 但它只有 6 个双打,而不是 9 个

标签: c++ c opengl matrix cairo


【解决方案1】:

我不认识 Cairo,所以如果有更好的答案,我会删除我的答案。

根据 Cairo 的文档:

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

请试试这个

【讨论】:

  • 我认为它不起作用,我正在画画,但什么都没看到,
  • 问题还在于这个 OpenGL 矩阵是为坐标从 (-1,1) 到 (1,-1) 的曲面构建的。不知道开罗是不是这样
  • 向左浮动;左 = cameraX - ((float)engineGL.controls.MainGlFrame.Dimensions.x) * scalediv;向右浮动;右 = cameraX + ((float)engineGL.controls.MainGlFrame.Dimensions.x) * scalediv;浮底;底部 = cameraY - ((float)engineGL.controls.MainGlFrame.Dimensions.y) * scalediv;浮顶; top = cameraY + ((float)engineGL.controls.MainGlFrame.Dimensions.y) * scalediv;
  • 试试left = cameraX - 1; right = cameraX + 1; top = cameraY + 1; bottom = cameraY - 1; 这是一种“黑客”,但它可能会起作用(再次抱歉,但我无法测试)。最好的解决方案是修改矩阵
  • 是否有其他方法可以通过翻译和缩放来实现这一目标?
猜你喜欢
  • 1970-01-01
  • 2021-11-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-14
  • 2019-07-31
  • 2015-07-23
  • 1970-01-01
相关资源
最近更新 更多