diff options
| author | mtgmonkey <mtgmonkey@nixos> | 2025-12-06 21:51:39 +0100 |
|---|---|---|
| committer | mtgmonkey <mtgmonkey@nixos> | 2025-12-06 21:51:39 +0100 |
| commit | ea56936a1529e776602186c50f7e7f587ecbf2de (patch) | |
| tree | 15cace2ff76fed0527d463556b8c2acf04b5ac13 /src/Game/Types.hs | |
| parent | b42579358ec4cc7ebc897dafffdc60433a1da416 (diff) | |
add types.hs, add README, add mouse movement
Diffstat (limited to 'src/Game/Types.hs')
| -rw-r--r-- | src/Game/Types.hs | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/src/Game/Types.hs b/src/Game/Types.hs new file mode 100644 index 0000000..738205f --- /dev/null +++ b/src/Game/Types.hs @@ -0,0 +1,128 @@ +{-# LANGUAGE NamedFieldPuns, OverloadedRecordDot #-} +{- | + - Module : Game.Types + - Description : + - Copyright : Andromeda 2025 + - License : WTFPL + - Maintainer : Matrix @Andromeda:tchncs.de + - Stability : Experimental + -} +module Game.Types + ( Object(..) + + , toGLMatrix + + , Model (objects, camera, cursorDeltaPos, cursorPos, program, keys, wprop) + , mkModel + + , Camera (camPos, camPitch, camYaw, camReference, mouseSensitivity, camVel, strafeStrength, jumpStrength, hasJumped, airTime) + , mkCamera + + , WorldProperties (g, friction, up) + , mkWorldProperties + + ) where + +import qualified Graphics.UI.GLFW as GLFW +import qualified Graphics.Rendering.OpenGL as GL + +import qualified Linear as L +import Linear (Quaternion, V3, V3(..), V4(..)) + +-- | represents a single draw call +data Object = + Object + { vao :: GL.VertexArrayObject + , numIndicies :: GL.NumArrayIndices + , numComponents :: GL.NumComponents + , primitiveMode :: GL.PrimitiveMode + } + deriving Show + +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 + ] + +-- | gamestate +data Model = + Model + { camera :: Camera + , cursorDeltaPos :: (Double, Double) + , cursorPos :: (Double, Double) + , keys :: [GLFW.Key] + , objects :: [Object] + , program :: GL.Program + , wprop :: WorldProperties + } + deriving Show + +mkModel :: Camera -> [Object] -> GL.Program -> WorldProperties -> Model +mkModel camera objects program wprop = Model camera (0,0) (0,0) [] objects program wprop + +-- | camera +data Camera = + Camera + { camPos :: V3 Float + , camPitch :: Float + , camYaw :: Float + , camReference :: V3 Float + , camVel :: V3 Float + , mouseSensitivity :: Float + , strafeStrength :: Float + , jumpStrength :: Float + , hasJumped :: Bool + , airTime :: Float + } + deriving Show + +mkCamera + :: V3 Float + -> Float + -> Float + -> V3 Float + -> V3 Float + -> Float + -> Float + -> Float + -> Camera +mkCamera + camPos + camPitch + camYaw + camReference + camVel + mouseSensitivity + strafeStrength + jumpStrength = + Camera + camPos + camPitch + camYaw + (L.normalize camReference) + (L.normalize camVel) + mouseSensitivity + strafeStrength + jumpStrength + False + 0 + +data WorldProperties = + WorldProperties + { g :: Float -- ^ gravity `g` + , friction :: Float -- ^ floor friction + , up :: V3 Float + } + deriving Show + +mkWorldProperties :: Float -> Float -> V3 Float-> WorldProperties +mkWorldProperties g friction up = + WorldProperties g friction (L.normalize up) |
