Added simple object and shape constructors
ray, aabb, obb, plane, sphere, line, triangle
This commit is contained in:
parent
7143dcadae
commit
10f472771b
@ -104,4 +104,77 @@ function utils.is_pot(value)
|
||||
return (frexp(value)) == 0.5
|
||||
end
|
||||
|
||||
--- Simple ray constructor.
|
||||
-- @param position
|
||||
-- @param direction
|
||||
-- @return table
|
||||
function utils.ray(position, direction)
|
||||
return {
|
||||
position = position,
|
||||
direction = direction
|
||||
}
|
||||
end
|
||||
|
||||
--- Simple aabb constructor.
|
||||
-- @param min
|
||||
-- @param max
|
||||
-- @return table
|
||||
function utils.aabb(min, max)
|
||||
return {
|
||||
min = min,
|
||||
max = max
|
||||
end
|
||||
|
||||
--- Simple obb constructor.
|
||||
-- @param min
|
||||
-- @param max
|
||||
-- @param rotation
|
||||
-- @return table
|
||||
function utils.obb(min, max, rotation)
|
||||
return {
|
||||
min = min,
|
||||
max = max,
|
||||
rotation = rotation
|
||||
}
|
||||
end
|
||||
|
||||
--- Simple plane constructor.
|
||||
-- @param position
|
||||
-- @param normal
|
||||
-- @return table
|
||||
function utils.plane(position, normal)
|
||||
return {
|
||||
position = position,
|
||||
normal = normal
|
||||
}
|
||||
end
|
||||
|
||||
--- Simple sphere/circle constructor.
|
||||
-- @param position
|
||||
-- @param radius
|
||||
-- @return table
|
||||
function utils.sphere(position, radius)
|
||||
return {
|
||||
position = position,
|
||||
radius = radius
|
||||
}
|
||||
end
|
||||
|
||||
--- Simple line/segment constructor.
|
||||
-- @param v1
|
||||
-- @param v2
|
||||
-- @return table
|
||||
function utils.line(v1, v2)
|
||||
return { v1, v2 }
|
||||
end
|
||||
|
||||
--- Simple triangle constructor.
|
||||
-- @param v1
|
||||
-- @param v2
|
||||
-- @param v3
|
||||
-- @return table
|
||||
function utils.triangle(v1, v2, v3)
|
||||
return { v1, v2, v3 }
|
||||
end
|
||||
|
||||
return utils
|
||||
|
Loading…
x
Reference in New Issue
Block a user