--
[ Picked text/plain from multipart/alternative ]
There is some explanation required before the question, sorry for the long
text:

In our mod, we have a full-screen vgui panel serving as our HUD.  It
functions similarly to World of Warcraft in that the HUD catches mouse input
unless the right-mouse button is depressed (in which case mouse input passes
through the HUD to allow mouse look).

We've implemented a feature to allow the user to move objects in the game
world by left-clicking on the object and moving the mouse while keeping the
left-mouse button depressed (remember at this point the cursor is still
displayed b/c the HUD is catching mouse input).

We're using Yahn's code (shown at bottom of the email) to find the world
position for the mouse pointer.  Our problem lies in getting that
information to the server in an efficient fashion in order to update the
position of the object.  Our first shot at implementation invokes a
con_command for every tick that the left-mouse button is depressed, sending
the "forward" vector from CreatePickingRay from the client to the server.
This works, but is a little buggy and it seems like we're missing something
obvious to do this better.

Anyone know a more efficient way?

Here's Yahn's code (may have slight modifications):

void CreatePickingRay(Vector& org, Vector& forward)
{
    int w = ScreenWidth();
    int h = ScreenHeight();

    int x, y;
    vgui::input()->GetCursorPos(x, y);

    const VMatrix& worldToScreen = engine->WorldToScreenMatrix();

    //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 thenear 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