* Calculates the direction for the UFO based * on the current raw speed and destination. */
| 399 | * on the current raw speed and destination. |
| 400 | */ |
| 401 | void Ufo::calculateSpeed() |
| 402 | { |
| 403 | MovingTarget::calculateSpeed(); |
| 404 | |
| 405 | double x = _speedLon; |
| 406 | double y = -_speedLat; |
| 407 | |
| 408 | // This section guards vs. divide-by-zero. |
| 409 | if (AreSame(x, 0.0) || AreSame(y, 0.0)) |
| 410 | { |
| 411 | if (AreSame(x, 0.0) && AreSame(y, 0.0)) |
| 412 | { |
| 413 | _direction = "STR_NONE_UC"; |
| 414 | } |
| 415 | else if (AreSame(x, 0.0)) |
| 416 | { |
| 417 | if (y > 0.f) |
| 418 | { |
| 419 | _direction = "STR_NORTH"; |
| 420 | } |
| 421 | else if (y < 0.f) |
| 422 | { |
| 423 | _direction = "STR_SOUTH"; |
| 424 | } |
| 425 | } |
| 426 | else if (AreSame(y, 0.0)) |
| 427 | { |
| 428 | if (x > 0.f) |
| 429 | { |
| 430 | _direction = "STR_EAST"; |
| 431 | } |
| 432 | else if (x < 0.f) |
| 433 | { |
| 434 | _direction = "STR_WEST"; |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | return; |
| 439 | } |
| 440 | |
| 441 | double theta = atan2(y, x); // radians |
| 442 | theta = theta * 180.f / M_PI; // +/- 180 deg. |
| 443 | |
| 444 | if (22.5f > theta && theta > -22.5f) |
| 445 | { |
| 446 | _direction = "STR_EAST"; |
| 447 | } |
| 448 | else if (-22.5f > theta && theta > -67.5f) |
| 449 | { |
| 450 | _direction = "STR_SOUTH_EAST"; |
| 451 | } |
| 452 | else if (-67.5f > theta && theta > -112.5f) |
| 453 | { |
| 454 | _direction = "STR_SOUTH"; |
| 455 | } |
| 456 | else if (-112.5f > theta && theta > -157.5f) |
| 457 | { |
| 458 | _direction = "STR_SOUTH_WEST"; |