C++ 使用中心点和比例因子变换垂直?
我的应用程序是一个矢量绘图应用程序。它与OpenGL一起工作。我将修改它,改为使用cairo2d图形库。问题在于缩放。使用openGL摄像头和比例因子,类似这样的工作:C++ 使用中心点和比例因子变换垂直?,c++,c,opengl,vector-graphics,cairo,C++,C,Opengl,Vector Graphics,Cairo,我的应用程序是一个矢量绘图应用程序。它与OpenGL一起工作。我将修改它,改为使用cairo2d图形库。问题在于缩放。使用openGL摄像头和比例因子,类似这样的工作: float scalediv = Current_Scene().camera.ScaleFactor / 2.0f; float cameraX = GetCameraX(); float cameraY = GetCameraY(); glMatrixMode(GL_PROJECTION); glLoadIdent
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;
}
鼠标位置如下所示:
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通常会设置视口,但我不认为我可以用Cairo实现这一点
GlOrtho可以更改视口矩阵而不是修改垂直,但是我如何修改垂直以获得相同的结果呢
谢谢
*给定从ScreenToWorld获得的顶点p,我如何修改它,以便根据摄影机和比例因子对其进行缩放和平移?因为通常OpenGL基本上可以做到这一点我认为Cairo可以做你想做的事情。。。看见这能解决你的问题吗?如果不能,为什么 基本上,我怎样才能让转换矩阵的行为和我在GL中所做的一样,告诉它最左上、最右和最底的坐标>好吧,你可以使用glgetfloatv来得到两个矩阵,乘以它们,给Cairo一个3x3的左上部分,并使用剩余最右边的列进行翻译(可能是cairoapi中的另一个函数?)