first face correct

This commit is contained in:
Nicole Dresselhaus 2014-12-03 12:23:50 +01:00
parent 95faa4c027
commit 89cefdb45c
3 changed files with 3 additions and 4 deletions

View File

@ -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,

View File

@ -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

View File

@ -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