Skip to content

Commit

Permalink
feat: final changes to replace Vectors with linear Vs
Browse files Browse the repository at this point in the history
  • Loading branch information
Anut-py committed May 16, 2024
1 parent 9dc220d commit b324430
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 34 deletions.
3 changes: 2 additions & 1 deletion examples/basic-automation-events/src/Main.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# OPTIONS -Wall #-}
{-# LANGUAGE PatternSynonyms #-}

module Main where

Expand Down Expand Up @@ -27,7 +28,7 @@ import Raylib.Types
Color (Color),
KeyboardKey (KeyDown, KeyLeft, KeyP, KeyR, KeyRight, KeyUp),
MouseButton (MouseButtonLeft),
Vector2 (Vector2),
pattern Vector2,
)
import Raylib.Util (drawing, whileWindowOpen_, withWindow)
import Raylib.Util.Colors (black, red, white)
Expand Down
3 changes: 2 additions & 1 deletion examples/basic-images/src/Main.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# OPTIONS -Wall #-}
{-# LANGUAGE PatternSynonyms #-}
module Main where

import Control.Monad (unless, void)
Expand All @@ -16,7 +17,7 @@ import Raylib.Core.Textures
loadRenderTexture,
loadTextureFromImage,
)
import Raylib.Types (Rectangle (Rectangle), RenderTexture (renderTexture'texture), Vector2 (Vector2))
import Raylib.Types (Rectangle (Rectangle), RenderTexture (renderTexture'texture), pattern Vector2)
import Raylib.Util (drawing, inGHCi, textureMode, whileWindowOpen0, withWindow)
import Raylib.Util.Colors (black, lightGray, orange, white)

Expand Down
3 changes: 2 additions & 1 deletion examples/basic-models/src/Main.hs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{-# OPTIONS -Wall #-}
{-# LANGUAGE PatternSynonyms #-}

module Main where

import Control.Monad (unless, void)
import Raylib.Core (changeDirectory, clearBackground, disableCursor, getApplicationDirectory)
import Raylib.Core.Camera (updateCamera)
import Raylib.Core.Models (drawGrid, drawModel, genMeshCube, loadModel, loadModelFromMesh)
import Raylib.Types (Camera3D (Camera3D), CameraMode (CameraModeFirstPerson), CameraProjection (CameraPerspective), Vector3 (Vector3))
import Raylib.Types (Camera3D (Camera3D), CameraMode (CameraModeFirstPerson), CameraProjection (CameraPerspective), pattern Vector3)
import Raylib.Util (drawing, inGHCi, mode3D, whileWindowOpen_, withWindow)
import Raylib.Util.Colors (orange, white)

Expand Down
4 changes: 3 additions & 1 deletion examples/basic-rlgl/src/Main.hs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{-# OPTIONS -Wall #-}
{-# LANGUAGE PatternSynonyms #-}

module Main where

import Control.Monad (unless, void)
import Raylib.Core (changeDirectory, clearBackground, getApplicationDirectory)
import Raylib.Core.Models (drawGrid)
import Raylib.Core.Textures (loadTexture)
import Raylib.Types (Camera3D (Camera3D), CameraProjection (CameraPerspective), Color (Color), RLDrawMode (RLQuads), Rectangle (Rectangle), Texture (texture'height, texture'id, texture'width), Vector3 (Vector3))
import Raylib.Types (Camera3D (Camera3D), CameraProjection (CameraPerspective), Color (Color), RLDrawMode (RLQuads), Rectangle (Rectangle), Texture (texture'height, texture'id, texture'width), Vector3, pattern Vector3)
import Raylib.Util (drawing, inGHCi, mode3D, whileWindowOpen0, withWindow)
import Raylib.Util.Colors (rayWhite, white)
import Raylib.Util.RLGL (rlBegin, rlColor4ub, rlEnd, rlNormal3f, rlPopMatrix, rlPushMatrix, rlRotatef, rlScalef, rlSetTexture, rlTexCoord2f, rlTranslatef, rlVertex3f)
Expand Down
6 changes: 4 additions & 2 deletions examples/basic-shaders/src/Main.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# OPTIONS -Wall #-}
{-# LANGUAGE PatternSynonyms #-}

module Main where

Expand Down Expand Up @@ -34,9 +35,10 @@ import Raylib.Types
ShaderUniformVec3,
ShaderUniformVec4
),
Vector3 (Vector3),
Vector4 (Vector4, vector4'w),
vector4'w,
vectorToColor,
pattern Vector3,
pattern Vector4,
)
import Raylib.Util (inGHCi, setMaterialShader, whileWindowOpen_)
import Raylib.Util.Colors (black, blue, lightGray, orange, white)
Expand Down
4 changes: 3 additions & 1 deletion examples/camera-ray-collision/src/Main.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{-# OPTIONS -Wall #-}
{-# LANGUAGE PatternSynonyms #-}

module Main where

import Control.Monad (when)
Expand All @@ -12,7 +14,7 @@ import Raylib.Types
CameraMode (CameraModeFirstPerson),
CameraProjection (CameraPerspective),
RayCollision (rayCollision'hit, rayCollision'point),
Vector3 (Vector3),
pattern Vector3,
)
import Raylib.Util (cameraDirectionRay, drawing, mode3D, whileWindowOpen_, withWindow)
import Raylib.Util.Colors (black, red, white)
Expand Down
4 changes: 3 additions & 1 deletion examples/custom-font-text/src/Main.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{-# OPTIONS -Wall #-}
{-# LANGUAGE PatternSynonyms #-}

module Main where

import Control.Monad (unless, void)
Expand All @@ -10,7 +12,7 @@ import Raylib.Core
isKeyPressed,
)
import Raylib.Core.Text (drawText, drawTextEx, loadFont)
import Raylib.Types (KeyboardKey (KeyDown, KeyUp), Vector2 (Vector2))
import Raylib.Types (KeyboardKey (KeyDown, KeyUp), pattern Vector2)
import Raylib.Util (inGHCi, whileWindowOpen_, withWindow, drawing)
import Raylib.Util.Colors (black, rayWhite)

Expand Down
4 changes: 3 additions & 1 deletion examples/first-person-camera/src/Main.hs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{-# OPTIONS -Wall #-}
{-# LANGUAGE PatternSynonyms #-}

module Main where

import Raylib.Core (clearBackground, disableCursor)
import Raylib.Core.Camera (updateCamera)
import Raylib.Core.Models (drawCircle3D, drawCubeWiresV, drawLine3D)
import Raylib.Core.Text (drawFPS)
import Raylib.Types (Camera3D (Camera3D), CameraMode (CameraModeFirstPerson), CameraProjection (CameraPerspective), Vector3 (Vector3))
import Raylib.Types (Camera3D (Camera3D), CameraMode (CameraModeFirstPerson), CameraProjection (CameraPerspective), pattern Vector3)
import Raylib.Util (drawing, mode3D, whileWindowOpen_, withWindow)
import Raylib.Util.Colors (black, white)

Expand Down
3 changes: 2 additions & 1 deletion examples/postprocessing-effects/src/Main.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# OPTIONS -Wall #-}
{-# LANGUAGE PatternSynonyms #-}

module Main where

Expand All @@ -8,7 +9,7 @@ import Raylib.Core.Camera (updateCamera)
import Raylib.Core.Models (drawCube, drawGrid, drawSphere)
import Raylib.Core.Text (drawText)
import Raylib.Core.Textures (drawTextureRec, loadRenderTexture)
import Raylib.Types (Camera3D (Camera3D), CameraMode (CameraModeOrbital), CameraProjection (CameraPerspective), KeyboardKey (KeyLeft, KeyRight), Rectangle (Rectangle), RenderTexture (renderTexture'texture), ShaderUniformData (ShaderUniformVec2), Vector2 (Vector2), Vector3 (Vector3))
import Raylib.Types (Camera3D (Camera3D), CameraMode (CameraModeOrbital), CameraProjection (CameraPerspective), KeyboardKey (KeyLeft, KeyRight), Rectangle (Rectangle), RenderTexture (renderTexture'texture), ShaderUniformData (ShaderUniformVec2), pattern Vector2, pattern Vector3)
import Raylib.Util (inGHCi, mode3D, textureMode, whileWindowOpen_, withWindow, drawing, shaderMode)
import Raylib.Util.Colors (black, blue, darkBlue, darkGreen, green, maroon, orange, red, white)

Expand Down
2 changes: 1 addition & 1 deletion h-raylib.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ library
, containers >=0.6.0 && <0.7.0
, exceptions >=0.10.4 && <0.10.8
, lens >=4.0 && <5.2.4
, linear >= 1.23 && <1.24
, linear >=1.23 && <1.24
, template-haskell >=2.16.0.0 && <2.22.0.0
, text >=2.0 && <2.2

Expand Down
4 changes: 4 additions & 0 deletions src/Raylib/Types/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,7 @@ pattern Vector2
{ vector2'x ,
vector2'y
} = V2 vector2'x vector2'y
{-# COMPLETE Vector2 :: V2 #-}

p'vector2'x :: Ptr Vector2 -> Ptr CFloat
p'vector2'x = (`plusPtr` 0)
Expand All @@ -678,6 +679,7 @@ pattern Vector3
vector3'y ,
vector3'z
} = V3 vector3'x vector3'y vector3'z
{-# COMPLETE Vector3 :: V3 #-}

p'vector3'x :: Ptr Vector3 -> Ptr CFloat
p'vector3'x = (`plusPtr` 0)
Expand All @@ -690,12 +692,14 @@ p'vector3'z = (`plusPtr` 8)

type Vector4 = V4 Float

pattern Vector4 :: a -> a -> a -> a -> V4 a
pattern Vector4
{ vector4'x,
vector4'y,
vector4'z,
vector4'w
} = V4 vector4'x vector4'y vector4'z vector4'w
{-# COMPLETE Vector4 :: V4 #-}

vectorToColor :: Vector4 -> Color
vectorToColor (Vector4 x y z w) = Color (round $ x * 255) (round $ y * 255) (round $ z * 255) (round $ w * 255)
Expand Down
50 changes: 27 additions & 23 deletions src/Raylib/Util/Lenses.hs
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
{-# LANGUAGE PatternSynonyms #-}
{-# OPTIONS -Wall #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE PatternSynonyms #-}

-- | Lenses for raylib types
module Raylib.Util.Lenses where

import Control.Lens (Lens', lens)
import Raylib.Internal.TH (genLenses)
import qualified Raylib.Types as RL
import Control.Lens (Lens', lens)




$( genLenses
[
-- Raylib.Types.Core
[ -- Raylib.Types.Core
''RL.Matrix,
''RL.Color,
''RL.Rectangle,
Expand Down Expand Up @@ -62,21 +58,29 @@ $( genLenses
]
)

_vector4'z :: Lens' RL.Vector4 Float
_vector4'y :: Lens' RL.Vector4 Float
_vector2'x :: Lens' RL.Vector2 Float
_vector2'x = lens RL.vector2'x (\x v -> x {RL.vector2'x = v})

_vector2'y :: Lens' RL.Vector2 Float
_vector2'y = lens RL.vector2'y (\x v -> x {RL.vector2'y = v})

_vector3'x :: Lens' RL.Vector3 Float
_vector3'x = lens RL.vector3'x (\x v -> x {RL.vector3'x = v})

_vector3'y :: Lens' RL.Vector3 Float
_vector3'y = lens RL.vector3'y (\x v -> x {RL.vector3'y = v})

_vector3'z :: Lens' RL.Vector3 Float
_vector3'z = lens RL.vector3'z (\x v -> x {RL.vector3'z = v})

_vector4'x :: Lens' RL.Vector4 Float
_vector4'x = lens RL.vector4'x (\x v -> x {RL.vector4'x = v})

_vector4'y :: Lens' RL.Vector4 Float
_vector4'y = lens RL.vector4'y (\x v -> x {RL.vector4'y = v})

_vector4'z :: Lens' RL.Vector4 Float
_vector4'z = lens RL.vector4'z (\x v -> x {RL.vector4'z = v})

_vector4'w :: Lens' RL.Vector4 Float
_vector3'z :: Lens' RL.Vector3 Float
_vector3'y :: Lens' RL.Vector3 Float
_vector3'x :: Lens' RL.Vector3 Float
_vector2'y :: Lens' RL.Vector2 Float
_vector2'x :: Lens' RL.Vector2 Float
_vector4'z = lens RL.vector4'z (\x v -> x { RL.vector4'z = v })
_vector4'y = lens RL.vector4'y (\x v -> x { RL.vector4'y = v })
_vector4'x = lens RL.vector4'x (\x v -> x { RL.vector4'x = v })
_vector4'w = lens RL.vector4'w (\x v -> x { RL.vector4'w = v })
_vector3'z = lens RL.vector3'z (\x v -> x { RL.vector3'z = v })
_vector3'y = lens RL.vector3'y (\x v -> x { RL.vector3'y = v })
_vector3'x = lens RL.vector3'x (\x v -> x { RL.vector3'x = v })
_vector2'y = lens RL.vector2'y (\x v -> x { RL.vector2'y = v })
_vector2'x = lens RL.vector2'x (\x v -> x { RL.vector2'x = v })
_vector4'w = lens RL.vector4'w (\x v -> x {RL.vector4'w = v})

0 comments on commit b324430

Please sign in to comment.