Added nunchuk support
This commit is contained in:
parent
d6b28723a2
commit
f86af7816c
2 changed files with 18 additions and 6 deletions
|
@ -66,7 +66,6 @@ mainLoop = do
|
||||||
liftIO $ usleep gl $ truncate $ 1e6*(minFrameTime - drender)
|
liftIO $ usleep gl $ truncate $ 1e6*(minFrameTime - drender)
|
||||||
|
|
||||||
currenttime <- liftIO getCurrentTime
|
currenttime <- liftIO getCurrentTime
|
||||||
liftIO $ print $ diffUTCTime currenttime rtime
|
|
||||||
let d = round $ 1e2*(diffUTCTime currenttime t)
|
let d = round $ 1e2*(diffUTCTime currenttime t)
|
||||||
|
|
||||||
replicateM_ d simulationStep
|
replicateM_ d simulationStep
|
||||||
|
|
|
@ -18,18 +18,31 @@ data WiimotePlayer = WiimotePlayer Wiimote
|
||||||
|
|
||||||
instance Player WiimotePlayer where
|
instance Player WiimotePlayer where
|
||||||
playerUpdate (WiimotePlayer wiimote) tank = do
|
playerUpdate (WiimotePlayer wiimote) tank = do
|
||||||
buttons <- hwiidGetState wiimote >>= return . stateButtons
|
state <- hwiidGetState wiimote
|
||||||
messages <- hwiidGetMesg wiimote
|
messages <- hwiidGetMesg wiimote
|
||||||
|
|
||||||
let shoot = any (\m -> (mesgType m == hwiidMesgTypeButton) && (test (mesgButtons m) hwiidButtonB)) $ messages
|
let buttons = stateButtons state
|
||||||
|
shoot = any (\m -> (mesgType m == hwiidMesgTypeButton) && (test (mesgButtons m) hwiidButtonB)) $ messages
|
||||||
|
foo = any (\m -> (mesgType m == hwiidMesgTypeButton) && (test (mesgButtons m) hwiidButtonA)) $ messages
|
||||||
x = (if (test buttons hwiidButtonLeft) then (-1) else 0) + (if (test buttons hwiidButtonRight) then 1 else 0)
|
x = (if (test buttons hwiidButtonLeft) then (-1) else 0) + (if (test buttons hwiidButtonRight) then 1 else 0)
|
||||||
y = (if (test buttons hwiidButtonDown) then (-1) else 0) + (if (test buttons hwiidButtonUp) then 1 else 0)
|
y = (if (test buttons hwiidButtonDown) then (-1) else 0) + (if (test buttons hwiidButtonUp) then 1 else 0)
|
||||||
|
ext = stateExt state
|
||||||
|
|
||||||
|
(mx, my) <- if (extType ext) /= hwiidExtNunchuk
|
||||||
|
then return (x, y)
|
||||||
|
else do
|
||||||
|
let nx = ((fromIntegral . extNunchukStickX $ ext) - 0x80)/0x80
|
||||||
|
ny = ((fromIntegral . extNunchukStickY $ ext) - 0x80)/0x80
|
||||||
|
return $ if (nx*nx + ny*ny) < 0.4 then (x, y) else (x+nx, y+ny)
|
||||||
|
|
||||||
--ax = aimx - (fromRational . toRational . tankX $ tank)
|
--ax = aimx - (fromRational . toRational . tankX $ tank)
|
||||||
--ay = aimy - (fromRational . toRational . tankY $ tank)
|
--ay = aimy - (fromRational . toRational . tankY $ tank)
|
||||||
move = (x /= 0 || y /= 0)
|
let move = (mx /= 0 || my /= 0)
|
||||||
|
angle = if move then Just $ fromRational $ round ((atan2 my mx)*1000000*180/pi)%1000000 else Nothing
|
||||||
|
|
||||||
|
|
||||||
angle = if move then Just $ fromRational $ round ((atan2 y x)*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
|
--aangle = if (ax /= 0 || ay /= 0) then Just $ fromRational $ round ((atan2 ay ax)*1000000*180/pi)%1000000 else Nothing
|
||||||
|
when foo $ print state
|
||||||
return (WiimotePlayer wiimote, angle, move, Nothing, shoot)
|
return (WiimotePlayer wiimote, angle, move, Nothing, shoot)
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,7 +50,7 @@ newWiimotePlayer :: IO WiimotePlayer
|
||||||
newWiimotePlayer = do
|
newWiimotePlayer = do
|
||||||
wiimote <- hwiidOpen bdAddrAny (hwiidFlagMesgInterface .|. hwiidFlagNonblock)
|
wiimote <- hwiidOpen bdAddrAny (hwiidFlagMesgInterface .|. hwiidFlagNonblock)
|
||||||
when (wiimote == nullWiimote) $ fail "Wiimote error"
|
when (wiimote == nullWiimote) $ fail "Wiimote error"
|
||||||
hwiidSetReportMode wiimote hwiidReportButtons
|
hwiidSetReportMode wiimote (hwiidReportButtons .|. hwiidReportIR .|. hwiidReportNunchuk)
|
||||||
return $ WiimotePlayer wiimote
|
return $ WiimotePlayer wiimote
|
||||||
|
|
||||||
test :: (Bits a) => a -> a -> Bool
|
test :: (Bits a) => a -> a -> Bool
|
||||||
|
|
Reference in a new issue