Is it possible to bend or warp OpenGL space through non-standard manipulation of the ModelView or Projection matrices?
For instance, the command glScale(scaleFactor, scaleFactor, noScaleFactor) would re-size all the elements of a scene in a uniform manner along the X and Y axes.
But if one could warp OpenGL space in a non-uniform way, it would greatly expand the potential for different effects. In particular, the effect I am after is a fishbowl-like zooming effect whereby elements would be magnified in a linear or nonlinear way relative to how close they are to the user (wh开发者_如何学JAVAich in my case is represented by the Z axis).
So the scaling of the glScale command above would be contingent upon each element’s location along the Z axis:
glScale( function1(Z distance), function2(Z distance), noScaleFactor)
Modelview & projection are matrices. So you can only have linear transformations. You can try your effects using a vertex shader, but you will need a relatively dense mesh in order your transform to look good. The shader will modify each vertex position, but the triangle made of 3 vertices will still be unmodified.
Here is a sample of a Fisheye Lens Vertex Shader.
Its been a while since I've played with open GL, but my initial reaction to this would be that you should take a look at using openGL shaders to solve this. take a look at this similar post: link text
If you turn on perspective (e.g., via gluPerspective
or glFrustum
) you'll get linear scaling depending on distance from the virtual camera -- which will be along the z-axis by default. Depending on the distances you set up for the camera position, the near plane and the far plane, you can/will get an exaggerated perspective similar to an extremely wide angle lens -- but it will still be a perfectly rectilinear lens, so just for example, the lines in a rectangle will always remain straight lines, without the curvature you get with a fisheye lens.
Ultimately, however, all that's done with the matrices are linear transforms, so you won't get warping or bending from them. If you want the barrel distortion of a fisheye lens, you'll need to do that differently, probably in a shader.
OpenGL doesn't have a concept of 'space.' You cannot say "i would like everything between [0, 0, 0] and [10, 10, 0] to be blue" or anything like that. Selective scaling would have to be done via your program, by transforming your verts as required before they hit the GL pipe at all. (That is to say, getting the distance, moving the vert along the axis you want, and then pushing THAT down the line). It'll mean a lot more work, but if i understand the effect you want to achieve, you can't do it with matrices.
精彩评论