module FWGL.Graphics.D3 (
module FWGL.Graphics.Generic,
Object3D,
IsObject3D,
Group3D,
IsGroup3D,
cube,
Geometry3D,
mesh,
mkGeometry3D,
trans,
rotX,
rotY,
rotZ,
rot,
scale,
scaleV,
transform,
view,
viewPersp,
viewOrtho,
viewVP,
layerS,
perspectiveMat4,
perspectiveMat4Size,
orthoMat4,
cameraMat4,
lookAtMat4,
transMat4,
rotXMat4,
rotYMat4,
rotZMat4,
rotMat4,
scaleMat4,
Uniforms3D,
Texture2(..),
Transform3(..),
View3(..),
) where
import Control.Applicative
import Data.Vect.Float
import FWGL.Backend hiding (Texture, Program)
import FWGL.Geometry
import FWGL.Graphics.Color
import FWGL.Graphics.Draw
import FWGL.Graphics.Generic
import FWGL.Graphics.Shapes
import FWGL.Graphics.Types
import FWGL.Internal.TList
import FWGL.Shader.Default3D (Texture2(..), Transform3(..), View3(..))
import FWGL.Shader.Program hiding (program)
import FWGL.Graphics.Texture
import FWGL.Transformation
type Uniforms3D = '[Transform3, Texture2]
type Object3D = Object Uniforms3D Geometry3D
type Group3D = Group (View3 ': Uniforms3D) Geometry3D
type IsObject3D globals inputs = ( Subset Geometry3D inputs
, Subset Uniforms3D globals
, Set inputs, Set globals )
type IsGroup3D gs is = ( Subset Geometry3D is, Subset (View3 ': Uniforms3D) gs
, Set is, Set gs )
cube :: Backend => Texture -> Object3D
cube = flip mesh cubeGeometry
mesh :: (IsObject3D Uniforms3D is, Backend)
=> Texture -> Geometry is -> Object Uniforms3D is
mesh t g = Transform3 -= idmtx :~> globalTexture Texture2 t :~> geom g
view :: (IsObject3D gs is, Backend)
=> Mat4 -> [Object gs is] -> Group (View3 ': gs) is
view m = viewVP $ const m
viewPersp :: (IsObject3D gs is, Backend)
=> Float
-> Float
-> Float
-> Mat4
-> [Object gs is] -> Group (View3 ': gs) is
viewPersp n f fov m = viewVP $ \s -> m .*. perspectiveMat4Size n f fov s
viewOrtho :: (IsObject3D gs is, Backend)
=> Float
-> Float
-> Float
-> Float
-> Float
-> Float
-> Mat4
-> [Object gs is] -> Group (View3 ': gs) is
viewOrtho n f l r b t m = view $ m .*. orthoMat4 n f l r b t
viewVP :: (IsObject3D gs is, Backend)
=> (Vec2 -> Mat4) -> [Object gs is] -> Group (View3 ': gs) is
viewVP mf = globalGroup (globalFramebufferSize View3 mf) . group
layerS :: IsGroup3D gs is => Group gs is -> Layer
layerS = layer defaultProgram3D
trans :: (MemberGlobal Transform3 gs, GLES) => Vec3
-> Object gs is -> Object gs is
trans v = transform $ transMat4 v
rotX :: (MemberGlobal Transform3 gs, GLES) => Float
-> Object gs is -> Object gs is
rotX a = transform $ rotXMat4 a
rotY :: (MemberGlobal Transform3 gs, GLES) => Float
-> Object gs is -> Object gs is
rotY a = transform $ rotYMat4 a
rotZ :: (MemberGlobal Transform3 gs, GLES) => Float
-> Object gs is -> Object gs is
rotZ a = transform $ rotZMat4 a
rot :: (MemberGlobal Transform3 gs, GLES) => Vec3
-> Float
-> Object gs is -> Object gs is
rot ax ag = transform $ rotMat4 ax ag
scale :: (MemberGlobal Transform3 gs, GLES) => Float
-> Object gs is -> Object gs is
scale f = transform $ scaleMat4 (Vec3 f f f)
scaleV :: (MemberGlobal Transform3 gs, GLES) => Vec3
-> Object gs is -> Object gs is
scaleV v = transform $ scaleMat4 v
transform :: (MemberGlobal Transform3 gs, GLES) => Mat4
-> Object gs is -> Object gs is
transform m' o = (\m -> Transform3 := (.*. m') <$> m) ~~> o
perspectiveMat4Size :: Float
-> Float
-> Float
-> Vec2
-> Mat4
perspectiveMat4Size n f fov (Vec2 w h) = perspectiveMat4 n f fov $ w / h