image not getting better...

This commit is contained in:
Nicole Dresselhaus 2014-12-01 12:43:30 +01:00
parent 4f8be66d27
commit 95faa4c027
2 changed files with 9 additions and 11 deletions

View File

@ -209,8 +209,8 @@ parseMesh' s m = do
mf = IM.fromList $ P.zip [0..] faces mf = IM.fromList $ P.zip [0..] faces
mfn = normal mv <$> mf mfn = normal mv <$> mf
normal :: IntMap (V3 Float) -> V3 Int -> V3 Float normal :: IntMap (V3 Float) -> V3 Int -> V3 Float
normal verts (V3 v1 v2 v3) = (*(-1)).normalize $ cross (verts ! v1 - verts ! v2) normal verts (V3 v1 v2 v3) = normalize $ cross (verts ! v2 - verts ! v1)
(verts ! v3 - verts ! v2) (verts ! v3 - verts ! v1)
-- maybe * (-1) -- maybe * (-1)
mn = IM.fromList $ P.zip [0..] $ vnormal mfn mf <$> [0..v] mn = IM.fromList $ P.zip [0..] $ vnormal mfn mf <$> [0..v]
vnormal :: IntMap (V3 Float) -> IntMap (V3 Int) -> Int -> V3 Float vnormal :: IntMap (V3 Float) -> IntMap (V3 Int) -> Int -> V3 Float

View File

@ -156,18 +156,16 @@ intersect (Ray ro rd) m@(M (Mesh s _ v f n fn b)) = case catMaybes . elems $ pos
where where
! det = dot rd' (norm IM.! f) --do we hit the plane ! det = dot rd' (norm IM.! f) --do we hit the plane
rd' = normalize rd rd' = normalize rd
t = (dot ((verts IM.! w2) - ro) (norm IM.! f))/det --when do we hit the plane t = (dot ((verts IM.! w1) - ro) (norm IM.! f))/det --when do we hit the plane
pos = ro + t *^ rd' --where do we hit the plane pos = ro + t *^ rd' --where do we hit the plane
v1 = (verts IM.! w1) - (verts IM.! w2) v1 = (verts IM.! w2) - (verts IM.! w1)
v2 = (verts IM.! w3) - (verts IM.! w2) v2 = (verts IM.! w3) - (verts IM.! w1)
det2v = V3 (normalize v1) (normalize v2) (norm IM.! f) !* (pos - (verts IM.! w2)) det2m = V3 (normalize v1) (normalize v2) (norm IM.! f) -- !* (pos - (verts IM.! w2))
--det2v = case D.trace (show $ det2m !* (pos - (verts IM.! w2))) (inv33 det2m) of det2v = det2m !* (pos - (verts IM.! w1))
-- Nothing -> V3 1 1 1
-- Just m -> m !* (pos - (verts IM.! w2))
-- fromJust is justified as we only make a base-change and all 3 -- fromJust is justified as we only make a base-change and all 3
-- vectors are linear independent. -- vectors are linear independent.
det2 = det2v ^. _x > 0 && det2v ^. _y > 0 det2 = det2v ^. _x > 0 && det2v ^. _y > 0
&& det2v ^. _x + det2v ^. _y < 1 && det2v ^. _x < 1 && det2v ^. _y < 1
--hitsPhong :: IntMap (V3 Float) -> IntMap (V3 Float) -> V3 Int -> Maybe Collision --hitsPhong :: IntMap (V3 Float) -> IntMap (V3 Float) -> V3 Int -> Maybe Collision