Fix normal map transformations for floor
This commit is contained in:
+15
-13
@@ -1,33 +1,35 @@
|
||||
module Tile
|
||||
( tileTexCoords
|
||||
, makeTileFromPoly
|
||||
)
|
||||
where
|
||||
import Data.Tile
|
||||
import Geometry
|
||||
|
||||
tileToRenderList :: Tile -> [(Point3,Point3)]
|
||||
tileToRenderList t = polyToTris $ zip ps3 coords3
|
||||
tileTexCoords :: Tile -> [Point2]
|
||||
tileTexCoords t = map
|
||||
(calcTexCoord (_tileZero t) tangent (- vNormal tangent))
|
||||
(_tilePoly t)
|
||||
where
|
||||
ps = _tilePoly t
|
||||
coords = map (calcTexCoord (_tileZero t) (_tileX t)) ps
|
||||
ps3 = map (addZ 0) ps
|
||||
coords3 = map (addZ (_tileZ t)) coords
|
||||
tangent = _tileTangentPos t - _tileZero t
|
||||
|
||||
calcTexCoord
|
||||
:: Point2 -- ^ tile (0,0)
|
||||
-> Point2 -- ^ tile (1,0)
|
||||
-> Point2 -- ^ tile tangent
|
||||
-> Point2 -- ^ tile cotangent
|
||||
-> Point2 -- ^ world point
|
||||
-> Point2
|
||||
calcTexCoord c p x = V2 (vectorAmountIn xdir) (vectorAmountIn ydir)
|
||||
calcTexCoord zp tangent cotangent p = V2 (f tangent) (f cotangent)
|
||||
where
|
||||
vectorAmountIn dir = 0.02 * dotV (p -.- c) dir
|
||||
xdir = x -.- c
|
||||
ydir = vNormal xdir
|
||||
f t = closestPointOnLineParam zp (zp + t) p
|
||||
|
||||
|
||||
makeTileFromPoly :: [Point2] -> Float -> Tile
|
||||
makeTileFromPoly poly z = Tile
|
||||
{ _tilePoly = poly
|
||||
, _tileZero = c
|
||||
, _tileX = c +.+ normalizeV ((poly !! 1) -.- c)
|
||||
, _tileTangentPos = c + (32 * normalizeV (d -.- c))
|
||||
, _tileZ = z
|
||||
}
|
||||
where
|
||||
c = head poly
|
||||
(c:d:_) = poly
|
||||
|
||||
Reference in New Issue
Block a user