Free aiming

Developer discussion of experimental fixes, changes, and improvements.

Moderators: Nexuiz Moderators, Moderators

Free aiming

Postby Rahsennor » Sun Aug 16, 2009 10:25 am

Just a simple idea to make the crosshair follow the mouse, in an effort to make Nexuiz play nice with my graphics tablet.

Updated to version 3.

Usage:
Code: Select all
seta freeaim 0 "enable free-aiming mode"
seta freeaim_sensitivity 6 "freeaim sensitivity"
seta freeaim_deadzone 0 "freeaim dead zone, as a factor of screen size (try 0.05)"


Code: Select all
Index: data/qcsrc/client/View.qc
===================================================================
--- data/qcsrc/client/View.qc   (revision 7452)
+++ data/qcsrc/client/View.qc   (working copy)
@@ -306,6 +306,19 @@
   return SHOTTYPE_HITWORLD;
}

+vector freeaim_angle, mouse_pos;
+float freeaim_active;
+void drawcrosshair(string name, float sizefloat, vector c, float a, float f)
+{
+   vector s;
+   s = drawgetimagesize(name);
+   s_x *= sizefloat;
+   s_y *= sizefloat;
+   drawpic(mouse_pos + '0.5 0 0' * (vid_conwidth - s_x) + '0 0.5 0' * (vid_conheight - s_y),
+      name, s, c, a, f);
+}
+
+
void CSQC_common_hud(void);

void CSQC_kh_hud(void);
@@ -334,11 +347,73 @@

   ticrate = getstatf(STAT_MOVEVARS_TICRATE) * getstatf(STAT_MOVEVARS_TIMESCALE);

+   vid_width = w;
+   vid_height = h;
+   fov = cvar("fov");
+
   // Render the Scene
   if(!intermission || !view_set)
   {
      view_origin = pmove_org + '0 0 1' * getstati(STAT_VIEWHEIGHT);
-      view_angles = input_angles;
+      view_angles = input_angles - freeaim_angle; // correct for last frame
+      if(cvar("freeaim") == 1)
+      {
+         if(!freeaim_active)
+         {
+            setwantsmousemove(1);
+            freeaim_active = 1;
+         }
+         mouse_pos = getmousepos();
+         if(mouse_pos != '0 0 0')
+         {
+            mouse_pos_x -= 0.5*vid_conwidth;
+            mouse_pos_y -= 0.5*vid_conheight;
+         }
+
+         v = GetCurrentFov(fov);
+         v_x = 1-(v_x/180);
+         v_y = mouse_pos_x/vid_conwidth;
+         v_z = -mouse_pos_y/vid_conwidth;
+         freeaim_angle = normalize(v);
+         f = cvar("freeaim_deadzone")*0.5;
+         if(fabs(v_y) > f || fabs(v_z) > f)
+         {
+            v_x = v_z*cvar("cl_pitchspeed")*-2;
+            v_y = v_y*cvar("cl_yawspeed")*-2;
+            v_z = 0;
+            view_angles += v*cvar_or("freeaim_sensitivity",6)*frametime;
+         }
+         view_angles_x = bound(cvar("in_pitch_min"),view_angles_x,cvar("in_pitch_max"));
+
+         v = freeaim_angle;
+         makevectors(view_angles);
+         input_angles = vectoangles(v_x*v_forward + v_y*v_right + v_z*v_up);
+         input_angles_x = 0-input_angles_x;   // correct vectoangles
+         if(input_angles_x < -90)input_angles_x += 360;
+         if(input_angles_y >= 180)input_angles_y -= 360;
+         freeaim_angle = input_angles - view_angles;
+         if(freeaim_angle_y >=  180)freeaim_angle_y -= 360; // This WILL happen.
+         if(freeaim_angle_y <= -180)freeaim_angle_y += 360;
+
+         if(cvar("chase_active") == 0 && cvar("crosshair") != 0)
+         {
+            R_SetView(VF_ORIGIN, view_origin);
+            R_SetView(VF_ANGLES, view_angles);
+         }
+         else mouse_pos = '0 0 0';
+         R_SetView(VF_CL_VIEWANGLES, input_angles);
+      }
+      else
+      {
+         if(freeaim_active)
+         {
+            input_angles -= freeaim_angle;
+            R_SetView(VF_CL_VIEWANGLES, input_angles);
+            setwantsmousemove(0);
+            freeaim_active = 0;
+         }
+         mouse_pos = freeaim_angle = '0 0 0';
+      }
      makevectors(view_angles);
      view_forward = v_forward;
      view_right = v_right;
@@ -346,9 +421,6 @@
      view_set = 1;
   }

