Nuclide
Software Development Kit for id Technology
NSDecal.h
1/*
2 * Copyright (c) 2016-2022 Vera Visions LLC.
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
13 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
14 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15*/
16
24class
26{
27public:
28 void NSDecal(void);
29
30#ifdef SERVER
31 virtual float SendEntity(entity, float);
32#else
33 virtual void ReceiveEntity(void);
34 virtual float predraw(void);
35 virtual void BuildShader(void);
36#endif
37
39 virtual void Place(vector, string);
40 virtual void PlaceAtScale(vector, string, float);
41
42private:
43 string m_strShader;
44 string m_strTexture;
45};
46
47typedef struct
48{
49 float fraction;
50 vector normal;
51 vector endpos;
52} traced_t;
53
54traced_t g_tracedDecal;
55
56void
57decal_pickwall(entity dself, vector vpos)
58{
59 traced_t tmp[6];
60 float frac = 1.0f;
61
62 g_tracedDecal.fraction = 1.0f;
63 g_tracedDecal.endpos = [0,0,0];
64 g_tracedDecal.normal = [0,0,0];
65
66 /* unrolled, trace against walls in all 6 directions */
67 makevectors([0, 0, 0]);
68 traceline(vpos + (v_forward * -1), vpos + (v_forward * 128), 0, dself);
69 tmp[0].fraction = trace_fraction;
70 tmp[0].normal = trace_plane_normal;
71 tmp[0].endpos = trace_endpos;
72 traceline(vpos + (v_forward * 1), vpos + (v_forward * -128), 0, dself);
73 tmp[1].fraction = trace_fraction;
74 tmp[1].normal = trace_plane_normal;
75 tmp[1].endpos = trace_endpos;
76 traceline(vpos + (v_right * -1), vpos + (v_right * 128), 0, dself);
77 tmp[2].fraction = trace_fraction;
78 tmp[2].normal = trace_plane_normal;
79 tmp[2].endpos = trace_endpos;
80 traceline(vpos + (v_right * 1), vpos + (v_right * -128), 0, dself);
81 tmp[3].fraction = trace_fraction;
82 tmp[3].normal = trace_plane_normal;
83 tmp[3].endpos = trace_endpos;
84 traceline(vpos + (v_up * -1), vpos + (v_up * 128), 0, dself);
85 tmp[4].fraction = trace_fraction;
86 tmp[4].normal = trace_plane_normal;
87 tmp[4].endpos = trace_endpos;
88 traceline(vpos + (v_up * 1), vpos + (v_up * -128), 0, dself);
89 tmp[5].fraction = trace_fraction;
90 tmp[5].normal = trace_plane_normal;
91 tmp[5].endpos = trace_endpos;
92
93 /* pick whatever wall is closest */
94 for (int i = 0; i < 6; i++) {
95 if (tmp[i].fraction < frac) {
96 frac = tmp[i].fraction;
97 g_tracedDecal.fraction = tmp[i].fraction;
98 g_tracedDecal.endpos = tmp[i].endpos;
99 g_tracedDecal.normal = tmp[i].normal;
100 }
101 }
102}
103
104void Decals_Init(void);
105NSDecal Decals_Next(vector pos);
106
108void Decals_Place(vector pos, string dname);
109
110#ifdef CLIENT
111string Decal_Precache(string decalTex);
112void Decal_Parse(void);
113void Decal_Reload(void);
114void Decal_Shutdown(void);
115#endif
This entity class represents decals
Definition: NSDecal.h:26
Definition: NSDecal.h:48
vector endpos
Definition: NSDecal.h:51
vector normal
Definition: NSDecal.h:50
float fraction
Definition: NSDecal.h:49