2010-08-28 31 views
0

既然我做這樣的事情:GlOrtho矩陣的開羅矩陣equivillant?

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在開羅製造的同樣的矩陣? 謝謝

+0

我不知道開羅但它看起來像'cairo_matrix_t'是一個3x3矩陣,而不是像那些OpenGL的一個4x4。如果你的觀點像'(x y 1)'(我不知道開羅),你必須刪除GL矩陣的第三行和第三列,而不是第四個 – Tomaka17 2010-08-28 05:05:15

+0

然後我應該怎麼做才能使它適用於3x3? – jmasterx 2010-08-28 05:07:14

+0

但它只有6個雙打,而不是9個 – jmasterx 2010-08-28 05:14:34

回答

0

我不知道開羅,所以我會刪除我的答案,如果一個更好的來。

根據開羅的文檔:

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

請試試這個

+0

我不認爲它的工作,我正在繪製,從來沒有看到任何東西, – jmasterx 2010-08-28 05:34:23

+0

問題是,這個OpenGL矩陣是建立表面的座標從(-1,1)到(1,-1)。我不知道開羅 – Tomaka17 2010-08-28 05:43:06

+0

是否屬於這種情況。 \t \t \t left = cameraX - ((float)engineGL.controls.MainGlFrame.Dimensions.x)* scalediv; \t \t \t float right; \t \t \t right = cameraX +((float)engineGL.controls.MainGlFrame.Dimensions.x)* scalediv; \t \t \t float bottom; \t \t \t bottom = cameraY - ((float)engineGL.controls.MainGlFrame.Dimensions.y)* scalediv; \t \t \t float top; \t \t \t top = cameraY +((float)engineGL.controls.MainGlFrame.Dimensions.y)* scalediv; – jmasterx 2010-08-28 05:45:12