]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/client/View.qc
zoom: do it entirely client side
[divverent/nexuiz.git] / data / qcsrc / client / View.qc
1 //include "main.qh"\r
2 \r
3 float drawtime;\r
4 \r
5 float tan(float x)\r
6\r
7         return sin(x) / cos(x);\r
8 }\r
9 float atan2(float y, float x)\r
10 {\r
11         vector v;\r
12         v = '1 0 0' * x + '0 1 0' * y;\r
13         v = vectoangles(v);\r
14         return v_y * 0.01745329251994329576;\r
15 }\r
16 \r
17 vector GetCurrentFov()\r
18 {\r
19         float zoomspeed, zoomfactor, zoomdir;\r
20 \r
21         zoomfactor = cvar("cl_zoomfactor");\r
22         if(zoomfactor < 1 || zoomfactor > 16)\r
23                 zoomfactor = 2.5;\r
24         zoomspeed = cvar("cl_zoomspeed");\r
25         if(zoomspeed >= 0)\r
26                 if(zoomspeed < 0.5 || zoomspeed > 16)\r
27                         zoomspeed = 3.5;\r
28 \r
29         zoomdir = button_zoom;\r
30         if(activeweapon == 7 && !minstagib)\r
31                 zoomdir += button_attack2;\r
32 \r
33         if(zoomdir)\r
34                 zoomin_effect = 0;\r
35 \r
36         if(zoomin_effect)\r
37         {\r
38                 current_viewzoom = min(1, current_viewzoom + drawframetime);\r
39         }\r
40         else\r
41         {\r
42                 if(zoomspeed < 0) // instant zoom\r
43                 {\r
44                         if(zoomdir)\r
45                                 current_viewzoom = 1 / zoomfactor;\r
46                         else\r
47                                 current_viewzoom = 1;\r
48                 }\r
49                 else\r
50                 {\r
51                         if(zoomdir)\r
52                                 current_viewzoom = 1 / bound(1, 1 / current_viewzoom + drawframetime * zoomspeed * (zoomfactor - 1), zoomfactor);\r
53                         else\r
54                                 current_viewzoom = bound(1 / zoomfactor, current_viewzoom + drawframetime * zoomspeed * (1 - 1 / zoomfactor), 1);\r
55                 }\r
56         }\r
57 \r
58         float frustumx, frustumy, fovx, fovy;\r
59         frustumy = tan(cvar("fov") * 0.00872664625997164788) * 0.75 * current_viewzoom;\r
60         frustumx = frustumy * cvar("vid_width") / cvar("vid_height") / cvar("vid_pixelheight");\r
61         fovx = atan2(frustumx, 1) / 0.00872664625997164788;\r
62         fovy = atan2(frustumy, 1) / 0.00872664625997164788;\r
63 \r
64         return '1 0 0' * fovx + '0 1 0' * fovy;\r
65 }\r
66 \r
67 void CSQC_common_hud(void);\r
68 \r
69 void CSQC_kh_hud(void);\r
70 void CSQC_ctf_hud(void);\r
71 void PostInit(void);\r
72 float Sbar_WouldDrawScoreboard ();\r
73 void CSQC_UpdateView(void)\r
74 {\r
75         entity e;\r
76 \r
77         drawframetime = time - drawtime;\r
78         drawtime = time;\r
79 \r
80         // watch for gametype changes here...\r
81         // in ParseStuffCMD the cmd isn't executed yet :/\r
82         // might even be better to add the gametype to TE_CSQC_INIT...?\r
83         if(!postinit)\r
84                 PostInit();\r
85         \r
86         sbar_alpha_fg = cvar("sbar_alpha_fg" );\r
87         sbar_hudselector = cvar("sbar_hudselector");\r
88         activeweapon = getstati(STAT_ACTIVEWEAPON);\r
89         teamplay = cvar("teamplay");\r
90 \r
91         if(last_weapon != activeweapon) {\r
92                 weapontime = time;\r
93                 last_weapon = activeweapon;\r
94         }\r
95 \r
96         // ALWAYS Clear Current Scene First\r
97         R_ClearScene();\r
98 \r
99         // Assign Standard Viewflags\r
100         // Draw the World (and sky)\r
101         R_SetView(VF_DRAWWORLD, 1);\r
102 \r
103         R_SetView(VF_FOV, GetCurrentFov());\r
104         \r
105         // Draw the Crosshair\r
106         R_SetView(VF_DRAWCROSSHAIR, !Sbar_WouldDrawScoreboard());\r
107         \r
108         // Draw the Engine Status Bar (the default Quake HUD)\r
109         draw_enginesbar = !cvar("sbar_usecsqc");\r
110         R_SetView(VF_DRAWENGINESBAR, draw_enginesbar);\r
111 \r
112         // Set the console size vars\r
113         vid_conwidth = cvar("vid_conwidth");\r
114         vid_conheight = cvar("vid_conheight");\r
115 \r
116         // Update the mouse position\r
117         /*\r
118         mousepos_x = vid_conwidth;\r
119         mousepos_y = vid_conheight;\r
120         mousepos = mousepos*0.5 + getmousepos();\r
121         */\r
122 \r
123         R_AddEntities(MASK_NORMAL | MASK_ENGINE | MASK_ENGINEVIEWMODELS);\r
124 \r
125         // Render the Scene\r
126         \r
127         view_origin = pmove_org + '0 0 1' * getstati(STAT_VIEWHEIGHT);\r
128         view_angles = input_angles;\r
129         makevectors(view_angles);\r
130         view_forward = v_forward;\r
131         view_right = v_right;\r
132         view_up = v_up;\r
133         \r
134         e = self;\r
135         for(self = world; (self = nextent(self)); )\r
136                 if(self.draw)\r
137                         self.draw();\r
138         self = e;\r
139         R_RenderScene();\r
140 \r
141         // Draw the mouse cursor\r
142         // NOTE: drawpic must happen after R_RenderScene for some reason\r
143         //drawpic(getmousepos(), "gfx/cursor.tga", '11 14 0', '1 1 1', 1, 0);\r
144         //drawstring('50 50', ftos(game), '10 10 0', '1 1 1', 1, 0);\r
145         //self = edict_num(player_localnum);\r
146         //drawstring('0 0', vtos(pmove_org), '8 8 0', '1 1 1', 1, 0);\r
147         //drawstring('0 8', strcat("ORG: ", vtos(self.origin), " state: ", ftos(self.ctf_state), " HP: ", ftos(self.health)), '8 8 0', '1 1 1', 1, 0);\r
148         // as long as the ctf part isn't in, this is useless\r
149         if(menu_visible)\r
150                 menu_show();\r
151         \r
152         /*if(gametype == GAME_CTF)\r
153         {\r
154                 ctf_view();\r
155         } else */\r
156         if(!draw_enginesbar)\r
157         {\r
158                 CSQC_common_hud();\r
159         }\r
160         \r
161         if(gametype == GAME_ONSLAUGHT)\r
162         {\r
163                 //drawstring('0 0', minimapname, '8 8 0', '1 1 1', 1, 0);\r
164                 //drawsetcliparea(0,0,800,600);\r
165                 ons_view();\r
166                 //drawresetcliparea();\r
167         }\r
168 }\r
169 \r
170 void Sbar_Draw();\r
171 void CSQC_common_hud(void)\r
172 {\r
173         // Sbar_SortFrags(); done in Sbar_Draw\r
174         Sbar_Draw();\r
175 }\r
176 \r
177 // KeyHunt HUD by victim\r
178 void CSQC_kh_hud(void)\r
179 {\r
180         // HUD 0 has the weapons on the right hand side - temporarily shown when needed\r
181         // HUD 1 has the weapons on the bottom - permanently\r
182 \r
183         // use the following two binds to check the icons move correctly\r
184         // bind g "toggle sbar_flagstatus_right; echo Menu right $sbar_flagstatus_right"  // move the icons\r
185         // bind h "toggle sbar_hudselector; echo HUD $sbar_hudselector"  // change the HUD\r
186 \r
187         float kh_keys, kh_keys_status, kh_teams_set;\r
188         float kh_margin_x, kh_margin_y, kh_key_box;\r
189         string kh_carrying, kh_outline;\r
190         vector red_pos, blue_pos, yellow_pos, pink_pos, kh_size;\r
191         vector red, blue, yellow, pink;\r
192 \r
193         kh_keys = getstati(STAT_KH_KEYS);\r
194         kh_keys_status = kh_keys / 256;\r
195         kh_teams_set = cvar("_teams_available");  // set in keyhunt.qc\r
196 \r
197         kh_margin_y = 8;\r
198         kh_margin_x = (cvar("sbar_flagstatus_right") * sbar_hudselector * (vid_conwidth - 67)) + 10;\r
199 //      sbar_flagstatus_right 0/1; sbar_hudselector 0/1; screen width - key width + margin\r
200 \r
201         red_pos_x = blue_pos_x = yellow_pos_x = pink_pos_x = kh_margin_x;\r
202 \r
203         kh_key_box = 120;\r
204 \r
205         pink_pos_y = kh_margin_y + 0;  // top\r
206         yellow_pos_y = kh_margin_y + kh_key_box;\r
207         blue_pos_y = kh_margin_y + kh_key_box * 2;\r
208         red_pos_y = kh_margin_y + kh_key_box * 3;  //bottom\r
209 \r
210         red = '1 0 0';\r
211         blue = '0 0 1';\r
212         yellow = '1 1 0';\r
213         pink = '1 0 1';\r
214 \r
215         kh_size = '0 0 0';  // don't resize the image\r
216 \r
217         kh_carrying = "gfx/sb_kh_full";\r
218         kh_outline = "gfx/sb_kh_outline";\r
219 \r
220 //      drawpic(vector position, string pic, vector size, vector rgb, float alpha, float flag)\r
221 //      vector position = '0 0';  // 'x y' 0 0 (the origin) is the top left. X 0 - 799, Y 0 - 599\r
222 \r
223 //      vector size = '0 0';  // 'x y' changes the x & y dimensions. '0 0' gives the default pic size\r
224 //      vector rgb = '0 0 0';  // 'r g b' range 0 - 1\r
225 \r
226         if (kh_keys_status & 1)  // red\r
227                 drawpic (red_pos, kh_carrying, kh_size, red, 0.2, 0);  // show 20% alpha key\r
228         else\r
229                 drawpic (red_pos, kh_outline, kh_size, red, 0.4, 0);  // show key outline 40% alpha\r
230 \r
231         if (kh_keys & 1)\r
232                 drawpic (red_pos, kh_carrying, kh_size, red, 1.0, 0);  // show solid key 100% alpha\r
233 \r
234 \r
235         if (kh_keys_status & 2)  // blue\r
236                 drawpic (blue_pos, kh_carrying, kh_size, blue, 0.2, 0);\r
237         else\r
238                 drawpic (blue_pos, kh_outline, kh_size, blue, 0.4, 0);\r
239 \r
240         if (kh_keys & 2)\r
241                 drawpic (blue_pos, kh_carrying, kh_size, blue, 1.0, 0);\r
242 \r
243 \r
244         if (kh_teams_set & 4)  // yellow\r
245         {\r
246                 if (kh_keys_status & 4)\r
247                         drawpic (yellow_pos, kh_carrying, kh_size, yellow, 0.2, 0);\r
248                 else\r
249                         drawpic (yellow_pos, kh_outline, kh_size, yellow, 0.4, 0);\r
250 \r
251                 if (kh_keys & 4)\r
252                         drawpic (yellow_pos, kh_carrying, kh_size, yellow, 1.0, 0);\r
253         }\r
254 \r
255 \r
256         if (kh_teams_set & 8)  // pink\r
257         {\r
258                 if (kh_keys_status & 8)\r
259                         drawpic (pink_pos, kh_carrying, kh_size, pink, 0.2, 0);\r
260                 else\r
261                         drawpic (pink_pos, kh_outline, kh_size, pink, 0.4, 0);\r
262 \r
263                 if (kh_keys & 8)\r
264                         drawpic (pink_pos, kh_carrying, kh_size, pink, 1.0, 0);\r
265         }\r
266 \r
267 }\r