]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/viewloc.qc
Merge branch 'master' into terencehill/spectatee_status_update
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / viewloc.qc
1 #include "viewloc.qh"
2 #include "util.qh"
3
4 #if defined(CSQC)
5     #include "../client/defs.qh"
6     #include "constants.qh"
7 #elif defined(MENUQC)
8 #elif defined(SVQC)
9         #include "../server/defs.qh"
10 #endif
11
12 // client movement
13 void viewloc_PlayerPhysics(entity this)
14 {
15         if(this.viewloc)
16         {
17                 vector old_movement = this.movement;
18                 this.movement_x = old_movement_y;
19                 this.movement_y = 0;
20
21                 if(this.movement_x < 0)
22                         this.movement_x = -this.movement_x;
23
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));
30
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;
35
36                 if(old_movement_x > 0)
37 #ifdef CSQC
38                         input_angles_x =
39 #endif
40                         this.v_angle_x = this.angles_x = -50;
41                 else if(old_movement_x < 0)
42 #ifdef CSQC
43                         input_angles_x =
44 #endif
45                         this.v_angle_x = this.angles_x = 50;
46
47                 //if(!PHYS_INPUT_BUTTON_CROUCH(this) && !IS_DUCKED(this))
48 #ifdef SVQC
49                         //PHYS_INPUT_BUTTON_CROUCH(this) = (old_movement_x < 0);
50                         if (old_movement.x < 0)
51                                 PHYS_INPUT_BUTTON_CROUCH(this) = true;
52 #elif defined(CSQC)
53                         if (old_movement.x < 0)
54                         {
55                                 input_buttons |= BIT(4);
56                                 this.flags |= FL_DUCKED;
57                         }
58                         //else { input_buttons &= ~16; this.flags &= ~FL_DUCKED; }
59 #endif
60         }
61 }
62
63 #ifdef CSQC
64
65 void viewloc_SetTags(entity this)
66 {
67         if(this.viewloc && wasfreed(this.viewloc))
68                 this.viewloc = NULL;
69
70         if(this.viewloc.entnum != this.tag_networkviewloc)
71         if(this.tag_networkviewloc == 0)
72                 this.viewloc = NULL;
73         else
74                 this.viewloc = findfloat(NULL, entnum, this.tag_networkviewloc);
75 }
76
77 vector old_camera_angle = '0 0 0';
78 void viewloc_SetViewLocation()
79 {
80         entity view = CSQCModel_server2csqc(player_localentnum - 1);
81         if (!view) return;
82         //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
83         if(view.viewloc && !wasfreed(view.viewloc) && view.viewloc.enemy && view.viewloc.goalentity)
84         {
85                 vector position_a, position_b, camera_position, camera_angle, forward, backward;
86                 //vector scratch;
87
88                 position_a = view.viewloc.enemy.origin;
89                 position_b = view.viewloc.goalentity.origin;
90
91 #if 0
92                 /*TODO: have the camera only move when a player moves too much from the center of the camera
93                  * basically the player can move around in a "box" in the center of th screen with out changing the camera position or angles
94                 */
95                 if (cvar("cam_box")) {
96                         camera_position = vec_bounds_in(view.origin, position_a, position_b);
97                 }
98                 else
99 #endif
100                         camera_position = vec_bounds_in(view.origin, position_a, position_b);
101
102
103                 camera_angle = '0 0 0';
104
105                 // a tracking camera follows the player when it leaves the world box
106                 if (cvar("cam_track")) {
107                         camera_angle = aim_vec (camera_position, view.origin);
108                 }
109
110                 // hard snap changes the angle as soon as it crosses over the nearest 90 degree mark
111                 if (cvar("cam_snap_hard")){
112                         camera_angle = angle_snap_vec(aim_vec(camera_position, view.origin), 90);
113                 }
114
115                 // tries to avoid snapping unless it *really* needs to
116                 if (cvar("cam_snap_close")){
117
118                         // like hard snap, but don't snap angles yet.
119                         camera_angle = aim_vec(camera_position, view.origin);
120
121                         /* if the difference between the old and new angle is 60 degrees or more, switch angles.
122                          * NOTE: bug/feature: this will use non-snaped angles for one frame.
123                          * doing this resualts in less code, faster code, and a smoother transisition between angles.
124                          */
125                         float camera_angle_diff = max(camera_angle_y, old_camera_angle_y) - min(camera_angle_y, old_camera_angle_y);
126
127                         if ( camera_angle_diff >= 60)
128                                 old_camera_angle_y = angle_snap_f(camera_angle_y, 90);
129                         else
130                                 camera_angle_y = old_camera_angle_y;
131                 }
132
133                 //unlocking this allows the camera to look up and down. this also allows a top-down view.
134                 if (!cvar("cam_snap_unlock")) {
135                         camera_angle_x = 0;
136                         camera_angle_z = 0;
137                 }
138
139 #if 0
140                 LOG_TRACE(vtos(camera_position));
141                 LOG_TRACE(vtos(old_camera_angle));
142                 LOG_TRACE(vtos(camera_angle));
143 #endif
144
145                 freeze_org = getpropertyvec(VF_ORIGIN);
146                 freeze_ang = getpropertyvec(VF_ANGLES);
147                 setproperty(VF_ORIGIN, camera_position);
148                 setproperty(VF_ANGLES, camera_angle);
149
150                 forward = vectoangles(normalize(vec_to_min(position_b, position_a) - vec_to_max(position_b, position_a)));
151                 backward = vectoangles(normalize(vec_to_max(position_b, position_a) - vec_to_min(position_b, position_a)));
152
153                 if(input_movevalues_y < 0) // left
154                         view.angles_y = backward_y;
155                 if(input_movevalues_y > 0) // favour right
156                         view.angles_y = forward_y;
157
158                 setproperty(VF_CL_VIEWANGLES, view.angles);
159         }
160 }
161
162 #endif