1 vector project_3d_to_2d(vector vec)
4 if(cs_project_is_b0rked)
6 vec_x += vid_width / 2;
7 vec_y += vid_height / 2;
9 vec_x *= vid_conwidth / vid_width;
10 vec_y *= vid_conheight / vid_height;
14 float waypointsprite_initialized;
15 float waypointsprite_fadedistance;
16 float waypointsprite_normdistance;
17 float waypointsprite_minscale;
18 float waypointsprite_minalpha;
19 float waypointsprite_distancealphaexponent;
20 float waypointsprite_timealphaexponent;
21 float waypointsprite_scale;
24 .string netname; // primary picture
25 .string netname2; // secondary picture
26 .string netname3; // tertiary picture
27 .float team; // team that gets netname2
33 vector SPRITE_SIZE = '128 32 0';
34 vector SPRITE_HOTSPOT = '64 32 0';
36 void drawrotpic(vector org, float rot, string pic, vector sz, vector hotspot, vector rgb, float a, float f)
38 vector v1, v2, v3, v4;
40 hotspot = -1 * hotspot;
42 // hotspot-relative coordinates of the corners
44 v2 = hotspot + '1 0 0' * sz_x;
45 v3 = hotspot + '1 0 0' * sz_x + '0 1 0' * sz_y;
46 v4 = hotspot + '0 1 0' * sz_y;
48 // rotate them, and make them absolute
49 rot = -rot; // rotate by the opposite angle, as our coordinate system is reversed
50 v1 = rotate(v1, rot) + org;
51 v2 = rotate(v2, rot) + org;
52 v3 = rotate(v3, rot) + org;
53 v4 = rotate(v4, rot) + org;
56 R_BeginPolygon(pic, f);
57 R_PolygonVertex(v1, '0 0 0', rgb, a);
58 R_PolygonVertex(v2, '1 0 0', rgb, a);
59 R_PolygonVertex(v3, '1 1 0', rgb, a);
60 R_PolygonVertex(v4, '0 1 0', rgb, a);
64 void Draw_WaypointSprite()
70 self.alpha = pow(bound(0, (self.fadetime - time) / self.lifetime, 1), waypointsprite_timealphaexponent);
74 if(self.hideflags & 2)
77 if(cvar("cl_hidewaypoints") >= 2)
80 if(self.hideflags & 1)
81 if(cvar("cl_hidewaypoints"))
82 return; // fixed waypoint
84 InterpolateOrigin_Do();
86 t = GetPlayerColor(player_localentnum - 1) + 1;
93 case SPRITERULE_DEFAULT:
97 spriteimage = self.netname;
102 spriteimage = self.netname;
104 case SPRITERULE_TEAMPLAY:
105 if(t == COLOR_SPECTATOR + 1)
106 spriteimage = self.netname3;
107 else if(self.team == t)
108 spriteimage = self.netname2;
110 spriteimage = self.netname;
113 error("Invalid waypointsprite rule!");
117 if(spriteimage == "")
121 dist = vlen(self.origin - view_origin);
126 if(self.maxdistance > waypointsprite_normdistance)
127 a *= pow(bound(0, (self.maxdistance - dist) / (self.maxdistance - waypointsprite_normdistance), 1), waypointsprite_distancealphaexponent);
128 else if(self.maxdistance > 0)
129 a *= pow(bound(0, (waypointsprite_fadedistance - dist) / (waypointsprite_fadedistance - waypointsprite_normdistance), 1), waypointsprite_distancealphaexponent) * (1 - waypointsprite_minalpha) + waypointsprite_minalpha;
134 // draw the sprite image
137 o = project_3d_to_2d(self.origin);
140 if(o_z < 0 || o_x < 0 || o_y < 0 || o_x > vid_conwidth || o_y > vid_conheight)
142 // scale it to be just in view
146 // get the waypoint angle vector
147 d_x = view_right * (self.origin - view_origin) * vid_conwidth / vid_width;
148 d_y = -view_up * (self.origin - view_origin) * vid_conheight / (vid_height * vid_pixelheight);
151 //d = o - '0.5 0 0' * vid_conwidth - '0 0.5 0' * vid_conheight;
153 f1 = d_x / vid_conwidth;
154 f2 = d_y / vid_conheight;
156 if(max(f1, -f1) > max(f2, -f2))
187 o = d + '0.5 0 0' * vid_conwidth + '0 0.5 0' * vid_conheight;
192 vidscale = max(vid_conwidth / vid_width, vid_conheight / vid_height);
194 t = stof(db_get(tempdb, strcat("/spriteframes/", spriteimage)));
196 spriteimage = strcat("models/sprites/", spriteimage);
198 spriteimage = strcat("models/sprites/", spriteimage, "_frame", ftos(mod(floor(time * 2), t)));
200 drawrotpic(o, rot * 90 * DEG2RAD, spriteimage, SPRITE_SIZE * waypointsprite_scale * vidscale, SPRITE_HOTSPOT * waypointsprite_scale * vidscale, '1 1 1', a, DRAWFLAG_MIPMAP);
203 void Ent_WaypointSprite()
206 sendflags = ReadByte();
208 self.draw2d = Draw_WaypointSprite;
210 InterpolateOrigin_Undo();
214 // unfortunately, this needs to be exact (for the 3D display)
215 self.origin_x = ReadCoord();
216 self.origin_y = ReadCoord();
217 self.origin_z = ReadCoord();
222 self.team = ReadByte();
223 self.rule = ReadByte();
229 strunzone(self.netname);
230 self.netname = strzone(ReadString());
236 strunzone(self.netname2);
237 self.netname2 = strzone(ReadString());
243 strunzone(self.netname3);
244 self.netname3 = strzone(ReadString());
249 self.lifetime = ReadCoord();
250 self.fadetime = ReadCoord();
251 self.maxdistance = ReadShort();
252 self.hideflags = ReadByte();
258 self.teamradar_icon = (f & 0x7F);
261 self.(teamradar_times[self.teamradar_time_index]) = time;
262 self.teamradar_time_index = mod(self.teamradar_time_index + 1, MAX_TEAMRADAR_TIMES);
264 self.teamradar_color_x = ReadByte() / 255.0;
265 self.teamradar_color_y = ReadByte() / 255.0;
266 self.teamradar_color_z = ReadByte() / 255.0;
269 InterpolateOrigin_Note();
272 void Ent_RemoveWaypointSprite()
275 strunzone(self.netname);
277 strunzone(self.netname2);
279 strunzone(self.netname3);
282 void WaypointSprite_Load()
284 waypointsprite_fadedistance = vlen(world.maxs - world.mins);
285 waypointsprite_normdistance = cvar("g_waypointsprite_normdistance");
286 waypointsprite_minscale = cvar("g_waypointsprite_minscale");
287 waypointsprite_minalpha = cvar("g_waypointsprite_minalpha");
288 waypointsprite_distancealphaexponent = cvar("g_waypointsprite_distancealphaexponent");
289 waypointsprite_timealphaexponent = cvar("g_waypointsprite_timealphaexponent");
290 waypointsprite_scale = cvar("g_waypointsprite_scale");
291 if(!waypointsprite_scale)
292 waypointsprite_scale = 1.0;
294 if(!waypointsprite_initialized)
296 float dh, n, i, o, f;
297 string s, sname, sframes;
298 dh = search_begin("models/sprites/*_frame*.tga", FALSE, FALSE);
299 n = search_getsize(dh);
300 for(i = 0; i < n; ++i)
302 s = search_getfilename(dh, i);
303 if(substring(s, 0, 15) != "models/sprites/")
305 if(substring(s, strlen(s) - 4, 4) != ".tga")
307 s = substring(s, 15, strlen(s) - 19);
309 o = strstrofs(s, "_frame", 0);
310 sname = strcat("/spriteframes/", substring(s, 0, o));
311 sframes = substring(s, o + 6, strlen(s) - o - 6);
312 f = stof(sframes) + 1;
313 db_put(tempdb, sname, ftos(max(f, stof(db_get(tempdb, sname)))));
317 waypointsprite_initialized = 1;