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_fadedistance;
15 float waypointsprite_normdistance;
16 float waypointsprite_minscale;
17 float waypointsprite_minalpha;
18 float waypointsprite_distancealphaexponent;
19 float waypointsprite_timealphaexponent;
20 float waypointsprite_scale;
23 .string netname; // primary picture
24 .string netname2; // secondary picture
25 .string netname3; // tertiary picture
26 .float team; // team that gets netname2
32 vector SPRITE_SIZE = '128 32 0';
33 vector SPRITE_HOTSPOT = '64 32 0';
35 void drawrotpic(vector org, float rot, string pic, vector sz, vector hotspot, vector rgb, float a, float f)
37 vector v1, v2, v3, v4;
39 hotspot = -1 * hotspot;
41 // hotspot-relative coordinates of the corners
43 v2 = hotspot + '1 0 0' * sz_x;
44 v3 = hotspot + '1 0 0' * sz_x + '0 1 0' * sz_y;
45 v4 = hotspot + '0 1 0' * sz_y;
47 // rotate them, and make them absolute
48 v1 = rotate(v1, rot) + org;
49 v2 = rotate(v2, rot) + org;
50 v3 = rotate(v3, rot) + org;
51 v4 = rotate(v4, rot) + org;
54 R_BeginPolygon(pic, f);
55 R_PolygonVertex(v1, '0 0 0', rgb, a);
56 R_PolygonVertex(v2, '1 0 0', rgb, a);
57 R_PolygonVertex(v3, '1 1 0', rgb, a);
58 R_PolygonVertex(v4, '0 1 0', rgb, a);
62 void Draw_WaypointSprite()
68 self.alpha = pow(bound(0, (self.fadetime - time) / self.lifetime, 1), waypointsprite_timealphaexponent);
72 if(self.hideflags & 2)
75 if(cvar("cl_hidewaypoints") >= 2)
78 if(self.hideflags & 1)
79 if(cvar("cl_hidewaypoints"))
80 return; // fixed waypoint
82 InterpolateOrigin_Do();
84 t = GetPlayerColor(player_localentnum - 1) + 1;
91 case SPRITERULE_DEFAULT:
95 spriteimage = self.netname;
100 spriteimage = self.netname;
102 case SPRITERULE_TEAMPLAY:
104 spriteimage = self.netname2;
106 spriteimage = self.netname;
109 error("Invalid waypointsprite rule!");
113 if(spriteimage == "")
117 dist = vlen(self.origin - view_origin);
122 if(self.maxdistance > waypointsprite_normdistance)
123 a *= pow(bound(0, (self.maxdistance - dist) / (self.maxdistance - waypointsprite_normdistance), 1), waypointsprite_distancealphaexponent);
124 else if(self.maxdistance > 0)
125 a *= pow(bound(0, (waypointsprite_fadedistance - dist) / (waypointsprite_fadedistance - waypointsprite_normdistance), 1), waypointsprite_distancealphaexponent) * (1 - waypointsprite_minalpha) + waypointsprite_minalpha;
130 // draw the sprite image
133 o = project_3d_to_2d(self.origin);
136 if(o_z < 0 || o_x < 0 || o_y < 0 || o_x > vid_conwidth || o_y > vid_conheight)
138 // scale it to be just in view
141 d = o - '0.5 0 0' * vid_conwidth - '0 0.5 0' * vid_conheight;
143 f1 = d_x / vid_conwidth;
144 f2 = d_y / vid_conheight;
146 if(max(f1, -f1) > max(f2, -f2))
177 o = d + '0.5 0 0' * vid_conwidth + '0 0.5 0' * vid_conheight;
182 vidscale = max(vid_conwidth / vid_width, vid_conheight / vid_height);
183 drawrotpic(o, rot * 90 * DEG2RAD, strcat("models/sprites/", spriteimage), SPRITE_SIZE * waypointsprite_scale * vidscale, SPRITE_HOTSPOT * waypointsprite_scale * vidscale, '1 1 1', a, 0);
186 void Ent_WaypointSprite()
189 sendflags = ReadByte();
191 self.draw2d = Draw_WaypointSprite;
193 InterpolateOrigin_Undo();
195 // unfortunately, this needs to be exact (for the 3D display)
196 self.origin_x = ReadCoord();
197 self.origin_y = ReadCoord();
198 self.origin_z = ReadCoord();
202 self.team = ReadByte();
203 self.rule = ReadByte();
209 strunzone(self.netname);
210 self.netname = strzone(ReadString());
216 strunzone(self.netname2);
217 self.netname2 = strzone(ReadString());
223 strunzone(self.netname3);
224 self.netname3 = strzone(ReadString());
229 self.lifetime = ReadCoord();
230 self.fadetime = ReadCoord();
231 self.maxdistance = ReadShort();
232 self.hideflags = ReadByte();
238 self.teamradar_icon = (f & 0x7F);
240 self.teamradar_time = time;
241 self.teamradar_color_x = ReadByte() / 255.0;
242 self.teamradar_color_y = ReadByte() / 255.0;
243 self.teamradar_color_z = ReadByte() / 255.0;
246 InterpolateOrigin_Note();
249 void Ent_RemoveWaypointSprite()
252 strunzone(self.netname);
254 strunzone(self.netname2);
256 strunzone(self.netname3);
259 void WaypointSprite_Load()
261 waypointsprite_fadedistance = vlen(world.maxs - world.mins);
262 waypointsprite_normdistance = cvar("g_waypointsprite_normdistance");
263 waypointsprite_minscale = cvar("g_waypointsprite_minscale");
264 waypointsprite_minalpha = cvar("g_waypointsprite_minalpha");
265 waypointsprite_distancealphaexponent = cvar("g_waypointsprite_distancealphaexponent");
266 waypointsprite_timealphaexponent = cvar("g_waypointsprite_timealphaexponent");
267 waypointsprite_scale = cvar("g_waypointsprite_scale");
268 if(!waypointsprite_scale)
269 waypointsprite_scale = 1.0;