aafa7cbfa02bfc6fdb538114e76ecf154c95f98c
[raymarcher.git] / Primitives.lua
1 -- Geometric primitives for raymarching
2 require "Vector"
3 local V = Vector
4
5 local function make_sphere(centre, radius, texture)
6    local norm = V.norm
7    return function(p)
8       return {dist = V.norm(p-centre) - radius,
9               texture = texture}
10    end
11 end
12
13 local function make_plane(centre, normal, texture)
14    return function(p)
15       return {dist = normal*(p-centre),
16               texture = texture}
17    end
18 end
19
20 Primitives = {
21    make_sphere = make_sphere,
22    make_plane = make_plane
23 }
24
25 return Primitives