From 09e46d1f780b006a59252fbcecf188ef848d00d5 Mon Sep 17 00:00:00 2001 From: Marc Sunet Date: Tue, 28 Aug 2012 23:42:07 +0200 Subject: Added Spatial2 and Spatial3; removed Spatial --- Spear.cabal | 5 +-- Spear.lkshs | 12 +++---- Spear.lkshw | 2 +- Spear/Math/Camera.hs | 6 ++-- Spear/Math/Entity.hs | 18 +++++----- Spear/Math/Spatial.hs | 92 -------------------------------------------------- Spear/Math/Spatial2.hs | 69 +++++++++++++++++++++++++++++++++++++ Spear/Math/Spatial3.hs | 84 +++++++++++++++++++++++++++++++++++++++++++++ Spear/Physics/Rigid.hs | 52 +++++++++++++--------------- Spear/Physics/Types.hs | 10 +++--- Spear/Scene/Light.hs | 9 +++-- 11 files changed, 210 insertions(+), 149 deletions(-) delete mode 100644 Spear/Math/Spatial.hs create mode 100644 Spear/Math/Spatial2.hs create mode 100644 Spear/Math/Spatial3.hs diff --git a/Spear.cabal b/Spear.cabal index 254f181..01a2b23 100644 --- a/Spear.cabal +++ b/Spear.cabal @@ -26,7 +26,7 @@ library Spear.GLSL.Uniform Spear.GLSL.VAO Spear.Math.Camera Spear.Math.Entity Spear.Math.Matrix3 Spear.Math.Matrix4 Spear.Math.MatrixUtils Spear.Math.Plane Spear.Math.Quaternion - Spear.Math.Spatial Spear.Math.Vector3 Spear.Math.Vector4 + Spear.Math.Vector3 Spear.Math.Vector4 Spear.Physics Spear.Physics.Rigid Spear.Render.AnimatedModel Spear.Render.Material Spear.Render.Model Spear.Render.Program Spear.Render.Renderable Spear.Render.StaticModel @@ -35,6 +35,7 @@ library Spear.Setup Spear.Sys.Timer Spear.Sys.Store Spear.Sys.Store.ID Spear.Updatable Spear.Math.Vector2 Spear.Math.Quad Spear.Math.Ray Spear.Math.Segment Spear.Math.Utils + Spear.Math.Spatial2 Spear.Math.Spatial3 exposed: True buildable: True build-tools: hsc2hs -any @@ -57,4 +58,4 @@ library Spear/Sys hs-source-dirs: . ghc-options: -O2 -rtsopts - \ No newline at end of file + diff --git a/Spear.lkshs b/Spear.lkshs index 8ff60d0..698ee98 100644 --- a/Spear.lkshs +++ b/Spear.lkshs @@ -1,18 +1,18 @@ Version of session file format: 1 Time of storage: - "Tue Aug 28 22:08:10 CEST 2012" -Layout: VerticalP (TerminalP {paneGroups = fromList [], paneTabs = Just TopP, currentPage = 3, detachedId = Nothing, detachedSize = Nothing}) (HorizontalP (TerminalP {paneGroups = fromList [("Browser",HorizontalP (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (HorizontalP (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) 308) 194)], paneTabs = Just BottomP, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) 683) 954 -Population: [(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Render/AnimatedModel.hs" 247)),[SplitP LeftP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Collision/Collision.hs" 2235)),[SplitP LeftP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Collision/Collisioner.hs" 1019)),[SplitP LeftP]),(Just (ErrorsSt ErrorsState),[SplitP RightP,SplitP TopP]),(Just (FilesSt FilesState),[SplitP RightP,SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Scene/GameObject.hs" 1898)),[SplitP LeftP]),(Just (InfoSt (InfoState Nothing)),[SplitP RightP,SplitP TopP,GroupP "Browser",SplitP BottomP,SplitP BottomP]),(Just (LogSt LogState),[SplitP RightP,SplitP BottomP]),(Just (ModulesSt (ModulesState 328 (PackageScope False,False) (Just (ModuleName ["Spear","Collision","Collision"]),Nothing) (ExpanderState {packageExp = ([],[]), packageExpNoBlack = ([[0,7],[0,4],[0,1],[0]],[]), packageDExp = ([],[]), packageDExpNoBlack = ([],[]), workspaceExp = ([],[]), workspaceExpNoBlack = ([],[]), workspaceDExp = ([],[]), workspaceDExpNoBlack = ([],[]), systemExp = ([],[]), systemExpNoBlack = ([],[])}))),[SplitP RightP,SplitP TopP,GroupP "Browser",SplitP BottomP,SplitP TopP]),(Just (WorkspaceSt WorkspaceState),[SplitP RightP,SplitP TopP,GroupP "Browser",SplitP TopP])] + "Tue Aug 28 23:41:10 CEST 2012" +Layout: VerticalP (TerminalP {paneGroups = fromList [], paneTabs = Just TopP, currentPage = 2, detachedId = Nothing, detachedSize = Nothing}) (HorizontalP (TerminalP {paneGroups = fromList [("Browser",HorizontalP (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (HorizontalP (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) 306) 200)], paneTabs = Just BottomP, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) (TerminalP {paneGroups = fromList [], paneTabs = Nothing, currentPage = 0, detachedId = Nothing, detachedSize = Nothing}) 692) 954 +Population: [(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Math/Camera.hs" 2313)),[SplitP LeftP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Math/Entity.hs" 1072)),[SplitP LeftP]),(Just (ErrorsSt ErrorsState),[SplitP RightP,SplitP TopP]),(Just (FilesSt FilesState),[SplitP RightP,SplitP TopP]),(Just (InfoSt (InfoState Nothing)),[SplitP RightP,SplitP TopP,GroupP "Browser",SplitP BottomP,SplitP BottomP]),(Just (LogSt LogState),[SplitP RightP,SplitP BottomP]),(Just (ModulesSt (ModulesState 328 (PackageScope False,False) (Just (ModuleName ["Spear","Physics","Types"]),Nothing) (ExpanderState {packageExp = ([],[]), packageExpNoBlack = ([[0,5],[0]],[]), packageDExp = ([],[]), packageDExpNoBlack = ([],[]), workspaceExp = ([],[]), workspaceExpNoBlack = ([],[]), workspaceDExp = ([],[]), workspaceDExpNoBlack = ([],[]), systemExp = ([],[]), systemExpNoBlack = ([],[])}))),[SplitP RightP,SplitP TopP,GroupP "Browser",SplitP BottomP,SplitP TopP]),(Just (BufferSt (BufferState "/home/jeanne/programming/haskell/Spear/Spear/Physics/Rigid.hs" 1395)),[SplitP LeftP]),(Just (WorkspaceSt WorkspaceState),[SplitP RightP,SplitP TopP,GroupP "Browser",SplitP TopP])] Window size: (1820,939) Completion size: (750,399) Workspace: Just "/home/jeanne/programming/haskell/Spear/Spear.lkshw" -Active pane: Just "GameObject.hs" +Active pane: Just "Rigid.hs" Toolbar visible: True -FindbarState: (False,FindState {entryStr = "asd", entryHist = ["copy_tr","asad","Octree","idxs","asd","elemIndexa","elemtIn","splitAt","allocaBytes","copyArray","allocaArray","allocaa"], replaceStr = "QuadTree", replaceHist = [], caseSensitive = True, entireWord = False, wrapAround = False, regex = False, lineNr = 1}) +FindbarState: (False,FindState {entryStr = "asdad", entryHist = ["asdad","translv","Vector3.","Vector.","copy_tr","asad","Octree","idxs","elemIndexa","elemtIn","splitAt","allocaBytes"], replaceStr = "V3.", replaceHist = [], caseSensitive = True, entireWord = False, wrapAround = False, regex = False, lineNr = 1}) Recently opened files: - ["/home/jeanne/programming/haskell/Spear/Spear/Collision/Collision.hs","/home/jeanne/programming/haskell/Spear/Spear/Math/Matrix3.hs","/home/jeanne/programming/haskell/Spear/Spear/Math/AABB.hs","/home/jeanne/programming/haskell/Spear/Spear/Render/Texture.hs","/home/jeanne/programming/haskell/Spear/Spear/Render/Program.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/Factory.hs","/home/jeanne/programming/haskell/Spear/Spear/Assets/Model.hsc","/home/jeanne/programming/haskell/Spear/Spear/Assets/Model/Model.h","/home/jeanne/programming/haskell/Spear/Spear/Assets/Model/Model.c","/home/jeanne/programming/haskell/Spear/Spear/App/Input.hs","/home/jeanne/programming/haskell/Spear/Spear/Scene/SceneResources.hs","/home/jeanne/programming/haskell/Spear/Spear/Render/StaticModel.hs"] + ["/home/jeanne/programming/haskell/Spear/Spear/Math/Spatial2.hs","/home/jeanne/programming/haskell/Spear/Spear/Math/Spatial3.hs","/home/jeanne/programming/haskell/Spear/Spear/Physics/Types.hs","/home/jeanne/programming/haskell/Spear/Spear/Scene/Light.hs","/home/jeanne/programming/haskell/Spear/Spear/Scene/GameObject.hs","/home/jeanne/programming/haskell/Spear/Spear/Math/Matrix4.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/Render.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject/Player.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameObject.hs","/home/jeanne/programming/haskell/Spear/demos/simple-scene/Game/GameMessage.hs","/home/jeanne/programming/haskell/Spear/Spear/Render/AnimatedModel.hs","/home/jeanne/programming/haskell/Spear/Spear/Collision/Collisioner.hs"] Recently opened workspaces: ["/home/jeanne/programming/haskell/hagen/hagen.lkshw","/home/jeanne/programming/haskell/foo/foo.lkshw","/home/jeanne/programming/haskell/Spear/Spear.lkshw","/home/jeanne/programming/haskell/nexus/nexus.lkshw","/home/jeanne/leksah.lkshw"] \ No newline at end of file diff --git a/Spear.lkshw b/Spear.lkshw index b41cb88..142cfb0 100644 --- a/Spear.lkshw +++ b/Spear.lkshw @@ -1,7 +1,7 @@ Version of workspace file format: 1 Time of storage: - "Tue Aug 28 21:08:58 CEST 2012" + "Tue Aug 28 22:48:22 CEST 2012" Name of the workspace: "Spear" File paths of contained packages: diff --git a/Spear/Math/Camera.hs b/Spear/Math/Camera.hs index 118997a..acde7d0 100644 --- a/Spear/Math/Camera.hs +++ b/Spear/Math/Camera.hs @@ -3,7 +3,7 @@ where import qualified Spear.Math.Matrix4 as M -import qualified Spear.Math.Spatial as S +import qualified Spear.Math.Spatial3 as S import Spear.Math.Vector3 @@ -51,7 +51,7 @@ ortho l r b t n f right up fwd pos = } -instance S.Spatial Camera where +instance S.Spatial3 Camera where move v cam = cam { transform = M.translv v * transform cam } moveFwd f cam = cam { transform = M.translv (scale f $ S.fwd cam) * transform cam } moveBack f cam = cam { transform = M.translv (scale (-f) $ S.fwd cam) * transform cam } @@ -66,4 +66,6 @@ instance S.Spatial Camera where right = M.right . transform transform (Camera _ t) = t setTransform t (Camera proj _) = Camera proj t + setPos pos (Camera proj t) = Camera proj $ + M.transform (M.right t) (M.up t) (M.forward t) pos diff --git a/Spear/Math/Entity.hs b/Spear/Math/Entity.hs index 298b611..022868b 100644 --- a/Spear/Math/Entity.hs +++ b/Spear/Math/Entity.hs @@ -5,27 +5,25 @@ module Spear.Math.Entity where -import qualified Spear.Math.Matrix4 as M -import qualified Spear.Math.Spatial as S -import qualified Spear.Math.Vector3 as V +import qualified Spear.Math.Matrix3 as M +import qualified Spear.Math.Spatial2 as S +import qualified Spear.Math.Vector2 as V --- | An entity in 3D space. -newtype Entity = Entity { transform :: M.Matrix4 } +-- | An entity in 2D space. +newtype Entity = Entity { transform :: M.Matrix3 } -instance S.Spatial Entity where +instance S.Spatial2 Entity where move v ent = ent { transform = M.translv v * transform ent } moveFwd f ent = ent { transform = M.translv (V.scale f $ S.fwd ent) * transform ent } moveBack f ent = ent { transform = M.translv (V.scale (-f) $ S.fwd ent) * transform ent } strafeLeft f ent = ent { transform = M.translv (V.scale (-f) $ S.right ent) * transform ent } strafeRight f ent = ent { transform = M.translv (V.scale f $ S.right ent) * transform ent } - pitch a ent = ent { transform = transform ent * M.axisAngle (S.right ent) a } - yaw a ent = ent { transform = transform ent * M.axisAngle (S.up ent) a } - roll a ent = ent { transform = transform ent * M.axisAngle (S.fwd ent) a } + rotate a ent = ent { transform = transform ent * M.rot a } pos = M.position . transform fwd = M.forward . transform - up = M.up . transform right = M.right . transform transform (Entity t) = t setTransform t (Entity _) = Entity t + setPos pos (Entity t) = Entity $ M.transform (M.right t) (M.forward t) pos diff --git a/Spear/Math/Spatial.hs b/Spear/Math/Spatial.hs deleted file mode 100644 index fe2700f..0000000 --- a/Spear/Math/Spatial.hs +++ /dev/null @@ -1,92 +0,0 @@ -module Spear.Math.Spatial -where - - -import Spear.Math.Vector3 -import Spear.Math.Matrix4 as M - - -class Spatial s where - -- | Move the 'Spatial'. - move :: Vector3 -> s -> s - - -- | Move the 'Spatial' forwards. - moveFwd :: Float -> s -> s - - -- | Move the 'Spatial' backwards. - moveBack :: Float -> s -> s - - -- | Make the 'Spatial' strafe left. - strafeLeft :: Float -> s -> s - - -- | Make the 'Spatial' Strafe right. - strafeRight :: Float -> s -> s - - -- | Rotate the 'Spatial' about its local X axis. - pitch :: Float -> s -> s - - -- | Rotate the 'Spatial' about its local Y axis. - yaw :: Float -> s -> s - - -- | Rotate the 'Spatial' about its local Z axis. - roll :: Float -> s -> s - - -- | Get the 'Spatial''s position. - pos :: s -> Vector3 - - -- | Get the 'Spatial''s forward vector. - fwd :: s -> Vector3 - - -- | Get the 'Spatial''s up vector. - up :: s -> Vector3 - - -- | Get the 'Spatial''s right vector. - right :: s -> Vector3 - - -- | Get the 'Spatial''s transform. - transform :: s -> Matrix4 - - -- | Set the 'Spatial''s transform. - setTransform :: Matrix4 -> s -> s - - -- | Set the 'Spatial''s position. - setPos :: Vector3 -> s -> s - setPos p s = setTransform t' s - where t' = M.transform r u f p - r = Spear.Math.Spatial.right s - u = Spear.Math.Spatial.up s - f = Spear.Math.Spatial.fwd s - - -- | Make the 'Spatial' look at the given point. - lookAt :: Vector3 -> s -> s - lookAt pt s = - let position = pos s - fwd = normalise $ pt - position - r = fwd `cross` unitY - u = r `cross` fwd - in - setTransform (M.transform r u (-fwd) position) s - - -- | Make the 'Spatial' orbit around the given point - orbit :: Vector3 -- ^ Target point - -> Float -- ^ Horizontal angle - -> Float -- ^ Vertical angle - -> Float -- ^ Orbit radius. - -> s - -> s - - orbit pt anglex angley radius s = - let ax = anglex * pi / 180 - ay = angley * pi / 180 - sx = sin ax - sy = sin ay - cx = cos ax - cy = cos ay - px = (x pt) + radius*cy*sx - py = (y pt) + radius*sy - pz = (z pt) + radius*cx*cy - r = Spear.Math.Spatial.right s - u = Spear.Math.Spatial.up s - f = Spear.Math.Spatial.fwd s - in - setTransform (M.transform u r f (vec3 px py pz)) s diff --git a/Spear/Math/Spatial2.hs b/Spear/Math/Spatial2.hs new file mode 100644 index 0000000..3c60412 --- /dev/null +++ b/Spear/Math/Spatial2.hs @@ -0,0 +1,69 @@ +module Spear.Math.Spatial2 +where + + +import Spear.Math.Vector2 +import Spear.Math.Matrix3 as M + + +-- | An entity that can be moved around in 2D space. +class Spatial2 s where + + -- | Move the spatial. + move :: Vector2 -> s -> s + + -- | Move the spatial forwards. + moveFwd :: Float -> s -> s + + -- | Move the spatial backwards. + moveBack :: Float -> s -> s + + -- | Make the spatial strafe left. + strafeLeft :: Float -> s -> s + + -- | Make the spatial Strafe right. + strafeRight :: Float -> s -> s + + -- | Rotate the spatial. + rotate :: Float -> s -> s + + -- | Get the spatial position. + pos :: s -> Vector2 + + -- | Get the spatial's forward vector. + fwd :: s -> Vector2 + + -- | Get the spatial's right vector. + right :: s -> Vector2 + + -- | Get the spatial's transform. + transform :: s -> Matrix3 + + -- | Set the spatial's transform. + setTransform :: Matrix3 -> s -> s + + -- | Set the spatial's position. + setPos :: Vector2 -> s -> s + + -- | Make the spatial look at the given point. + lookAt :: Vector2 -> s -> s + lookAt pt s = + let position = pos s + fwd = normalise $ pt - position + r = perp fwd + in + setTransform (M.transform r fwd position) s + + -- | Make the 'Spatial' orbit around the given point + orbit :: Vector2 -- ^ Target point + -> Float -- ^ Angle + -> Float -- ^ Orbit radius + -> s + -> s + + orbit pt angle radius s = + let a = angle * pi / 180 + px = (x pt) + radius * sin a + py = (y pt) + radius * cos a + in + setPos (vec2 px py) s diff --git a/Spear/Math/Spatial3.hs b/Spear/Math/Spatial3.hs new file mode 100644 index 0000000..9f9812f --- /dev/null +++ b/Spear/Math/Spatial3.hs @@ -0,0 +1,84 @@ +module Spear.Math.Spatial3 +where + + +import Spear.Math.Vector3 +import Spear.Math.Matrix4 as M + + +class Spatial3 s where + -- | Move the 'Spatial'. + move :: Vector3 -> s -> s + + -- | Move the 'Spatial' forwards. + moveFwd :: Float -> s -> s + + -- | Move the 'Spatial' backwards. + moveBack :: Float -> s -> s + + -- | Make the 'Spatial' strafe left. + strafeLeft :: Float -> s -> s + + -- | Make the 'Spatial' Strafe right. + strafeRight :: Float -> s -> s + + -- | Rotate the 'Spatial' about its local X axis. + pitch :: Float -> s -> s + + -- | Rotate the 'Spatial' about its local Y axis. + yaw :: Float -> s -> s + + -- | Rotate the 'Spatial' about its local Z axis. + roll :: Float -> s -> s + + -- | Get the 'Spatial''s position. + pos :: s -> Vector3 + + -- | Get the 'Spatial''s forward vector. + fwd :: s -> Vector3 + + -- | Get the 'Spatial''s up vector. + up :: s -> Vector3 + + -- | Get the 'Spatial''s right vector. + right :: s -> Vector3 + + -- | Get the 'Spatial''s transform. + transform :: s -> Matrix4 + + -- | Set the 'Spatial''s transform. + setTransform :: Matrix4 -> s -> s + + -- | Set the 'Spatial''s position. + setPos :: Vector3 -> s -> s + + -- | Make the 'Spatial' look at the given point. + lookAt :: Vector3 -> s -> s + lookAt pt s = + let position = pos s + fwd = normalise $ pt - position + r = fwd `cross` unitY + u = r `cross` fwd + in + setTransform (M.transform r u (-fwd) position) s + + -- | Make the 'Spatial' orbit around the given point + orbit :: Vector3 -- ^ Target point + -> Float -- ^ Horizontal angle + -> Float -- ^ Vertical angle + -> Float -- ^ Orbit radius. + -> s + -> s + + orbit pt anglex angley radius s = + let ax = anglex * pi / 180 + ay = angley * pi / 180 + sx = sin ax + sy = sin ay + cx = cos ax + cy = cos ay + px = (x pt) + radius*cy*sx + py = (y pt) + radius*sy + pz = (z pt) + radius*cx*cy + in + setPos (vec3 px py pz) s diff --git a/Spear/Physics/Rigid.hs b/Spear/Physics/Rigid.hs index 6d3c4d7..396cae4 100644 --- a/Spear/Physics/Rigid.hs +++ b/Spear/Physics/Rigid.hs @@ -10,9 +10,9 @@ module Spear.Physics.Rigid where -import qualified Spear.Math.Matrix4 as M4 -import Spear.Math.Spatial -import Spear.Math.Vector3 as V3 +import qualified Spear.Math.Matrix3 as M3 +import Spear.Math.Spatial2 +import Spear.Math.Vector2 import Spear.Physics.Types import Data.List (foldl') @@ -20,55 +20,49 @@ import Control.Monad.State data RigidBody = RigidBody - { mass :: !Float - , position :: !Vector3 - , velocity :: !Vector3 - , acceleration :: !Vector3 + { mass :: {-# UNPACK #-} !Float + , position :: {-# UNPACK #-} !Vector2 + , velocity :: {-# UNPACK #-} !Vector2 + , acceleration :: {-# UNPACK #-} !Vector2 } -instance Spatial RigidBody where +instance Spatial2 RigidBody where move v body = body { position = v + position body } - moveFwd speed body = body { position = position body + scale (-speed) unitZ } + moveFwd speed body = body { position = position body + scale speed unity } - moveBack speed body = body { position = position body + scale speed unitZ } + moveBack speed body = body { position = position body + scale (-speed) unity } - strafeLeft speed body = body { position = position body + scale (-speed) unitX } + strafeLeft speed body = body { position = position body + scale (-speed) unitx } - strafeRight speed body = body { position = position body + scale speed unitX } + strafeRight speed body = body { position = position body + scale speed unitx } - pitch angle = id - - yaw angle = id - - roll angle = id + rotate angle = id pos = position - fwd _ = unitZ - - up _ = unitY + fwd _ = unity - right _ = unitX + right _ = unitx - transform body = M4.transform unitX unitY unitZ $ position body + transform body = M3.transform unitx unity $ position body - setTransform transf body = body { position = M4.position transf } + setTransform transf body = body { position = M3.position transf } setPos p body = body { position = p } -- | Build a 'RigidBody'. rigidBody :: Mass -> Position -> RigidBody -rigidBody m x = RigidBody m x V3.zero V3.zero +rigidBody m x = RigidBody m x zero zero -- | Update the given 'RigidBody'. update :: [Force] -> Dt -> RigidBody -> RigidBody update forces dt body = - let netforce = foldl' (+) V3.zero forces + let netforce = foldl' (+) zero forces m = mass body r1 = position body v1 = velocity body @@ -92,8 +86,8 @@ setAcceleration a body = body { acceleration = a } -- test -gravity = vec3 0 (-10) 0 -b0 = rigidBody 50 $ vec3 0 1000 0 +gravity = vec2 0 (-10) +b0 = rigidBody 50 $ vec2 0 1000 debug :: IO () @@ -110,7 +104,7 @@ debug' = do step $ update [gravity*50] 1 step $ update [gravity*50] 1 lift . putStrLn $ "Jumping" - step $ update [gravity*50, vec3 0 9000 0] 1 + step $ update [gravity*50, vec2 0 9000] 1 lift . putStrLn $ "Falling..." step $ update [gravity*50] 1 step $ update [gravity*50] 1 @@ -131,4 +125,4 @@ show' body = ", acceleration " ++ (showVec $ acceleration body) -showVec v = (show $ x v) ++ ", " ++ (show $ y v) ++ ", " ++ (show $ z v) +showVec v = (show $ x v) ++ ", " ++ (show $ y v) diff --git a/Spear/Physics/Types.hs b/Spear/Physics/Types.hs index 49c307e..de889ee 100644 --- a/Spear/Physics/Types.hs +++ b/Spear/Physics/Types.hs @@ -2,12 +2,12 @@ module Spear.Physics.Types where -import Spear.Math.Vector3 +import Spear.Math.Vector2 type Dt = Float -type Force = Vector3 +type Force = Vector2 type Mass = Float -type Position = Vector3 -type Velocity = Vector3 -type Acceleration = Vector3 +type Position = Vector2 +type Velocity = Vector2 +type Acceleration = Vector2 diff --git a/Spear/Scene/Light.hs b/Spear/Scene/Light.hs index 76ff074..f482560 100644 --- a/Spear/Scene/Light.hs +++ b/Spear/Scene/Light.hs @@ -6,7 +6,7 @@ where import qualified Spear.Math.Matrix4 as M -import qualified Spear.Math.Spatial as S +import qualified Spear.Math.Spatial3 as S import Spear.Math.Vector3 import qualified Spear.Math.Vector4 as V4 @@ -32,7 +32,7 @@ data Light } -instance S.Spatial Light where +instance S.Spatial3 Light where move _ l@DirectionalLight {} = l move v l = l { transform = M.translv v * transform l} @@ -80,3 +80,8 @@ instance S.Spatial Light where setTransform _ l@DirectionalLight {} = l setTransform t l = l { Spear.Scene.Light.transform = t } + + setPos _ l@DirectionalLight {} = l + setPos pos l = + let t = Spear.Scene.Light.transform l + in l { transform = M.transform (M.right t) (M.up t) (M.forward t) pos } -- cgit v1.2.3