hullfile.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #include "csg.h"
  2. #ifdef SYSTEM_WIN32
  3. #pragma warning(disable:4996)
  4. #endif
  5. vec3_t g_hull_size[NUM_HULLS][2] =
  6. {
  7. {// 0x0x0
  8. {0, 0, 0}, {0, 0, 0}
  9. }
  10. ,
  11. {// 32x32x72
  12. {-16, -16, -36}, {16, 16, 36}
  13. }
  14. ,
  15. {// 64x64x64
  16. {-32, -32, -32}, {32, 32, 32}
  17. }
  18. ,
  19. {// 32x32x36
  20. {-16, -16, -18}, {16, 16, 18}
  21. }
  22. };
  23. void LoadHullfile(const char* filename)
  24. {
  25. if (filename == NULL)
  26. {
  27. return;
  28. }
  29. if (q_exists(filename))
  30. {
  31. Log("Loading hull definitions from '%s'\n", filename);
  32. }
  33. else
  34. {
  35. Error("Could not find hull definition file '%s'\n", filename);
  36. return;
  37. }
  38. float x1,y1,z1;
  39. float x2,y2,z2;
  40. char magic;
  41. FILE* file = fopen(filename, "r");
  42. int count;
  43. int i;
  44. magic = (char)fgetc(file);
  45. rewind(file);
  46. if(magic == '(')
  47. { // Test for old-style hull-file
  48. for (i=0; i < NUM_HULLS; i++)
  49. {
  50. count = fscanf(file, "( %f %f %f ) ( %f %f %f )\n", &x1, &y1, &z1, &x2, &y2, &z2);
  51. if (count != 6)
  52. {
  53. Error("Could not parse old hull definition file '%s' (%d, %d)\n", filename, i, count);
  54. }
  55. g_hull_size[i][0][0] = x1;
  56. g_hull_size[i][0][1] = y1;
  57. g_hull_size[i][0][2] = z1;
  58. g_hull_size[i][1][0] = x2;
  59. g_hull_size[i][1][1] = y2;
  60. g_hull_size[i][1][2] = z2;
  61. }
  62. }
  63. else
  64. {
  65. // Skip hull 0 (visibile polygons)
  66. for (i=1; i<NUM_HULLS; i++)
  67. {
  68. count = fscanf(file, "%f %f %f\n", &x1, &y1, &z1);
  69. if (count != 3)
  70. {
  71. Error("Could not parse new hull definition file '%s' (%d, %d)\n", filename, i, count);
  72. }
  73. x1 *= 0.5;
  74. y1 *= 0.5;
  75. z1 *= 0.5;
  76. g_hull_size[i][0][0] = -x1;
  77. g_hull_size[i][0][1] = -y1;
  78. g_hull_size[i][0][2] = -z1;
  79. g_hull_size[i][1][0] = x1;
  80. g_hull_size[i][1][1] = y1;
  81. g_hull_size[i][1][2] = z1;
  82. }
  83. }
  84. fclose(file);
  85. }