4
\$\begingroup\$

I am using Render texture to make a Mini Map it is working fine but now I want to go further on side map and want world space position from render texture click point.

Is there any way available that i get world space position from render texture's specific click point?

If i click somewhere in render texture then, how can I get that point in 3D world space.

For example, I click a car object on render texture How can I highlight or get it in 3D world space.?

Update: Actual Scenario is:

  1. One Main Camera Rendering the Scene.
  2. NGUI Camera Rendering the GUI.
  3. That GUI contains the Render Texture(minimap) which rendering the scene on texture using GUI Camera.

Now how can i get 3D position from 2D render texture!

\$\endgroup\$
  • \$\begingroup\$ i didnt get what you want to say \$\endgroup\$ – Muhammad Faizan Khan Apr 29 '16 at 11:03
  • 2
    \$\begingroup\$ As always, It kind of depends.. I'll have to assume a lot about how your minimap system works I think. If you have a 2d minimap of 100X100 pixels which you view top dowwn. Your world is 1km by 1km then each pixel on your minimap is 10m world units. so say you click the minimaps middle pixel ( 50,50 ). multiply the pixel coord by the 10m world units gives you 500m, 500m. So thats 500m in x, 500m in z in world units. \$\endgroup\$ – RobM Apr 29 '16 at 11:25
  • \$\begingroup\$ my godness what a calculation you have mention! is this real and applicable??? \$\endgroup\$ – Muhammad Faizan Khan Apr 29 '16 at 11:30
  • \$\begingroup\$ Yes and yes. You'll have to elaborate \$\endgroup\$ – RobM Apr 29 '16 at 12:30
  • \$\begingroup\$ Dont you think that it is too hard and it can cause inaccurate results as well. I say u mention 20+ experirence in your profile! did you ever make a minimap where you go minimap to 3d? \$\endgroup\$ – Muhammad Faizan Khan Apr 29 '16 at 13:13
1
\$\begingroup\$

I am not aware of an easy way of doing this. The way I'd do this is the following:

  • Determine XY position of click on texture (x = 0..1, y = 0..1) How to do this depends on where you use it, but will likely require raycasting.
  • Go to the camera that sends the image to the texture.

Assuming the camera uses perspective projection:

  • Calculate the 3D position on the camera's far plane that is at position x and y (xy was derived earlier from the texture)
  • Do a raycast from the camera's position to this calculated position on the far plane.
  • The first position it hits (in 3D) is the 3D position of what was clicked on. If nothing is hit, then it's the position on the far plane.

Assuming the camera uses orthogonal projection:

  • Determine XYZ position of point on the near plane that is at the XY position, determined from the template
  • Determine XYZ position of point on the far plane that is at the XY position, determined from the template
  • Do a raycast from the position on the near plane to the one on the far plane.
  • The first position it hits (in 3D) is the 3D position of what was clicked on. If nothing is hit, then it's the position on the far plane.

Now determining all of this requires some knowledge of vector math. I'm however not aware of any simpler way of doing it, at least if you want to use the Rendered Texture. It may be easier to do if you simply overlay the camera's output on the main viewport (by setting Viewport Rect parameters on the minimap camera)

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.