I know, the question is asked time and time again. No worries if you
have an object you can hit detect on. I don't. No worries if you're
looking at the scene from a reasonable (i.e. dead on) angle. I do
sometimes, but not always.
For my application, I just want a real simple routine that will take
mouse coordinates, and convert them to 3D coordinates relative to the
coordinate plane itself (e.g. a plane that is parallel to XY,
orthogonal to Z, and located at Z=0) no matter what the camera viewing
angle.
I have it working great for those dead on views by passing in screenX,
screenY = mouse X, Y and screenZ = 0:
var n3D:Number3D = new Number3D;
var persp:Number = view.camera.zoom / view.camera.focus;
var inv:MatrixAway3D = view.camera.invViewMatrix;
n3D.x = screenX / persp * inv.sxx + screenY / persp * inv.sxy +
screenZ * inv.sxz + inv.tx;
n3D.y = screenX / persp * inv.syx + screenY / persp * inv.syy +
screenZ * inv.syz + inv.ty;
n3D.z = screenX / persp * inv.szx + screenY / persp * inv.szy +
screenZ * inv.szz + inv.tz;
Gives no good answers though for that arbitrary camera angle view.
Please sir, may I have another bowl of gruel? I bet this would be
handy to others too!
Sincerely,
BW
PS Incidentally, this is for a CAD/CAM application where I have to
show a 3D view of the milling cutter flying through the part being
machined. Some sketchy details here for the curious:
http://www.cnccookbook.com/CCGWizardE.html