Jeu de FPS en multijoueur. Voir la description sur planete casio
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.

coord.c 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #include "coord.h"
  2. #include "FxEngine.h"
  3. /* Cosinus and sinus implementation */
  4. /// Math values
  5. const double pi=3.141592653589793238462643383279;
  6. const double pi2=pi*2;
  7. const double pi_sur2=pi/2;
  8. /// Internal Use
  9. // cos function with 0<a<pi/2
  10. static const int precision=15;
  11. static double reducted_cos(const double a)
  12. {
  13. double u=1.0; const double a2=a*a;
  14. // precision%2=1 && precision>1
  15. for(int p=precision;p>=1;p-=2)
  16. u=1-a2/(p*p+p)*u;
  17. return u;
  18. }
  19. // return a with -pi<=a<pi
  20. double FE_modulo_2pi(double a)
  21. {
  22. while (a<=-pi) a+=pi2;
  23. while (a>pi) a-=pi2;
  24. return a;
  25. }
  26. static double cos_recursive(double angle)
  27. {
  28. if (angle<0)
  29. return cos_recursive(-angle);
  30. if (angle>=pi_sur2)
  31. return -reducted_cos(angle-pi);
  32. return reducted_cos(angle); // OK
  33. }
  34. /// External functions
  35. // Official FE_cos function
  36. double FE_cos(double angle)
  37. {
  38. angle=FE_modulo_2pi(angle);
  39. return cos_recursive(angle);
  40. }
  41. // Official FE_sin function
  42. double FE_sin(double angle)
  43. {return FE_cos(angle-pi_sur2);}
  44. #define sgn(x) (x>=0?x:-x)
  45. static double matrice[3][3]=
  46. {
  47. {0,0,0},
  48. {0,0,0},
  49. {0,0,0}
  50. };
  51. void FE_calc(FE_point* point)
  52. {
  53. static FE_position temp;
  54. temp.x = point->real.x - FE_user.x;
  55. temp.y = point->real.y - FE_user.y;
  56. temp.z = point->real.z - FE_user.z;
  57. point->rotated.x = (double)(matrice[0][0]*(double)temp.x + matrice[0][1]*(double)temp.y + matrice[0][2]*(double)temp.z);
  58. point->rotated.z = (double)(matrice[1][0]*(double)temp.x + matrice[1][1]*(double)temp.y + matrice[1][2]*(double)temp.z);
  59. point->rotated.y = (double)(matrice[2][0]*(double)temp.x + matrice[2][1]*(double)temp.y + matrice[2][2]*(double)temp.z);
  60. //point->translated.x*=10;
  61. //point->translated.y*=10;
  62. point->rotated.x*=64;
  63. point->rotated.y*=64;
  64. point->translated.z=point->rotated.z;
  65. if (point->translated.z>0)
  66. {
  67. point->translated.x=point->rotated.x/point->translated.z;
  68. point->translated.y=point->rotated.y/point->translated.z;
  69. }
  70. else
  71. {
  72. point->translated.x=point->rotated.x*10000*sgn(point->translated.z);
  73. point->translated.y=point->rotated.y*10000*sgn(point->translated.z);
  74. }
  75. (point->translated.x*1000)/point->translated.z;
  76. (point->translated.y*1000)/point->translated.z;
  77. point->translated.x+=63;
  78. point->translated.y+=31;
  79. }
  80. // FIABLE
  81. void FE_set_matrice(void)
  82. {
  83. const double A=FE_cos(FE_dv), B=FE_sin(FE_dv);
  84. const double C=FE_cos(FE_roulis), D=FE_sin(FE_roulis);
  85. const double E=FE_cos(FE_dh), F=FE_sin(FE_dh);
  86. const double AD=A*D, BD=B*D;
  87. matrice[0][0]=C*E;
  88. matrice[0][1]=-C*F;
  89. matrice[0][2]=D;
  90. matrice[1][0]=BD*E+A*F;
  91. matrice[1][1]=-BD*F+A*E;
  92. matrice[1][2]=-B*C;
  93. matrice[2][0]=-AD*E+B*F;
  94. matrice[2][1]=AD*F+B*E;
  95. matrice[2][2]=A*C;
  96. }