15 protected ref array<ref SCR_CameraCoordinates> m_aPositions;
22 bool GetRandomPosition(out vector transform[4])
24 if (!m_aPositions || m_aPositions.Count() == 0)
return false;
27 coordinates.GetTransform(transform);
39 BaseGameMode gameMode =
GetGame().GetGameMode();
43 if (result)
return result;
46 GenericWorldEntity world =
GetGame().GetWorldEntity();
50 if (result)
return result;
57 override void _WB_OnContextMenu(IEntity owner,
int id)
60 if (!genericOwner)
return;
62 WorldEditorAPI api = genericOwner._WB_GetEditorAPI();
65 BaseWorld world = api.GetWorld();
68 api.BeginEntityAction();
70 IEntitySource ownerSource = api.EntityToSource(owner);
71 int index = m_aPositions.Count();
72 array<ref ContainerIdPathEntry> path = {
new ContainerIdPathEntry(Type().ToString())};
73 api.CreateObjectArrayVariableMember(ownerSource, path,
"m_aPositions",
"SCR_CameraCoordinates",
index);
76 world.GetCurrentCamera(transform);
77 vector pos = transform[3];
78 vector dir = Math3D.MatrixToAngles(transform);
80 path.Insert(
new ContainerIdPathEntry(
"m_aPositions",
index));
81 api.SetVariableValue(ownerSource, path,
"m_vCameraPosition",
string.Format(
"%1 %2 %3", pos[0], pos[1], pos[2]));
82 api.SetVariableValue(ownerSource, path,
"m_vCameraAngles",
string.Format(
"%1 %2 %3", dir[1], dir[0], dir[2]));
85 api.EndEntityAction();
87 override array<ref WB_UIMenuItem> _WB_GetContextMenuItems(IEntity owner)
89 return {
new WB_UIMenuItem(
"Add current camera coordinates", 0) };
91 override void _WB_AfterWorldUpdate(IEntity owner,
float timeSlice)
93 if (!m_aPositions)
return;
96 if (!genericOwner)
return;
98 WorldEditorAPI api = genericOwner._WB_GetEditorAPI();
99 if (!api || !api.IsEntitySelected(api.EntityToSource(owner)))
return;
108 coordinate.GetTransform(transform);
112 points[0] = transform[3];
113 points[1] = transform[3] + transform[2] * length + transform[1] * height + transform[0] * -width;
114 points[2] = transform[3] + transform[2] * length + transform[1] * height + transform[0] * width;
116 points[3] = transform[3];
117 points[4] = transform[3] + transform[2] * length + transform[1] * -height + transform[0] * width;
118 points[5] = transform[3] + transform[2] * length + transform[1] * height + transform[0] * width;
120 points[6] = transform[3];
121 points[7] = transform[3] + transform[2] * length + transform[1] * -height + transform[0] * -width;
122 points[8] = transform[3] + transform[2] * length + transform[1] * -height + transform[0] * width;
124 points[9] = transform[3];
125 points[10] = transform[3] + transform[2] * length + transform[1] * -height + transform[0] * -width;
126 points[11] = transform[3] + transform[2] * length + transform[1] * height + transform[0] * -width;
128 Shape.CreateTris(ARGBF(0.1, 1, 0, 1), ShapeFlags.ONCE | ShapeFlags.TRANSP | ShapeFlags.DOUBLESIDE, points, 4);
129 Shape.CreateSphere(ARGBF(1, 1, 0, 1), ShapeFlags.ONCE, transform[3], 1);
138 [
Attribute(
desc:
"Camera position in format lateral, vertical, longitudinal")]
139 protected vector m_vCameraPosition;
141 [
Attribute(
desc:
"Camera angles in format pitch, yaw, roll\n(the same as World Editor camera, you can copy the value from there)")]
142 protected vector m_vCameraAngles;
144 void GetTransform(out vector transform[4])
146 vector angles = Vector(m_vCameraAngles[1], m_vCameraAngles[0], m_vCameraAngles[2]);
147 Math3D.AnglesToMatrix(angles, transform);
148 transform[3] = m_vCameraPosition;