diff options
author | Marc Sunet <jeannekamikaze@gmail.com> | 2012-08-28 23:42:07 +0200 |
---|---|---|
committer | Marc Sunet <jeannekamikaze@gmail.com> | 2012-08-28 23:42:07 +0200 |
commit | 09e46d1f780b006a59252fbcecf188ef848d00d5 (patch) | |
tree | 6876b5edc16364a4e92ef15b042afa32f4a09f53 | |
parent | 7aa01fe67996eec8d967a1bb73d168d6cc2b3434 (diff) |
Added Spatial2 and Spatial3; removed Spatial
-rw-r--r-- | Spear.cabal | 5 | ||||
-rw-r--r-- | Spear.lkshs | 12 | ||||
-rw-r--r-- | Spear.lkshw | 2 | ||||
-rw-r--r-- | Spear/Math/Camera.hs | 6 | ||||
-rw-r--r-- | Spear/Math/Entity.hs | 18 | ||||
-rw-r--r-- | Spear/Math/Spatial2.hs | 69 | ||||
-rw-r--r-- | Spear/Math/Spatial3.hs (renamed from Spear/Math/Spatial.hs) | 14 | ||||
-rw-r--r-- | Spear/Physics/Rigid.hs | 52 | ||||
-rw-r--r-- | Spear/Physics/Types.hs | 10 | ||||
-rw-r--r-- | Spear/Scene/Light.hs | 9 |
10 files changed, 129 insertions, 68 deletions
diff --git a/Spear.cabal b/Spear.cabal index 254f181..01a2b23 100644 --- a/Spear.cabal +++ b/Spear.cabal | |||
@@ -26,7 +26,7 @@ library | |||
26 | Spear.GLSL.Uniform Spear.GLSL.VAO Spear.Math.Camera | 26 | Spear.GLSL.Uniform Spear.GLSL.VAO Spear.Math.Camera |
27 | Spear.Math.Entity Spear.Math.Matrix3 Spear.Math.Matrix4 | 27 | Spear.Math.Entity Spear.Math.Matrix3 Spear.Math.Matrix4 |
28 | Spear.Math.MatrixUtils Spear.Math.Plane Spear.Math.Quaternion | 28 | Spear.Math.MatrixUtils Spear.Math.Plane Spear.Math.Quaternion |
29 | Spear.Math.Spatial Spear.Math.Vector3 Spear.Math.Vector4 | 29 | Spear.Math.Vector3 Spear.Math.Vector4 |
30 | Spear.Physics Spear.Physics.Rigid Spear.Render.AnimatedModel | 30 | Spear.Physics Spear.Physics.Rigid Spear.Render.AnimatedModel |
31 | Spear.Render.Material Spear.Render.Model Spear.Render.Program | 31 | Spear.Render.Material Spear.Render.Model Spear.Render.Program |
32 | Spear.Render.Renderable Spear.Render.StaticModel | 32 | Spear.Render.Renderable Spear.Render.StaticModel |
@@ -35,6 +35,7 @@ library | |||
35 | Spear.Setup Spear.Sys.Timer Spear.Sys.Store Spear.Sys.Store.ID | 35 | Spear.Setup Spear.Sys.Timer Spear.Sys.Store Spear.Sys.Store.ID |
36 | Spear.Updatable Spear.Math.Vector2 Spear.Math.Quad Spear.Math.Ray | 36 | Spear.Updatable Spear.Math.Vector2 Spear.Math.Quad Spear.Math.Ray |
37 | Spear.Math.Segment Spear.Math.Utils | 37 | Spear.Math.Segment Spear.Math.Utils |
38 | Spear.Math.Spatial2 Spear.Math.Spatial3 | ||
38 | exposed: True | 39 | exposed: True |
39 | buildable: True | 40 | buildable: True |
40 | build-tools: hsc2hs -any | 41 | build-tools: hsc2hs -any |
@@ -57,4 +58,4 @@ library | |||
57 | Spear/Sys | 58 | Spear/Sys |
58 | hs-source-dirs: . | 59 | hs-source-dirs: . |
59 | ghc-options: -O2 -rtsopts | 60 | ghc-options: -O2 -rtsopts |
60 | \ No newline at end of file | 61 | |
diff --git a/Spear.lkshs b/Spear.lkshs index 8ff60d0..698ee98 100644 --- a/Spear.lkshs +++ b/Spear.lkshs | |||
@@ -1,18 +1,18 @@ | |||
1 | Version of session file format: | 1 | Version of session file format: |
2 | 1 | 2 | 1 |
3 | Time of storage: | 3 | Time of storage: |
4 | "Tue Aug 28 22:08:10 CEST 2012" | 4 | "Tue Aug 28 23:41:10 CEST 2012" |
5 | 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 | 5 | 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 |
6 | 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])] | 6 | 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])] |
7 | Window size: (1820,939) | 7 | Window size: (1820,939) |
8 | Completion size: | 8 | Completion size: |
9 | (750,399) | 9 | (750,399) |
10 | Workspace: Just "/home/jeanne/programming/haskell/Spear/Spear.lkshw" | 10 | Workspace: Just "/home/jeanne/programming/haskell/Spear/Spear.lkshw" |
11 | Active pane: Just "GameObject.hs" | 11 | Active pane: Just "Rigid.hs" |
12 | Toolbar visible: | 12 | Toolbar visible: |
13 | True | 13 | True |
14 | 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}) | 14 | 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}) |
15 | Recently opened files: | 15 | Recently opened files: |
16 | ["/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"] | 16 | ["/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"] |
17 | Recently opened workspaces: | 17 | Recently opened workspaces: |
18 | ["/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 | 18 | ["/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 @@ | |||
1 | Version of workspace file format: | 1 | Version of workspace file format: |
2 | 1 | 2 | 1 |
3 | Time of storage: | 3 | Time of storage: |
4 | "Tue Aug 28 21:08:58 CEST 2012" | 4 | "Tue Aug 28 22:48:22 CEST 2012" |
5 | Name of the workspace: | 5 | Name of the workspace: |
6 | "Spear" | 6 | "Spear" |
7 | File paths of contained packages: | 7 | 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 | |||
3 | 3 | ||
4 | 4 | ||
5 | import qualified Spear.Math.Matrix4 as M | 5 | import qualified Spear.Math.Matrix4 as M |
6 | import qualified Spear.Math.Spatial as S | 6 | import qualified Spear.Math.Spatial3 as S |
7 | import Spear.Math.Vector3 | 7 | import Spear.Math.Vector3 |
8 | 8 | ||
9 | 9 | ||
@@ -51,7 +51,7 @@ ortho l r b t n f right up fwd pos = | |||
51 | } | 51 | } |
52 | 52 | ||
53 | 53 | ||
54 | instance S.Spatial Camera where | 54 | instance S.Spatial3 Camera where |
55 | move v cam = cam { transform = M.translv v * transform cam } | 55 | move v cam = cam { transform = M.translv v * transform cam } |
56 | moveFwd f cam = cam { transform = M.translv (scale f $ S.fwd cam) * transform cam } | 56 | moveFwd f cam = cam { transform = M.translv (scale f $ S.fwd cam) * transform cam } |
57 | moveBack f cam = cam { transform = M.translv (scale (-f) $ S.fwd cam) * transform cam } | 57 | moveBack f cam = cam { transform = M.translv (scale (-f) $ S.fwd cam) * transform cam } |
@@ -66,4 +66,6 @@ instance S.Spatial Camera where | |||
66 | right = M.right . transform | 66 | right = M.right . transform |
67 | transform (Camera _ t) = t | 67 | transform (Camera _ t) = t |
68 | setTransform t (Camera proj _) = Camera proj t | 68 | setTransform t (Camera proj _) = Camera proj t |
69 | setPos pos (Camera proj t) = Camera proj $ | ||
70 | M.transform (M.right t) (M.up t) (M.forward t) pos | ||
69 | 71 | ||
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 | |||
5 | where | 5 | where |
6 | 6 | ||
7 | 7 | ||
8 | import qualified Spear.Math.Matrix4 as M | 8 | import qualified Spear.Math.Matrix3 as M |
9 | import qualified Spear.Math.Spatial as S | 9 | import qualified Spear.Math.Spatial2 as S |
10 | import qualified Spear.Math.Vector3 as V | 10 | import qualified Spear.Math.Vector2 as V |
11 | 11 | ||
12 | 12 | ||
13 | -- | An entity in 3D space. | 13 | -- | An entity in 2D space. |
14 | newtype Entity = Entity { transform :: M.Matrix4 } | 14 | newtype Entity = Entity { transform :: M.Matrix3 } |
15 | 15 | ||
16 | 16 | ||
17 | instance S.Spatial Entity where | 17 | instance S.Spatial2 Entity where |
18 | move v ent = ent { transform = M.translv v * transform ent } | 18 | move v ent = ent { transform = M.translv v * transform ent } |
19 | moveFwd f ent = ent { transform = M.translv (V.scale f $ S.fwd ent) * transform ent } | 19 | moveFwd f ent = ent { transform = M.translv (V.scale f $ S.fwd ent) * transform ent } |
20 | moveBack f ent = ent { transform = M.translv (V.scale (-f) $ S.fwd ent) * transform ent } | 20 | moveBack f ent = ent { transform = M.translv (V.scale (-f) $ S.fwd ent) * transform ent } |
21 | strafeLeft f ent = ent { transform = M.translv (V.scale (-f) $ S.right ent) * transform ent } | 21 | strafeLeft f ent = ent { transform = M.translv (V.scale (-f) $ S.right ent) * transform ent } |
22 | strafeRight f ent = ent { transform = M.translv (V.scale f $ S.right ent) * transform ent } | 22 | strafeRight f ent = ent { transform = M.translv (V.scale f $ S.right ent) * transform ent } |
23 | pitch a ent = ent { transform = transform ent * M.axisAngle (S.right ent) a } | 23 | rotate a ent = ent { transform = transform ent * M.rot a } |
24 | yaw a ent = ent { transform = transform ent * M.axisAngle (S.up ent) a } | ||
25 | roll a ent = ent { transform = transform ent * M.axisAngle (S.fwd ent) a } | ||
26 | pos = M.position . transform | 24 | pos = M.position . transform |
27 | fwd = M.forward . transform | 25 | fwd = M.forward . transform |
28 | up = M.up . transform | ||
29 | right = M.right . transform | 26 | right = M.right . transform |
30 | transform (Entity t) = t | 27 | transform (Entity t) = t |
31 | setTransform t (Entity _) = Entity t | 28 | setTransform t (Entity _) = Entity t |
29 | setPos pos (Entity t) = Entity $ M.transform (M.right t) (M.forward t) pos | ||
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 @@ | |||
1 | module Spear.Math.Spatial2 | ||
2 | where | ||
3 | |||
4 | |||
5 | import Spear.Math.Vector2 | ||
6 | import Spear.Math.Matrix3 as M | ||
7 | |||
8 | |||
9 | -- | An entity that can be moved around in 2D space. | ||
10 | class Spatial2 s where | ||
11 | |||
12 | -- | Move the spatial. | ||
13 | move :: Vector2 -> s -> s | ||
14 | |||
15 | -- | Move the spatial forwards. | ||
16 | moveFwd :: Float -> s -> s | ||
17 | |||
18 | -- | Move the spatial backwards. | ||
19 | moveBack :: Float -> s -> s | ||
20 | |||
21 | -- | Make the spatial strafe left. | ||
22 | strafeLeft :: Float -> s -> s | ||
23 | |||
24 | -- | Make the spatial Strafe right. | ||
25 | strafeRight :: Float -> s -> s | ||
26 | |||
27 | -- | Rotate the spatial. | ||
28 | rotate :: Float -> s -> s | ||
29 | |||
30 | -- | Get the spatial position. | ||
31 | pos :: s -> Vector2 | ||
32 | |||
33 | -- | Get the spatial's forward vector. | ||
34 | fwd :: s -> Vector2 | ||
35 | |||
36 | -- | Get the spatial's right vector. | ||
37 | right :: s -> Vector2 | ||
38 | |||
39 | -- | Get the spatial's transform. | ||
40 | transform :: s -> Matrix3 | ||
41 | |||
42 | -- | Set the spatial's transform. | ||
43 | setTransform :: Matrix3 -> s -> s | ||
44 | |||
45 | -- | Set the spatial's position. | ||
46 | setPos :: Vector2 -> s -> s | ||
47 | |||
48 | -- | Make the spatial look at the given point. | ||
49 | lookAt :: Vector2 -> s -> s | ||
50 | lookAt pt s = | ||
51 | let position = pos s | ||
52 | fwd = normalise $ pt - position | ||
53 | r = perp fwd | ||
54 | in | ||
55 | setTransform (M.transform r fwd position) s | ||
56 | |||
57 | -- | Make the 'Spatial' orbit around the given point | ||
58 | orbit :: Vector2 -- ^ Target point | ||
59 | -> Float -- ^ Angle | ||
60 | -> Float -- ^ Orbit radius | ||
61 | -> s | ||
62 | -> s | ||
63 | |||
64 | orbit pt angle radius s = | ||
65 | let a = angle * pi / 180 | ||
66 | px = (x pt) + radius * sin a | ||
67 | py = (y pt) + radius * cos a | ||
68 | in | ||
69 | setPos (vec2 px py) s | ||
diff --git a/Spear/Math/Spatial.hs b/Spear/Math/Spatial3.hs index fe2700f..9f9812f 100644 --- a/Spear/Math/Spatial.hs +++ b/Spear/Math/Spatial3.hs | |||
@@ -1,4 +1,4 @@ | |||
1 | module Spear.Math.Spatial | 1 | module Spear.Math.Spatial3 |
2 | where | 2 | where |
3 | 3 | ||
4 | 4 | ||
@@ -6,7 +6,7 @@ import Spear.Math.Vector3 | |||
6 | import Spear.Math.Matrix4 as M | 6 | import Spear.Math.Matrix4 as M |
7 | 7 | ||
8 | 8 | ||
9 | class Spatial s where | 9 | class Spatial3 s where |
10 | -- | Move the 'Spatial'. | 10 | -- | Move the 'Spatial'. |
11 | move :: Vector3 -> s -> s | 11 | move :: Vector3 -> s -> s |
12 | 12 | ||
@@ -51,11 +51,6 @@ class Spatial s where | |||
51 | 51 | ||
52 | -- | Set the 'Spatial''s position. | 52 | -- | Set the 'Spatial''s position. |
53 | setPos :: Vector3 -> s -> s | 53 | setPos :: Vector3 -> s -> s |
54 | setPos p s = setTransform t' s | ||
55 | where t' = M.transform r u f p | ||
56 | r = Spear.Math.Spatial.right s | ||
57 | u = Spear.Math.Spatial.up s | ||
58 | f = Spear.Math.Spatial.fwd s | ||
59 | 54 | ||
60 | -- | Make the 'Spatial' look at the given point. | 55 | -- | Make the 'Spatial' look at the given point. |
61 | lookAt :: Vector3 -> s -> s | 56 | lookAt :: Vector3 -> s -> s |
@@ -85,8 +80,5 @@ class Spatial s where | |||
85 | px = (x pt) + radius*cy*sx | 80 | px = (x pt) + radius*cy*sx |
86 | py = (y pt) + radius*sy | 81 | py = (y pt) + radius*sy |
87 | pz = (z pt) + radius*cx*cy | 82 | pz = (z pt) + radius*cx*cy |
88 | r = Spear.Math.Spatial.right s | ||
89 | u = Spear.Math.Spatial.up s | ||
90 | f = Spear.Math.Spatial.fwd s | ||
91 | in | 83 | in |
92 | setTransform (M.transform u r f (vec3 px py pz)) s | 84 | 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 | |||
10 | where | 10 | where |
11 | 11 | ||
12 | 12 | ||
13 | import qualified Spear.Math.Matrix4 as M4 | 13 | import qualified Spear.Math.Matrix3 as M3 |
14 | import Spear.Math.Spatial | 14 | import Spear.Math.Spatial2 |
15 | import Spear.Math.Vector3 as V3 | 15 | import Spear.Math.Vector2 |
16 | import Spear.Physics.Types | 16 | import Spear.Physics.Types |
17 | 17 | ||
18 | import Data.List (foldl') | 18 | import Data.List (foldl') |
@@ -20,55 +20,49 @@ import Control.Monad.State | |||
20 | 20 | ||
21 | 21 | ||
22 | data RigidBody = RigidBody | 22 | data RigidBody = RigidBody |
23 | { mass :: !Float | 23 | { mass :: {-# UNPACK #-} !Float |
24 | , position :: !Vector3 | 24 | , position :: {-# UNPACK #-} !Vector2 |
25 | , velocity :: !Vector3 | 25 | , velocity :: {-# UNPACK #-} !Vector2 |
26 | , acceleration :: !Vector3 | 26 | , acceleration :: {-# UNPACK #-} !Vector2 |
27 | } | 27 | } |
28 | 28 | ||
29 | 29 | ||
30 | instance Spatial RigidBody where | 30 | instance Spatial2 RigidBody where |
31 | 31 | ||
32 | move v body = body { position = v + position body } | 32 | move v body = body { position = v + position body } |
33 | 33 | ||
34 | moveFwd speed body = body { position = position body + scale (-speed) unitZ } | 34 | moveFwd speed body = body { position = position body + scale speed unity } |
35 | 35 | ||
36 | moveBack speed body = body { position = position body + scale speed unitZ } | 36 | moveBack speed body = body { position = position body + scale (-speed) unity } |
37 | 37 | ||
38 | strafeLeft speed body = body { position = position body + scale (-speed) unitX } | 38 | strafeLeft speed body = body { position = position body + scale (-speed) unitx } |
39 | 39 | ||
40 | strafeRight speed body = body { position = position body + scale speed unitX } | 40 | strafeRight speed body = body { position = position body + scale speed unitx } |
41 | 41 | ||
42 | pitch angle = id | 42 | rotate angle = id |
43 | |||
44 | yaw angle = id | ||
45 | |||
46 | roll angle = id | ||
47 | 43 | ||
48 | pos = position | 44 | pos = position |
49 | 45 | ||
50 | fwd _ = unitZ | 46 | fwd _ = unity |
51 | |||
52 | up _ = unitY | ||
53 | 47 | ||
54 | right _ = unitX | 48 | right _ = unitx |
55 | 49 | ||
56 | transform body = M4.transform unitX unitY unitZ $ position body | 50 | transform body = M3.transform unitx unity $ position body |
57 | 51 | ||
58 | setTransform transf body = body { position = M4.position transf } | 52 | setTransform transf body = body { position = M3.position transf } |
59 | 53 | ||
60 | setPos p body = body { position = p } | 54 | setPos p body = body { position = p } |
61 | 55 | ||
62 | 56 | ||
63 | -- | Build a 'RigidBody'. | 57 | -- | Build a 'RigidBody'. |
64 | rigidBody :: Mass -> Position -> RigidBody | 58 | rigidBody :: Mass -> Position -> RigidBody |
65 | rigidBody m x = RigidBody m x V3.zero V3.zero | 59 | rigidBody m x = RigidBody m x zero zero |
66 | 60 | ||
67 | 61 | ||
68 | -- | Update the given 'RigidBody'. | 62 | -- | Update the given 'RigidBody'. |
69 | update :: [Force] -> Dt -> RigidBody -> RigidBody | 63 | update :: [Force] -> Dt -> RigidBody -> RigidBody |
70 | update forces dt body = | 64 | update forces dt body = |
71 | let netforce = foldl' (+) V3.zero forces | 65 | let netforce = foldl' (+) zero forces |
72 | m = mass body | 66 | m = mass body |
73 | r1 = position body | 67 | r1 = position body |
74 | v1 = velocity body | 68 | v1 = velocity body |
@@ -92,8 +86,8 @@ setAcceleration a body = body { acceleration = a } | |||
92 | 86 | ||
93 | 87 | ||
94 | -- test | 88 | -- test |
95 | gravity = vec3 0 (-10) 0 | 89 | gravity = vec2 0 (-10) |
96 | b0 = rigidBody 50 $ vec3 0 1000 0 | 90 | b0 = rigidBody 50 $ vec2 0 1000 |
97 | 91 | ||
98 | 92 | ||
99 | debug :: IO () | 93 | debug :: IO () |
@@ -110,7 +104,7 @@ debug' = do | |||
110 | step $ update [gravity*50] 1 | 104 | step $ update [gravity*50] 1 |
111 | step $ update [gravity*50] 1 | 105 | step $ update [gravity*50] 1 |
112 | lift . putStrLn $ "Jumping" | 106 | lift . putStrLn $ "Jumping" |
113 | step $ update [gravity*50, vec3 0 9000 0] 1 | 107 | step $ update [gravity*50, vec2 0 9000] 1 |
114 | lift . putStrLn $ "Falling..." | 108 | lift . putStrLn $ "Falling..." |
115 | step $ update [gravity*50] 1 | 109 | step $ update [gravity*50] 1 |
116 | step $ update [gravity*50] 1 | 110 | step $ update [gravity*50] 1 |
@@ -131,4 +125,4 @@ show' body = | |||
131 | ", acceleration " ++ (showVec $ acceleration body) | 125 | ", acceleration " ++ (showVec $ acceleration body) |
132 | 126 | ||
133 | 127 | ||
134 | showVec v = (show $ x v) ++ ", " ++ (show $ y v) ++ ", " ++ (show $ z v) | 128 | 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 | |||
2 | where | 2 | where |
3 | 3 | ||
4 | 4 | ||
5 | import Spear.Math.Vector3 | 5 | import Spear.Math.Vector2 |
6 | 6 | ||
7 | 7 | ||
8 | type Dt = Float | 8 | type Dt = Float |
9 | type Force = Vector3 | 9 | type Force = Vector2 |
10 | type Mass = Float | 10 | type Mass = Float |
11 | type Position = Vector3 | 11 | type Position = Vector2 |
12 | type Velocity = Vector3 | 12 | type Velocity = Vector2 |
13 | type Acceleration = Vector3 | 13 | 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 | |||
6 | 6 | ||
7 | 7 | ||
8 | import qualified Spear.Math.Matrix4 as M | 8 | import qualified Spear.Math.Matrix4 as M |
9 | import qualified Spear.Math.Spatial as S | 9 | import qualified Spear.Math.Spatial3 as S |
10 | import Spear.Math.Vector3 | 10 | import Spear.Math.Vector3 |
11 | import qualified Spear.Math.Vector4 as V4 | 11 | import qualified Spear.Math.Vector4 as V4 |
12 | 12 | ||
@@ -32,7 +32,7 @@ data Light | |||
32 | } | 32 | } |
33 | 33 | ||
34 | 34 | ||
35 | instance S.Spatial Light where | 35 | instance S.Spatial3 Light where |
36 | move _ l@DirectionalLight {} = l | 36 | move _ l@DirectionalLight {} = l |
37 | move v l = l { transform = M.translv v * transform l} | 37 | move v l = l { transform = M.translv v * transform l} |
38 | 38 | ||
@@ -80,3 +80,8 @@ instance S.Spatial Light where | |||
80 | 80 | ||
81 | setTransform _ l@DirectionalLight {} = l | 81 | setTransform _ l@DirectionalLight {} = l |
82 | setTransform t l = l { Spear.Scene.Light.transform = t } | 82 | setTransform t l = l { Spear.Scene.Light.transform = t } |
83 | |||
84 | setPos _ l@DirectionalLight {} = l | ||
85 | setPos pos l = | ||
86 | let t = Spear.Scene.Light.transform l | ||
87 | in l { transform = M.transform (M.right t) (M.up t) (M.forward t) pos } | ||