<p>What you are asking about is 'mouse picking'. If a user clicks a pixel on the screen how can you get corresponding world space coordinates of an object being clicked on. 
Imagine a ray from that pixel, through the view volume all the way to the far plane. That ray is a set of all possible points the user is clicking on. So we want to perform ray/poly ntersections with every object in the scene, and return the first intersect.</p>

<p>To transform the pixel into world space, you first have to turn your x,y point in screen space into NDC coordinates (-1 to 1) use -1 for your Z component and 1 for W to create a 4 float component vector and then multiply that vector by the inverse projection and then inverse view matrices.
There are many examples of this process if you want to see code, but this is the basic process. 
Now we have a ray from the camera/eye position into the scene, we want to do intersection tests with our objects. There are many ways of achieving this, take your pick.</p>

<p>Hope this helps, good luck!</p>

CC BY-SA 4.0
2019-09-13T05:17:23.730Z
Aha! That's exactly what I needed to hear. I had a feeling the -1 z plane of the NDC cube would be the screen, but I couldn't confirm it. Thanks
oorst
CC BY-SA 4.0
2019-09-13T04:01:11.973Z
2019-09-13T04:01:11.973Z
Gabriel Rohweder
<p>I'm trying to learn the fundamentals of 3d computer graphics by writing a toy framework in WebGL.</p>

<p>I'm currently working on mouse based camera controls. There are plenty of good resources in the ACM SIGGRAPH library to be found, but there are some aspects of this area that I can't find answers to.</p>

<p>A lot of orbit controls simply use the origin as the pivot point, but other implementations can orbit around any arbitrary point in a scene and the camera stays 'still'. I'm trying to implement the latter.</p>

<p>It seems that a good way to do this would be to simply get the cross product of the two vectors made by the pivot point and 3d coords of the corresponding pixels on the image plane, but I can't anything like this approach anywhere which leads me to believe I've misunderstood some fundamental aspect of image projection/image planes.</p>

<p>Is the image plane an abstract construct that doesn't really have 3d coords or can pixels in the image plane actually be mapped to world coords?</p>

CC BY-SA 4.0
2019-09-08T21:52:31.650Z
"other implementations can orbit around any arbitrary point in a scene and the camera stays 'still'." - please elaborate.
lightxbulb
CC BY-SA 4.0
2019-09-09T00:07:10.663Z
Imagine several objects in a scene and all those objects are placed around the origin. The camera looks at the origin (which is in the center of the image plane). Normally, the camera orbits the origin (which is also the pivot point), but by picking a different pivot point, the camera remains looking at the origin, but all the objects rotate around the pivot point.
oorst
CC BY-SA 4.0
2019-09-09T08:01:41.540Z
So you want a collection of objects revolving around some point in space?
lightxbulb
CC BY-SA 4.0
2019-09-09T22:07:22.533Z
Amongst other things, yes. But I want to experiment with this stuff to help me understand. I guess what I'm really after is a way to determine the vector from a pixel on the image plane to any point in the scene and to know if that's even possible.
oorst
CC BY-SA 4.0
2019-09-11T08:29:58.420Z
A collection of objects rotating around another object, can be done through hierarchical transformations. In your case `T_pivot * R_pivot * T_model * pos`. Transforming screen-space coords to world coords is an entirely different problem. There are many articles on this, here's one that includes it: https://mynameismjp.wordpress.com/2010/09/05/position-from-depth-3/
lightxbulb
<transformations><projections><camera><camera-matrix>
Can pixels on the image plane be mapped to world space coordinates?
oorst
# Can pixels on the image plane be mapped to world space coordinates?

(Asked by: username_0 on 2019-09-08)

I'm trying to learn the fundamentals of 3d computer graphics by writing a toy framework in WebGL.

I'm currently working on mouse based camera controls. There are plenty of good resources in the ACM SIGGRAPH library to be found, but there are some aspects of this area that I can't find answers to.

A lot of orbit controls simply use the origin as the pivot point, but other implementations can orbit around any arbitrary point in a scene and the camera stays 'still'. I'm trying to implement the latter.

It seems that a good way to do this would be to simply get the cross product of the two vectors made by the pivot point and 3d coords of the corresponding pixels on the image plane, but I can't anything like this approach anywhere which leads me to believe I've misunderstood some fundamental aspect of image projection/image planes.

Is the image plane an abstract construct that doesn't really have 3d coords or can pixels in the image plane actually be mapped to world coords?

**Tags:** transformations, projections, camera, camera-matrix

> **Comments:**
> **username_1**: "other implementations can orbit around any arbitrary point in a scene and the camera stays 'still'." - please elaborate.  
> **username_0**: Imagine several objects in a scene and all those objects are placed around the origin. The camera looks at the origin (which is in the center of the image plane). Normally, the camera orbits the origin (which is also the pivot point), but by picking a different pivot point, the camera remains looking at the origin, but all the objects rotate around the pivot point.  
> **username_1**: So you want a collection of objects revolving around some point in space?  
> **username_0**: Amongst other things, yes. But I want to experiment with this stuff to help me understand. I guess what I'm really after is a way to determine the vector from a pixel on the image plane to any point in the scene and to know if that's even possible.  
> **username_1**: A collection of objects rotating around another object, can be done through hierarchical transformations. In your case `T_pivot * R_pivot * T_model * pos`. Transforming screen-space coords to world coords is an entirely different problem. There are many articles on this, here's one that includes it: https://mynameismjp.wordpress.com/2010/09/05/position-from-depth-3/  

---

## 1 answers

### Answer by username_2 on 2019-09-13. Score: 1 | Accepted answer

What you are asking about is 'mouse picking'. If a user clicks a pixel on the screen how can you get corresponding world space coordinates of an object being clicked on.
Imagine a ray from that pixel, through the view volume all the way to the far plane. That ray is a set of all possible points the user is clicking on. So we want to perform ray/poly ntersections with every object in the scene, and return the first intersect.

To transform the pixel into world space, you first have to turn your x,y point in screen space into NDC coordinates (-1 to 1) use -1 for your Z component and 1 for W to create a 4 float component vector and then multiply that vector by the inverse projection and then inverse view matrices.
There are many examples of this process if you want to see code, but this is the basic process.
Now we have a ray from the camera/eye position into the scene, we want to do intersection tests with our objects. There are many ways of achieving this, take your pick.

Hope this helps, good luck!

> **Comments:**
> **username_0**: Aha! That's exactly what I needed to hear. I had a feeling the -1 z plane of the NDC cube would be the screen, but I couldn't confirm it. Thanks  

---

