4

I'm working on a ray-tracer and have come up with something that I think could be quite novel, but I'm struggling with the mapping of a Vector3 to it's corresponding 2D screen coordinate. I've searched and found a couple of different takes on the subject but they always end up giving me the wrong results.

Given:

A perspective Camera (consisting of a vectors for position, up, right and left) A vector representing the 3D point in space I want to map back to the screen

Have:

I have a function that will take an (x,y) coordinate and a Camera object and it gives me back a Vector (x,y,z)

Want: A function to do the reverse - i.e. take a 3D world coordinate and the camera and give me back the (x,y) coordinate in return...

I've tried several methods to do this and all of them return incorrect data.

Thank you!

James Colyer
  • 53
  • 1
  • 5

2 Answers2

0

What you're looking for is called a projection matrix. You multiply some 3D point by this matrix to project it onto some 2D viewing surface, in our case the computer screen.

I know you're not using OpenGL, but this link outlines exactly how OpenGL constructs such a matrix:

http://www.songho.ca/opengl/gl_projectionmatrix.html

Ben P
  • 129
  • 9
0

I answered a few previous questions on this, you might find them useful. If not my answers then the comments made by other users also!

Community
  • 1
  • 1
Dr. Andrew Burnett-Thompson
  • 20,980
  • 8
  • 88
  • 178