Author Topic: Z Component in reproject2D3DWS?  (Read 953 times)

Offline AGP

  • quad
  • ******
  • Posts: 1526
    • View Profile
Z Component in reproject2D3DWS?
« on: August 27, 2014, 02:35:18 pm »
What is the z component in this line?

Code: [Select]
Interact2D.reproject2D3DWS(theCamera, buffer, destination.x*Grid.SQUARE_SIZE, destination.y*Grid.SQUARE_SIZE, 1f);

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Z Component in reproject2D3DWS?
« Reply #1 on: August 27, 2014, 02:46:11 pm »
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.

Offline AGP

  • quad
  • ******
  • Posts: 1526
    • View Profile
Re: Z Component in reproject2D3DWS?
« Reply #2 on: August 27, 2014, 02:48:30 pm »
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?

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Z Component in reproject2D3DWS?
« Reply #3 on: August 27, 2014, 03:05:00 pm »
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.

Offline AGP

  • quad
  • ******
  • Posts: 1526
    • View Profile
Re: Z Component in reproject2D3DWS?
« Reply #4 on: August 27, 2014, 03:10:59 pm »
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...

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Z Component in reproject2D3DWS?
« Reply #5 on: August 27, 2014, 03:25:50 pm »
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.

Offline AGP

  • quad
  • ******
  • Posts: 1526
    • View Profile
Re: Z Component in reproject2D3DWS?
« Reply #6 on: August 27, 2014, 03:36:28 pm »
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.


Offline AGP

  • quad
  • ******
  • Posts: 1526
    • View Profile
Re: Z Component in reproject2D3DWS?
« Reply #7 on: August 27, 2014, 05:03:10 pm »
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?

Online EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11776
    • View Profile
    • http://www.jpct.net
Re: Z Component in reproject2D3DWS?
« Reply #8 on: August 27, 2014, 07:34:17 pm »
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.