Author Topic: Project mouse coords to a RayCollision  (Read 170 times)

Shalmu Yakubov   «   on: June 14, 2012, 08:49:01 AM »
I need to get the point on an object, where a mouse points now. In flash I know how to get a mouse coordinates, in Flare stage I know how to cast the ray and get its collision point. But how do I transform the mouse coordinates to Vector3D, pointing forward to a depth of the screen, so I can use it for a RayCollision?

Jason Huang   «   Reply #1 on: June 14, 2012, 10:12:44 AM »
Ariel said:
camPos = camera.getPosition(false);
camDir = camera.getPointDir( Input3D.mouseX, Input3D.mouseY );


private function rayPlane( pNormal:Vector3D, pCenter:Vector3D, rFrom:Vector3D, rDir:Vector3D ):Vector3D
{
   var dist:Number = -( pNormal.dotProduct( rFrom ) - pNormal.dotProduct( pCenter ) ) / pNormal.dotProduct( rDir );

        return new Vector3D( rFrom.x + rDir.x * dist,
                                        rFrom.y + rDir.y * dist,
                                        rFrom.z + rDir.z * dist );

}

result = rayPlane( planeNormal, planeOrigin, camPos, camDir );


Shalmu Yakubov   «   Reply #2 on: June 14, 2012, 10:57:30 AM »
Jason, thank you! But meanwhile I have found an excellent class, which combines it all in a very good and easy-to-use way, it is called "MouseCollision" - a fascinating way to do the job!