From 2628b42a54ae36ac4706114ed7a0abb6d52eefd5 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Thu, 1 Dec 2022 08:43:57 -0500 Subject: [PATCH] Fix rendering bugs --- src/Render/Camera.idr | 6 ++++-- src/Render/Scene.idr | 3 +-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Render/Camera.idr b/src/Render/Camera.idr index 197138f..c1627d7 100644 --- a/src/Render/Camera.idr +++ b/src/Render/Camera.idr @@ -24,5 +24,7 @@ PictureType cam = Array [cam.pixh, cam.pixw, 3] Double export pointToPix : Camera -> Point 2 Double -> Point 2 Integer pointToPix (MkCamera mat sw sh pw ph) p = - let p' = applyInv mat p - in point [cast (p'.x / sw * cast pw), cast (p'.y / sh * cast ph)] + let pw' = cast pw + ph' = cast ph + p' = applyInv mat p + in point [cast (p'.x / sw * pw' + pw' / 2), cast (p'.y / sh * ph' + ph' / 2)] diff --git a/src/Render/Scene.idr b/src/Render/Scene.idr index b9e3b81..cd9a9d1 100644 --- a/src/Render/Scene.idr +++ b/src/Render/Scene.idr @@ -28,7 +28,7 @@ render cam sc = joinAxes $ foldl drawObject (repeat _ sc.bgcolor) sc.objects drawPixel (x, y, col) arr = fromMaybe arr $ do x' <- integerToFin x _ y' <- integerToFin y _ - pure $ indexUpdate [x',y'] (over col) arr + pure $ indexUpdate [y',x'] (over col) arr drawObject : Array [cam.pixh, cam.pixw] Color -> Object -> Array [cam.pixh, cam.pixw] Color drawObject pic (MkObject obj) = @@ -50,7 +50,6 @@ renderToPPM dest cam sc = do setByte buf i (cast $ x * 255) modifyIORef ind (+1) - _ <- if !(exists dest) then removeFile {io} dest else pure $ Right () Right h <- openFile dest Append | Left err => pure $ Left err