{-# OPTIONS -Wno-incomplete-uni-patterns #-} 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 :: -- | tile (0,0) Point2 -> -- | tile tangent Point2 -> -- | tile cotangent Point2 -> -- | world point Point2 -> Point2 calcTexCoord zp tangent cotangent p = V2 (f tangent) (f cotangent) where f t = closestPointOnLineParam zp (zp + t) p -- # OPTIONS -Wno-incomplete-uni-patterns #-} makeTileFromPoly :: [Point2] -> Float -> Tile makeTileFromPoly poly z = Tile { _tilePoly = poly , _tileZero = c , _tileTangentPos = c + (baseFloorTileSize *.* normalizeV (d -.- c)) , _tileArrayZ = z , _tileZeroShift = Nothing } where (c : d : _) = poly baseFloorTileSize :: Float baseFloorTileSize = 50