我的应用程序是矢量绘图应用程序。它适用于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的三角形。这允许我平移和放大。鉴于Cairo只能基于坐标进行绘制,我如何才能使顶点在不使用变换的情况下正确缩放和平移。基本上GlOrtho通常会设置视口,但我不认为我可以用开罗来做这个。
好的GlOrtho能够改变视口矩阵而不是修改顶点但是我怎样才能修改顶点以获得相同的结果?
由于
*鉴于从ScreenToWorld获得的顶点P,我如何修改它以便根据相机和比例因子进行缩放和平移?因为通常OpenGL基本上会这样做
答案 0 :(得分:0)
我认为开罗可以做你想做的事......见http://cairographics.org/matrix_transform/。这会解决您的问题,如果没有,为什么?