Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

153 lines
3.3 KiB

  1. #include <windows.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <GL/gl.h>
  5. #include "atlantis.h"
  6. void FishTransform(fishRec *fish)
  7. {
  8. glTranslatef(fish->y, fish->z, -fish->x);
  9. glRotatef(-fish->psi, 0.0, 1.0, 0.0);
  10. glRotatef(fish->theta, 1.0, 0.0, 0.0);
  11. glRotatef(-fish->phi, 0.0, 0.0, 1.0);
  12. }
  13. void WhalePilot(fishRec *fish)
  14. {
  15. fish->phi = -20.0;
  16. fish->theta = 0.0;
  17. fish->psi -= 0.5;
  18. fish->x += WHALESPEED * fish->v * cos(fish->psi/RAD) * cos(fish->theta/RAD);
  19. fish->y += WHALESPEED * fish->v * sin(fish->psi/RAD) * cos(fish->theta/RAD);
  20. fish->z += WHALESPEED * fish->v * sin(fish->theta/RAD);
  21. }
  22. void SharkPilot(fishRec *fish)
  23. {
  24. static int sign = 1;
  25. float X, Y, Z, tpsi, ttheta, thetal;
  26. fish->xt = 60000.0;
  27. fish->yt = 0.0;
  28. fish->zt = 0.0;
  29. X = fish->xt - fish->x;
  30. Y = fish->yt - fish->y;
  31. Z = fish->zt - fish->z;
  32. thetal = fish->theta;
  33. ttheta = RAD * atan(Z/(sqrt(X*X+Y*Y)));
  34. if (ttheta > fish->theta+0.25) {
  35. fish->theta += 0.5;
  36. } else if (ttheta < fish->theta-0.25) {
  37. fish->theta -= 0.5;
  38. }
  39. if (fish->theta > 90.0) {
  40. fish->theta = 90.0;
  41. }
  42. if (fish->theta < -90.0) {
  43. fish->theta = -90.0;
  44. }
  45. fish->dtheta = fish->theta - thetal;
  46. tpsi = RAD * atan2(Y, X);
  47. fish->attack = 0;
  48. if (fabs(tpsi-fish->psi) < 10.0) {
  49. fish->attack = 1;
  50. } else if (fabs(tpsi-fish->psi) < 45.0) {
  51. if (fish->psi > tpsi) {
  52. fish->psi -= 0.5;
  53. if (fish->psi < -180.0) {
  54. fish->psi += 360.0;
  55. }
  56. } else if (fish->psi < tpsi) {
  57. fish->psi += 0.5;
  58. if (fish->psi > 180.0) {
  59. fish->psi -= 360.0;
  60. }
  61. }
  62. } else {
  63. if (rand()%100 > 98) {
  64. sign = 1 - sign;
  65. }
  66. fish->psi += sign;
  67. if (fish->psi > 180.0) {
  68. fish->psi -= 360.0;
  69. }
  70. if (fish->psi < -180.0) {
  71. fish->psi += 360.0;
  72. }
  73. }
  74. if (fish->attack) {
  75. if (fish->v < 1.1) {
  76. fish->spurt = 1;
  77. }
  78. if (fish->spurt) {
  79. fish->v += 0.2;
  80. }
  81. if (fish->v > 5.0) {
  82. fish->spurt = 0;
  83. }
  84. if ((fish->v > 1.0) && (!fish->spurt)) {
  85. fish->v -= 0.2;
  86. }
  87. } else {
  88. if (!(rand()%400) && (!fish->spurt)) {
  89. fish->spurt = 1;
  90. }
  91. if (fish->spurt) {
  92. fish->v += 0.05;
  93. }
  94. if (fish->v > 3.0) {
  95. fish->spurt = 0;
  96. }
  97. if ((fish->v > 1.0) && (!fish->spurt)) {
  98. fish->v -= 0.05;
  99. }
  100. }
  101. fish->x += SHARKSPEED * fish->v * cos(fish->psi/RAD) * cos(fish->theta/RAD);
  102. fish->y += SHARKSPEED * fish->v * sin(fish->psi/RAD) * cos(fish->theta/RAD);
  103. fish->z += SHARKSPEED * fish->v * sin(fish->theta/RAD);
  104. }
  105. void SharkMiss(int i)
  106. {
  107. int j;
  108. float avoid, thetal;
  109. float X, Y, Z, R;
  110. for (j = 0; j < NUM_SHARKS; j++) {
  111. if (j != i) {
  112. X = sharks[j].x - sharks[i].x;
  113. Y = sharks[j].y - sharks[i].y;
  114. Z = sharks[j].z - sharks[i].z;
  115. R = sqrt(X*X+Y*Y+Z*Z);
  116. avoid = 1.0;
  117. thetal = sharks[i].theta;
  118. if (R < SHARKSIZE) {
  119. if (Z > 0.0) {
  120. sharks[i].theta -= avoid;
  121. } else {
  122. sharks[i].theta += avoid;
  123. }
  124. }
  125. sharks[i].dtheta += (sharks[i].theta - thetal);
  126. }
  127. }
  128. }