diff options
Diffstat (limited to 'src/Game/Internal/Types.hs')
| -rw-r--r-- | src/Game/Internal/Types.hs | 167 |
1 files changed, 62 insertions, 105 deletions
diff --git a/src/Game/Internal/Types.hs b/src/Game/Internal/Types.hs index ad220e4..8095cfb 100644 --- a/src/Game/Internal/Types.hs +++ b/src/Game/Internal/Types.hs @@ -1,4 +1,5 @@ {-# LANGUAGE NamedFieldPuns, OverloadedRecordDot #-} + {- | - Module : Game.Internal.Types - Description : @@ -9,116 +10,83 @@ -} module Game.Internal.Types ( Object(..) - , toGLMatrix - - , Model ( camera - , objects - , cursorDeltaPos - , cursorPos - , program - , keys - , wprop - ) + , Model(camera, objects, cursorDeltaPos, cursorPos, program, keys, wprop) , mkModel - - , Camera ( camPos - , camPitch - , camYaw - , camReference - , mouseSensitivity - , camVel - , strafeStrength - , jumpStrength - , hasJumped - , airTime - ) + , Camera(camPos, camPitch, camYaw, camReference, mouseSensitivity, camVel, strafeStrength, jumpStrength, hasJumped, airTime) , mkCamera - - , WorldProperties (g, friction, up) + , WorldProperties(g, friction, up) , mkWorldProperties - ) where -import qualified Graphics.UI.GLFW as GLFW import qualified Graphics.Rendering.OpenGL as GL +import qualified Graphics.UI.GLFW as GLFW import qualified Linear as L -import Linear (V3, V3(..), V4(..)) +import Linear (V3, V3(..), V4(..)) -- | represents a single draw call -data Object = - Object - { vao :: GL.VertexArrayObject -- ^ vao of vertex buffer - , numIndicies :: GL.NumArrayIndices -- ^ number of vertices - , numComponents :: GL.NumComponents -- ^ dimensionallity; vec3, vec4, etc. - , primitiveMode :: GL.PrimitiveMode -- ^ primitive mode to be drawn with - } - deriving Show +data Object = Object + { vao :: GL.VertexArrayObject -- ^ vao of vertex buffer + , numIndicies :: GL.NumArrayIndices -- ^ number of vertices + , numComponents :: GL.NumComponents -- ^ dimensionallity; vec3, vec4, etc. + , primitiveMode :: GL.PrimitiveMode -- ^ primitive mode to be drawn with + } deriving (Show) -- | converts M44 to a 16array for OpenGL toGLMatrix :: L.M44 GL.GLfloat -> [GL.GLfloat] -toGLMatrix - (V4 - (V4 c00 c01 c02 c03) - (V4 c10 c11 c12 c13) - (V4 c20 c21 c22 c23) - (V4 c30 c31 c32 c33)) = - [ c00, c01, c02, c03 - , c10, c11, c12, c13 - , c20, c21, c22, c23 - , c30, c31, c32, c33 +toGLMatrix (V4 (V4 c00 c01 c02 c03) (V4 c10 c11 c12 c13) (V4 c20 c21 c22 c23) (V4 c30 c31 c32 c33)) = + [ c00 + , c01 + , c02 + , c03 + , c10 + , c11 + , c12 + , c13 + , c20 + , c21 + , c22 + , c23 + , c30 + , c31 + , c32 + , c33 ] -- | gamestate -data Model = - Model - { camera :: Camera - , cursorDeltaPos :: (Double, Double) -- ^ frame-on-frame delta mouse position - , cursorPos :: (Double, Double) -- ^ current mouse position - , keys :: [GLFW.Key] -- ^ currently pressed keys - , objects :: [Object] -- ^ draw calls - , program :: GL.Program -- ^ shader program - , wprop :: WorldProperties - } - deriving Show +data Model = Model + { camera :: Camera + , cursorDeltaPos :: (Double, Double) -- ^ frame-on-frame delta mouse position + , cursorPos :: (Double, Double) -- ^ current mouse position + , keys :: [GLFW.Key] -- ^ currently pressed keys + , objects :: [Object] -- ^ draw calls + , program :: GL.Program -- ^ shader program + , wprop :: WorldProperties + } deriving (Show) -- | smart constructor for Model -mkModel - :: Camera - -> [Object] - -> GL.Program - -> WorldProperties - -> Model +mkModel :: Camera -> [Object] -> GL.Program -> WorldProperties -> Model mkModel camera objects program wprop = - Model - camera - (0,0) - (0,0) - [] - objects - program - wprop + Model camera (0, 0) (0, 0) [] objects program wprop -- | camera -data Camera = - Camera - { camPos :: V3 Float -- ^ position in world space - , camPitch :: Float -- ^ pitch in radians, up positive - , camYaw :: Float -- ^ yaw in radians, right positive - , camReference :: V3 Float -- ^ reference direction; orientation applied to - , camVel :: V3 Float -- ^ velocity in world space - , mouseSensitivity :: Float -- ^ scale factor for mouse movement - , strafeStrength :: Float -- ^ scale factor for strafe - , jumpStrength :: Float -- ^ scale factor for jump initial velocity - , hasJumped :: Bool -- ^ whether the camera still has jumping state - , airTime :: Float -- ^ time since jumping state entered in seconds - } - deriving Show +data Camera = Camera + { camPos :: V3 Float -- ^ position in world space + , camPitch :: Float -- ^ pitch in radians, up positive + , camYaw :: Float -- ^ yaw in radians, right positive + , camReference :: V3 Float -- ^ reference direction; orientation applied to + , camVel :: V3 Float -- ^ velocity in world space + , mouseSensitivity :: Float -- ^ scale factor for mouse movement + , strafeStrength :: Float -- ^ scale factor for strafe + , jumpStrength :: Float -- ^ scale factor for jump initial velocity + , hasJumped :: Bool -- ^ whether the camera still has jumping state + , airTime :: Float -- ^ time since jumping state entered in seconds + } deriving (Show) -- | smart constructor for Camera -mkCamera - :: V3 Float +mkCamera :: + V3 Float -> Float -> Float -> V3 Float @@ -127,15 +95,7 @@ mkCamera -> Float -> Float -> Camera -mkCamera - camPos - camPitch - camYaw - camReference - camVel - mouseSensitivity - strafeStrength - jumpStrength = +mkCamera camPos camPitch camYaw camReference camVel mouseSensitivity strafeStrength jumpStrength = Camera camPos camPitch @@ -149,15 +109,12 @@ mkCamera 0 -- | physical properties of the world -data WorldProperties = - WorldProperties - { g :: Float -- ^ gravity `g` - , friction :: Float -- ^ scale factor for floor friction - , up :: V3 Float -- ^ global up vector - } - deriving Show +data WorldProperties = WorldProperties + { g :: Float -- ^ gravity `g` + , friction :: Float -- ^ scale factor for floor friction + , up :: V3 Float -- ^ global up vector + } deriving (Show) -- | smart constructor for WorldProperties -mkWorldProperties :: Float -> Float -> V3 Float-> WorldProperties -mkWorldProperties g friction up = - WorldProperties g friction (L.normalize up) +mkWorldProperties :: Float -> Float -> V3 Float -> WorldProperties +mkWorldProperties g friction up = WorldProperties g friction (L.normalize up) |
