36 lines
1.3 KiB
Haskell
36 lines
1.3 KiB
Haskell
module Shader.Poke.Cloud (
|
|
pokeCloud,
|
|
) where
|
|
|
|
import qualified Data.Vector.Unboxed as UV
|
|
import Dodge.Data.Cloud
|
|
import Foreign
|
|
import Geometry
|
|
import Graphics.GL.Core45
|
|
|
|
pokeCloud :: Ptr Float -> Ptr GLushort -> (Int, Int) -> Cloud -> IO (Int, Int)
|
|
pokeCloud vptr iptr (nv,ni) cl = do
|
|
UV.imapM_ (pokeCloudVerx vptr cl nv) $ UV.fromList [(1, 1), (-1, 1), (-1, -1), (1, -1)]
|
|
UV.imapM_ (pokeCloudIndex iptr nv ni) $ UV.fromList [0, 1, 2, 2, 0, 3]
|
|
return (nv + 4, ni + 6)
|
|
|
|
pokeCloudVerx :: Ptr Float -> Cloud -> Int -> Int -> (Float, Float) -> IO ()
|
|
{-# INLINE pokeCloudVerx #-}
|
|
pokeCloudVerx ptr cl nv i (dx, dy) =
|
|
UV.imapM_ (pokeCloudFloat ptr (nv + i)) $ UV.fromList
|
|
[x, y, cz, 1, r, g, b, a, cx, cy, cz, rad, dx, dy, 0, 0]
|
|
where
|
|
V3 cx cy cz = _clPos cl
|
|
V2 x y = V2 cx cy - rad *.* V2 dx dy
|
|
CloudColor rad' fadet col = _clPict cl
|
|
(rad,V4 r g b a') = (rad'*_clRad cl, col)
|
|
a = a' * min 1 (fromIntegral (_clTimer cl) / fadet)
|
|
|
|
pokeCloudFloat :: Ptr Float -> Int -> Int -> Float -> IO ()
|
|
{-# INLINE pokeCloudFloat #-}
|
|
pokeCloudFloat ptr nv i = pokeElemOff ptr (nv * 16 + i)
|
|
|
|
pokeCloudIndex :: Ptr GLushort -> Int -> Int -> Int -> Int -> IO ()
|
|
{-# INLINE pokeCloudIndex #-}
|
|
pokeCloudIndex ptr nv ni ioff voff = pokeElemOff ptr (ni + ioff) (fromIntegral $ nv + voff)
|