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