Files
loop/src/Tile.hs
T

40 lines
911 B
Haskell

module Tile
( tileTexCoords
, makeTileFromPoly
, baseFloorTileSize
)
where
import Data.Tile
import Geometry
tileTexCoords :: Tile -> [Point2]
tileTexCoords t = map
(calcTexCoord (_tileZero t) tangent (- vNormal tangent))
(_tilePoly t)
where
tangent = _tileTangentPos t - _tileZero t
calcTexCoord
:: Point2 -- ^ tile (0,0)
-> Point2 -- ^ tile tangent
-> Point2 -- ^ tile cotangent
-> Point2 -- ^ world point
-> Point2
calcTexCoord zp tangent cotangent p = V2 (f tangent) (f cotangent)
where
f t = closestPointOnLineParam zp (zp + t) p
makeTileFromPoly :: [Point2] -> Float -> Tile
makeTileFromPoly poly z = Tile
{ _tilePoly = poly
, _tileZero = c
, _tileTangentPos = c + (baseFloorTileSize *.* normalizeV (d -.- c))
, _tileArrayZ = z
}
where
(c:d:_) = poly
baseFloorTileSize :: Float
baseFloorTileSize = 50