gpt4 book ai didi

c++ - glReadPixels 移动坐标缩放

转载 作者:太空宇宙 更新时间:2023-11-04 13:54:51 27 4
gpt4 key购买 nike

我正在尝试通过使用带有 C++ 代码的 glReadPixels 选择两个点(对角)来读取一个像素矩形。选择 Y 轴值时出现问题。

目前,我设法让 glReadPixels 工作直到缩放。当您放大(放大或缩小)时,该工具会从其他 Y 值读取像素(X 始终正常)

我做错了什么?

格洛索:

IZDA = mCameraPosition.x - ((double)(rectangleDim.x/SCRARatio)) * mZoomFactor / 2;
DCHA = mCameraPosition.x + ((double)(rectangleDim.x/SCRARatio)) * mZoomFactor / 2
ABAJO = mCameraPosition.y - ((double)rectangleDim.y) * mZoomFactor / 2;
ARRIBA = mCameraPosition.y + ((double)rectangleDim.y) * mZoomFactor / 2;

glOrtho(IZDA, DCHA, ABAJO, ARRIBA, -1.0f, 1.0f);

获取屏幕坐标

realDim.x = dimension.x * (dimension.x * mZoomFactor / 2);
realDim.y = dimension.y * (dimension.y * mZoomFactor / 2);

GSC.x = (dimension.x*(x-mCameraPosition.x)) / realDim.x;
GSC.y = (dimension.y/realDim.y) * ((pow(dimension.y, 2)*mZoomFactor/2)+mCameraPosition.y + y - imgDim.y);

获取世界坐标

realDim.x = dimension.x * (dimension.x * mZoomFactor / 2);
realDim.y = dimension.y * (dimension.y * mZoomFactor / 2);

GWC.x =
((x * realDim.x) / dimension.x) + mCameraPosition.x;

GWC.y =
((y * realDim.y) / dimension.y)
-((dimension.y * (dimension.y * mZoomFactor/2)) + mCameraPosition.y)
+ imgDim.y;

CHECKFILLVALUE(使用 glReadPixels)

ComplexData::Point a, b;

// Set points screen coordinates
getScreenCoords(FIP.x, FIP.y);
a.x = GSC.x;
a.y = GSC.y;
getScreenCoords(FEP.x, FEP.y);
b.x = GSC.x;
b.y = GSC.y;

// Set length and width to read (and write)
double RX_Length, RY_Length;
if (b.x < a.x) RX_Length = a.x - b.x;
else RX_Length = b.x - a.x;
if (b.y < a.y) RY_Length = a.y - b.y;
else RY_Length = b.y - a.y;

// Pixel data vector
float *tdata = new float[3*RX_Length*RY_Length];

double desp = (mZoomFactor*dvcamera)/dvzoom;

getScreenCoords(min(FIP.x, FEP.x), gHeight-FIP.y-2*(mCameraPosition.y-desp));
// Reading from the GET SCREEN COORDINATES global values (GSC)
glReadPixels(GSC.x, GSC.y, RX_Length, RY_Length, GL_RGB, GL_FLOAT, tdata); // <--- Works great until zooming

glRasterPos2d(min(FIP.x, FEP.x), gHeight-max(FIP.y, FEP.y));
glDrawPixels(RX_Length, RY_Length, GL_RGB, GL_FLOAT, tdata); // <--- Works great
delete[] tdata;

鼠标滚轮(缩放)

Drawing::Point pt = e->Location;
getWorldCoords(pt.X, pt.Y);

Initial_Zoom.X = rectangleDim.x - GWC.x;
Initial_Zoom.Y = GWC.y;

// ZOOM IN
if (e->Delta > 0){
if (mZoomFactor > float::Epsilon * 1000.0f){
mZoomFactor /= 1.15f;
}
}
// ZOOM OUT
else {
if (mZoomFactor < float::MaxValue / 1000.0f){
mZoomFactor *= 1.15f;
}
}

最佳答案

我设法找到了解决方案。

替换:

getScreenCoords(min(FIP.x, FEP.x), gHeight-FIP.y-2*(mCameraPosition.y-desp));
glReadPixels(GSC.x, GSC.y, RX_Length, RY_Length, GL_RGB, GL_FLOAT, tdata);

与:

getScreenCoords(std::min(FIP.x, FEP.x), FIP.y);
glReadPixels(GSC.x, rectangleDim.y - GSC.y, RX, RY, GL_RGB, GL_FLOAT, tdata);

瞧瞧。有效^^

关于c++ - glReadPixels 移动坐标缩放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21958104/

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