WiimotePlayer: Use IR sensor for aiming
This commit is contained in:
parent
6af7b89939
commit
083619cc87
1 changed files with 20 additions and 12 deletions
|
@ -8,11 +8,13 @@ import Control.Monad
|
|||
import Data.Bits
|
||||
import Data.Function (on)
|
||||
import Data.List (sortBy)
|
||||
import Data.Maybe
|
||||
import Data.Ratio ((%))
|
||||
import Data.Typeable
|
||||
import HWiid
|
||||
|
||||
import Player
|
||||
import Tank
|
||||
|
||||
|
||||
data WiimotePlayer = WiimotePlayer Wiimote
|
||||
|
@ -36,30 +38,36 @@ instance Player WiimotePlayer where
|
|||
let nx = ((fromIntegral . extNunchukStickX $ ext) - 0x80)/0x80
|
||||
ny = ((fromIntegral . extNunchukStickY $ ext) - 0x80)/0x80
|
||||
in if (nx*nx + ny*ny) < 0.4 then (x, y) else (x+nx, y+ny)
|
||||
|
||||
--ax = aimx - (fromRational . toRational . tankX $ tank)
|
||||
--ay = aimy - (fromRational . toRational . tankY $ tank)
|
||||
|
||||
aim = handleIR state
|
||||
aangle = if isJust aim
|
||||
then
|
||||
let aimx = fst $ fromJust aim
|
||||
aimy = snd $ fromJust aim
|
||||
ax = aimx - (fromRational . toRational . tankX $ tank)
|
||||
ay = aimy - (fromRational . toRational . tankY $ tank)
|
||||
in if (ax /= 0 || ay /= 0) then Just $ fromRational $ round ((atan2 ay ax)*1000000*180/pi)%1000000 else Nothing
|
||||
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
|
||||
|
||||
|
||||
--aangle = if (ax /= 0 || ay /= 0) then Just $ fromRational $ round ((atan2 ay ax)*1000000*180/pi)%1000000 else Nothing
|
||||
when foo $ print $ handleIR state
|
||||
return (WiimotePlayer wiimote, moveangle, move, Nothing, shoot)
|
||||
when foo $ print $ state
|
||||
return (WiimotePlayer wiimote, moveangle, move, aangle, shoot)
|
||||
|
||||
|
||||
irXScale :: Float
|
||||
irXScale = 1
|
||||
irXScale = 20
|
||||
|
||||
irXTranslate :: Float
|
||||
irXTranslate = 0
|
||||
irXTranslate = 0 + 7
|
||||
|
||||
irYScale :: Float
|
||||
irYScale = 1
|
||||
irYScale = 20
|
||||
|
||||
irYTranslate :: Float
|
||||
irYTranslate = 0
|
||||
irYTranslate = -10 + 8
|
||||
|
||||
handleIR :: WiimoteState -> Maybe (Float, Float)
|
||||
handleIR state = handle $ sortIRSourcesByPos $ take 2 $ sortIRSourcesBySize $ stateIRSources state
|
||||
|
|
Reference in a new issue