-   vid_width = w;
-   vid_height = h;
-
#ifdef BLURTEST
   if(time > blurtest_time0 && time < blurtest_time1)
   {
@@ -382,7 +454,6 @@
   CheckForGamestartChange();
   maptimeAnnouncer();

-   fov = cvar("fov");
   if(button_zoom || fov <= 59.5)
   {
      if(!zoomscript_caught)
@@ -551,12 +622,8 @@
     hud = getstati(STAT_HUD);
     if(hud == HUD_SPIDERBOT)
     {
-        vector sz;
-        CSQC_spider_HUD();
-        sz = drawgetimagesize(SPIDER_CROSS);
-        sz_x *= cvar_or("cl_vehicle_spiderbot_cross_size",1);
-        sz_y *= cvar_or("cl_vehicle_spiderbot_cross_size",1);
-        drawpic('0.5 0 0' * (vid_conwidth - sz_x) + '0 0.5 0' * (vid_conheight - sz_y), SPIDER_CROSS, sz, '1 1 1', cvar_or("cl_vehicle_spiderbot_cross_alpha",0.6), DRAWFLAG_NORMAL);
+   CSQC_spider_HUD();
+   drawcrosshair(SPIDER_CROSS, cvar_or("cl_vehicle_spiderbot_cross_size",1), '1 1 1', cvar_or("cl_vehicle_spiderbot_cross_alpha",0.6), DRAWFLAG_NORMAL);
     }
     else
     {
@@ -595,7 +662,7 @@
             wcross_style = cvar_string("crosshair");

             if (wcross_style != "0") {
-                vector wcross_color, wcross_size;
+                vector wcross_color;
                 string wcross_wep, wcross_name;
                 float wcross_alpha, wcross_sizefloat;

@@ -631,10 +698,6 @@
               wcross_sizefloat *= cvar("crosshair_hittest"); // is not queried if hittest is 0
            if(shottype == SHOTTYPE_HITTEAM)
               wcross_sizefloat /= cvar("crosshair_hittest"); // is not queried if hittest is 0
-
-                wcross_size = drawgetimagesize(wcross_name);
-                wcross_size_x *= wcross_sizefloat;
-                wcross_size_y *= wcross_sizefloat;
            
            // ring around crosshair representing bullets left in camping rifle clip
            if (activeweapon == WEP_CAMPINGRIFLE)
@@ -652,15 +715,15 @@
                         for(j = -2; j <= 2; ++j)
                  {
                     if (bullets)
-                        drawpic(wcross_origin - '0.5 0 0' * (wcross_size_x * ring_scale + i) - '0 0.5 0' * (wcross_size_y * ring_scale + j), strcat("gfx/hud/rifle_ring_", ftos(bullets)), wcross_size * ring_scale, wcross_color, wcross_alpha, DRAWFLAG_NORMAL);
-                            drawpic(wcross_origin - '0.5 0 0' * (wcross_size_x + i) - '0 0.5 0' * (wcross_size_y + j), wcross_name, wcross_size, wcross_color, wcross_alpha, DRAWFLAG_NORMAL);
+                        drawcrosshair(strcat("gfx/hud/rifle_ring_", ftos(bullets)), wcross_sizefloat * ring_scale, wcross_color, wcross_alpha, DRAWFLAG_NORMAL);
+                            drawcrosshair( wcross_name, wcross_sizefloat, wcross_color, wcross_alpha, DRAWFLAG_NORMAL);
                  }
                 }
                 else
                 {
               if (bullets)
-                  drawpic(wcross_origin - '0.5 0 0' * (wcross_size_x * ring_scale) - '0 0.5 0' * (wcross_size_y * ring_scale), strcat("gfx/hud/rifle_ring_", ftos(bullets)), wcross_size * ring_scale, wcross_color, wcross_alpha, DRAWFLAG_NORMAL);
-                    drawpic(wcross_origin - '0.5 0 0' * (wcross_size_x) - '0 0.5 0' * ( wcross_size_y), wcross_name, wcross_size, wcross_color, wcross_alpha, DRAWFLAG_NORMAL);
+                  drawcrosshair(strcat("gfx/hud/rifle_ring_", ftos(bullets)), wcross_sizefloat * ring_scale, wcross_color, wcross_alpha, DRAWFLAG_NORMAL);
+                    drawcrosshair(wcross_name, wcross_sizefloat, wcross_color, wcross_alpha, DRAWFLAG_NORMAL);
                 }
             }
         }
Last edited by Rahsennor on Tue Aug 18, 2009 4:55 am, edited 3 times in total.
Rahsennor
Member
 
Posts: 13
Joined: Tue Jul 21, 2009 9:54 am
Location: Torven

Postby FruitieX » Sun Aug 16, 2009 1:52 pm

FruitieX
Keyboard killer
 
Posts: 588
Joined: Mon Nov 13, 2006 4:47 pm
Location: Finland

Postby divVerent » Sun Aug 16, 2009 4:50 pm

Patch is cool idea, not so cool implementation... as you removed lots of existing features, like the spiderbot support, and the wcross_size handling.

Can you add that back in?
1. Open Notepad
2. Paste: ÿþMSMSMS
3. Save
4. Open the file in Notepad again

You can vary the number of "MS", so you can clearly see it's MS which is causing it.
divVerent
Site admin and keyboard killer
 
Posts: 3809
Joined: Thu Mar 02, 2006 4:46 pm
Location: BRLOGENSHFEGLE

Postby Rahsennor » Sun Aug 16, 2009 11:26 pm

Have you tested the spiderbot? I didn't intend to remove it... wcross_size got factored into drawcrosshair. It works exactly as before. Has anyone actually tested it? I can't tell what I broke vs. what not having the full svn broke... :roll:

Proof-of-concept, 2 hours max, round 2 coming right up.
Rahsennor
Member
 
Posts: 13
Joined: Tue Jul 21, 2009 9:54 am
Location: Torven

Postby terencehill » Mon Aug 17, 2009 2:10 am

I've tested it but with the mouse, I don't have a graphics tablet.

So, with the mouse it seems too much sensitive, maybe it is ok with the tablet...
Maybe adding a tiny dead zone (could be another cvar), to avoid small unwanted movements would be nice...

Since the crosshair no longer follows the target, maybe it should be better to show 2 kinds of crosshair: the REAL crosshair, fixed at the center, and the fake crosshair to indicate the movement, as it is now.

BUG: When resetting the normal aim with freeaim 0, the crosshair just disappears!


PS: U can create a new issue here http://dev.alientrap.org/projects/nexuiz/issues it's the recommended place to post the patches, u need to be registered though.
terencehill
Alien
 
Posts: 176
Joined: Thu Jul 10, 2008 10:33 pm
Location: Italy

Postby Rahsennor » Mon Aug 17, 2009 5:19 am

Thanks for testing! I've fixed the vanishing crosshair. :lol: The fire follows the crosshair, so why have a second one? :?:

New version in first post. Also uses accurate aim, accounting for FOV and solving gimbal lock. Unfortunately, it got messier. If anything else breaks, I really want to know!

Sorry for the rush, I have to be somewhere ten minutes ago! :shock:
Last edited by Rahsennor on Mon Aug 17, 2009 12:28 pm, edited 1 time in total.
Rahsennor
Member
 
Posts: 13
Joined: Tue Jul 21, 2009 9:54 am
Location: Torven

Postby Sven » Mon Aug 17, 2009 9:53 am

for what is this: @@ -652,15 +700,15 @@?
i think its the lines where add or delete something but if im right for what is ",15"?

+ is add and -delete ,right?
German Nexuiz Clan:
Image
Sven
Alien trapper
 
Posts: 315
Joined: Sun Jun 01, 2008 8:38 am
Location: Berlin; Germany

Postby Rahsennor » Mon Aug 17, 2009 12:59 pm

With a tablet, it takes sensitivity 0.5 to make the game playable - in a very framerate-dependant way. This patch makes it actually fun. :D It doesn't need a dead zone for this, but adding a cvar for it won't hurt.

Gimbal lock makes aiming up/down impossible, but fixing it breaks things. The screen center stays locked inside min/max pitch, but you can aim right to the edge. Shouldn't matter for gameplay, but it looks silly to other players and since movement follows pointer it flips the controls. :shock:

Dammit, I can't fix bugs I can't see. How does it look with weaponmodels? Should I make them turn to point at the crosshair?

Sven wrote:for what is this: @@ -652,15 +700,15 @@?
i think its the lines where add or delete something but if im right for what is ",15"?

+ is add and -delete ,right?

It's a diff. Meant for computers, not humans. Try Wikipedia or Google if you really want to know.
Rahsennor
Member
 
Posts: 13
Joined: Tue Jul 21, 2009 9:54 am
Location: Torven

Postby terencehill » Mon Aug 17, 2009 1:09 pm

The patch v2 is broken, cannot be applied. Somehow the TAB characters were replaced with spaces.

BTW, looking at your patch again, still CSQC_spider_HUD(); is removed, breaking the HUD of the spiderbot I think...


Another better place than this to post your patch is http://pastebin.com/ , no need to be registered there. This way we can download the patch with one click, instead of doing copy, open a text editor, paste, save file...

EDIT: Crap! I forgot to press the button quote to copy the patch, for that reason it was broken... add this too :/
Last edited by terencehill on Mon Aug 17, 2009 1:14 pm, edited 1 time in total.
terencehill
Alien
 
Posts: 176
Joined: Thu Jul 10, 2008 10:33 pm
Location: Italy

Postby Sven » Mon Aug 17, 2009 1:11 pm

kk :wink: thy but also dont what diff is xDD
German Nexuiz Clan:
Image
Sven
Alien trapper
 
Posts: 315
Joined: Sun Jun 01, 2008 8:38 am
Location: Berlin; Germany

Next

Return to Nexuiz - Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron