Z Component in reproject2D3DWS?

Started by AGP, August 27, 2014, 02:35:18 PM

Previous topic - Next topic

AGP

What is the z component in this line?

Interact2D.reproject2D3DWS(theCamera, buffer, destination.x*Grid.SQUARE_SIZE, destination.y*Grid.SQUARE_SIZE, 1f);

EgonOlsen

The depth of the resulting position in 3d. If you project from 3d into 2d, you are losing one dimension: the depth. So, if you do it the other way round, you have to reintroduce it or you would end up with an unlimited number of possibilities of points in 3d that match one point in 2d. That's what this parameter does. If you are viewing the resulting vector as a direction vector from the camera's position into world space (what you usually do when using this for picking), then this value doesn't matter. If you want to pick some point on a plane that you know the depth of, you can set it here to simplify your calculations.

AGP

In my case, a character is walking according to my pathfinder's 2d coordinates. But I have to move him, naturally, in 3d space. So, does it matter?

EgonOlsen

Maybe. But you would need a mapping between your 2d coordinates to the depth at that point in 3d anyway, so you could store the 3d coordinates in the first place and don't need any reprojection at all. Or you use the vector as picking/collision ray to some plane that defines the ground. In that case, it doesn't matter and you can leave it at default.

AGP

Yeah, I used to do it with a 3d plane. I'm moving away from that implementation for various reasons. How would I go about "mapping my 2d coordinates to the depth (what exactly does that mean-simply specifying how deep the screen is supposed to be?)?"

Also, I that the docs could use with a little more description on that z component...

EgonOlsen

You somehow have to know which point on screen has which depth. Otherwise, you can't do a proper matching. However, this sounds like a hen-egg problem to me. If you would have this depth, you wouldn't try to find a solution for this problem because it would be solved already. If you have a 2d graph and want to get rid of the 3d objects that try to mimic the area in which the player can move, you might want to try to use one large plane instead that simply acts as picking plane to find the point in 3d. You would still have to orient it so that it matches the perspective of the scene, but it might be easier that way and you could get away with some inaccuracies.

AGP

Everything 3d in this case won't exist as objects for the hero. The 2D spaces are mapped according to the following screenshot, where green is walkable, blue is climbable and red is obstructed. I only have to respect the backgrounds themselves.


AGP

I figure that I would make the z value a function of the y (the lower the y, the higher the z?). Does that make sense to you?

EgonOlsen

Yes, but that's not as easy as it seems, i think. You have to keep in mind that z isn't linear in screen space (but 1/z is, so you can use that instead) and that everything depends on camera position, orientation and fov...so basically, you'll end up with the same problems as before just in another taste.