Author Topic: Screen Space to 3D Space  (Read 2580 times)

Offline AGP

  • quad
  • ******
  • Posts: 1620
    • View Profile
Screen Space to 3D Space
« on: September 30, 2009, 12:14:59 am »
I asked an old professor for help on transforming screen coordinates into worldspace coordinates, and his solution was for me to put four objects on the world with known positions and print their screen coordinates, then do the following. The first numbers are my results (worldspace, then screen), and the last description was his response to me. I just got two books on matrices off Amazon but they haven't arrived yet and I don't remember a lot about matrices, so I need help from someone who does.

-300, -300, 0.008033752
300, -300, 0.008033752
300, 300, 0.008033752
-300, 300, 0.008033752
Screen coordinates: 209, 180
Screen coordinates: 594, 180
Screen coordinates: 595, 563
Screen coordinates: 210, 564

After getting those values I would have the following matrices.
M(P1) => S1
M(P2) => S2
M(P3) => S3
M(P4) =>S4
Where Pi is the position (in the world) of the 4 objects.  This is known.
Si is the position (on the screen) of the 4 objects.  Also known - via
the print function.
Those equations will be enough to compute the map functions you need -
particularly from your view.  Just solve the equations by hand or use
the following observation.

Let P be the matrix formed with P1 P2 P3 P4 (as columns).
The same for S.
Then the above becomes
MP = S

Multiply both sides by the inverse of P (assuming it is non-singular) -
actually if done right might only need 3 objects.
MP P^-1 = S P^-1
Which becomes
M = S P^-1

Actually you want the inverse of M (to reverse the process).  But this
is then:
M^-1 = P S^-1
That is compute S inverse and multiply with P to get the inverse matrix.

Then for any screen point S_i you would be able to do M S_i and get P_i.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11977
    • View Profile
    • http://www.jpct.net
Re: Screen Space to 3D Space
« Reply #1 on: September 30, 2009, 07:16:18 am »
Didn't the solution that i sent you yesterday work?

Offline AGP

  • quad
  • ******
  • Posts: 1620
    • View Profile
Re: Screen Space to 3D Space
« Reply #2 on: September 30, 2009, 07:24:47 am »
You sent something? Check your outbox because I thought I was annoying you to the point in which you stopped responding. :- ) I haven't gotten anything from you since, I think, Saturday.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11977
    • View Profile
    • http://www.jpct.net
Re: Screen Space to 3D Space
« Reply #3 on: September 30, 2009, 07:29:35 am »
The mail was send correctly. I know because i've send it as BCC to my work address and it's just here. Give a mail address that works and i'll re-send it.

Offline AGP

  • quad
  • ******
  • Posts: 1620
    • View Profile
Re: Screen Space to 3D Space
« Reply #4 on: September 30, 2009, 07:35:31 am »
I used the wrong address on the second last e-mail I sent you, but immediately re-sent it with the right address and the title "disregard the last address." Could that be it?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11977
    • View Profile
    • http://www.jpct.net
Re: Screen Space to 3D Space
« Reply #5 on: September 30, 2009, 07:40:33 am »
I've send it to the same address that is in your forum profile... ???

Offline AGP

  • quad
  • ******
  • Posts: 1620
    • View Profile
Re: Screen Space to 3D Space
« Reply #6 on: September 30, 2009, 07:43:18 am »
Sorry about that, I'll change the profile. Years ago (but after I made the profile) I had to turn on a filter on the server that doesn't allow me to retrieve blocked messages. But I sent you an e-mail 10 minutes ago with my address.