]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - view.c
try to fix the gun origin for view bobbing
[xonotic/darkplaces.git] / view.c
diff --git a/view.c b/view.c
index 94db8d2bfbc50517dc1796d44182384144d7e3bb..685957dc8212df9e1187db9f402ec5c33d0e2a98 100644 (file)
--- a/view.c
+++ b/view.c
@@ -531,7 +531,6 @@ void V_CalcRefdef (void)
                                VectorAdd(vieworg, cl.punchvector, vieworg);
                                if (cl.stats[STAT_HEALTH] > 0)
                                {
-                                       // gun model bobbing code
                                        double xyspeed, bob;
                                        vec_t d;
                                        vec_t ef_speed = cl.realframetime;
@@ -545,7 +544,7 @@ void V_CalcRefdef (void)
                                                if(cl.viewmodel_push_x - cl.viewangles[PITCH] >= 180)
                                                        cl.viewmodel_push_x -= 360;
 
-                                               d = cl.viewmodel_push_x - cl.viewangles[PITCH];
+                                               d = cl.viewangles[PITCH] - cl.viewmodel_push_x;
                                                cl.viewmodel_push_x = bound(cl.viewangles[PITCH] - cl_leanmodel_up_limit.value, cl.viewmodel_push_x + d * cl_leanmodel_up_speed.value * ef_speed, cl.viewangles[PITCH] + cl_leanmodel_up_limit.value);
                                        }
                                        else
@@ -559,7 +558,7 @@ void V_CalcRefdef (void)
                                                if(cl.viewmodel_push_y - cl.viewangles[YAW] >= 180)
                                                        cl.viewmodel_push_y -= 360;
 
-                                               d = cl.viewmodel_push_y - cl.viewangles[YAW];
+                                               d = cl.viewangles[YAW] - cl.viewmodel_push_y;
                                                cl.viewmodel_push_y = bound(cl.viewangles[YAW] - cl_leanmodel_side_limit.value, cl.viewmodel_push_y + d * cl_leanmodel_side_speed.value * ef_speed, cl.viewangles[YAW] + cl_leanmodel_side_limit.value);
                                        }
                                        else
@@ -568,7 +567,6 @@ void V_CalcRefdef (void)
                                        VectorSet(gunangles, cl.viewmodel_push_x, cl.viewmodel_push_y, viewangles[2]);
 
                                        // gun model following code
-                                       // TODO: make the weapon model not shake when looking around horizontally (due to X axis vs. Y axis)
                                        if(cl_followmodel_side.value && cl_followmodel_side_speed.value * ef_speed < 1) // bad things happen if this goes over 1, so prevent the effect
                                        {
                                                vec_t d0 = vieworg[0] - cl.gunorg_follow[0];
@@ -602,6 +600,7 @@ void V_CalcRefdef (void)
 
                                        VectorCopy(cl.gunorg_follow, gunorg);
 
+                                       // gun model bobbing code
                                        xyspeed = sqrt(cl.movement_velocity[0]*cl.movement_velocity[0] + cl.movement_velocity[1]*cl.movement_velocity[1]);
                                        if (cl_bob.value && cl_bobcycle.value)
                                        {
@@ -621,6 +620,13 @@ void V_CalcRefdef (void)
                                                bob = xyspeed * cl_bob.value;
                                                bob = bob*0.3 + bob*0.7*cycle;
                                                vieworg[2] += bound(-7, bob, 4);
+                                               // we also need to adjust gunorg, or this appears like
+                                               // pushing the gun! In the old code, this was applied
+                                               // to vieworg BEFORE copying to gunorg, but this is not
+                                               // viable with the new followmodel code as that would
+                                               // mean that followmodel would work on the
+                                               // munged-by-bob vieworg and do feedback
+                                               gunorg[2] += bound(-7, bob, 4);
                                        }
 
                                        if (cl_bob.value && cl_bobmodel.value)