Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_EditorSnapManualCameraComponent.c
Go to the documentation of this file.
1 
4 [BaseContainerProps(), SCR_BaseManualCameraComponentTitle()]
6 {
7  [Attribute("8", desc: "How agressively does the camera rotates towards the entity under cursor.")]
8  private float m_fSnapStrength;
9 
10  [Attribute("0.25", uiwidget: UIWidgets.Slider, desc: "When hovering over geometry, what's its maximum screen ration for the snap to happen.\nIt would be impractical to snap to too large objects, especially when they're encompassing the camera (e.g., building interiors).", params: "0 1 0.01")]
11  private float m_fMaxGeometryRatio;
12 
13  private bool m_bSnapped;
14  private SCR_EditableEntityComponent m_EntityPrev;
15  private vector m_vPosPrev;
16  private vector m_vRotPrev;
17 
18  private SCR_HoverEditableEntityFilter m_HoverManager;
19  private SCR_TransformingEditorComponent m_TransformingManager;
20  private SCR_PreviewEntityEditorComponent m_PreviewManager;
21 
22  //------------------------------------------------------------------------------------------------
23  override void EOnCameraFrame(SCR_ManualCameraParam param)
24  {
25  if (!param.isManualInputEnabled)
26  return;
27 
28  if (!m_HoverManager)
29  {
30  Print(string.Format("%1 requires SCR_HoverEditableEntityFilter on the editor manager!", Type()), LogLevel.ERROR);
31  SetEnabled(false);
32  return;
33  }
34 
35  if (!GetInputManager() || GetInputManager().IsUsingMouseAndKeyboard())
36  return;
37 
38  bool isDelegate = false;
39  SCR_EditableEntityComponent entity = m_HoverManager.GetEntityUnderCursor(isDelegate);
40  if (!entity)
41  {
42  ResetSnap(param.transform, entity);
43  return;
44  }
45 
46  //--- Ignore currently edited entity
47  if (m_TransformingManager && m_TransformingManager.IsEditing(entity))
48  return;
49 
50  //--- Ignore when transforming an entity vertically (would mess up camera snapping there)
51  if (m_PreviewManager && m_PreviewManager.IsMovingVertically())
52  return;
53 
54  //--- Geometry (not icon) under cursor, check if it's not too close
55  if (!isDelegate)
56  {
57  vector bboxMin, bboxMax;
58  IEntity owner = entity.GetOwner();
59  owner.GetWorldBounds(bboxMin, bboxMax);
60  if (vector.Distance(bboxMin, bboxMax) > 0)
61  {
62  WorkspaceWidget workspace = GetGame().GetWorkspace();
63  BaseWorld world = owner.GetWorld();
64  bboxMin = workspace.ProjWorldToScreen(bboxMin, world);
65  bboxMax = workspace.ProjWorldToScreen(bboxMax, world);
66  int refW, refH;
67  WidgetManager.GetReferenceScreenSize(refW, refH);
68  if (vector.Distance(bboxMin, bboxMax) / refH > m_fMaxGeometryRatio)
69  {
70  //--- Too close, ignore
71  ResetSnap(param.transform, entity);
72  return;
73  }
74  }
75  }
76 
77  //--- Don't start snap when camera is moving
78  if (!m_bSnapped && (entity != m_EntityPrev || param.transform[3] != m_vPosPrev || param.transform[2] != m_vRotPrev))
79  {
80  ResetSnap(param.transform, entity);
81  return;
82  }
83 
84  //--- Snap to entity's composition
85  //entity = m_HoverManager.GetParentBelowCurrentLayer(entity);
86 
87  vector target;
88  if (!entity.GetPos(target))
89  return;
90 
91  target = CoordToCamera(target);
92 
93  target = vector.Direction(param.transform[3], target).Normalized();
94  param.transform[2] = vector.Lerp(param.transform[2], target, Math.Min(m_fSnapStrength * param.timeSlice, 1));
95 
96  m_bSnapped = true;
97  m_EntityPrev = entity;
98  m_vPosPrev = param.transform[3];
99  m_vRotPrev = param.transform[2];
100 
101  param.isDirty = true;
102  }
103 
104  //------------------------------------------------------------------------------------------------
105  protected bool ResetSnap(vector transformationNew[4], SCR_EditableEntityComponent entity)
106  {
107  m_EntityPrev = entity;
108  m_vPosPrev = transformationNew[3];
109  m_vRotPrev = transformationNew[2];
110  m_bSnapped = false;
111  return false;
112  }
113 
114  //------------------------------------------------------------------------------------------------
115  override bool EOnCameraInit()
116  {
119 
121  if (entitiesManager)
122  m_HoverManager = SCR_HoverEditableEntityFilter.Cast(entitiesManager.GetFilter(EEditableEntityState.HOVER));
123 
124  return true;
125  }
126 }
EEditableEntityState
EEditableEntityState
Definition: EEditableEntityState.c:37
SCR_BaseManualCameraComponent
Parent class from which all SCR_ManualCamera components inherit.
Definition: SCR_BaseManualCameraComponent.c:5
SetEnabled
void SetEnabled(bool enabled)
Definition: SCR_BaseManualCameraComponent.c:91
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_PreviewManager
private SCR_PreviewEntityEditorComponent m_PreviewManager
Definition: SCR_CursorEditorUIComponent.c:22
SCR_EntitiesManagerEditorComponent
Definition: SCR_EntitiesManagerEditorComponent.c:13
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
CoordToCamera
protected vector CoordToCamera(vector pos)
Definition: SCR_BaseManualCameraComponent.c:71
SCR_TransformingEditorComponent
Definition: SCR_TransformingEditorComponent.c:33
m_HoverManager
SCR_BaseActionsEditorComponentClass m_HoverManager
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_HoverEditableEntityFilter
Definition: SCR_HoverEditableEntityFilter.c:6
SCR_ManualCameraParam
Parameter for carrying information between individual camera components.
Definition: SCR_ManualCameraParam.c:5
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
GetInputManager
protected InputManager GetInputManager()
Definition: SCR_BaseManualCameraComponent.c:65
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
SCR_EditorSnapManualCameraComponent
Snap camera to specific target.
Definition: SCR_EditorSnapManualCameraComponent.c:5
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468
SCR_PreviewEntityEditorComponent
Definition: SCR_PreviewEntityEditorComponent.c:12