11 [
Attribute(
desc:
"Show debug shape in World Editor even when the entity is not selected.")]
12 protected bool m_bShowDebugViewCone;
20 bool IsInView(vector worldPos, WorkspaceWidget workspace =
null)
23 workspace =
GetGame().GetWorkspace();
25 return IsInView(worldPos, workspace.GetWidth() / (
float)workspace.GetHeight());
33 bool IsInView(vector worldPos,
float aspectRatio)
35 vector localPos = CoordToLocal(worldPos);
36 float angleV =
SCR_Math.DeltaAngle(Math.Atan2(localPos[2], localPos[1]) * Math.RAD2DEG, 90);
37 float angleH =
SCR_Math.DeltaAngle(Math.Atan2(localPos[2], localPos[0]) * Math.RAD2DEG, 90);
40 float fovH = Math.Atan2(Math.Tan(fovV * Math.DEG2RAD) * aspectRatio, 1) * Math.RAD2DEG;
42 return Math.InverseLerp(-fovV, fovV, angleV) < 1 && Math.InverseLerp(-fovH, fovH, angleH) < 1;
49 private ref ScriptInvoker Event_EOnActivate =
new ScriptInvoker;
54 private ref ScriptInvoker Event_EOnDeactivate =
new ScriptInvoker;
59 private ref ScriptInvoker Event_CameraActivate =
new ScriptInvoker;
64 private ref ScriptInvoker Event_CameraDeactivate =
new ScriptInvoker;
66 ScriptInvoker GetOnActivate()
68 return Event_EOnActivate;
70 ScriptInvoker GetOnDeactivate()
72 return Event_EOnDeactivate;
74 ScriptInvoker GetOnCameraActivate()
76 return Event_CameraActivate;
78 ScriptInvoker GetOnCameraDeactivate()
80 return Event_CameraDeactivate;
83 override void EOnActivate(IEntity owner)
85 super.EOnActivate(owner);
87 Event_EOnActivate.Invoke();
89 override void EOnDeactivate(IEntity owner)
91 super.EOnDeactivate(owner);
93 if (Event_EOnDeactivate)
94 Event_EOnDeactivate.Invoke();
96 override void CameraActivate()
98 Event_CameraActivate.Invoke();
100 override void CameraDeactivate()
102 Event_CameraDeactivate.Invoke();
106 override void _WB_AfterWorldUpdate(
float timeSlice)
108 WorldEditorAPI api = _WB_GetEditorAPI();
109 if (!api || (!api.IsEntitySelected(api.EntityToSource(
this)) && !m_bShowDebugViewCone))
113 float height = Math.Tan(
GetVerticalFOV() / 2 * Math.DEG2RAD) * length;
114 float width = height * (api.GetScreenWidth() / api.GetScreenHeight());
117 GetTransform(transform);
122 points[0] = transform[3];
123 points[1] = transform[3] + transform[2] * length + transform[1] * height + transform[0] * width;
124 points[2] = transform[3] + transform[2] * length + transform[1] * height + transform[0] * -width;
127 points[3] = points[0];
128 points[4] = transform[3] + transform[2] * length + transform[1] * -height + transform[0] * width;
129 points[5] = points[1];
132 points[6] = points[0];
133 points[7] = transform[3] + transform[2] * length + transform[1] * -height + transform[0] * -width;
134 points[8] = points[4];
137 points[9] = points[0];
138 points[10] = points[2];
139 points[11] = points[7];
141 Shape.CreateTris(ARGBF(0.25, 0.5, 0, 1), ShapeFlags.ONCE | ShapeFlags.TRANSP | ShapeFlags.DOUBLESIDE, points, 4);