C++ GlOrtho矩阵的Cairo矩阵等价?
考虑到我是这样做的:C++ GlOrtho矩阵的Cairo矩阵等价?,c++,c,opengl,matrix,cairo,C++,C,Opengl,Matrix,Cairo,考虑到我是这样做的: void glOrtho( GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble nearVal, GLdouble farVal); 结果是:我能得到这样的矩阵吗 我试过这个: cairo_matrix_t mat; mat.xx = 2 / (right - left
void glOrtho( GLdouble left,
GLdouble right,
GLdouble bottom,
GLdouble top,
GLdouble nearVal,
GLdouble farVal);
结果是:我能得到这样的矩阵吗
我试过这个:
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);
但它没有起作用。我怎么能得到格洛托在开罗制作的相同矩阵?
谢谢我不知道开罗,所以如果有更好的答案,我会删除我的答案 根据开罗的文件:
x_new = xx * x + xy * y + x0;
y_new = yx * x + yy * y + y0;
使用OpenGL时,公式如下:(m
为矩阵)
(注意,为了简单起见,我没有提到第四个坐标)
因此,您需要做的只是匹配两个公式:
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);
请试试这个我不知道Cairo,但它看起来像是一个3x3矩阵,而不是像OpenGL那样的4x4矩阵。如果你的点像
(x y 1)
(我也不知道开罗),你必须删除GL矩阵的第三行和第四列,而不是第四行,那么我该怎么做才能使它适用于3x3?但它只有6个双倍,而不是9个。我认为它不起作用,我在画图,而且什么都看不到,问题还在于,这个OpenGL矩阵是为坐标从(-1,1)到(1,-1)的曲面构建的。我不知道Cairofloat是否会离开;左=cameraX-((浮动)引擎控件.MainGlFrame.Dimensions.x)*缩放div;向右浮动;右=cameraX+((浮动)引擎控件.MainGlFrame.Dimensions.x)*缩放div;浮底;底部=cameraY-((浮动)引擎控件.MainGlFrame.Dimensions.y)*缩放div;浮顶;top=cameraY+((浮动)引擎控件.MainGlFrame.Dimensions.y)*缩放div;尝试left=cameraX-1;右=摄影机X+1;top=cameraY+1;底部=cameraY-1代码>这是一种“黑客”,但它可能会工作(再次抱歉,但我无法测试)。最好的解决方案是修改矩阵,还有其他方法可以通过平移和缩放来实现吗?
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);