Home Download Tutorial Algorithms GitHub



3D Vertex Picking
Zachary Ferguson



Let E be the Eye world coordinates, C be the viewing direction where |C| is the viewing distance, U be the up vector, and θ and φ are the view half angles.

Convert the point selected in Normalized Device Coordinates to world coordinates and use it to create a ray equation in 3D space.
Step 1: Compute the horizontal screen vector, H, at the point E.
  1. A = C x U, where A||H and starts at E.
  2. H = (A*|C|*tan(θ))/(|A|), rescale A to H.
Step 2: Compute the vertical screen vector, V, at the point E.
  1. B = A x C, where B||V and starts at E.
  2. V = (B*|C|*tan(φ))/(|B|), rescale B to V.
Step 3: Compute the midpoint of the screen, M.
  1. M = E + C.
Step 4: Compute P, the point in world 2D coordinates that the user points at, given the point in Normalized Device Coordinates, (sx, sy), where 0 ≤ sx ≤ 1 and 0 ≤ sy ≤ 1.
  1. P = M + (2sx-1)*H + (2sy-1)*V.
Step 5: Compute the ray equation, R.
  1. R = E + (t*(P - E))/(|P-E|), where t is the independent variable.
Check for the vertices that the ray passes through, within a radius of r from the vertex.
Step 6: For each vertex, v, in the mesh, compute the distance from v to the ray, R, computed in step 5. If the distance is less than or equal to r, then select that vertex.
  1. R01 = R(1) - R(0), where R01 is the direction vector of the ray.
  2. d = |(R01 x (v - R(0)))|, where d is the distance from the point to the ray and R(0) is the rays origin.
  3. If d ≤ r, then select v.