views:

191

answers:

3

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.

+2  A: 

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.

second
+5  A: 

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.

e.James
+1  A: 

Every pixel on the screen represents a line from the eye of the beholder into the imaginary 3D world behind the screen. You have to intersect this line with whatever objects may lurk in that world in order to get 3D coordinates.

Svante