diff options
author | orwell96 <orwell@bleipb.de> | 2018-04-26 23:35:19 +0200 |
---|---|---|
committer | orwell96 <orwell@bleipb.de> | 2018-06-14 17:39:42 +0200 |
commit | caf2bda7bc02f0bbe6dbbeb415e7881158d143b9 (patch) | |
tree | 6cf81bb311517b3ae1108c6533fa8f28c803ed9e /advtrains/helpers.lua | |
parent | 139a26fccce1e622d58f1673284e2addfb0d1ed2 (diff) | |
download | advtrains-caf2bda7bc02f0bbe6dbbeb415e7881158d143b9.tar.gz advtrains-caf2bda7bc02f0bbe6dbbeb415e7881158d143b9.tar.bz2 advtrains-caf2bda7bc02f0bbe6dbbeb415e7881158d143b9.zip |
Fix path_dir to actually be an angle, path item deletion and orientation of wagons
The occupation system as it is now will change. For each position, I will save the index in the train's path,
and implement a callback system. I need this because the occupation window system will not be enough to cover all use cases
(e.g. to make a train stop with it's center or back at a certain position, I need 3 different brake distances, which doesn't fit into the scheme)
Diffstat (limited to 'advtrains/helpers.lua')
-rw-r--r-- | advtrains/helpers.lua | 51 |
1 files changed, 21 insertions, 30 deletions
diff --git a/advtrains/helpers.lua b/advtrains/helpers.lua index 9ad5a8e..9add1b8 100644 --- a/advtrains/helpers.lua +++ b/advtrains/helpers.lua @@ -30,6 +30,11 @@ function advtrains.dirCoordSet(coord, dir) end
advtrains.pos_add_dir = advtrains.dirCoordSet
+function advtrains.pos_add_angle(pos, ang)
+ -- 0 is +Z -> meaning of sin/cos swapped
+ return vector.add(pos, {x=math.sin(ang), y=0, z=math.cos(ang)})
+end
+
function advtrains.dirToCoord(dir)
return advtrains.dirCoordSet({x=0, y=0, z=0}, dir)
end
@@ -104,12 +109,11 @@ end function advtrains.dir_to_angle(dir)
local uvec = vector.normalize(advtrains.dirToCoord(dir))
- return math.atan2(uvec.z, -uvec.x)
+ return math.atan2(uvec.z, uvec.x)
end
-
+local pi, pi2 = math.pi, 2*math.pi
function advtrains.minAngleDiffRad(r1, r2)
- local pi, pi2 = math.pi, 2*math.pi
while r1>pi2 do
r1=r1-pi2
end
@@ -138,19 +142,19 @@ function advtrains.minAngleDiffRad(r1, r2) end
end
-function advtrains.dumppath(path)
- atlog("Dumping a path:")
- if not path then atlog("dumppath: no path(nil)") return end
- local temp_path={}
- for ipt, iit in pairs(path) do
- temp_path[#temp_path+1]={i=ipt, p=iit}
- end
- table.sort(temp_path, function (k1, k2) return k1.i < k2.i end)
- for _,pit in ipairs(temp_path) do
- atlog(pit.i.." > "..minetest.pos_to_string(pit.p))
- end
+
+-- Takes 2 connections (0...AT_CMAX) as argument
+-- Returns the angle median of those 2 positions from the pov
+-- of standing on the cdir1 side and looking towards cdir2
+-- cdir1 - >NODE> - cdir2
+function advtrains.conn_angle_median(cdir1, cdir2)
+ local ang1 = advtrains.dir_to_angle(advtrains.oppd(cdir1))
+ local ang2 = advtrains.dir_to_angle(cdir2)
+ return ang1 + advtrains.minAngleDiffRad(ang1, ang2)/2
end
+-- TODO removed dumppath, where is this used?
+
function advtrains.merge_tables(a, ...)
local new={}
for _,t in ipairs({a,...}) do
@@ -165,22 +169,9 @@ function advtrains.save_keys(tbl, keys) end
return new
end
-function advtrains.yaw_from_3_positions(prev, curr, next)
- local pts=minetest.pos_to_string
- --atprint("p3 "..pts(prev)..pts(curr)..pts(next))
- local prev2curr=math.atan2((curr.x-prev.x), (prev.z-curr.z))
- local curr2next=math.atan2((next.x-curr.x), (curr.z-next.z))
- --atprint("y3 "..(prev2curr*360/(2*math.pi)).." "..(curr2next*360/(2*math.pi)))
- return prev2curr+(advtrains.minAngleDiffRad(prev2curr, curr2next)/2)
-end
-function advtrains.get_wagon_yaw(front, first, second, back, pct)
- local pts=minetest.pos_to_string
- --atprint("p "..pts(front)..pts(first)..pts(second)..pts(back))
- local y2=advtrains.yaw_from_3_positions(second, first, front)
- local y1=advtrains.yaw_from_3_positions(back, second, first)
- --atprint("y "..(y1*360/(2*math.pi)).." "..(y2*360/(2*math.pi)))
- return y1+advtrains.minAngleDiffRad(y1, y2)*pct
-end
+
+-- TODO yaw_from_3_positions and get_wagon_yaw removed
+
function advtrains.get_real_index_position(path, index)
if not path or not index then return end
|