Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unprojecting an on screen point back to an isometrically projected world

I am doing a behind the curtains 3d simulation while rendering the world in my 2d isometric engine. I've never done an isometric engine before, and my matrix math is rusty in general so I am having problems.

I have a projection matrix, which in its simplest form is this:

 0.7       0.35     0
 0        -0.87     0
-0.71      0.35     1

A couple of signs are flipped because my engines coordinate system is 0,0 in the top left, with +X to the right/east and +Z to the south.

Now, the inverse of that is:

1.4080  0.5670   0.0000
0.0000 -1.1490   0.0000
1.0000  0.8050   1.0000

Now, these matrices mostly work.

For instance

WC: 500,0,500 = Screen: -1.44, 350, 500 (X and Y are correct)

WC: 0,0,500 = Screen: -355, 175, 500 (X and Y are correct again)

But, now if you need to go the other way, you no longer have that handy Z value, so

Screen: -1.44, 350, 0 = WC: -2, -402.97, 0 (So, garbage.)

And lots more - as soon as I no longer have that Z value, I can't retrieve the world coords from the screen coords.

What's the workaround here?

EDIT

I should point out that the point of the unproject is to get a ray for mouse picking..

It seems like it's just my misperception of what I was doing that was screwing me up here.

like image 273
Jason Maskell Avatar asked May 26 '09 19:05

Jason Maskell


2 Answers

As you discovered, your conversion back into 3D space requires some kind of Z coordinate to make any sense at all.

I would suggest that you do the reverse transformation twice. Once with a Z coordinate near the screen (closest to the observer), and once with a Z coordinate at the back of your 3D scene. These two 3D points would give you a 3D line, which would occupy all of the positions "behind" that 2D point.

like image 84
e.James Avatar answered Sep 28 '22 01:09

e.James


you can't. you are projecting onto the screen which loses information.

If you think about it, several 3d coordinates get projected onto the same point on the screen, and just knowing that screen coordinate isn't enough to retrieve the original coordinate.

[edit] looking at your screen coordinates, you give them all z-value 0. which means the last columns of your projection matrix should have all zeros, making that matrix non-invertible.

like image 42
second Avatar answered Sep 28 '22 02:09

second