2 Replies Latest reply: May 10, 2013 12:14 PM by colin-java RSS

    Perspective Camera

    colin-java
      Hi,

      I'm trying to figure out how perspective camera works, I've been looking at my old code, but I'm stumped.

      If the FIELD_OF_VIEW is known, then distance from eye to screen (d) is:
      d = HEIGHT * 0.5 / Math.tan(0.5 * Math.toRadians(FIELD_OF_VIEW));

      Thats fairly obvious, so lets assume there is a cube, side of 100, with corners at
      (-50,-50,-50),(-50,-50,50),(-50,50,-50),(-50,50,50),(50,-50,-50),(50,-50,50),(50,50,-50),(50,50,50).

      So this distance d, I guess goes from the eye to the centre of cube.
      The perspective would shrink the back face of the cube, and make the front face bigger,
      but I'm trying to work out the factor of enlargement (so I can get mouse presses to work correctly).

      Normally with these perspective things, you have a 'screen' in xy plane, for sake of argument, lets suppose it is at z=0,
      so it cuts the cube in half.

      Considering the corner (50,50,-50), the front top right corner of cube.
      this would stretch by factor f = d / (d-50)
      There by distorting the corner to (50*f, 50*f, -50)

      However for some reason in my old code, I'm using the factor f = d / (d + z - 100), and I have no clue why its 100, but it seems to work perfectly.

      Can anyone help, thanks
        • 1. Re: Perspective Camera
          jsmith
          I'm trying to work out the factor of enlargement (so I can get mouse presses to work correctly).
          Try using JavaFX 8, I think picking faces should work there as it includes a fully revamped 3D engine.
          It's still in development, so expect some glitches initially, but it's already way better than what is in JavaFX 2.2.
          It's likely a lot easier to adopt the picking mechanism implemented in JavaFX 8, then develop your own for JavaFX 2.2.

          https://wikis.oracle.com/display/OpenJDK/3D+Features

          Though . . .
          However for some reason in my old code, I'm using the factor f = d / (d + z - 100), and I have no clue why its 100, but it seems to work perfectly.
          If it ain't broke don't fix it ;-)
          Sorry, little too tired to work through the math right now.
          • 2. Re: Perspective Camera
            colin-java
            Thanks, I just tried it using d/(d+z), which basically puts the 'xy-screen' at z=0 exactly...

            And it appears to be work perfectly with my new program, I'm not sure where that -100 was from in old program though