ScreenPointToRay (433885)

Could someone help me clarify the funciton ScreenPointToRay? In the docs it says the function returns a ray “starting on the near plane of the camera and going through position’s (x,y) pixel coordinates on the screen.”

The near plane of the camera is essentially the screen itself, correct? …but defined in World Space. So “starting from the near plane” would mean what? the middle of the screen? Even though the origin in screen space is the bottom left corner?

Is this ray just two dimensional then? It sounds to me like, by definition, the “near plane” and the “screen space” are the same plane defined in two different ways (one in world space coordinates and the other in horizontal and vertical pixels), right?

So if I make an object face it’s positive Z-axis in the direction returned by the function, the object should be spinning about the camera’s forward axis…

or am I totally confused? thanks in advance.

Well i think this Ray Starts at the camera an goes at it says Though the coords of the near plane As the near plane is Set a Little Bit for the Camera so the Ray goes to the direction you Point on the screen

Without checking, I’m not sure where the ray returned by ScreenPointToRay() starts (that is, whether it starts at the camera position, on the near plane, or somewhere else). But, don’t let that detail throw you. The ray functions exactly as you’d expect it to; that is, it points in the same direction as a ray starting at the camera position and passing through the specified screen-space point from the camera’s point of view. (The ray may start on the near plane in world space, but it still points in the direction you’d expect it to point.)

[Edit: Note also that with an orthographic projection, a picking ray cannot in general originate at the camera position, which is one of the reasons the origin of a picking ray is often placed on the near plane in world space.]

No, starting from the near plane in the forward direction. The code example in the docs illustrates what’s happening very well.

–Eric