--
[ Picked text/plain from multipart/alternative ]
Direct Copy paste from another email with same problem,

>From Yahn at Valve:
Note that the client .dll can request the last worldToScreen from the
engine through the engine->GetWorldToScreenMatrix API.  You might have
to do this differently if the view model code hoses that matrix, though,
or you could cache the matrix during the rendering of regular entities
and use it later when you need it.

This gives you and origin an direction for what's under the mouse and
then you just trace a ray from that origin in the forward direction and
see what it hits.

Yahn


// x and y are the mouse position relative to the viewport/engine view
which is w wide and h high
void CreatePickingRay( float x, float y, int w, int h, Vector& org,
Vector& forward, const Vmatrix& worldToScreen )
{
       // Remap x and y into -1 to 1 normalized space
       float xf, yf;
       xf = ( 2.0f * x / (float)(w-1) ) - 1.0f;
       yf = ( 2.0f * y / (float)(h-1) ) - 1.0f;

       // Flip y axis
       yf = -yf;

       VMatrix screenToWorld;
       MatrixInverseGeneral( worldToScreen, screenToWorld );

       // Create two points at the normalized mouse x, y pos and at the
near and far z planes (0 and 1 depth)
       Vector v1, v2;
       v1.Init( xf, yf, 0.0f );
       v2.Init( xf, yf, 1.0f );

       Vector o2;
       // Transform the two points by the screen to world matrix
       screenToWorld.V3Mul( v1, org ); // ray start origin
       screenToWorld.V3Mul( v2, o2 );  // ray end origin
       VectorSubtract( o2, org, forward );
       forward.NormalizeInPlace();
--

_______________________________________________
To unsubscribe, edit your list preferences, or view the list archives, please 
visit:
http://list.valvesoftware.com/mailman/listinfo/hlcoders

Reply via email to