Skip to content

Commit 4dabfb8

Browse files
committed
limiting angle to one's that are valid
1 parent 66f0650 commit 4dabfb8

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

physics.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,12 @@ void sailing_physics_update(Boat *boat, const struct wind *wind, const double dt
105105
boat->rotational_velocity += delta_rotational_velocity(boat, wind) * dt;
106106
boat->v += delta_velocity(boat, wind) * dt;
107107
boat->angle += boat->rotational_velocity * dt;
108+
109+
//keep angle between 0 and 2*pi
110+
111+
if ( boat->angle < 0 ) {
112+
boat->angle += M_PI * 2;
113+
}
114+
115+
boat->angle = fmod(boat->angle,M_PI*2);
108116
}

0 commit comments

Comments
 (0)