Arma Reforger Explorer
1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Toggle main menu visibility
Loading...
Searching...
No Matches
MeasureTool.c
Go to the documentation of this file.
1
[WorkbenchToolAttribute(
2
"Measure Tool"
,
3
"Measure length along a 3D line\n"
+
4
"Line segment length is rendered at the center of segment.\nTotal length rendered next to the cursor.\n\n"
+
5
"LMB - Start measuring\nESC - Cancel measuring"
,
6
awesomeFontCode: 0xF545)]
7
class
MeasureTool
: WorldEditorTool
8
{
9
[
Attribute
(
desc
:
"Measure against objects"
,
category
:
"General"
)]
10
protected
bool
m_bCheckAgainstEntities
;
11
12
protected
ref
DebugTextScreenSpace
m_Text
;
13
protected
ref
DebugTextScreenSpace
m_Crosshair
;
14
protected
ref array<ref DebugTextWorldSpace>
m_aSegmentLengths
;
15
protected
ref
Shape
m_Polyline
;
16
17
protected
vector
m_vPrevious3DPoint
;
18
protected
vector
m_vCurrent3DPoint
;
19
protected
float
m_fDistancePrevious
;
20
protected
float
m_fDistanceCurrent
;
21
protected
vector
m_aLinePoints
[1000];
22
protected
int
m_iLinePointsCount
;
23
protected
float
m_fLastX
;
24
protected
float
m_fLastY
;
25
protected
bool
m_bActivated
=
false
;
26
27
//------------------------------------------------------------------------------------------------
28
override
void
OnMouseMoveEvent
(
float
x,
float
y)
29
{
30
vector
traceStart;
31
vector
traceEnd;
32
vector
traceDir;
33
34
m_Crosshair
.SetPosition(x, y);
35
m_Crosshair
.SetText(
"+"
);
36
m_Text
.SetPosition(x, y);
37
38
TraceFlags
traceFlags =
TraceFlags
.WORLD;
39
if
(
m_bCheckAgainstEntities
)
40
traceFlags =
TraceFlags
.ENTS |
TraceFlags
.WORLD;
41
42
if
(m_API.TraceWorldPos(x, y, traceFlags, traceStart, traceEnd, traceDir))
43
{
44
m_vCurrent3DPoint
= traceEnd;
45
46
if
(
m_iLinePointsCount
>= 1)
47
{
48
m_fDistanceCurrent
= (
m_vPrevious3DPoint
-
m_vCurrent3DPoint
).Length();
49
m_Text
.SetText(
" "
+ (
m_fDistanceCurrent
+
m_fDistancePrevious
).
ToString
() +
" m"
);
50
m_aLinePoints
[
m_iLinePointsCount
] = traceEnd;
51
m_Polyline
=
Shape
.CreateLines(
ARGB
(255, 255, 255, 255),
ShapeFlags
.NOZBUFFER |
ShapeFlags
.TRANSP,
m_aLinePoints
,
m_iLinePointsCount
+ 1);
52
m_fLastX
= x;
53
m_fLastY
= y;
54
}
55
}
56
else
57
{
58
// line is being drawn and cursor is out of terrain bounds, stick cursor and length info to terrain's edge
59
if
(
m_iLinePointsCount
>= 1)
60
{
61
m_Crosshair
.SetPosition(
m_fLastX
,
m_fLastY
);
62
m_Text
.SetPosition(
m_fLastX
,
m_fLastY
);
63
}
64
else
65
// line is not being drawn and cursor is out of terrain bounds
66
{
67
m_Crosshair
.SetText(
""
);
68
}
69
}
70
}
71
72
//------------------------------------------------------------------------------------------------
73
override
void
OnMousePressEvent
(
float
x,
float
y, WETMouseButtonFlag buttons)
74
{
75
vector
traceStart;
76
vector
traceEnd;
77
vector
traceDir;
78
vector
text_position;
79
80
if
(
m_iLinePointsCount
== 0)
81
{
82
m_vPrevious3DPoint
=
m_vCurrent3DPoint
;
83
}
84
85
TraceFlags
traceFlags =
TraceFlags
.WORLD;
86
if
(
m_bCheckAgainstEntities
)
87
traceFlags =
TraceFlags
.ENTS |
TraceFlags
.WORLD;
88
89
if
(m_API.TraceWorldPos(x, y, traceFlags, traceStart, traceEnd, traceDir))
90
{
91
m_vCurrent3DPoint
= traceEnd;
92
m_fDistancePrevious
+=
m_fDistanceCurrent
;
93
94
//Render line segments length
95
if
(
m_iLinePointsCount
!= 0)
96
{
97
text_position =
m_vPrevious3DPoint
+ ((
m_vCurrent3DPoint
-
m_vPrevious3DPoint
).Normalized() * (
m_vPrevious3DPoint
-
m_vCurrent3DPoint
).Length() * 0.5);
98
m_aSegmentLengths
.Insert(
99
DebugTextWorldSpace
.Create(
100
m_API.GetWorld(),
101
(
m_vPrevious3DPoint
-
m_vCurrent3DPoint
).Length().ToString() +
" m"
,
102
0,
103
text_position[0],
104
text_position[1],
105
text_position[2],
106
15,
107
ARGBF
(1, 1, 1, 1),
108
0x00000000));
109
}
110
111
m_aLinePoints
[
m_iLinePointsCount
] =
m_vCurrent3DPoint
;
112
// Print(linePts[m_iLinePointsCount]);
113
m_iLinePointsCount
++;
114
// Print(m_iLinePointsCount);
115
m_vPrevious3DPoint
=
m_vCurrent3DPoint
;
116
}
117
}
118
119
//------------------------------------------------------------------------------------------------
120
override
void
OnKeyPressEvent
(
KeyCode
key,
bool
isAutoRepeat)
121
{
122
//Cancel measuring
123
if
(key ==
KeyCode
.KC_ESCAPE && isAutoRepeat ==
false
)
124
{
125
m_Text
.SetText(
""
);
126
m_aSegmentLengths
.Clear();
127
m_fDistancePrevious
= 0.0;
128
m_fDistanceCurrent
= 0.0;
129
m_vPrevious3DPoint
=
"0 0 0"
;
130
m_iLinePointsCount
= 0;
131
m_Polyline
=
Shape
.CreateLines(
ARGB
(255, 255, 0, 0),
ShapeFlags
.NOZBUFFER |
ShapeFlags
.TRANSP,
m_aLinePoints
,
m_iLinePointsCount
+ 1);
132
}
133
}
134
135
//------------------------------------------------------------------------------------------------
136
void
Init
()
137
{
138
m_Text
=
DebugTextScreenSpace
.Create(
139
m_API.GetWorld(),
""
,
140
DebugTextFlags
.DONT_SCALE_POS,
141
100, 100, 14,
ARGBF
(1, 1, 1, 1), 0x00000000
142
);
143
m_Crosshair
=
DebugTextScreenSpace
.Create(
144
m_API.GetWorld(),
""
,
145
DebugTextFlags
.DONT_SCALE_POS |
DebugTextFlags
.CENTER,
146
0, 0, 30,
ARGBF
(1, 1, 1, 1), 0x00000000
147
);
148
m_fDistancePrevious
= 0.0;
149
m_aSegmentLengths
= {};
150
}
151
152
//------------------------------------------------------------------------------------------------
153
void
Deinit
()
154
{
155
m_Text
= null;
156
m_Crosshair
= null;
157
m_aSegmentLengths
.Clear();
158
m_fDistancePrevious
= 0.0;
159
m_fDistanceCurrent
= 0.0;
160
m_vPrevious3DPoint
=
"0 0 0"
;
161
m_iLinePointsCount
= 0;
162
m_Polyline
= null;
163
}
164
165
//------------------------------------------------------------------------------------------------
166
override
void
OnActivate
()
167
{
168
Init
();
169
m_bActivated
=
true
;
170
}
171
172
173
override
void
OnDeActivate
()
174
{
175
Deinit
();
176
m_bActivated
=
false
;
177
}
178
179
override
void
OnAfterLoadWorld
()
180
{
181
if
(
m_bActivated
)
182
{
183
// Loaded a world while the tool was activated
184
// => everything was deinitialized in OnBeforeUnloadWorld
185
// => reinit
186
Init
();
187
}
188
}
189
override
void
OnBeforeUnloadWorld
()
190
{
191
if
(
m_bActivated
)
192
{
193
// Everything is invalid => deinitialize
194
Deinit
();
195
}
196
}
197
198
};
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition
SCR_RespawnBriefingComponent.c:17
category
params category
Definition
SCR_VehicleDamageManagerComponent.c:302
DebugTextScreenSpace
Definition
DebugTextScreenSpace.c:13
DebugTextWorldSpace
Definition
DebugTextWorldSpace.c:13
MeasureTool
Definition
MeasureTool.c:8
MeasureTool::m_iLinePointsCount
int m_iLinePointsCount
Definition
MeasureTool.c:22
MeasureTool::OnMousePressEvent
override void OnMousePressEvent(float x, float y, WETMouseButtonFlag buttons)
Definition
MeasureTool.c:73
MeasureTool::OnKeyPressEvent
override void OnKeyPressEvent(KeyCode key, bool isAutoRepeat)
Definition
MeasureTool.c:120
MeasureTool::m_fLastX
float m_fLastX
Definition
MeasureTool.c:23
MeasureTool::Init
void Init()
Definition
MeasureTool.c:136
MeasureTool::m_vPrevious3DPoint
vector m_vPrevious3DPoint
Definition
MeasureTool.c:17
MeasureTool::m_Text
ref DebugTextScreenSpace m_Text
Definition
MeasureTool.c:12
MeasureTool::m_aSegmentLengths
ref array< ref DebugTextWorldSpace > m_aSegmentLengths
Definition
MeasureTool.c:14
MeasureTool::m_fLastY
float m_fLastY
Definition
MeasureTool.c:24
MeasureTool::OnMouseMoveEvent
override void OnMouseMoveEvent(float x, float y)
Definition
MeasureTool.c:28
MeasureTool::Deinit
void Deinit()
Definition
MeasureTool.c:153
MeasureTool::OnDeActivate
override void OnDeActivate()
Definition
MeasureTool.c:173
MeasureTool::OnActivate
override void OnActivate()
Definition
MeasureTool.c:166
MeasureTool::m_aLinePoints
vector m_aLinePoints[1000]
Definition
MeasureTool.c:21
MeasureTool::m_bActivated
bool m_bActivated
Definition
MeasureTool.c:25
MeasureTool::m_bCheckAgainstEntities
bool m_bCheckAgainstEntities
Definition
MeasureTool.c:10
MeasureTool::OnBeforeUnloadWorld
override void OnBeforeUnloadWorld()
Definition
MeasureTool.c:189
MeasureTool::m_vCurrent3DPoint
vector m_vCurrent3DPoint
Definition
MeasureTool.c:18
MeasureTool::m_Polyline
ref Shape m_Polyline
Definition
MeasureTool.c:15
MeasureTool::m_Crosshair
ref DebugTextScreenSpace m_Crosshair
Definition
MeasureTool.c:13
MeasureTool::m_fDistanceCurrent
float m_fDistanceCurrent
Definition
MeasureTool.c:20
MeasureTool::OnAfterLoadWorld
override void OnAfterLoadWorld()
Definition
MeasureTool.c:179
MeasureTool::m_fDistancePrevious
float m_fDistancePrevious
Definition
MeasureTool.c:19
Shape
Instance of created debug visualizer.
Definition
Shape.c:14
vector
Definition
vector.c:13
DebugTextFlags
DebugTextFlags
Definition
DebugTextFlags.c:13
ShapeFlags
ShapeFlags
Definition
ShapeFlags.c:13
Attribute
SCR_FieldOfViewSettings Attribute
Definition
SendGoalMessage.c:170
KeyCode
KeyCode
Definition
KeyCode.c:13
ToString
proto external string ToString()
Plain C++ pointer, no weak pointers, no memory management.
TraceFlags
TraceFlags
Definition
TraceFlags.c:13
ARGBF
proto int ARGBF(float fa, float fr, float fg, float fb)
Converts <0.0, 1.0> ARGB into color.
ARGB
proto int ARGB(int a, int r, int g, int b)
scripts
WorkbenchCommon
MeasureTool.c
Generated by
1.17.0