X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=blobdiff_plain;f=Primitives.lua;h=c13966be230c0d4eb89bd3eee180010531a04f2f;hb=0ac50eee0cbfd76513c03244f3a7a5643f80af91;hp=88a3849cd74bc3950ef506a7c7be71f38a876b0c;hpb=c86e8c7637a7368950add912b9bce244bbf9e689;p=raymarcher.git diff --git a/Primitives.lua b/Primitives.lua index 88a3849..c13966b 100644 --- a/Primitives.lua +++ b/Primitives.lua @@ -3,14 +3,32 @@ require "Vector" local V = Vector local function make_sphere(centre, radius, texture) - return function(p) - return {dist = V.norm(p-centre) - radius, - texture = texture} - end + local norm = V.norm + return function(p) + return {dist = V.norm(p-centre) - radius, + texture = texture} + end end +local function make_plane(centre, normal, texture) + return function(p) + return {dist = normal*(p-centre), + texture = texture} + end +end + +local function make_pipe(centre, radius, axis, texture) + return function(p) + return {dist = V.norm(V.cross(p-centre, axis)) - radius, + texture = texture} + end +end + + Primitives = { - make_sphere = make_sphere + make_sphere = make_sphere, + make_plane = make_plane, + make_pipe = make_pipe } return Primitives