Files
loop/src/Dodge/Movement/Turn.hs
T
2022-03-01 18:22:47 +00:00

34 lines
1.1 KiB
Haskell

module Dodge.Movement.Turn where
import Geometry
turnTo :: Float -> Point2 -> Point2 -> Float -> Float
turnTo turnSpeed sp tp a
| vToTarg == V2 0 0 = a
| angleVV vToTarg vdir <= turnSpeed
= argV vToTarg
| isLHS (sp +.+ vdir) sp tp = a - turnSpeed
| otherwise = a + turnSpeed
where
vdir = unitVectorAtAngle a
vToTarg = tp -.- sp
turnToAmount :: Float -> Point2 -> Point2 -> Float -> Float
turnToAmount turnSpeed sp tp a
| vToTarg == V2 0 0 = 0
| angleVV vToTarg vdir <= turnSpeed
= diffAngles a (argV vToTarg) -- TODO check correctness
| isLHS (sp +.+ vdir) sp tp = negate turnSpeed
| otherwise = turnSpeed
where
vdir = unitVectorAtAngle a
vToTarg = tp -.- sp
vecTurnTo :: Float -> Point2 -> Point2 -> Point2 -> Point2
vecTurnTo turnSpeed sp tp vdir
| angleVV vToTarg vdir <= turnSpeed
= magV vdir *.* normalizeV vToTarg
| isLHS (sp +.+ vdir) sp tp = rotateV (negate turnSpeed) vdir
| otherwise = rotateV turnSpeed vdir
where
vToTarg = tp -.- sp