summaryrefslogtreecommitdiffstats
path: root/src/HWiidPlayer.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/HWiidPlayer.hs')
-rw-r--r--src/HWiidPlayer.hs12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/HWiidPlayer.hs b/src/HWiidPlayer.hs
index 04ea38e..d98b9c9 100644
--- a/src/HWiidPlayer.hs
+++ b/src/HWiidPlayer.hs
@@ -20,6 +20,8 @@ import Graphics.Rendering.OpenGL.GL.VertexSpec
import Player
import Tank
+import qualified Transformable as T
+import qualified Vector as V
data HWiidPlayer = HWiidPlayer Wiimote WiimoteAccCal [(Float, Float)]
@@ -51,15 +53,15 @@ instance Player HWiidPlayer where
then take irSkipSmooth newaims
else newaims
(aimx, aimy) = if null aims then (0, 0) else mulV (1/(fromIntegral $ length aims)) (foldr addV (0, 0) aims)
- ax = aimx - (fromRational . toRational . tankX $ tank)
- ay = aimy - (fromRational . toRational . tankY $ tank)
- aangle = if (ax /= 0 || ay /= 0) then Just $ fromRational $ round ((atan2 ay ax)*1000000*180/pi)%1000000 else Nothing
+ ax = realToFrac $ aimx - (fromRational . toRational . tankX $ tank)
+ ay = realToFrac $ aimy - (fromRational . toRational . tankY $ tank)
+ aim = if (ax /= 0 || ay /= 0) then Just $ V.Vector ax ay else Nothing
move = (mx /= 0 || my /= 0)
angle = atan2 my mx
- moveangle = if move then Just $ fromRational $ round ((angle - (sin $ 8*x)/8)*1000000*180/pi)%1000000 else Nothing
+ dir = if move then Just $ T.rotate (fromRational $ round ((angle - (sin $ 8*x)/8)*1000000*180/pi)%1000000) T.>< V.Vector 1 0 else Nothing
when foo $ print state
- return (HWiidPlayer wiimote cal aims, moveangle, move, aangle, shoot)
+ return (HWiidPlayer wiimote cal aims, dir, move, aim, shoot)
renderPlayer (HWiidPlayer _ _ []) = return ()
renderPlayer (HWiidPlayer _ _ aims) = unsafePreservingMatrix $ do