1
$\begingroup$

I'm creating a game for my games class assignment, and in the advanced section we're tasked with implementing mouse picking, meaning clicking on a game object to select it, which is essentially worldpoint to pixel which is straightforward enough, however to click somewhere and have an object move there is pixel to worldpoint which is more challenging.

Essentially after performing the calculations as instructed in the lecture notes, I end up with a 3D point on the camera's near clip plane, and by normalizing the subtraction of the camera position from that 3D point I get its direction, however there are no detailed further instructions on how to proceed from there.

What I want is the 3D point on the "ground" which is at $y = 0$, so the way I think about it is, I should move that point from its starting position along its direction until its $y$ position becomes $0$, and then I have the point my object should go to, however I'm unsure of how to do this. Any help would be appreciated, thank you.

EDIT: Alright, so I have a CVector3 startingPos = [x, y, z], and a CVector3 direction = [x, y, z] which is constructed from normalise(startingPos - cameraPos), and I want to find out the calculations I have to perform in order to plot that point's movement along that calculated direction until the $y$ component of startingPos becomes $0$ so I get the point on the "ground" I want.

  • 0
    Provide a little figure with notations in order there is no ambiguity on the used terms, which is so often the case in geometry, in particular in 3D.2017-01-22
  • 0
    We can parametrize the line going through $[x_0,y_0,z_0]$ in the direction $[x_1,y_1,z_1]$ as $[x(t),y(t),z(t)] = [x_0+x_1t, y_0 + y_1t, z_0+z_1t]$. The starting point corresponds to $t=0$ and the point where $y(t) = 0$ corresponds to $t = -y_0/y_1$.2017-01-22
  • 0
    Thank you for your reply! I will test it thoroughly and come back with results cause it currently doesn't work, however I suspect there might be something else wrong as is usually the case with code. :P Essentially I say worldPt.x = startingPos .x + dir.x*(-startingPos .y / dir.y); worldPt.y = startingPos .y + dir.y*(-startingPos .y / dir.y); worldPt.z = startingPos .z + dir.z*(-startingPos .y / dir.y);2017-01-22
  • 0
    Thank you so much for your help, it works perfectly. :)2017-01-24

0 Answers 0