Arma Reforger Explorer
1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Toggle main menu visibility
Loading...
Searching...
No Matches
SCR_ShapeDistanceRuler.c
Go to the documentation of this file.
1
class
SCR_ShapeDistanceRuler
2
{
3
vector
m_aShapeMatrix[4];
4
protected
ref array<ref array<vector>>
m_aRelativeSegments
;
5
6
//------------------------------------------------------------------------------------------------
9
float
GetDistance
(
vector
relativePos)
10
{
11
float
resultSq =
float
.INFINITY;
12
foreach
(
int
i, array<vector> segment :
m_aRelativeSegments
)
13
{
14
float
distanceSq =
Math3D
.PointLineSegmentDistanceSqr(relativePos, segment[0], segment[1]);
15
if
(distanceSq < resultSq)
16
resultSq = distanceSq;
17
}
18
19
if
(resultSq ==
float
.INFINITY)
20
return
-1;
21
22
return
Math
.Sqrt(resultSq);
23
}
24
25
//------------------------------------------------------------------------------------------------
28
float
GetDistanceXZ
(
vector
relativePos)
29
{
30
relativePos[1] = 0;
31
32
float
resultSq =
float
.INFINITY;
33
foreach
(
int
i, array<vector> segment :
m_aRelativeSegments
)
34
{
35
vector
start = segment[0];
36
vector
end = segment[1];
37
start[1] = 0;
38
end[1] = 0;
39
40
float
distanceSq =
Math3D
.PointLineSegmentDistanceSqr(relativePos, start, end);
41
if
(distanceSq < resultSq)
42
resultSq = distanceSq;
43
}
44
45
if
(resultSq ==
float
.INFINITY)
46
return
-1;
47
48
return
Math
.Sqrt(resultSq);
49
}
50
51
//------------------------------------------------------------------------------------------------
56
bool
IsWithinDistance
(
vector
relativePos,
float
distance
,
bool
equalCounts =
true
)
57
{
58
distance
*=
distance
;
// square it
59
foreach
(
int
i, array<vector> segment :
m_aRelativeSegments
)
60
{
61
if
(equalCounts)
62
{
63
if
(
Math3D
.PointLineSegmentDistanceSqr(relativePos, segment[0], segment[1]) <=
distance
)
64
return
true
;
65
}
66
else
67
{
68
if
(
Math3D
.PointLineSegmentDistanceSqr(relativePos, segment[0], segment[1]) <
distance
)
69
return
true
;
70
}
71
}
72
73
return
false
;
74
}
75
76
//------------------------------------------------------------------------------------------------
81
bool
IsWithinDistanceXZ
(
vector
relativePos,
float
distance
,
bool
equalCounts =
true
)
82
{
83
relativePos[1] = 0;
84
85
distance
*=
distance
;
// square it
86
foreach
(
int
i, array<vector> segment :
m_aRelativeSegments
)
87
{
88
vector
start = segment[0];
89
vector
end = segment[1];
90
start[1] = 0;
91
end[1] = 0;
92
93
if
(equalCounts)
94
{
95
if
(
Math3D
.PointLineSegmentDistanceSqr(relativePos, start, end) <=
distance
)
96
return
true
;
97
}
98
else
99
{
100
if
(
Math3D
.PointLineSegmentDistanceSqr(relativePos, start, end) <
distance
)
101
return
true
;
102
}
103
}
104
105
return
false
;
106
}
107
108
//------------------------------------------------------------------------------------------------
112
vector
CoordToLocal
(
vector
worldPos)
113
{
114
return
worldPos.InvMultiply4(m_aShapeMatrix);
115
}
116
117
//------------------------------------------------------------------------------------------------
121
static
SCR_ShapeDistanceRuler
CreateFromShape
(notnull ShapeEntity shapeEntity)
122
{
123
array<vector> tesselatedRelPoints = {};
124
shapeEntity.GenerateTesselatedShape(tesselatedRelPoints);
125
126
int
countMinus1 = tesselatedRelPoints.Count() - 1;
127
if
(countMinus1 < 0)
128
{
129
Print
(
"[SCR_ShapeDistanceRuler] empty shape provided"
,
LogLevel
.WARNING);
130
return
null;
131
}
132
133
SCR_ShapeDistanceRuler
result =
new
SCR_ShapeDistanceRuler
();
134
135
shapeEntity.GetTransform(result.m_aShapeMatrix);
136
result.
m_aRelativeSegments
= {};
137
result.
m_aRelativeSegments
.Reserve(countMinus1);
138
139
vector
prevPoint;
140
foreach
(
int
i,
vector
currPoint : tesselatedRelPoints)
141
{
142
if
(i != 0)
143
result.
m_aRelativeSegments
.Insert({ prevPoint, currPoint });
144
145
prevPoint = currPoint;
146
}
147
148
return
result;
149
}
150
151
//------------------------------------------------------------------------------------------------
152
// constructor - not available for creation
153
protected
void
SCR_ShapeDistanceRuler
();
154
}
distance
float distance
Definition
SCR_DestructibleTreeV2.c:29
Math3D
Definition
Math3D.c:13
Math
Definition
Math.c:13
SCR_ShapeDistanceRuler::IsWithinDistance
bool IsWithinDistance(vector relativePos, float distance, bool equalCounts=true)
Definition
SCR_ShapeDistanceRuler.c:56
SCR_ShapeDistanceRuler::SCR_ShapeDistanceRuler
void SCR_ShapeDistanceRuler()
SCR_ShapeDistanceRuler::GetDistance
float GetDistance(vector relativePos)
Definition
SCR_ShapeDistanceRuler.c:9
SCR_ShapeDistanceRuler::IsWithinDistanceXZ
bool IsWithinDistanceXZ(vector relativePos, float distance, bool equalCounts=true)
Definition
SCR_ShapeDistanceRuler.c:81
SCR_ShapeDistanceRuler::CoordToLocal
vector CoordToLocal(vector worldPos)
Definition
SCR_ShapeDistanceRuler.c:112
SCR_ShapeDistanceRuler::GetDistanceXZ
float GetDistanceXZ(vector relativePos)
Definition
SCR_ShapeDistanceRuler.c:28
SCR_ShapeDistanceRuler::CreateFromShape
static SCR_ShapeDistanceRuler CreateFromShape(notnull ShapeEntity shapeEntity)
Definition
SCR_ShapeDistanceRuler.c:121
SCR_ShapeDistanceRuler::m_aRelativeSegments
ref array< ref array< vector > > m_aRelativeSegments
Definition
SCR_ShapeDistanceRuler.c:4
vector
Definition
vector.c:13
Print
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
LogLevel
Enum with severity of the logging message.
Definition
LogLevel.c:14
scripts
Game
Generators
Common
SCR_ShapeDistanceRuler.c
Generated by
1.17.0