From aad8b04bea3046898c505bf6ab7f7bbb567a2a26 Mon Sep 17 00:00:00 2001 From: Anand Swaroop Date: Fri, 8 Mar 2024 20:56:20 -0500 Subject: [PATCH] chore: update submodules --- flake.lock | 6 +- flake.nix | 8 +-- lib/rl_bindings.c | 13 ++-- lib/rl_bindings.h | 6 +- raygui | 2 +- raylib | 2 +- src/Raylib/Core.hs | 31 +++++---- src/Raylib/Core/Textures.hs | 8 +-- src/Raylib/Types/Util/GUI.hs | 18 +++--- src/Raylib/Util/Math.hs | 118 ++++++++++++++++++++++------------- 10 files changed, 128 insertions(+), 84 deletions(-) diff --git a/flake.lock b/flake.lock index 2d9034d..f1a43e6 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1708564076, - "narHash": "sha256-KKkqoxlgx9n3nwST7O2kM8tliDOijiSSNaWuSkiozdQ=", + "lastModified": 1709780214, + "narHash": "sha256-p4iDKdveHMhfGAlpxmkCtfQO3WRzmlD11aIcThwPqhk=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "98b00b6947a9214381112bdb6f89c25498db4959", + "rev": "f945939fd679284d736112d3d5410eb867f3b31c", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index af5b58b..1278b60 100644 --- a/flake.nix +++ b/flake.nix @@ -9,10 +9,10 @@ forAllSystems' = nixpkgs.lib.genAttrs; forAllSystems = forAllSystems' supportedSystems; - raylibRev = "54e0af40c1c534b3f3958264c67270434183639e"; - raylibHash = "sha256-VwqLD0TYOFShav1OSJnlbIVR8ixMm3sB5pNigJey/dQ="; - rayguiRev = "bc67f42209cc32965c7d1c00028e3ed0c4158659"; - rayguiHash = "sha256-yevM/m6Mven/U2KrxVvm9yL9PQtffeU+Vxfdrvj5Vdk="; + raylibRev = "ba066656f7be07f8f3f5e9028f053068789755a4"; + raylibHash = "sha256-WeT9lW4Qs3K5+dEscAKfyvKX6BHJCJNWspbABlrXPgs="; + rayguiRev = "b5693d0c418e4b2572de2992b795c6407e8106cf"; + rayguiHash = "sha256-u7BIpMB3ofv4Fia8TJ0523FhfN8dkz/UvvGrKRjKEnY="; pkgsForSystem = system: diff --git a/lib/rl_bindings.c b/lib/rl_bindings.c index 54453bf..2babb4d 100644 --- a/lib/rl_bindings.c +++ b/lib/rl_bindings.c @@ -126,17 +126,17 @@ RLBIND void UnloadShader_(Shader *a) UnloadShader(*a); } -RLBIND Ray *GetMouseRay_(Vector2 *a, Camera3D *b) +RLBIND Ray *GetScreenToWorldRay_(Vector2 *a, Camera3D *b) { Ray *ptr = (Ray *)malloc(sizeof(Ray)); - *ptr = GetMouseRay(*a, *b); + *ptr = GetScreenToWorldRay(*a, *b); return ptr; } -RLBIND Ray *GetViewRay_(Vector2 *a, Camera3D *b, float c, float d) +RLBIND Ray *GetScreenToWorldRayEx_(Vector2 *a, Camera3D *b, float c, float d) { Ray *ptr = (Ray *)malloc(sizeof(Ray)); - *ptr = GetViewRay(*a, *b, c, d); + *ptr = GetScreenToWorldRayEx(*a, *b, c, d); return ptr; } @@ -2580,6 +2580,11 @@ RLBIND int SetGamepadMappings_(const char *a) return SetGamepadMappings(a); } +RLBIND void SetGamepadVibration_(int a, float b, float c) +{ + SetGamepadVibration(a, b, c); +} + RLBIND bool IsMouseButtonPressed_(int a) { return IsMouseButtonPressed(a); diff --git a/lib/rl_bindings.h b/lib/rl_bindings.h index 529edcb..99f43f5 100644 --- a/lib/rl_bindings.h +++ b/lib/rl_bindings.h @@ -54,9 +54,9 @@ void SetShaderValueTexture_(Shader *a, int b, Texture *c); void UnloadShader_(Shader *a); -Ray *GetMouseRay_(Vector2 *a, Camera3D *b); +Ray *GetScreenToWorldRay_(Vector2 *a, Camera3D *b); -Ray *GetViewRay_(Vector2 *a, Camera3D *b, float c, float d); +Ray *GetScreenToWorldRayEx_(Vector2 *a, Camera3D *b, float c, float d); Matrix *GetCameraMatrix_(Camera3D *a); @@ -944,6 +944,8 @@ float GetGamepadAxisMovement_(int a, int b); int SetGamepadMappings_(const char *a); +void SetGamepadVibration_(int a, float b, float c); + bool IsMouseButtonPressed_(int a); bool IsMouseButtonDown_(int a); diff --git a/raygui b/raygui index bc67f42..b5693d0 160000 --- a/raygui +++ b/raygui @@ -1 +1 @@ -Subproject commit bc67f42209cc32965c7d1c00028e3ed0c4158659 +Subproject commit b5693d0c418e4b2572de2992b795c6407e8106cf diff --git a/raylib b/raylib index 54e0af4..ba06665 160000 --- a/raylib +++ b/raylib @@ -1 +1 @@ -Subproject commit 54e0af40c1c534b3f3958264c67270434183639e +Subproject commit ba066656f7be07f8f3f5e9028f053068789755a4 diff --git a/src/Raylib/Core.hs b/src/Raylib/Core.hs index 7d17545..991c394 100644 --- a/src/Raylib/Core.hs +++ b/src/Raylib/Core.hs @@ -92,8 +92,8 @@ module Raylib.Core setShaderValueMatrix, setShaderValueTexture, unloadShader, - getMouseRay, - getViewRay, + getScreenToWorldRay, + getScreenToWorldRayEx, getCameraMatrix, getCameraMatrix2D, getWorldToScreen, @@ -171,6 +171,7 @@ module Raylib.Core getGamepadAxisCount, getGamepadAxisMovement, setGamepadMappings, + setGamepadVibration, isMouseButtonPressed, isMouseButtonDown, isMouseButtonReleased, @@ -286,8 +287,8 @@ module Raylib.Core c'setShaderValueMatrix, c'setShaderValueTexture, c'unloadShader, - c'getMouseRay, - c'getViewRay, + c'getScreenToWorldRay, + c'getScreenToWorldRayEx, c'getCameraMatrix, c'getCameraMatrix2D, c'getWorldToScreen, @@ -369,6 +370,7 @@ module Raylib.Core c'getGamepadAxisCount, c'getGamepadAxisMovement, c'setGamepadMappings, + c'setGamepadVibration, c'isMouseButtonPressed, c'isMouseButtonDown, c'isMouseButtonReleased, @@ -414,12 +416,13 @@ import qualified Data.Map as Map import Foreign ( Ptr, Storable (peek, poke, sizeOf), + castFunPtr, castPtr, fromBool, malloc, newArray, peekArray, - toBool, castFunPtr, + toBool, ) import Foreign.C ( CBool (..), @@ -435,7 +438,7 @@ import Foreign.C withCString, ) import Foreign.Ptr (nullPtr) -import Raylib.Internal (WindowResources, addAutomationEventList, addShaderId, defaultWindowResources, shaderLocations, unloadAutomationEventLists, unloadFrameBuffers, unloadShaders, unloadSingleAutomationEventList, unloadSingleShader, unloadTextures, unloadVaoIds, unloadVboIds, addFunPtr, unloadFunPtrs) +import Raylib.Internal (WindowResources, addAutomationEventList, addFunPtr, addShaderId, defaultWindowResources, shaderLocations, unloadAutomationEventLists, unloadFrameBuffers, unloadFunPtrs, unloadShaders, unloadSingleAutomationEventList, unloadSingleShader, unloadTextures, unloadVaoIds, unloadVboIds) import Raylib.Internal.Foreign (c'free, configsToBitflag, pop, popCArray, popCString, withFreeable, withFreeableArray, withFreeableArrayLen, withMaybeCString) import Raylib.Internal.TH (genNative) import Raylib.Types @@ -566,8 +569,8 @@ $( genNative ("c'setShaderValueMatrix", "SetShaderValueMatrix_", "rl_bindings.h", [t|Ptr Shader -> CInt -> Ptr Matrix -> IO ()|], False), ("c'setShaderValueTexture", "SetShaderValueTexture_", "rl_bindings.h", [t|Ptr Shader -> CInt -> Ptr Texture -> IO ()|], False), ("c'unloadShader", "UnloadShader_", "rl_bindings.h", [t|Ptr Shader -> IO ()|], False), - ("c'getMouseRay", "GetMouseRay_", "rl_bindings.h", [t|Ptr Vector2 -> Ptr Camera3D -> IO (Ptr Ray)|], False), - ("c'getViewRay", "GetViewRay_", "rl_bindings.h", [t|Ptr Vector2 -> Ptr Camera3D -> CFloat -> CFloat -> IO (Ptr Ray)|], False), + ("c'getScreenToWorldRay", "GetScreenToWorldRay_", "rl_bindings.h", [t|Ptr Vector2 -> Ptr Camera3D -> IO (Ptr Ray)|], False), + ("c'getScreenToWorldRayEx", "GetScreenToWorldRayEx_", "rl_bindings.h", [t|Ptr Vector2 -> Ptr Camera3D -> CFloat -> CFloat -> IO (Ptr Ray)|], False), ("c'getCameraMatrix", "GetCameraMatrix_", "rl_bindings.h", [t|Ptr Camera3D -> IO (Ptr Matrix)|], False), ("c'getCameraMatrix2D", "GetCameraMatrix2D_", "rl_bindings.h", [t|Ptr Camera2D -> IO (Ptr Matrix)|], False), ("c'getWorldToScreen", "GetWorldToScreen_", "rl_bindings.h", [t|Ptr Vector3 -> Ptr Camera3D -> IO (Ptr Vector2)|], False), @@ -649,6 +652,7 @@ $( genNative ("c'getGamepadAxisCount", "GetGamepadAxisCount_", "rl_bindings.h", [t|CInt -> IO CInt|], False), ("c'getGamepadAxisMovement", "GetGamepadAxisMovement_", "rl_bindings.h", [t|CInt -> CInt -> IO CFloat|], False), ("c'setGamepadMappings", "SetGamepadMappings_", "rl_bindings.h", [t|CString -> IO CInt|], False), + ("c'setGamepadVibration", "SetGamepadVibration_", "rl_bindings.h", [t|CInt -> CFloat -> CFloat -> IO ()|], False), ("c'isMouseButtonPressed", "IsMouseButtonPressed_", "rl_bindings.h", [t|CInt -> IO CBool|], False), ("c'isMouseButtonDown", "IsMouseButtonDown_", "rl_bindings.h", [t|CInt -> IO CBool|], False), ("c'isMouseButtonReleased", "IsMouseButtonReleased_", "rl_bindings.h", [t|CInt -> IO CBool|], False), @@ -992,11 +996,11 @@ setShaderValueTexture shader locIndex tex = withFreeable shader (\s -> withFreea unloadShader :: Shader -> WindowResources -> IO () unloadShader shader = unloadSingleShader (shader'id shader) -getMouseRay :: Vector2 -> Camera3D -> IO Ray -getMouseRay mousePosition camera = withFreeable mousePosition (withFreeable camera . c'getMouseRay) >>= pop +getScreenToWorldRay :: Vector2 -> Camera3D -> IO Ray +getScreenToWorldRay position camera = withFreeable position (withFreeable camera . c'getScreenToWorldRay) >>= pop -getViewRay :: Vector2 -> Camera3D -> Float -> Float -> IO Ray -getViewRay mousePosition camera width height = withFreeable mousePosition (\p -> withFreeable camera (\c -> c'getViewRay p c (realToFrac width) (realToFrac height))) >>= pop +getScreenToWorldRayEx :: Vector2 -> Camera3D -> Float -> Float -> IO Ray +getScreenToWorldRayEx position camera width height = withFreeable position (\p -> withFreeable camera (\c -> c'getScreenToWorldRayEx p c (realToFrac width) (realToFrac height))) >>= pop getCameraMatrix :: Camera3D -> IO Matrix getCameraMatrix camera = withFreeable camera c'getCameraMatrix >>= pop @@ -1312,6 +1316,9 @@ getGamepadAxisMovement gamepad axis = realToFrac <$> c'getGamepadAxisMovement (f setGamepadMappings :: String -> IO Int setGamepadMappings mappings = fromIntegral <$> withCString mappings c'setGamepadMappings +setGamepadVibration :: Int -> Float -> Float -> IO () +setGamepadVibration gamepad leftMotor rightMotor = c'setGamepadVibration (fromIntegral gamepad) (realToFrac leftMotor) (realToFrac rightMotor) + isMouseButtonPressed :: MouseButton -> IO Bool isMouseButtonPressed button = toBool <$> c'isMouseButtonPressed (fromIntegral $ fromEnum button) diff --git a/src/Raylib/Core/Textures.hs b/src/Raylib/Core/Textures.hs index 49cf3fd..5af19e9 100644 --- a/src/Raylib/Core/Textures.hs +++ b/src/Raylib/Core/Textures.hs @@ -698,11 +698,11 @@ unloadRenderTexture renderTexture wr = do unloadSingleTexture (texture'id $ renderTexture'texture renderTexture) wr unloadSingleFrameBuffer (renderTexture'id renderTexture) wr -updateTexture :: Texture -> Ptr () -> IO Texture -updateTexture texture pixels = withFreeable texture (\t -> c'updateTexture t pixels >> peek t) +updateTexture :: Texture -> Ptr () -> IO () +updateTexture texture pixels = withFreeable texture (\t -> c'updateTexture t pixels) -updateTextureRec :: Texture -> Rectangle -> Ptr () -> IO Texture -updateTextureRec texture rect pixels = withFreeable texture (\t -> withFreeable rect (\r -> c'updateTextureRec t r pixels) >> peek t) +updateTextureRec :: Texture -> Rectangle -> Ptr () -> IO () +updateTextureRec texture rect pixels = withFreeable texture (\t -> withFreeable rect (\r -> c'updateTextureRec t r pixels)) genTextureMipmaps :: Texture -> IO Texture genTextureMipmaps texture = withFreeable texture (\t -> c'genTextureMipmaps t >> peek t) diff --git a/src/Raylib/Types/Util/GUI.hs b/src/Raylib/Types/Util/GUI.hs index f16180a..c71a9f9 100644 --- a/src/Raylib/Types/Util/GUI.hs +++ b/src/Raylib/Types/Util/GUI.hs @@ -865,9 +865,9 @@ data GuiIconName | IconFolder | IconFile | IconSandTimer - | Icon220 - | Icon221 - | Icon222 + | IconWarning + | IconHelpBox + | IconInfoBox | Icon223 | Icon224 | Icon225 @@ -1125,9 +1125,9 @@ instance Enum GuiIconName where IconFolder -> 217 IconFile -> 218 IconSandTimer -> 219 - Icon220 -> 220 - Icon221 -> 221 - Icon222 -> 222 + IconWarning -> 220 + IconHelpBox -> 221 + IconInfoBox -> 222 Icon223 -> 223 Icon224 -> 224 Icon225 -> 225 @@ -1382,9 +1382,9 @@ instance Enum GuiIconName where 217 -> IconFolder 218 -> IconFile 219 -> IconSandTimer - 220 -> Icon220 - 221 -> Icon221 - 222 -> Icon222 + 220 -> IconWarning + 221 -> IconHelpBox + 222 -> IconInfoBox 223 -> Icon223 224 -> Icon224 225 -> Icon225 diff --git a/src/Raylib/Util/Math.hs b/src/Raylib/Util/Math.hs index d6fd95f..d2d61c6 100644 --- a/src/Raylib/Util/Math.hs +++ b/src/Raylib/Util/Math.hs @@ -29,6 +29,7 @@ module Raylib.Util.Math vector2Transform, vector2Reflect, vector2Rotate, + vector2Refract, -- ** Vector3 math vector3CrossProduct, @@ -90,8 +91,8 @@ module Raylib.Util.Math ) where -import Raylib.Types (Matrix (..), Quaternion, Vector2 (Vector2), Vector3 (Vector3), Vector4 (Vector4)) import Data.Foldable (foldl') +import Raylib.Types (Matrix (..), Quaternion, Vector2 (Vector2), Vector3 (Vector3), Vector4 (Vector4)) epsilon :: Float epsilon = 0.000001 @@ -233,7 +234,7 @@ class Vector a where constant val = fromList $ repeat val -- | Sum of all vectors in a structure - vectorSum :: Foldable t => t a -> a + vectorSum :: (Foldable t) => t a -> a vectorSum = foldl' (|+|) zero -- | Vector additive inverse @@ -345,7 +346,7 @@ vector2Angle (Vector2 x1 y1) (Vector2 x2 y2) = atan2 (x1 * x2 + y1 * y2) (x1 * y -- | Angle created by the line between two 2D vectors (parameters must be normalized) vector2LineAngle :: Vector2 -> Vector2 -> Float -vector2LineAngle (Vector2 sx sy) (Vector2 ex ey) = - atan2 (ey - sy) (ex - sx) +vector2LineAngle (Vector2 sx sy) (Vector2 ex ey) = -atan2 (ey - sy) (ex - sx) -- | Transform a 2D vector by the given matrix vector2Transform :: Vector2 -> Matrix -> Vector2 @@ -367,6 +368,22 @@ vector2Rotate (Vector2 x y) angle = Vector2 (x * c - y * s) (x * s + y * c) c = cos angle s = sin angle +-- | Compute the direction of a refracted ray +vector2Refract :: + -- | Normalized direction of the incoming ray + Vector2 -> + -- | Normalized normal vector of the interface of two optical media + Vector2 -> + -- | Ratio of the refractive index of the medium from where the ray comes + -- to the refractive index of the medium on the other side of the surface + Float -> + Vector2 +vector2Refract (Vector2 vx vy) (Vector2 nx ny) r = if d >= 0 then Vector2 (r * vx - (r * dot + d') * nx) (r * vy - (r * dot + d') * ny) else Vector2 0 0 + where + dot = vx * nx + vy * ny + d = 1 - r * r * (1 - dot * dot) + d' = sqrt d + ------------------------------------------------ -- Vector3 math -------------------------------- ------------------------------------------------ @@ -516,20 +533,20 @@ vector3Unproject (Vector3 x y z) projection view = Vector3 (rx / rw) (ry / rw) ( matViewProjInv = Matrix ((a11 * b11 - a12 * b10 + a13 * b09) * invDet) - ((- a01 * b11 + a02 * b10 - a03 * b09) * invDet) + ((-a01 * b11 + a02 * b10 - a03 * b09) * invDet) ((a31 * b05 - a32 * b04 + a33 * b03) * invDet) - ((- a21 * b05 + a22 * b04 - a23 * b03) * invDet) - ((- a10 * b11 + a12 * b08 - a13 * b07) * invDet) + ((-a21 * b05 + a22 * b04 - a23 * b03) * invDet) + ((-a10 * b11 + a12 * b08 - a13 * b07) * invDet) ((a00 * b11 - a02 * b08 + a03 * b07) * invDet) - ((- a30 * b05 + a32 * b02 - a33 * b01) * invDet) + ((-a30 * b05 + a32 * b02 - a33 * b01) * invDet) ((a20 * b05 - a22 * b02 + a23 * b01) * invDet) ((a10 * b10 - a11 * b08 + a13 * b06) * invDet) - ((- a00 * b10 + a01 * b08 - a03 * b06) * invDet) + ((-a00 * b10 + a01 * b08 - a03 * b06) * invDet) ((a30 * b04 - a31 * b02 + a33 * b00) * invDet) - ((- a20 * b04 + a21 * b02 - a23 * b00) * invDet) - ((- a10 * b09 + a11 * b07 - a12 * b06) * invDet) + ((-a20 * b04 + a21 * b02 - a23 * b00) * invDet) + ((-a10 * b09 + a11 * b07 - a12 * b06) * invDet) ((a00 * b09 - a01 * b07 + a02 * b06) * invDet) - ((- a30 * b03 + a31 * b01 - a32 * b00) * invDet) + ((-a30 * b03 + a31 * b01 - a32 * b00) * invDet) ((a20 * b03 - a21 * b01 + a22 * b00) * invDet) (Vector4 rx ry rz rw) = quaternionTransform (Vector4 x y z 1) matViewProjInv @@ -574,16 +591,29 @@ matrixConstant n = matrixFromList $ repeat n matrixDeterminant :: Matrix -> Float matrixDeterminant (Matrix a00 a10 a20 a30 a01 a11 a21 a31 a02 a12 a22 a32 a03 a13 a23 a33) = - a30 * a21 * a12 * a03 - a20 * a31 * a12 * a03 - a30 * a11 * a22 * a03 + a10 * a31 * a22 * a03 - + a20 * a11 * a32 * a03 - a10 * a21 * a32 * a03 - a30 * a21 * a02 * a13 + a30 * a21 * a12 * a03 + - a20 * a31 * a12 * a03 + - a30 * a11 * a22 * a03 + + a10 * a31 * a22 * a03 + + a20 * a11 * a32 * a03 + - a10 * a21 * a32 * a03 + - a30 * a21 * a02 * a13 + a20 * a31 * a02 * a13 - + a30 * a01 * a22 * a13 - a00 * a31 * a22 * a13 - a20 * a01 * a32 * a13 + + a30 * a01 * a22 * a13 + - a00 * a31 * a22 * a13 + - a20 * a01 * a32 * a13 + a00 * a21 * a32 * a13 - + a30 * a11 * a02 * a23 - a10 * a31 * a02 * a23 - a30 * a01 * a12 * a23 + + a30 * a11 * a02 * a23 + - a10 * a31 * a02 * a23 + - a30 * a01 * a12 * a23 + a00 * a31 * a12 * a23 - + a10 * a01 * a32 * a23 - a00 * a11 * a32 * a23 - a20 * a11 * a02 * a33 + + a10 * a01 * a32 * a23 + - a00 * a11 * a32 * a23 + - a20 * a11 * a02 * a33 + a10 * a21 * a02 * a33 - + a20 * a01 * a12 * a33 - a00 * a21 * a12 * a33 - a10 * a01 * a22 * a33 + + a20 * a01 * a12 * a33 + - a00 * a21 * a12 * a33 + - a10 * a01 * a22 * a33 + a00 * a11 * a22 * a33 -- | Trace of a matrix (sum of the values along the diagonal) @@ -602,20 +632,20 @@ matrixInvert (Matrix a00 a10 a20 a30 a01 a11 a21 a31 a02 a12 a22 a32 a03 a13 a23 a33) = Matrix ((a11 * b11 - a12 * b10 + a13 * b09) * invDet) - ((- a10 * b11 + a12 * b08 - a13 * b07) * invDet) + ((-a10 * b11 + a12 * b08 - a13 * b07) * invDet) ((a10 * b10 - a11 * b08 + a13 * b06) * invDet) - ((- a10 * b09 + a11 * b07 - a12 * b06) * invDet) - ((- a01 * b11 + a02 * b10 - a03 * b09) * invDet) + ((-a10 * b09 + a11 * b07 - a12 * b06) * invDet) + ((-a01 * b11 + a02 * b10 - a03 * b09) * invDet) ((a00 * b11 - a02 * b08 + a03 * b07) * invDet) - ((- a00 * b10 + a01 * b08 - a03 * b06) * invDet) + ((-a00 * b10 + a01 * b08 - a03 * b06) * invDet) ((a00 * b09 - a01 * b07 + a02 * b06) * invDet) ((a31 * b05 - a32 * b04 + a33 * b03) * invDet) - ((- a30 * b05 + a32 * b02 - a33 * b01) * invDet) + ((-a30 * b05 + a32 * b02 - a33 * b01) * invDet) ((a30 * b04 - a31 * b02 + a33 * b00) * invDet) - ((- a30 * b03 + a31 * b01 - a32 * b00) * invDet) - ((- a21 * b05 + a22 * b04 - a23 * b03) * invDet) + ((-a30 * b03 + a31 * b01 - a32 * b00) * invDet) + ((-a21 * b05 + a22 * b04 - a23 * b03) * invDet) ((a20 * b05 - a22 * b02 + a23 * b01) * invDet) - ((- a20 * b04 + a21 * b02 - a23 * b00) * invDet) + ((-a20 * b04 + a21 * b02 - a23 * b00) * invDet) ((a20 * b03 - a21 * b01 + a22 * b00) * invDet) where b00 = a00 * a11 - a01 * a10 @@ -706,39 +736,39 @@ matrixRotate axis angle = Matrix (x * x * t + c) (x * y * t - z * s) (x * z * t -- | x-rotation matrix (angle should be in radians) matrixRotateX :: Float -> Matrix -matrixRotateX angle = Matrix 1 0 0 0 0 c (- s) 0 0 s c 0 0 0 0 1 +matrixRotateX angle = Matrix 1 0 0 0 0 c (-s) 0 0 s c 0 0 0 0 1 where s = sin angle c = cos angle -- | y-rotation matrix (angle should be in radians) matrixRotateY :: Float -> Matrix -matrixRotateY angle = Matrix c 0 s 0 0 1 0 0 (- s) 0 c 0 0 0 0 1 +matrixRotateY angle = Matrix c 0 s 0 0 1 0 0 (-s) 0 c 0 0 0 0 1 where s = sin angle c = cos angle -- | z-rotation matrix (angle should be in radians) matrixRotateZ :: Float -> Matrix -matrixRotateZ angle = Matrix c (- s) 0 0 s c 0 0 0 0 1 0 0 0 0 1 +matrixRotateZ angle = Matrix c (-s) 0 0 s c 0 0 0 0 1 0 0 0 0 1 where s = sin angle c = cos angle -- | Euler angle xyz rotation matrix (angles should be in radians) matrixRotateXYZ :: Vector3 -> Matrix -matrixRotateXYZ (Vector3 x y z) = Matrix (cz - cy) (sz * cy) (- sy) 0 (cz * sy * sx - sz * cx) (sz * sy * sx + cz * cx) (cy * sx) 0 (cz * sy * cx + sz * sx) (sz * sy * cx - cz * sx) (cy * cx) 0 0 0 0 1 +matrixRotateXYZ (Vector3 x y z) = Matrix (cz - cy) (sz * cy) (-sy) 0 (cz * sy * sx - sz * cx) (sz * sy * sx + cz * cx) (cy * sx) 0 (cz * sy * cx + sz * sx) (sz * sy * cx - cz * sx) (cy * cx) 0 0 0 0 1 where - cx = cos (- x) - sx = sin (- x) - cy = cos (- y) - sy = sin (- y) - cz = cos (- z) - sz = sin (- z) + cx = cos (-x) + sx = sin (-x) + cy = cos (-y) + sy = sin (-y) + cz = cos (-z) + sz = sin (-z) -- | Euler angle zyx rotation matrix (angles should be in radians) matrixRotateZYX :: Vector3 -> Matrix -matrixRotateZYX (Vector3 x y z) = Matrix (cz * cy) (cz * sy * sx - cx * sz) (sz * sx + cz * cx * sy) 0 (cy * sz) (cz * cx + sz * sy * sx) (cx * sz * sy - cz * sx) 0 (- sy) (cy * sx) (cy * cx) 0 0 0 0 1 +matrixRotateZYX (Vector3 x y z) = Matrix (cz * cy) (cz * sy * sx - cx * sz) (sz * sx + cz * cx * sy) 0 (cy * sz) (cz * cx + sz * sy * sx) (cx * sz * sy - cz * sx) 0 (-sy) (cy * sx) (cy * cx) 0 0 0 0 1 where cz = cos z sz = sin z @@ -778,8 +808,8 @@ matrixFrustum left right bottom top near far = 0 0 0 - (- (far + near) / z) - (- far * near * 2 / z) + (-(far + near) / z) + (-far * near * 2 / z) 0 0 (-1) @@ -803,9 +833,9 @@ matrixPerspective :: matrixPerspective fovy aspect near far = matrixFrustum left right bottom top near far where top = near * tan (fovy / 2) - bottom = - top + bottom = -top right = top * aspect - left = - right + left = -right -- | Orthographic projection matrix matrixOrtho :: @@ -823,7 +853,7 @@ matrixOrtho :: Float -> Matrix matrixOrtho left right bottom top near far = - Matrix (2 / x) 0 0 (- (left + right) / x) 0 (2 / y) 0 (- (top + bottom) / y) 0 0 (-2 / z) (- (far + near) / z) 0 0 0 1 + Matrix (2 / x) 0 0 (-(left + right) / x) 0 (2 / y) 0 (-(top + bottom) / y) 0 0 (-2 / z) (-(far + near) / z) 0 0 0 1 where x = right - left y = top - bottom @@ -838,7 +868,7 @@ matrixLookAt :: -- | World up vector Vector3 -> Matrix -matrixLookAt eye target up = Matrix xx xy xz (- vx |.| eye) yx yy yz (- vy |.| eye) zx zy zz (- vz |.| eye) 0 0 0 1 +matrixLookAt eye target up = Matrix xx xy xz (-vx |.| eye) yx yy yz (-vy |.| eye) zx zy zz (-vz |.| eye) 0 0 0 1 where vz@(Vector3 zx zy zz) = vectorNormalize $ eye |-| target vx@(Vector3 xx xy xz) = vectorNormalize $ vector3CrossProduct up vz @@ -854,7 +884,7 @@ quaternionIdentity = Vector4 0 0 0 1 -- | Invert a quaternion quaternionInvert :: Quaternion -> Quaternion -quaternionInvert q@(Vector4 x y z w) = Vector4 (- x * invLength) (- y * invLength) (- z * invLength) (w * invLength) +quaternionInvert q@(Vector4 x y z w) = Vector4 (-x * invLength) (-y * invLength) (-z * invLength) (w * invLength) where invLength = 1 / magnitudeSqr q @@ -903,7 +933,7 @@ quaternionSLerp q1 q2 amount | abs sinHalfTheta < epsilon = (q1 |+| q2') |/ 2 | otherwise = (q1 |* ratioA) |+| (q2 |* ratioB) where - cosHalfTheta = if dot < 0 then - dot else dot + cosHalfTheta = if dot < 0 then -dot else dot sinHalfTheta = sqrt (1 - cosHalfTheta * cosHalfTheta) halfTheta = acos cosHalfTheta