0
我的應用程序是一個矢量繪圖應用程序。它適用於OpenGL。我將修改它來改爲使用Cairo 2D圖形庫。問題在於縮放。 OpenGL的攝像頭和比例因子排序工作是這樣的:用中心點和比例因子轉換頂點?
float scalediv = Current_Scene().camera.ScaleFactor/2.0f;
float cameraX = GetCameraX();
float cameraY = GetCameraY();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
float left = cameraX - ((float)controls.MainGlFrame.Dimensions.x) * scalediv;
float right = cameraX + ((float)controls.MainGlFrame.Dimensions.x) * scalediv;
float bottom = cameraY - ((float)controls.MainGlFrame.Dimensions.y) * scalediv;
float top = cameraY + ((float)controls.MainGlFrame.Dimensions.y) * scalediv;
glOrtho(left,
right,
bottom,
top,
-0.01f,0.01f);
// Set the model matrix as the current matrix
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
hdc = BeginPaint(controls.MainGlContext.mhWnd,&ps);
鼠標位置是這樣獲得的:
POINT _mouse = controls.MainGlFrame.GetMousePos();
vector2f mouse = functions.ScreenToWorld(_mouse.x,_mouse.y,GetCameraX(),GetCameraY(),
Current_Scene().camera.ScaleFactor,
controls.MainGlFrame.Dimensions.x,
controls.MainGlFrame.Dimensions.y);
vector2f CGlEngineFunctions::ScreenToWorld(int x, int y, float camx, float camy, float scale, int width, int height)
{
// Move the given point to the origin, multiply by the zoom factor and
// add the model coordinates of the center point (camera position)
vector2f p;
p.x = (float)(x - width/2.0f) * scale +
camx;
p.y = -(float)(y - height/2.0f) * scale +
camy;
return p;
}
從那裏我畫三角形的VBO的。這使我可以平移和放大。鑑於開羅只能根據座標繪製,我怎樣才能使它在不使用轉換的情況下正確縮放和平移頂點。基本上GlOrtho通常會設置視口,但我不認爲我可以在開羅這樣做。
Well GlOrtho能夠更改視口矩陣而不是修改頂點,但我怎麼能修改頂點以獲得相同的結果呢?
感謝
*定頂點P,這是從ScreenToWorld得到,我怎麼可能修改,使其縮放和平移accordng到相機和規模因素是什麼?因爲通常OpenGL基本上會這樣做
那麼基本上我怎麼能得到的轉換矩陣行爲與我在做什麼在GL中,這是告訴它最頂端的最左邊,最右邊和最底部的座標> – jmasterx 2010-08-28 04:23:51
嗯,你可以使用glgetfloatv獲得兩個矩陣,乘他們將3x3的左上角部分交給開羅,並使用剩下的最右邊一欄進行翻譯(可能是開羅API的另一個功能)? – Calvin1602 2010-09-01 13:31:32