forked from Courseplay/courseplay
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdistance.lua
More file actions
38 lines (29 loc) · 1.36 KB
/
distance.lua
File metadata and controls
38 lines (29 loc) · 1.36 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
-- distance between two coordinates
function courseplay:distance(x1, z1, x2, z2)
if x1 == nil or x2 == nil or z1 == nil or z2 == nil then
return 1000;
end;
local xd = math.pow(x1 - x2, 2);
local zd = math.pow(z1 - z2, 2);
return math.sqrt(math.abs(xd + zd));
end
-- displays arrow and distance to previous point
function courseplay:distanceCheck(vehicle)
local number = vehicle.cp.recordingIsPaused and vehicle.recordnumber - 1 or 1;
local cx, cz = vehicle.Waypoints[number].cx, vehicle.Waypoints[number].cz;
local lx, ly, lz = worldToLocal(vehicle.rootNode, cx, 0, cz);
local arrowRotation = Utils.getYRotationFromDirection(lx, lz);
vehicle.cp.directionArrowOverlay:setRotation(arrowRotation, vehicle.cp.directionArrowOverlay.width/2, vehicle.cp.directionArrowOverlay.height/2);
vehicle.cp.directionArrowOverlay:render();
local ctx, cty, ctz = getWorldTranslation(vehicle.rootNode);
vehicle.cp.infoText = string.format("%s: %.1fm", courseplay:loc("CPDistance"), courseplay:distance(ctx, ctz, cx, cz));
end;
function courseplay:distance_to_object(self, object)
local x, y, z = getWorldTranslation(self.rootNode)
local ox, oy, oz = worldToLocal(object.rootNode, x, y, z)
return Utils.vector2Length(ox, oz)
end
function courseplay:distance_to_point(self, x, y, z)
local ox, oy, oz = worldToLocal(self.cp.DirectionNode, x, y, z)
return Utils.vector2Length(ox, oz)
end