我想实现一个缩放到鼠标位置与滚动轮算法的一个CAD应用程序,我的工作。
This one
但是我找到的所有解决方案都使用了
-
转换为原点
-
-
向后翻译
接近。虽然这在原则上是可行的,但它会导致对象在高缩放级别上被剪裁掉,因为它们变大了,那么观看音量就变大了。一个更优雅的解决方案是修改用于缩放的投影矩阵。
glGetIntegerv(GL_VIEWPORT, @fViewport);
//convert window coordinates of the mouse to gl's coordinates
zoomtoxgl := mouse.zoomtox;
zoomtoygl := (fviewport[3] - (mouse.zoomtoy));
//set up projection matrix
glMatrixMode(GL_PROJECTION);
glLoadidentiy;
left := -width / 2 * scale;
right := width / 2 * scale;
top := height / 2 * scale;
bottom := -height / 2 * scale;
glOrtho(left, right, bottom, top, near, far);
我的问题是:是否可以在正交视图中单独使用投影矩阵对任意点执行缩放,如果可以,如何将缩放目标位置分解到投影矩阵中?
我把密码改成
zoomtoxgl := camera.zoomtox;
zoomtoygl := (fviewport[3] - camera.zoomtoy);
dx := zoomtoxgl-width/2;
dy := zoomtoygl-height/2;
a := width * 0.5 * scale;
b := width * 0.5 * scale;
c := height * 0.5 * scale;
d := height * 0.5 * scale;
left := - a - dx * scale;
right := +b - dx * scale;
bottom := -c - dy * scale;
top := d - dy * scale;
glOrtho(left, right, bottom, top, -10000.5, Camera.viewdepth);
结果是:
我可以知道将世界原点移动到任何我希望的屏幕位置,而不是围绕光标位置缩放。很高兴拥有,但不是我想要的。
因为我已经被困在这个问题上很长一段时间了,我想知道:仅仅通过修改投影矩阵就可以生成相对于任意屏幕位置的缩放吗?还是我必须修改我的Modelview矩阵?