0

Here is my reasoning:

  • openGL draws everything within a 2x2x2 cube
  • the x,y values inside this cube determine where the point is drawn on the screen. The z value is used for other stuff...
  • if you want the z value to have some effect on perspective you need to mutate the scene (usually with a matrix) so that it gives an illusion of distant objects being smaller.

  • the z values of the cube go from -1 to 1.

Now I want it so that objects that are at z = 1 are infinitely zoomed, and objects that are at z = 0 are normal size, and objects that are at z = -1 are 1/2 size.

When I say an object is zoomed, I mean that the (x,y) coordinates of its points are multiplied by scaler zoom factor, which is based on its z coordinate.

If a point lies outside the 2x2x2 cube I want the calculations to still be done on it if it is between z = 1 and z = -1. Since the z value doesn't change I don't care what happens to any points that are not within this range, as long as their z value is not changed.


Generalized point transformation:

If I have a point P = (x, y, z), and -1 <= z <= 1 then:

the Zoom Factor, S = 1 / (1 - z)

so the translation is as follows:

(x, y, z) ==> (x * S, y * S, z)


Creating the matrix?

This is where I am having issues. I don't know how to create a matrix so that it will transform a generalized point to have the desired effect.

I am considering not using a matrix and applying this transformation via a function in glsl...

If someone has insight on how to create such a matrix I would like to know.

Theo Walton
  • 1,085
  • 9
  • 24
  • 1
    that sounds like your camera position is `z=+1` focal length is `1.0` and viewing direction is `Z+` so just translate and mirror the `Z` in perspective matrix `gluPerspective`. You can not do with simple Matrix what you intend to do as you need perspective division but OpenGL does it for you so .... – Spektre Nov 29 '17 at 07:53
  • Have a look at http://www.songho.ca/opengl/gl_projectionmatrix.html. This explains in detail the mathematics behind the typical projection matrix. – bernie Nov 29 '17 at 13:49

0 Answers0