http://dev.minetest.net/vector doesn't have anything to say about it.
print("Vector",dump(vector.direction({x=1,y=2,z=3},{x=4,y=5,z=6})))
Vector {
y = 0.11111111111111,
x = 0.11111111111111,
z = 0.11111111111111
}
print("Vector",dump(vector.direction({x=1,y=1,z=1},{x=1,y=1,z=1})))
Vector {
y = nan,
x = nan,
z = nan
}
print("Vector",dump(vector.direction({x=1,y=1,z=1},{x=2,y=2,z=2})))
Vector {
y = 1,
x = 1,
z = 1
}
print("Vector",dump(vector.direction({x=5,y=3,z=4},{x=1,y=5,z=7})))
Vector {
y = 0.5,
x = -1,
z = 0.75
}
print("Vector",dump(vector.direction({x=1,y=2,z=3},{x=4,y=5,z=6})))
print("Vector",dump(vector.direction({x=0,y=0,z=0},{x=3,y=3,z=3})))
print("Vector2",dump(vector.normalize{x=3,y=3,z=3}))
print("Vector2",dump{x=3/math.sqrt(3^2+3^2+3^2),y=3/math.sqrt(3^2+3^2+3^2),z=3/math.sqrt(3^2+3^2+3^2)})
print("Vector2",dump{x=1/math.sqrt(3),y=1/math.sqrt(3),z=1/math.sqrt(3)})
local function calc_velocity(pos1, pos2, old_vel, power)
local vel = vector.direction(pos1, pos2)
vel = vector.normalize(vel)
vel = vector.multiply(vel, power)
-- Divide by distance
local dist = vector.distance(pos1, pos2)
dist = math.max(dist, 1)
vel = vector.divide(vel, dist)
-- Add old velocity
vel = vector.add(vel, old_vel)
return vel
end
local function node_contents_within_reach(center, direction, position)
local cluster = node_cuboids(center)
local i, j = box_distance_minimum(direction, position, cluster)
local reach = point_interval(node_ray_intersection(vector.direction(center, position), center), position)
local value = false
if not (i == 0) then
if (reach.x < 4.0) and (reach.y < 4.0) and (reach.z < 4.0) then
if (math.abs(vector.distance(box_side_intersection(direction, position, cluster[i], j), position)) < 5.0) then
value = true
end
end
elseif (i == 0) then
value = true
end
return value
end
local function calc_velocity(pos1, pos2, old_vel, power)
local vel = vector.subtract(pos2, pos1)
vel = vector.normalize(vel)
vel = vector.multiply(vel, power)
[…]
local function calc_velocity(pos1, pos2, old_vel, power)
local vel = vector.subtract(pos2, pos1)
vel = vector.multiply(vel, power / vector.length(vel))
[…]
normalise(to - from)
where
normalise(A) = A / |A|
burli wrote:I'm not sure, but I think this function calculates a vector between two positions
function vector.direction(a, b)
return vector.normalize(vector.subtract(b, a))
end
Users browsing this forum: No registered users and 17 guests