【发布时间】:2019-04-22 01:19:07
【问题描述】:
我目前正在尝试为我一直在处理的 Mandelbrot Set 代码实现缩放功能。这个想法是放大/缩小我左/右键单击的位置。到目前为止,每当我单击屏幕时,分形确实被放大了。问题是分形不是在原点呈现的——换句话说,它没有在我想要的点上放大。我希望通过这里我可以对如何放大一个点进行代码审查和概念性理解。
这是我在使用转义算法之前转换像素坐标的方式:
MandelBrot.Frag
vec2 normalizedFragPos = (gl_FragCoord.xy/windowSize); //normalize fragment position
dvec2 scaledFragPos = normalizedFragPos*aspectRatio;
scaledFragPos -= aspectRatio/2; //Render the fractal at center of window
scaledFragPos /= scale; //Factor to zoom in or out coordinates.
scaledFragPos -= translation; //Translate coordinate
//Escape Algorithm Below
在我的左键单击手柄上,我认为我应该将光标位置转换为与 Mandelbrot Range 相同的坐标范围。所以我基本上做了和片段着色器一样的事情:
窗口.cpp
float x_coord{ float(GET_X_LPARAM(informaton_long))/size.x }; // normalized mouse x-coordinate
float y_coord{ float(GET_Y_LPARAM(informaton_long))/size.y }; // normalized mouse y-coordinate
x_coord *= aspectRatio[0]; //move point based of relative position to length of window.
y_coord *= aspectRatio[1]; //move point based of relative position to width of window.
x_coord /= scale; //Scale point to match previous zoom factor
y_coord /= scale; //Scale point to match previous zoom factor
translation[0] = x_coord;
translation[1] = y_coord;
//increment scale
scale += .15f;
【问题讨论】:
标签: c++ opengl zooming translation