- Home /
object projection from one camera to another
i have a 3d object and 2 orthographical cameras with the same aspect ratio. The object is seen by only one camera. I need to calculate the projection of the object on the second camera. how can i do so?
More specific details: i have a 3d menu viewable by the first camera but not the second. I can zoom on to various positions with the second camera. The thing is that when i click a 3d object on the first camera, i need to create another 3d object on the second camera (even when zoomed) so that it looks like the newly created object is coming from the 3d menu object.
Answer by robertbu · Sep 04, 2013 at 04:59 PM
You don't specify the coordinates for your 3d menu nor which camera sees the newly created object. I'm going to assume the second camera see the new object, and your 3D menu is in world space. What I would do is use Camera.WorldToViewportPoint() using the first camera to get the viewport point of the menu. Then you can use Camera.ViewportToWorldPoint() using the second camera to translate that position back into the world space of the second camera.
Awesome. This pointed me in the right direction. For anybody else this is the code I used to correspond a 3D object from one camera to the location of a 3D object on another camera where the 2 overlap on the screen but are not looking at the world coordinates in the exact same way:
var sourceLocation = myGameObject.transform.position;
var cam1Screen = cam1.WorldToScreenPoint(sourceLocation);
var targetLocation = cam2.ScreenToWorldPoint(cam1Screen);
Your answer
Follow this Question
Related Questions
Galak Z like UI element 0 Answers
Can i load a scene with no Camera 1 Answer
Cloud recognition in Vuforia 0 Answers
weird camera preview behaviour 0 Answers