1
$\begingroup$

I need to create a ray to pick objects in 3d environment using cursor.

I'm not going to go into detailed math for this question. There's tons of information on that. In short terms, for orthogonal projection we accomplish this by taking the cursor position, and we unproject it to the near and far plane of the view frustum. The direction of the ray is then the normalized difference of the unprojected points $p_{far}-p_{near}$. The origin of the ray should be $p_{near}$.

However I'm not completely sure about how we should approach this problem for perspective projection. Should we consider the camera position as the ray origin or should it be $p_{near}$? And should the direction then be the normalized difference `$p_{far}-p_{near}$ or $p_{far}-p_{camera}$?

$\endgroup$
1
  • $\begingroup$ Use the camera position, then offset along the ray until $p_{near}$ in terms of $z$ in order to find the origin that will ignore anything not being drawn (alternatively equip the ray with a $t_{min}$ parameter corresponding to a $z$ of $p_{near}$). $\endgroup$
    – lightxbulb
    Commented Jul 10, 2021 at 19:14

0

Browse other questions tagged or ask your own question.