Research Article

Fast and Reliable Mouse Picking Using Graphics Hardware

Algorithm 1

Object-based intersection test.
(1)   float edge; float4 Picker
(2)   edge = input − input
(3)   edge = input − input
(4)   Picker.w = det(float (−Ray, edge , edge )
(5)   if Picker.w == 0 then
(6)   return
(7)   end if
(8)   if Picker.w 0 then
(9)   Picker.w = −Picker.w
(10) edge = input − float3(0, 0, 0)
(11) else
(12) edge = float3(0, 0, 0) − input
(13) Picker.x = det(float (−Ray, edge , edge )
(14) end if
(15) if Picker.x 0 Picker.x Picker.w
(16) return
(17) end if
(18) Picker.y = det(float (−Ray, edge , edge )
(19) if Picker.y 0 Picker.x + Picker.y Picker.w
(20) return
(21) end if
(22) get the distance in the view-space
(23) Picker.z = det(float (edge , edge , edge )
(24) Picker.z = Picker.z / Picker.w PickingRay.z
(25) PICKING_GS_OUTPUT output
(26) output.Pos = float4(0, 0, Picker.z, 1)
(27) transform the distance value into projection space
(28) output.Pos.zw = mul(output.Pos.zw,
float (mxProj .yz, mxProj .yz)
(29) output.Info = float4(Picker.xy/Picker.w, FacetID,
ObjectID)
(30) outStream.Append(output)