+#if 1
+ vec3_t offset;
+ vec3_t bestvieworg;
+#endif
+ vec3_t up;
+ viewangles[PITCH] = 0;
+ AngleVectors(viewangles, forward, NULL, up);
+ // trace a little further so it hits a surface more consistently (to avoid 'snapping' on the edge of the range)
+ chase_dest[0] = vieworg[0] - forward[0] * camback + up[0] * camup;
+ chase_dest[1] = vieworg[1] - forward[1] * camback + up[1] * camup;
+ chase_dest[2] = vieworg[2] - forward[2] * camback + up[2] * camup;
+#if 0
+ //trace = CL_Move(vieworg, eyeboxmins, eyeboxmaxs, chase_dest, MOVE_NOMONSTERS, NULL, SUPERCONTENTS_SOLID | SUPERCONTENTS_BODY | SUPERCONTENTS_SKY, true, false, NULL, false);
+ trace = CL_Move(vieworg, vec3_origin, vec3_origin, chase_dest, MOVE_NOMONSTERS, NULL, SUPERCONTENTS_SOLID | SUPERCONTENTS_BODY | SUPERCONTENTS_SKY, true, false, NULL, false);
+ VectorCopy(trace.endpos, vieworg);
+ vieworg[2] -= 8;
+#else
+ trace = CL_Move(vieworg, vec3_origin, vec3_origin, chase_dest, MOVE_NOMONSTERS, NULL, SUPERCONTENTS_SOLID | SUPERCONTENTS_BODY | SUPERCONTENTS_SKY, true, false, NULL, false);
+ VectorCopy(trace.endpos, bestvieworg);
+ offset[2] = 0;
+ for (offset[0] = -16;offset[0] <= 16;offset[0] += 8)
+ {
+ for (offset[1] = -16;offset[1] <= 16;offset[1] += 8)
+ {
+ AngleVectors(viewangles, NULL, NULL, up);
+ chase_dest[0] = vieworg[0] - forward[0] * camback + up[0] * camup + offset[0];
+ chase_dest[1] = vieworg[1] - forward[1] * camback + up[1] * camup + offset[1];
+ chase_dest[2] = vieworg[2] - forward[2] * camback + up[2] * camup + offset[2];
+ trace = CL_Move(vieworg, vec3_origin, vec3_origin, chase_dest, MOVE_NOMONSTERS, NULL, SUPERCONTENTS_SOLID | SUPERCONTENTS_BODY | SUPERCONTENTS_SKY, true, false, NULL, false);
+ if (bestvieworg[2] > trace.endpos[2])
+ bestvieworg[2] = trace.endpos[2];
+ }
+ }
+ bestvieworg[2] -= 8;
+ VectorCopy(bestvieworg, vieworg);
+#endif
+ viewangles[PITCH] = 90;