forked from Courseplay/courseplay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
distance.lua
46 lines (35 loc) · 1.66 KB
/
distance.lua
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
44
45
46
-- 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;
return Utils.vector2Length(x2 - x1, z2 - z1);
end
function courseplay:distance3D(x1,y1,z1,x2,y2,z2)
return Utils.vector3Length(x2 - x1, y2 - y1, z2 - z1);
end
-- displays arrow and distance to previous point
function courseplay:distanceCheck(vehicle)
local number = vehicle.cp.recordingIsPaused and vehicle.cp.waypointIndex - 1 or 1;
local cx, cz = vehicle.Waypoints[number].cx, vehicle.Waypoints[number].cz;
local lx, ly, lz = worldToLocal(vehicle.cp.DirectionNode, 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.cp.DirectionNode);
courseplay:setInfoText(vehicle, ('COURSEPLAY_DISTANCE;%d'):format(courseplay:distance(ctx, ctz, cx, cz)));
end;
function courseplay:distanceToObject(vehicle, object)
local x, y, z = getWorldTranslation(vehicle.cp.DirectionNode or vehicle.rootNode);
local ox, oy, oz = worldToLocal(object.rootNode, x, y, z);
return Utils.vector2Length(ox, oz);
end;
function courseplay:distanceToPoint(vehicle, x, y, z)
local ox, oy, oz = worldToLocal(vehicle.cp.DirectionNode, x, y, z);
return Utils.vector2Length(ox, oz);
end;
function courseplay:nodeToNodeDistance(node1, node2)
local x1,y1,z1 = getWorldTranslation(node1);
local x2,y2,z2 = getWorldTranslation(node2);
return Utils.vector3Length(x2 - x1, y2 - y1, z2 - z1);
end;