From 89cefdb45c095ca088c8643cdde0acc96badf989 Mon Sep 17 00:00:00 2001 From: Stefan Dresselhaus Date: Wed, 3 Dec 2014 12:23:50 +0100 Subject: [PATCH] first face correct --- raytrace.cabal | 2 +- src/Scene/Parser.hs | 1 - src/Scene/Renderer.hs | 4 ++-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/raytrace.cabal b/raytrace.cabal index 8058a77..4ceba2c 100644 --- a/raytrace.cabal +++ b/raytrace.cabal @@ -56,7 +56,7 @@ executable raytrace -- other-extensions: -- Other library packages from which modules are imported. - build-depends: base >=4.7 && <4.8, + build-depends: base >=4.6 && <4.8, attoparsec >= 0.12, bytestring >= 0.10, linear >= 1.10, diff --git a/src/Scene/Parser.hs b/src/Scene/Parser.hs index 2d9cd13..7e9e611 100644 --- a/src/Scene/Parser.hs +++ b/src/Scene/Parser.hs @@ -211,7 +211,6 @@ parseMesh' s m = do normal :: IntMap (V3 Float) -> V3 Int -> V3 Float normal verts (V3 v1 v2 v3) = normalize $ cross (verts ! v2 - verts ! v1) (verts ! v3 - verts ! v1) - -- maybe * (-1) mn = IM.fromList $ P.zip [0..] $ vnormal mfn mf <$> [0..v] vnormal :: IntMap (V3 Float) -> IntMap (V3 Int) -> Int -> V3 Float vnormal norms faces i = normalize $ F.foldl' (+) (V3 0 0 0) $ (!) norms <$> fs diff --git a/src/Scene/Renderer.hs b/src/Scene/Renderer.hs index 0611c31..b9d2443 100644 --- a/src/Scene/Renderer.hs +++ b/src/Scene/Renderer.hs @@ -160,12 +160,12 @@ intersect (Ray ro rd) m@(M (Mesh s _ v f n fn b)) = case catMaybes . elems $ pos pos = ro + t *^ rd' --where do we hit the plane v1 = (verts IM.! w2) - (verts IM.! w1) v2 = (verts IM.! w3) - (verts IM.! w1) - det2m = V3 (normalize v1) (normalize v2) (norm IM.! f) -- !* (pos - (verts IM.! w2)) + det2m = fromJust $ inv33 $ V3 v1 v2 (norm IM.! f) -- base-change-matrix into triangle-coordinates det2v = det2m !* (pos - (verts IM.! w1)) -- fromJust is justified as we only make a base-change and all 3 -- vectors are linear independent. det2 = det2v ^. _x > 0 && det2v ^. _y > 0 - && det2v ^. _x < 1 && det2v ^. _y < 1 + && det2v ^. _x + det2v ^. _y < 1 --hitsPhong :: IntMap (V3 Float) -> IntMap (V3 Float) -> V3 Int -> Maybe Collision