gpt4 book ai didi

c++ - 使用中心点和比例因子变换顶点?

转载 作者:行者123 更新时间:2023-11-30 18:08:18 24 4
gpt4 key购买 nike

我的应用程序是一个 vector 绘图应用程序。它与 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 通常会设置视口(viewport),但我认为我不能在 Cairo 上做到这一点。

GlOrtho 能够更改视口(viewport)矩阵而不是修改顶点,但我怎样才能修改顶点以获得相同的结果?

谢谢

*给定从 ScreenToWorld 获得的顶点 P,我如何修改它,以便根据相机和比例因子对其进行缩放和平移?因为通常 OpenGL 本质上会这样做

最佳答案

我认为开罗可以做你想做的事......参见http://cairographics.org/matrix_transform/ 。这能解决您的问题吗?如果没有,为什么?

关于c++ - 使用中心点和比例因子变换顶点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3588848/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com