module Cube (cubeSet) where import Graphics.Rendering.OpenGL import Graphics.UI.GLUT import Control.Applicative import States import VectorMaps import qualified Data.Map as Map ------四角形の描画 cube :: DState -> MState -> GObject -> IO () cube dst mst gObj = do let oWidth = vectorElementX (widthGObj gObj) oHeight = vectorElementY (widthGObj gObj) --textureBinding Texture2D $= Just tObj --texture Texture2D $= Enabled renderPrimitive Quads $ mapM_ vertextex ( map (vertexVector (posGObj gObj)) [ (0 , 0 , 0 , 0) ,(0 , oHeight , 0 , 0) , ( oWidth, oHeight, 0 , 0),( oWidth , 0 , 0 , 0)]) --texture Texture2D $= Disabled ------四角形の描画--テクスチャ指定 cubeSet :: DState -> MState -> GObject -> IO () cubeSet dst mst gObj = cube dst mst gObj ------桁のリスト (再帰) getDegitNumList :: Int -> GLint -> [(Int , GLint)] getDegitNumList m a | a < 0 = [(0 , 10)] | m < 0 = [] | a >= (tpm * 10) = (getDegitNumList m (a - 1)) | otherwise = (m , ( a `quot` tpm) ) : (getDegitNumList (m - 1) (a `rem` tpm)) where tpm = (fromIntegral (10 ^ m)) :: GLint ------コンテナ座標と与えられた位置ベクトルを移動した後、座標とテクスチャ座標を分離してベクトルのペアを返す --vertexVectorContainer :: Table -> (Vector2 GLfloat) -> (GLfloat ,GLfloat,GLfloat ,GLfloat) -> ((Vector2 GLfloat) , (Vector2 GLfloat)) --vertexVectorContainer con v (x ,y, a ,b) = let cPosX = tableX con -- cPosY = tableY con -- in (vectorAdd v (vectorAdd (Vector2 x y) (Vector2 cPosX cPosY)) , (Vector2 a b)) ------座標とテクスチャ座標のペアからrenderPrimitiveで使うIOアクションを返す vertextex :: ((Vector2 GLfloat) , (Vector2 GLfloat)) -> IO () vertextex vt = if (vectorElementY (snd vt)) >= 0 then do texCoord (setTexCoord (snd vt)) vertex (setVertex (fst vt)) else do vertex (setVertex (fst vt)) ------与えられた位置ベクトルだけ移動した後、座標とテクスチャ座標を分離してベクトルのペアを返す vertexVector :: (Vector2 GLfloat) -> (GLfloat ,GLfloat,GLfloat ,GLfloat) -> ((Vector2 GLfloat) , (Vector2 GLfloat)) vertexVector vect (x,y,a,b) = ( (vectorAdd (Vector2 x y) vect) , (Vector2 a b)) ------テーブル座標分と与えられた位置ベクトル分だけ移動した後、座標とテクスチャ座標を分離してベクトルのペアを返す --vertexVectorTb :: Table -> MState -> TipTile -> (GLfloat ,GLfloat,GLfloat ,GLfloat) -> ((Vector2 GLfloat) , (Vector2 GLfloat)) --vertexVectorTb tb mst ttile (x,y,a,b) = let tPos = tilePosition ttile -- texPos = texPosition ttile -- in ((vectorAdd (Vector2 x y) (transTileIntoPosition tb mst tPos)) , (vectorAdd (Vector2 ((rdivTileNum mst) - a) b) (transTileIntoTexCoord texPos mst))) setVertex :: (Vector2 GLfloat) -> (Vertex2 GLfloat) setVertex (Vector2 x y) = (Vertex2 x y) setTexCoord :: (Vector2 GLfloat) -> (TexCoord2 GLfloat) setTexCoord (Vector2 x y) = (TexCoord2 x y)