first face correct
This commit is contained in:
parent
95faa4c027
commit
89cefdb45c
@ -56,7 +56,7 @@ executable raytrace
|
|||||||
-- other-extensions:
|
-- other-extensions:
|
||||||
|
|
||||||
-- Other library packages from which modules are imported.
|
-- 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,
|
attoparsec >= 0.12,
|
||||||
bytestring >= 0.10,
|
bytestring >= 0.10,
|
||||||
linear >= 1.10,
|
linear >= 1.10,
|
||||||
|
@ -211,7 +211,6 @@ parseMesh' s m = do
|
|||||||
normal :: IntMap (V3 Float) -> V3 Int -> V3 Float
|
normal :: IntMap (V3 Float) -> V3 Int -> V3 Float
|
||||||
normal verts (V3 v1 v2 v3) = normalize $ cross (verts ! v2 - verts ! v1)
|
normal verts (V3 v1 v2 v3) = normalize $ cross (verts ! v2 - verts ! v1)
|
||||||
(verts ! v3 - verts ! v1)
|
(verts ! v3 - verts ! v1)
|
||||||
-- 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
|
||||||
vnormal norms faces i = normalize $ F.foldl' (+) (V3 0 0 0) $ (!) norms <$> fs
|
vnormal norms faces i = normalize $ F.foldl' (+) (V3 0 0 0) $ (!) norms <$> fs
|
||||||
|
@ -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
|
pos = ro + t *^ rd' --where do we hit the plane
|
||||||
v1 = (verts IM.! w2) - (verts IM.! w1)
|
v1 = (verts IM.! w2) - (verts IM.! w1)
|
||||||
v2 = (verts IM.! w3) - (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))
|
det2v = det2m !* (pos - (verts IM.! w1))
|
||||||
-- 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 < 1 && det2v ^. _y < 1
|
&& det2v ^. _x + 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
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user