2010-08-28 77 views
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基本上会这样做

回答

0

我认为开罗可以做你想做的事......看到http://cairographics.org/matrix_transform/。这是否解决了你的问题,如果没有,为什么?

+0

那么基本上我怎么能得到的转换矩阵行为与我在做什么在GL中,这是告诉它最顶端的最左边,最右边和最底部的坐标> – jmasterx 2010-08-28 04:23:51

+0

嗯,你可以使用glgetfloatv获得两个矩阵,乘他们将3x3的左上角部分交给开罗,并使用剩下的最右边一栏进行翻译(可能是开罗API的另一个功能)? – Calvin1602 2010-09-01 13:31:32