我如何将缩放合并到这个坐标系中

How can I incorporate zoom into this coordinate system?

本文关键字:坐标系 合并 缩放      更新时间:2023-10-16

我有一堆具有以下属性的对象:

xPos = x coordinate of position in world
yPos = y coordinate of position in world
size = size of object

我有一个函数将这些对象绘制到屏幕上。屏幕有x和y偏移量,因此用户可以平移,物体将根据需要在屏幕上下移动。这一切都很完美。现在我想添加放大和缩小的功能,但是我不知道如何对位置应用缩放。

render(int xOff, int yOff, int zoom){
    int x = xPos + xOff;
    int y = yPos + yOff;
    s->addRenderJob(texID, x, y, size * zoom, size * zoom);
}

缩放对象的大小很简单,但我如何通过缩放来修改x和y位置,以便对象之间的距离也乘以缩放?

render(int xOff, int yOff, int zoom){ int x = xPos + xOff; int y = yPos + yOff; s->addRenderJob(texID, x* zoom, y* zoom, size * zoom, size * zoom); }

如果需要,可以下载游戏引擎。研究如何处理游戏中的坐标系

halfX = SCREEN_WIDTH/2
halfY = SCREEN_HEIGHT/2
deltaX = xPos - halfX;
deltaY = yPos - halfY;
x = halfX + deltaX * zoom + xOff;
y = halfY + deltaY * zoom + yOff;

感谢VermillionAzure帮我解决了这个问题。