From 7be64ca1fc92fdbdf10fe6bc49263b33cef915de Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Thu, 22 Jul 2010 15:23:45 -0600 Subject: [PATCH] =?UTF-8?q?Replace=20=CF=80=20with=20=CF=84;=20=CF=84=20?= =?UTF-8?q?=3D=202=CF=80=20=20(http://tauday.com/)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ctanks.c | 16 ++++++++-------- ctanks.h | 9 +++++---- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/ctanks.c b/ctanks.c index 2386f3f..3fe1c7a 100644 --- a/ctanks.c +++ b/ctanks.c @@ -14,7 +14,7 @@ #define DUMP_f(v) DUMPf("%s = %f", #v, v) #define DUMP_p(v) DUMPf("%s = %p", #v, v) #define DUMP_xy(v) DUMPf("%s = (%f, %f)", #v, v[0], v[1]); -#define DUMP_angle(v) DUMPf("%s = %.3fπ", #v, (v/PI)); +#define DUMP_angle(v) DUMPf("%s = %.3fτ", #v, (v/TAU)); #define sq(x) ((x) * (x)) @@ -55,7 +55,7 @@ tank_get_turret(struct tank *tank) void tank_set_turret(struct tank *tank, float angle) { - tank->turret.desired = fmodf(angle, 2*PI); + tank->turret.desired = fmodf(angle, TAU); } int @@ -253,13 +253,13 @@ tanks_move_tank(struct tanks_game *game, /* Constrain rot_angle to between -PI and PI */ rot_angle = tank->turret.desired - tank->turret.current; while (rot_angle < 0) { - rot_angle += 2*PI; + rot_angle += TAU; } - rot_angle = fmodf(PI + rot_angle, 2*PI) - PI; + rot_angle = fmodf(PI + rot_angle, TAU) - PI; rot_angle = min(TANK_MAX_TURRET_ROT, rot_angle); rot_angle = max(-TANK_MAX_TURRET_ROT, rot_angle); - tank->turret.current = fmodf(tank->turret.current + rot_angle, 2*PI); + tank->turret.current = fmodf(tank->turret.current + rot_angle, TAU); } /* Fakey acceleration */ @@ -322,9 +322,9 @@ tanks_move_tank(struct tanks_game *game, The fraction of the circle traveled is equal to the speed of the outer tread over the circumference of the circle: - Ft = So/(2*pi*r) + Ft = So/(tau*r) The angle traveled is: - theta = Ft * 2*pi + theta = Ft * tau This reduces to a simple theta = So/r We multiply it by dir to adjust for the direction of rotation @@ -336,7 +336,7 @@ tanks_move_tank(struct tanks_game *game, } /* Now move the tank */ - tank->angle = fmodf(tank->angle + angle + 2*PI, 2*PI); + tank->angle = fmodf(tank->angle + angle + TAU, TAU); { float m[2]; diff --git a/ctanks.h b/ctanks.h index 7c3cbfa..da42fe7 100644 --- a/ctanks.h +++ b/ctanks.h @@ -2,7 +2,8 @@ #define __CTANKS_H__ /* Some useful constants */ -#define PI 3.14159265358979323846 +#define TAU 6.28318530717958647692 +#define PI 3.14159265358979323846 #define TANK_MAX_SENSORS 10 #define TANK_RADIUS 7.5 @@ -10,7 +11,7 @@ #define TANK_CANNON_RECHARGE 20 /* Turns to recharge cannon */ #define TANK_CANNON_RANGE (TANK_SENSOR_RANGE / 2) #define TANK_MAX_ACCEL 35 -#define TANK_MAX_TURRET_ROT (PI/10) +#define TANK_MAX_TURRET_ROT (TAU/20) #define TANK_TOP_SPEED 7 /* (tank radius + tank radius)^2 */ @@ -27,8 +28,8 @@ ((TANK_CANNON_RANGE + TANK_RADIUS) * (TANK_CANNON_RANGE + TANK_RADIUS)) #ifndef rad2deg -#define rad2deg(r) ((int)(180*(r)/PI)) -#define deg2rad(r) ((r*PI)/180) +#define rad2deg(r) ((int)(360*(r)/TAU)) +#define deg2rad(r) ((r*TAU)/360) #endif #ifndef max