5 #include "../client/defs.qh"
6 #include "constants.qh"
9 #include "../server/defs.qh"
13 void viewloc_PlayerPhysics(entity this)
17 vector old_movement = this.movement;
18 this.movement_x = old_movement_y;
21 if(this.movement_x < 0)
22 this.movement_x = -this.movement_x;
24 vector level_start, level_end;
25 level_start = this.viewloc.enemy.origin;
26 level_end = this.viewloc.goalentity.origin;
27 vector forward, backward;
28 forward = vectoangles(normalize(level_end - level_start));
29 backward = vectoangles(normalize(level_start - level_end));
31 if(this.movement_x < 0) // left
32 this.angles_y = backward_y;
33 if(this.movement_x > 0) // right
34 this.angles_y = forward_y;
36 if(old_movement_x > 0)
40 this.v_angle_x = this.angles_x = -50;
41 else if(old_movement_x < 0)
45 this.v_angle_x = this.angles_x = 50;
47 //if(!PHYS_INPUT_BUTTON_CROUCH(this) && !IS_DUCKED(this))
49 //PHYS_INPUT_BUTTON_CROUCH(this) = (old_movement_x < 0);
50 if (old_movement.x < 0)
51 PHYS_INPUT_BUTTON_CROUCH(this) = true;
53 if (old_movement.x < 0)
55 input_buttons |= BIT(4);
56 this.flags |= FL_DUCKED;
58 //else { input_buttons &= ~16; this.flags &= ~FL_DUCKED; }
65 void viewloc_SetTags(entity this)
67 if(this.viewloc && wasfreed(this.viewloc))
70 if(this.viewloc.entnum != this.tag_networkviewloc)
71 if(this.tag_networkviewloc == 0)
74 this.viewloc = findfloat(NULL, entnum, this.tag_networkviewloc);
77 vector old_camera_angle = '0 0 0';
78 bool autocvar_cam_snap_close;
79 bool autocvar_cam_track;
80 bool autocvar_cam_snap_hard;
81 bool autocvar_cam_snap_unlock;
82 void viewloc_SetViewLocation()
84 entity view = CSQCModel_server2csqc(player_localentnum - 1);
86 //NOTE: the "cam_" cvars sould probably be changed out with a spawnflag or an entity key. I have it like this for my testing -- Player_2
87 if(view.viewloc && !wasfreed(view.viewloc) && view.viewloc.enemy && view.viewloc.goalentity)
89 vector position_a, position_b, camera_position, camera_angle = '0 0 0', forward, backward;
92 position_a = view.viewloc.enemy.origin;
93 position_b = view.viewloc.goalentity.origin;
96 /*TODO: have the camera only move when a player moves too much from the center of the camera
97 * basically the player can move around in a "box" in the center of th screen with out changing the camera position or angles
99 if (cvar("cam_box")) {
100 camera_position = vec_bounds_in(view.origin, position_a, position_b);
104 camera_position = vec_bounds_in(view.origin, position_a, position_b);
107 // a tracking camera follows the player when it leaves the world box
108 if (autocvar_cam_track) {
109 camera_angle = aim_vec (camera_position, view.origin);
112 // hard snap changes the angle as soon as it crosses over the nearest 90 degree mark
113 if (autocvar_cam_snap_hard){
114 camera_angle = angle_snap_vec(aim_vec(camera_position, view.origin), 90);
117 // tries to avoid snapping unless it *really* needs to
118 if (autocvar_cam_snap_close){
120 // like hard snap, but don't snap angles yet.
121 camera_angle = aim_vec(camera_position, view.origin);
123 /* if the difference between the old and new angle is 60 degrees or more, switch angles.
124 * NOTE: bug/feature: this will use non-snaped angles for one frame.
125 * doing this resualts in less code, faster code, and a smoother transisition between angles.
127 float camera_angle_diff = max(camera_angle_y, old_camera_angle_y) - min(camera_angle_y, old_camera_angle_y);
129 if ( camera_angle_diff >= 60)
130 old_camera_angle_y = angle_snap_f(camera_angle_y, 90);
132 camera_angle_y = old_camera_angle_y;
135 //unlocking this allows the camera to look up and down. this also allows a top-down view.
136 if (!autocvar_cam_snap_unlock) {
142 LOG_TRACE(vtos(camera_position));
143 LOG_TRACE(vtos(old_camera_angle));
144 LOG_TRACE(vtos(camera_angle));
147 freeze_org = getpropertyvec(VF_ORIGIN);
148 freeze_ang = getpropertyvec(VF_ANGLES);
149 setproperty(VF_ORIGIN, camera_position);
150 setproperty(VF_ANGLES, camera_angle);
152 forward = vectoangles(normalize(vec_to_min(position_b, position_a) - vec_to_max(position_b, position_a)));
153 backward = vectoangles(normalize(vec_to_max(position_b, position_a) - vec_to_min(position_b, position_a)));
155 if(input_movevalues_y < 0) // left
156 view.angles_y = backward_y;
157 if(input_movevalues_y > 0) // favour right
158 view.angles_y = forward_y;
160 setproperty(VF_CL_VIEWANGLES, view.angles);