Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
Decal.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameLib/Generic", description: "Decal entity", dynamicBox: true, insertable: false)]
2class WorldDecalClass: GenericEntityClass
3{
4
5}
6
7//------------------------------------------------------------------------------
8class WorldDecal: GenericEntity
9{
10 [Attribute(defvalue: "1", uiwidget: UIWidgets.EditBox, desc: "Far plane", "0.01 10")]
11 private float FarPlane;
12 [Attribute(defvalue: "1", uiwidget: UIWidgets.Slider, desc: "Stretch", "0.01 100")]
13 private float Stretch;
14 [Attribute(defvalue: "0", uiwidget: UIWidgets.Slider, desc: "Lifetime in seconds, 0 is valid and means the decal is permanent", "0 360 0.1")]
15 private float Angle;
16 [Attribute(defvalue: "", uiwidget: UIWidgets.ResourcePickerThumbnail, desc: "Decal material", "emat")]
17 private ResourceName Mat;
18 [Attribute(defvalue: "300", uiwidget: UIWidgets.EditBox, desc: "Lifetime in seconds, 0 is valid and means the decal is permanent", "")]
19 private float Lifetime;
20 [Attribute(defvalue: "1", uiwidget: UIWidgets.CheckBox, desc: "Terrain only")]
21 private bool TerrainOnly;
22
23 Decal m_decal;
24 const float NearPlane = 0;
25
26 #ifdef WORKBENCH
27 ref Shape m_ArrowVis;
28 ref Shape m_ProjBox;
29 ref Shape m_IntersectionShape;
30
31 bool m_bCheckIntersection;
32 vector m_vIntersection;
33 #endif
34
35 //------------------------------------------------------------------------------
36 void WorldDecal(IEntitySource src, IEntity parent)
37 {
38 ClearFlags(EntityFlags.ACTIVE, false);
39 SetFlags(EntityFlags.STATIC, false);
41
42 #ifdef WORKBENCH
43 m_bCheckIntersection = false;
44 #endif
45 }
46
47 //------------------------------------------------------------------------------
48 void ~WorldDecal()
49 {
50 Destroy();
51 }
52
53 //------------------------------------------------------------------------------
54 vector GetForwardVec()
55 {
56 return GetTransformAxis(0).Normalized();
57 }
58
59 //------------------------------------------------------------------------------
60 float GetSize()
61 {
62 float scale = GetScale();
63 return Math.Clamp(scale, 0.01, 10.0);
64 }
65
66#ifdef WORKBENCH
67 //------------------------------------------------------------------------------
68 Shape CreateArrow(vector from, vector to, float size, int color, ShapeFlags flags)
69 {
70 vector dir = to - from;
71 float len = dir.Length();
72 if (len < 0.01)
73 len = 0.01;
74 dir /= len;
75 vector dir1 = dir * size;
76 vector center = to - dir1;
77 size = size * 0.5;
78
79 vector dir2 = dir.Perpend() * size;
80
81 vector pts[6];
82 pts[0] = from;
83 pts[1] = center;
84 pts[2] = to - dir1 - dir2;
85 pts[3] = to;
86 pts[4] = to - dir1 + dir2;
87 pts[5] = center;
88
89 return Shape.CreateLines(color, flags, pts, 6);
90 }
91
92 //------------------------------------------------------------------------------
93 void GetPitchMatrix(float pitchRad, out vector rotMat[3])
94 {
95 float sp = Math.Sin(pitchRad);
96 float cp = Math.Cos(pitchRad);
97
98 rotMat[0][0] = 1;
99 rotMat[1][0] = 0;
100 rotMat[2][0] = 0;
101
102 rotMat[0][1] = 0;
103 rotMat[1][1] = cp;
104 rotMat[2][1] = sp;
105
106 rotMat[0][2] = 0;
107 rotMat[1][2] = -sp;
108 rotMat[2][2] = cp;
109 }
110
111 //------------------------------------------------------------------------------
112 void RecreateVisualizers()
113 {
114 float dist = (FarPlane - NearPlane)*0.5;
115 vector forward = GetForwardVec();
116 m_ArrowVis = CreateArrow(GetOrigin() - forward*dist, GetOrigin() + forward*dist, 0.1, 0xFFFF0000, ShapeFlags.NOZBUFFER|ShapeFlags.DEPTH_DITHER);
117
118 vector entMat[4];
119 GetTransform(entMat);
120
121 //Normalize() doesn't work on vector array, so now in this way
122 entMat[0] = entMat[0].Normalized();
123 entMat[1] = entMat[1].Normalized();
124 entMat[2] = entMat[2].Normalized();
125
126 //rotation
127 vector rotMat[3];
128 GetPitchMatrix((Angle)*Math.DEG2RAD, rotMat);
129
130 vector mat[3];
131 Math3D.MatrixMultiply3(entMat, rotMat, mat);
132
133 float size = GetSize();
134
135 vector point[6];
136 float s = size*0.5;
137 float w = s*Stretch;
138 float f = FarPlane*0.5;
139 point[0] = GetOrigin() + Vector(f, w, s).Multiply3(mat);
140 point[1] = GetOrigin() + Vector(f, w,-s).Multiply3(mat);
141 point[2] = GetOrigin() + Vector(f,-w,-s).Multiply3(mat);
142
143 point[3] = point[2];
144 point[4] = GetOrigin() + Vector(f,-w, s).Multiply3(mat);
145 point[5] = point[0];
146
147
148 int color = 0x80FF4000;
149 if (m_bCheckIntersection)
150 color = 0x20FF4000;
151
152 m_ProjBox = Shape.CreateTris(color, ShapeFlags.NOZBUFFER|ShapeFlags.DEPTH_DITHER|ShapeFlags.NOOUTLINE|ShapeFlags.DOUBLESIDE|ShapeFlags.TRANSP, point, 2);
153
154 if (m_bCheckIntersection)
155 {
156 float sphereSize = Math.Clamp(size*0.025, 0.01, 0.5);
157 m_IntersectionShape = Shape.CreateSphere(
158 0xFFFF8000,
159 ShapeFlags.NOZBUFFER|ShapeFlags.DEPTH_DITHER|ShapeFlags.NOOUTLINE,
160 m_vIntersection,
161 sphereSize);
162 }
163 else
164 {
165 m_IntersectionShape = null;
166 }
167 }
168
169 //------------------------------------------------------------------------------
170 override void _WB_GetBoundBox(inout vector min, inout vector max, IEntitySource src)
171 {
172 //HACK as we are in local coords, we have to scale it inversely as the entity matrix
173 //will scale it back
174 float size = GetSize();
175 size = Math.Max(GetSize(), GetSize()*Stretch);
176 /*
177 it's not visible when rotating with Angle
178 float s = Math.Sin(Angle*Math.DEG2RAD);
179 float c = Math.Cos(Angle*Math.DEG2RAD);
180
181 float x = s + c;
182 float y = -c + s;
183 float a = Math.Sqrt(x*x + y*y);
184 */
185
186 float a = 0.707*Math.Max(1, Stretch);
187
188 min = Vector((NearPlane - FarPlane*0.5)/GetSize(), -a, -a);
189 max = Vector(FarPlane*0.5/GetSize(), a, a);
190 }
191
192
193 //------------------------------------------------------------------------------
194 void ClearShapes()
195 {
196 if (m_ArrowVis)
197 delete m_ArrowVis;
198
199 if (m_ProjBox)
200 delete m_ProjBox;
201
202 if (m_IntersectionShape)
203 delete m_IntersectionShape;
204 }
205
206 //------------------------------------------------------------------------------
207 override void _WB_SetExtraVisualiser(EntityVisualizerType type, IEntitySource src)
208 {
209 /*
210 EVT_NONE, //no visualizer
211 EVT_NORMAL, //normal visualizer
212 EVT_SELECTED, //selected entity visualiser (but no as main)
213 EVT_SELECTED_AS_MAIN, //selected as main entity visualiser
214 EVT_UNDER_CURSOR, //under cursor entity visualiser
215 */
216 if (type == EntityVisualizerType.EVT_NONE)
217 {
218
219 ClearShapes();
220 }
221 else
222 {
223 RecreateVisualizers();
224 }
225 }
226
227 //------------------------------------------------------------------------------
228 override void _WB_SetTransform(inout vector mat[4], IEntitySource src)
229 {
230 Destroy();
231 Create();
232
233 RecreateVisualizers();
234 }
235
236#endif
237
238 //------------------------------------------------------------------------------
239 override void EOnInit(IEntity owner)
240 {
241 Create();
242 }
243
244 //------------------------------------------------------------------------------
245 void Destroy()
246 {
247 if (m_decal)
248 {
249 GetWorld().RemoveDecal(m_decal);
250 m_decal = null;
251 }
252
253 #ifdef WORKBENCH
254 ClearShapes();
255 #endif
256 }
257
258 //------------------------------------------------------------------------------
259 void Create()
260 {
261 if (Mat == string.Empty)
262 return;
263
264 vector origin = GetOrigin();
265 vector forward = GetForwardVec();
266
267 float farPlane = FarPlane*0.5;
268 auto param = new TraceParam;
269 param.Start = origin - forward*farPlane;
270 param.End = origin + forward*farPlane;
271 param.Flags = TraceFlags.WORLD;
272 if (!TerrainOnly)
273 param.Flags |= TraceFlags.ENTS;
274 param.Exclude = this;
275
276 float frac = GetWorld().TraceMove(param, NULL);
277
278 #ifdef WORKBENCH
279 m_bCheckIntersection = false;
280 #endif
281
282 if (param.TraceEnt)
283 {
284 World world = GetWorld();
285 Decal decal = world.CreateDecal(param.TraceEnt, param.Start, forward, NearPlane, FarPlane, Angle* Math.DEG2RAD, GetSize(), Stretch, Mat, Lifetime, 0xFFFFFFFF, 0);
286
287 #ifdef WORKBENCH
288 m_bCheckIntersection = true;
289 m_vIntersection = param.Start + (param.End - param.Start)*frac;
290
291 //save always when we are in editor mode
292 if ((_WB_GetEditorAPI() && _WB_GetEditorAPI().IsEditMode()) || Lifetime == 0)
293 #else
294 if (Lifetime == 0)
295 #endif
296 m_decal = decal;
297 else
298 m_decal = null
299 }
300 }
301}
SCR_EAIThreatSectorFlags flags
vector scale
int size
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
EDamageType type
override bool Destroy(int editorPlayerID)
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
float NearPlane
float FarPlane
enum EVehicleType IEntity
Definition Decal.c:13
event void _WB_GetBoundBox(inout vector min, inout vector max, IEntitySource src)
Editor needs to know a bound box of entity (For ray-casting, visualizers etc.). You can return any cu...
proto external WorldEditorAPI _WB_GetEditorAPI()
This returns world editor API, which is safe to use from editor events bellow.
event void _WB_SetTransform(inout vector mat[4], IEntitySource src)
Editor changed transformation matrix source. This is the place to apply it on entity....
event void _WB_SetExtraVisualiser(EntityVisualizerType type, IEntitySource src)
If entity needs to have a special visualizer instead of default one, here is the place where you can ...
proto external EntityEvent SetEventMask(EntityEvent e)
proto external float GetScale()
void EOnInit(IEntity owner)
proto external vector GetOrigin()
proto external BaseWorld GetWorld()
proto external EntityFlags SetFlags(EntityFlags flags, bool recursively=false)
proto external vector GetTransformAxis(int axis)
See IEntity::GetTransformAxis.
proto external void GetTransform(out vector mat[])
proto external EntityFlags ClearFlags(EntityFlags flags, bool recursively=false)
Instance of created debug visualizer.
Definition Shape.c:14
@ NULL
Unknown type.
Definition DataVarType.c:21
ShapeFlags
Definition ShapeFlags.c:13
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14
EntityFlags
Various entity flags.
Definition EntityFlags.c:14
EntityVisualizerType
Game editor entity visualizer type.
proto native vector Vector(float x, float y, float z)
TraceFlags
Definition TraceFlags.c:13