C++ Zoom into the centre of the screen in 2D coordinates

拈花ヽ惹草 提交于 2019-12-02 08:15:11

I will do this the easy way (not most efficient but works fine) and only for single axis (second is the same)

it is better to have offset unscaled:

scaledpos = (unscaledpos*zoomscale)+scrolloffset

know center point should not move after scale change (0 means before 1 means after):

scaledpos0 == scaledpos1

so do this:

scaledpos0 = (midpointpos*zoomscale0)+scrolloffset0; // old scale
scaledpos1 = (midpointpos*zoomscale1)+scrolloffset0; // change zoom only
scrolloffset1+=scaledpos0-scaledpos1;                  // correct offset so midpoint stays where is ... i usualy use mouse coordinate instead of midpoint so i zoom where the mouse is 

when you can not change the scaling equation then just do the same with yours

scaledpos0 = (midpointpos+scrolloffset0)*zoomscale0;
scaledpos1 = (midpointpos+scrolloffset0)*zoomscale1;
scrolloffset1+=(scaledpos0-scaledpos1)/zoomscale1;

Hope I did no silly error in there (writing from memory). For more info see

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!