diff options
| author | mtgmonkey <mtgmonkey@nixos> | 2025-12-08 11:21:14 +0100 |
|---|---|---|
| committer | mtgmonkey <mtgmonkey@nixos> | 2025-12-08 11:21:14 +0100 |
| commit | 5585a49393a05c25b7df7a6a48d1f39db6324b69 (patch) | |
| tree | 9f96a496c4c00da9fd286d2b6742d95eb8ae17e1 /src/Game/Internal/Types.hs | |
| parent | e767a5ee5becd575039ff39db40a7373ccca7eaf (diff) | |
semantics, readability, relicense, initResource argument removal
Diffstat (limited to 'src/Game/Internal/Types.hs')
| -rw-r--r-- | src/Game/Internal/Types.hs | 74 |
1 files changed, 46 insertions, 28 deletions
diff --git a/src/Game/Internal/Types.hs b/src/Game/Internal/Types.hs index 719905e..ad220e4 100644 --- a/src/Game/Internal/Types.hs +++ b/src/Game/Internal/Types.hs @@ -1,9 +1,9 @@ {-# LANGUAGE NamedFieldPuns, OverloadedRecordDot #-} {- | - - Module : Game.Types + - Module : Game.Internal.Types - Description : - - Copyright : Andromeda 2025 - - License : WTFPL + - Copyright : 2025 Andromeda + - License : BSD 3-clause - Maintainer : Matrix @Andromeda:tchncs.de - Stability : Experimental -} @@ -44,18 +44,19 @@ 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(..)) +import Linear (V3, V3(..), V4(..)) -- | represents a single draw call data Object = Object - { vao :: GL.VertexArrayObject - , numIndicies :: GL.NumArrayIndices - , numComponents :: GL.NumComponents - , primitiveMode :: GL.PrimitiveMode + { 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 @@ -73,34 +74,49 @@ toGLMatrix data Model = Model { camera :: Camera - , cursorDeltaPos :: (Double, Double) - , cursorPos :: (Double, Double) - , keys :: [GLFW.Key] - , objects :: [Object] - , program :: GL.Program + , 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 -mkModel :: Camera -> [Object] -> GL.Program -> WorldProperties -> Model -mkModel camera objects program wprop = Model camera (0,0) (0,0) [] objects program wprop +-- | smart constructor for Model +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 + { 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 -> Float @@ -132,14 +148,16 @@ mkCamera False 0 +-- | physical properties of the world data WorldProperties = WorldProperties - { g :: Float -- ^ gravity `g` - , friction :: Float -- ^ floor friction - , up :: V3 Float + { 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) |
