14 protected static const float TRACE_DIS = 2000;
28 [
Attribute(defvalue:
"45",
desc:
"When vertical mode is GEOMETRY, hovering over surface with at least this slope will place preview entity below the surface, not on it.\n\nCurrently disabled, entity editing will be disable beyond this angle.")]
31 [
Attribute(defvalue:
"101",
desc:
"When vertical mode is GEOMETRY, hovering over surface with at least this slope will prevent showing preview entity and confirming the change.")]
34 [
Attribute(defvalue:
"1",
desc:
"When adjusting entity height, camera will move together with the entity when above this vertical offset.\nWhen below, the camera will rotate towards the entity instead.")]
72 if (entitiesRemove && entitiesRemove.Count() == 1)
81 if (entitiesInsert && entitiesInsert.Count() == 1)
84 bool isDelegate =
true;
110 set<SCR_EditableEntityComponent> hoverEntities =
new set<SCR_EditableEntityComponent>();
181 vector previewTransform[4];
212 ArmaReforgerScripted game =
GetGame();
216 WorkspaceWidget workspace = game.GetWorkspace();
221 vector cameraPos = workspace.ProjScreenToWorld(clickPos[0], clickPos[1], clickDir,
m_World, -1);
231 ArmaReforgerScripted game =
GetGame();
235 WorkspaceWidget workspace = game.GetWorkspace();
246 protected void GetCursorPos(out vector cameraPos, out vector cursorDir)
248 ArmaReforgerScripted game =
GetGame();
252 WorkspaceWidget workspace = game.GetWorkspace();
257 cameraPos = workspace.ProjScreenToWorld(cursorPos[0], cursorPos[1], cursorDir,
m_World, -1);
261 protected float GetTraceDis(vector pos, vector dir,
float cameraHeight)
263 TraceParam trace =
new TraceParam();
265 trace.End = trace.Start + dir;
266 if (cameraHeight >=
m_World.GetOceanBaseHeight())
267 trace.Flags = TraceFlags.WORLD | TraceFlags.OCEAN;
269 trace.Flags = TraceFlags.WORLD;
273 return m_World.TraceMove(trace,
null);
285 EntitySpawnParams spawnParams =
new EntitySpawnParams();
290 vector previewBoundMin, previewBoundMax;
292 float previewSize = vector.DistanceXZ(previewBoundMin, previewBoundMax);
293 float offsetSize = vector.DistanceXZ(vector.Zero, previewBoundMin + previewBoundMax);
301 vector angles = Math3D.MatrixToAngles(previewTransform);
305 vector orientedTransform[4];
306 Math3D.AnglesToMatrix(angles, orientedTransform);
333 vector cameraPos, cursorDir;
335 cursorDir *= TRACE_DIS;
336 vector pos = transform[3];
338 switch (verticalMode)
378 vector pos = transform[3];
379 transform[3][1] = pos[1] + moveVertical;
392 vector cameraPos = camera.GetWorldTransformAxis(3) + transform[3] - pos;
398 camera.SetOrigin(cameraPos);
403 vector cameraTransform[4] = {vector.Right, vector.Up, vector.Forward, camera.GetWorldTransformAxis(3)};
404 Math3D.DirectionAndUpMatrix(transform[3] - cameraTransform[3], vector.Up, cameraTransform);
405 camera.SetTransform(cameraTransform);
408 camera.SetDirty(
true);
418 vector cameraPos, cursorDir;
421 float dis = vector.DistanceXZ(cameraPos, transform[3]);
422 float angle = cursorDir.VectorToAngles()[1];
423 vector tracePos = cameraPos + cursorDir * (dis / Math.Cos(angle * Math.DEG2RAD));
424 transform[3][1] = tracePos[1];
432 string text =
string.Format(
" %1 m",
m_PreviewEntityManager.GetPreviewHeightAboveTerrain().ToString(lenDec: 3));
433 DebugTextWorldSpace.Create(
m_World, text, DebugTextFlags.ONCE | DebugTextFlags.FACE_CAMERA, transform[3][0], transform[3][1], transform[3][2], color: Color.PINK);
439 protected void Rotate(
float tDelta, out vector transform[4],
float rotationValue)
441 vector angles = transform[2].VectorToAngles();
442 bool freeRotation =
true;
446 if (!
RotateInSlot(target, rotationValue, angles, freeRotation))
453 angles[0] = angles[0] + rotationValue;
457 Math3D.AnglesToMatrix(angles, basis);
475 float step = slotEntity.GetRotationStep();
482 angles[0] = angles[0] + step * rotationValue.Sign();
502 vector targetTransform[4];
503 target.GetTransform(targetTransform);
504 pivotPos = targetTransform[3];
513 vector cameraPos, cursorDir;
516 float dir = (worldPos - pivotPos).VectorToAngles()[0] -
m_vAnglesOrigin[0];
519 Math3D.AnglesToMatrix(Vector(dir, 0, 0), basis);
539 TraceParam trace =
new TraceParam();
540 trace.Start = cameraPos;
541 trace.End = trace.Start + cursorDir;
542 trace.LayerMask = EPhysicsLayerPresets.Projectile;
543 trace.Flags = TraceFlags.ENTS | TraceFlags.WORLD;
544 if (cameraPos[1] >=
m_World.GetOceanBaseHeight())
545 trace.Flags |= TraceFlags.OCEAN;
548 float traceCursor =
m_World.TraceMove(trace,
null);
551 if (traceCursor == 1)
554 worldPos = cameraPos + cursorDir * traceCursor;
557 if (!trace.TraceEnt || trace.TraceEnt.Type() == GenericTerrainEntity || trace.TraceEnt.Type() == RoadEntity)
562 float dotProduct = vector.Dot(trace.TraceNorm, vector.Up);
563 float slope = 90 - Math.Tan(dotProduct) * Math.RAD2DEG;
617 vector offsetPos = cameraPos;
619 offsetPos -= vector.Up * heightATL;
621 float traceDis =
GetTraceDis(offsetPos, cursorDir, cameraPos[1]);
625 worldPos = offsetPos + cursorDir * traceDis;
626 worldPos[1] = worldPos[1] + heightATL;
633 if (cursorDir[1] > 0)
650 traceDis =
GetTraceDis(cameraPos, cursorDir, cameraPos[1]);
660 traceDis = Math3D.IntersectionRayBox(cameraPos, cameraPos + cursorDir, Vector(-
float.MAX, heightASL, -
float.MAX), Vector(
float.MAX, heightASL,
float.MAX));
666 worldPos = cameraPos + cursorDir * traceDis;
667 worldPos[1] = heightASL;
683 bool canTransform =
true;
684 bool instant =
false;
685 vector previewTransform[4];
707 float moveVertical =
m_InputManagerBase.GetActionValue(
"EditorTransformMoveVertical") * tDelta;
708 float rotateYaw =
m_InputManagerBase.GetActionValue(
"EditorTransformRotateYaw") * tDelta;
794 ArmaReforgerScripted game =
GetGame();
818 super.HandlerDeattached(w);