diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-06-24 21:50:32 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-06-24 21:50:32 +0200 |
commit | 83f0606ea9dfd6b493097dc97330055dff4a2867 (patch) | |
tree | 464d7f3ed2c02f48b6463d1528e3e0b5f50e79c6 /src/Transformable.hs | |
parent | d7971385e844e24d9d851d3d142895b5cb89c91b (diff) | |
download | htanks-83f0606ea9dfd6b493097dc97330055dff4a2867.tar htanks-83f0606ea9dfd6b493097dc97330055dff4a2867.zip |
Added Transformable class to simplify collision calculation
Diffstat (limited to 'src/Transformable.hs')
-rw-r--r-- | src/Transformable.hs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/Transformable.hs b/src/Transformable.hs new file mode 100644 index 0000000..2fd64fe --- /dev/null +++ b/src/Transformable.hs @@ -0,0 +1,37 @@ +{-# LANGUAGE TypeOperators, TypeSynonymInstances #-} + +module Transformable ( Coord + , Vector3 + , Transform + , Transformable(..) + , translate + , rotate + , scale + ) where + +import Data.LinearMap + +type Coord = Double + +type Vector3 = (Coord, Coord, Coord) +type Transform = Vector3 :-* Vector3 + +class Transformable a where + (><) :: Transform -> a -> a + +instance Transformable Transform where + t1 >< t2 = t1 *.* t2 + +instance Transformable Vector3 where + t >< v = t `lapply` v + +translate :: Coord -> Coord -> Transform +translate dx dy = linear $ \(x, y, w) -> (x + w*dx, y + w*dy, w) + +rotate :: Coord -> Transform +rotate a = linear $ \(x, y, w) -> (c*x - s*y, s*x + c*y, w) where + c = cos a + s = sin a + +scale :: Coord -> Transform +scale s = linear $ \(x, y, w) -> (s*y, s*y, w) |