+
+struct {
+ int circleX[3];
+ int circleY[3];
+} wheelState;
+
+static void updateWheel(float t) {
+ float x = 0.0f;
+ float y = 18.0f;
+ float nx, ny;
+ float cost, sint;
+ static float sin120 = 0.86602540378f;
+ static float cos120 = -0.5f;
+
+ /* Rotate */
+ sint = sin(t);
+ cost = cos(t);
+ nx = x * cost - y * sint;
+ ny = y * cost + x * sint;
+ x = nx;
+ y = ny;
+ wheelState.circleX[0] = (int)(x + 0.5f) + 16;
+ wheelState.circleY[0] = (int)(y + 0.5f) + 16;
+
+ /* Rotate by 120 degrees, for the second circle */
+ nx = x * cos120 - y * sin120;
+ ny = y * cos120 + x * sin120;
+ x = nx;
+ y = ny;
+ wheelState.circleX[1] = (int)(x + 0.5f) + 16;
+ wheelState.circleY[1] = (int)(y + 0.5f) + 16;
+
+ /* 3rd circle */
+ nx = x * cos120 - y * sin120;
+ ny = y * cos120 + x * sin120;
+ x = nx;
+ y = ny;
+ wheelState.circleX[2] = (int)(x + 0.5f) + 16;
+ wheelState.circleY[2] = (int)(y + 0.5f) + 16;
+}
+
+#define WHEEL_CIRCLE_RADIUS 18
+#define WHEEL_CIRCLE_RADIUS_SQ (WHEEL_CIRCLE_RADIUS * WHEEL_CIRCLE_RADIUS)
+
+static unsigned short wheel(int x, int y) {
+ int cx, cy, count=0;
+
+ /* First circle */
+ cx = wheelState.circleX[0] - x;
+ cy = wheelState.circleY[0] - y;
+ if (cx*cx + cy*cy < WHEEL_CIRCLE_RADIUS_SQ) count++;
+
+ /* 2nd circle */
+ cx = wheelState.circleX[1] - x;
+ cy = wheelState.circleY[1] - y;
+ if (cx*cx + cy*cy < WHEEL_CIRCLE_RADIUS_SQ) count++;
+
+ /* 3rd circle */
+ cx = wheelState.circleX[2] - x;
+ cy = wheelState.circleY[2] - y;
+ if (cx*cx + cy*cy < WHEEL_CIRCLE_RADIUS_SQ) count++;
+
+ if (count >= 2) return 0xFFFF;
+
+ return 0x000F;
+}
+