-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandomPosInMarker.sqf
More file actions
43 lines (34 loc) · 1.65 KB
/
Copy pathrandomPosInMarker.sqf
File metadata and controls
43 lines (34 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
Script to generate a random position, within the bounds of a marker.
Supports any marker type*, size and orientation.
Input: marker name.
Output: position, technically in 3D form, but the z-coord is always 0.
position = "markerName" call compile preprocessfilelinenumbers "randomPosInMarker.sqf";
*except POLYLINE (hand-drawn lines), as they cannot be interacted with via scripts (yet)
by Professor Cupcake
*/
_return = [0,0,0];
if (markerShape _this == "ICON") then {_return = markerPos _this;}
else
{
_dispVector = [0,0];
if (markerShape _this == "RECTANGLE") then
{
_dispVector = [(random 2) - 1, (random 2) - 1]; //Generate displacement from centre of unit square
};
if (markerShape _this == "ELLIPSE") then
{
_direction = random 360; //Generate direction to move from centre
_distance = random 1; //Generate distance from centre of unit circle
_dispVector = [sqrt(_distance)*cos(_direction), sqrt(_distance)*sin(_direction)]; //Get displacement in unit circle, as defined by above distance/direction
};
_size = markerSize _this;
_dispVector = [(_dispVector select 0)*(_size select 0), (_dispVector select 1)*(_size select 1)]; //Scale to size of marker
_angle = -(markerDir _this);
//Rotate to fit marker
//Also adds the z-coord (0)
_dispVector = [((cos _angle)*(_dispVector select 0)) - ((sin _angle)*(_dispVector select 1)), ((sin _angle)*(_dispVector select 0)) + ((cos _angle)*(_dispVector select 1)),0];
_return = (markerPos _this) vectorAdd (_dispVector); //Add displacement to marker pos to get final position
};
if (markerShape _this == "POLYLINE") then {diag_log "You're a monster.";};
_return