Hi! Can someone help me with this code. It doesn't work that way I want. It's for firing at the vgui mouse position.
In inputw32.cpp in IN_MouseMove: ... if ( !iMouseInUse && !g_iVisibleMouse && !gHUD.m_iIntermission ) { GetCursorPos (¤t_pos); mx = current_pos.x - gEngfuncs.GetWindowCenterX() + mx_accum; my = current_pos.y - gEngfuncs.GetWindowCenterY() + my_accum; mx_accum = 0; my_accum = 0; mtestx = mx; // Picking Ray mtesty = my; // Picking Ray ... at the end of inputw32.cpp: /////////////////////PickingRay////////////////////////////// Vector CreatePickingRay( float fov, int mousex, int mousey, int screenwidth, int screenheight, Vector& vecRenderOrigin, Vector& vecRenderAngles ) { float dx, dy; float c_x, c_y; float dist; vec3_t vpn, vup, vright; Vector vecPickingRay; c_x = screenwidth / 2; c_y = screenheight / 2; dx = (float)mousex - c_x; // Invert Y dy = c_y - (float)mousey; // Convert view plane distance dist = c_x / tan( M_PI * fov / 360.0 ); // Decompose view angles AngleVectors( vecRenderAngles, vpn, vright, vup ); // Offset forward by view plane distance, and then by pixel offsets vecPickingRay = vpn * dist + vright * ( dx ) + vup * ( dy ); // Convert to unit vector VectorNormalize( vecPickingRay ); return vecPickingRay; } /////////////////////PickingRay////////////////////////////// in the ev_hldm.cpp: void V_PunchAxis( int axis, float punch ); void VectorAngles( const float *forward, float *angles ); extern cvar_t *cl_lw; /////////////////////PickingRay////////////////////////////// #ifndef M_PI #define M_PI 3.14159265358979323846 // matches value in gcc v2 math.h #endif extern float in_fov; float CalcFov (float fov_x, float width, float height) { float a; float x; if (fov_x < 1 || fov_x > 179) fov_x = 90; // error, set to 90 x = width/tan(fov_x/360*M_PI); a = atan (height/x); a = a*360/M_PI; return a; } extern int mtestx; extern int mtesty; extern Vector CreatePickingRay(float fov, int mousex, int mousey, int screenwidth, int screenheight, Vector& vedRenderOrigin, Vector& vecRenderAngles ); /////////////////////PickingRay////////////////////////////// extern "C" { and in EV_FireMP5 in ev_hldm.cpp: idx = args->entindex; VectorCopy( args->origin, origin ); VectorCopy( args->angles, angles ); VectorCopy( args->velocity, velocity ); AngleVectors( angles, forward, right, up ); /////////////////////PickingRay////////////////////////////// float fov; fov = CalcFov(in_fov, (float)ScreenWidth, (float)ScreenHeight); forward = CreatePickingRay(fov, mtestx, mtesty, ScreenWidth, ScreenHeight, origin, angles); if (forward == Vector(0.0, 0.0, 1.0)) { forward = Vector(0.0, 0.0, 0.99); } right = CrossProduct( forward, Vector(0.0, 0.0, 1.0) ); up = CrossProduct( forward, right ); /////////////////////PickingRay////////////////////////////// shell = gEngfuncs.pEventAPI->EV_FindModelIndex ("models/shell.mdl");// brass shell It's for HL1. Thanks. -- 5 GB Mailbox, 50 FreeSMS http://www.gmx.net/de/go/promail +++ GMX - die erste Adresse für Mail, Message, More +++ _______________________________________________ To unsubscribe, edit your list preferences, or view the list archives, please visit: http://list.valvesoftware.com/mailman/listinfo/hlcoders