module Cube (cubeSet) where import Graphics.Rendering.OpenGL import Graphics.UI.GLUT import Control.Applicative import States import VectorMaps import TextureObjects vertify3 :: [(Vertex3 GLfloat)] -> IO () vertify3 verts = mapM_ vertex verts ------四角形の描画 cube :: GLfloat -> (Vector3 GLfloat) -> TextureObject -> IO() cube w v texObj = do textureBinding Texture2D $= Just texObj texture Texture2D $= Enabled renderPrimitive Quads $ mapM_ vertextex ( map (vertexVector v) [( w, w, w ,0.9 ,0.9), ( w,-w, w ,0.1 ,0.9), (-w,-w, w,0.1 ,0.1), (-w, w, w ,0.9 , 0.1) ]) texture Texture2D $= Disabled ------四角形の描画(テクスチャなどを指定) cubeSet :: TexObjsGroup -> BObject -> IO() cubeSet tOGp bObj = cube (objWidth bObj) (objPosition bObj) (textureDetermine (objTexture bObj) tOGp) ------座標とテクスチャ座標のペアからrenderPrimitiveで使うIOアクションを返す vertextex :: ((Vertex3 GLfloat) , (TexCoord2 GLfloat)) -> IO () vertextex vt = do vertex (fst vt) texCoord (snd vt) ------与えられたベクトル分だけ移動した後、座標とテクスチャ座標を分離してベクトルのペアを返す vertexVector :: (Vector3 GLfloat) -> (GLfloat,GLfloat ,GLfloat,GLfloat ,GLfloat) -> ((Vertex3 GLfloat) , (TexCoord2 GLfloat)) vertexVector v (x,y,z ,a,b) = (((\(Vector3 x y z) -> (Vertex3 x y z)) (vectorAdd (Vector3 x y z) v)) , (TexCoord2 a b))