points.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. ===========================================================================
  3. Copyright (C) 1997-2006 Id Software, Inc.
  4. This file is part of Quake 2 Tools source code.
  5. Quake 2 Tools source code is free software; you can redistribute it
  6. and/or modify it under the terms of the GNU General Public License as
  7. published by the Free Software Foundation; either version 2 of the License,
  8. or (at your option) any later version.
  9. Quake 2 Tools source code is distributed in the hope that it will be
  10. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with Quake 2 Tools source code; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. ===========================================================================
  17. */
  18. #include "qe3.h"
  19. #define MAX_POINTFILE 8192
  20. static vec3_t s_pointvecs[MAX_POINTFILE];
  21. static int s_num_points, s_check_point;
  22. void Pointfile_Delete (void)
  23. {
  24. char name[1024];
  25. strcpy (name, currentmap);
  26. StripExtension (name);
  27. strcat (name, ".lin");
  28. remove(name);
  29. }
  30. // advance camera to next point
  31. void Pointfile_Next (void)
  32. {
  33. vec3_t dir;
  34. if (s_check_point >= s_num_points-2)
  35. {
  36. Sys_Status ("End of pointfile", 0);
  37. return;
  38. }
  39. s_check_point++;
  40. VectorCopy (s_pointvecs[s_check_point], camera.origin);
  41. VectorCopy (s_pointvecs[s_check_point], g_qeglobals.d_xy.origin);
  42. VectorSubtract (s_pointvecs[s_check_point+1], camera.origin, dir);
  43. VectorNormalize (dir);
  44. camera.angles[1] = atan2 (dir[1], dir[0])*180/3.14159;
  45. camera.angles[0] = asin (dir[2])*180/3.14159;
  46. Sys_UpdateWindows (W_ALL);
  47. }
  48. // advance camera to previous point
  49. void Pointfile_Prev (void)
  50. {
  51. vec3_t dir;
  52. if ( s_check_point == 0)
  53. {
  54. Sys_Status ("Start of pointfile", 0);
  55. return;
  56. }
  57. s_check_point--;
  58. VectorCopy (s_pointvecs[s_check_point], camera.origin);
  59. VectorCopy (s_pointvecs[s_check_point], g_qeglobals.d_xy.origin);
  60. VectorSubtract (s_pointvecs[s_check_point+1], camera.origin, dir);
  61. VectorNormalize (dir);
  62. camera.angles[1] = atan2 (dir[1], dir[0])*180/3.14159;
  63. camera.angles[0] = asin (dir[2])*180/3.14159;
  64. Sys_UpdateWindows (W_ALL);
  65. }
  66. void Pointfile_Check (void)
  67. {
  68. char name[1024];
  69. FILE *f;
  70. vec3_t v;
  71. strcpy (name, currentmap);
  72. StripExtension (name);
  73. strcat (name, ".lin");
  74. f = fopen (name, "r");
  75. if (!f)
  76. return;
  77. Sys_Printf ("Reading pointfile %s\n", name);
  78. if (!g_qeglobals.d_pointfile_display_list)
  79. g_qeglobals.d_pointfile_display_list = glGenLists(1);
  80. s_num_points = 0;
  81. glNewList (g_qeglobals.d_pointfile_display_list, GL_COMPILE);
  82. glColor3f (1, 0, 0);
  83. glDisable(GL_TEXTURE_2D);
  84. glDisable(GL_TEXTURE_1D);
  85. glLineWidth (4);
  86. glBegin(GL_LINE_STRIP);
  87. do
  88. {
  89. if (fscanf (f, "%f %f %f\n", &v[0], &v[1], &v[2]) != 3)
  90. break;
  91. if (s_num_points < MAX_POINTFILE)
  92. {
  93. VectorCopy (v, s_pointvecs[s_num_points]);
  94. s_num_points++;
  95. }
  96. glVertex3fv (v);
  97. } while (1);
  98. glEnd();
  99. glLineWidth (1);
  100. glEndList ();
  101. s_check_point = 0;
  102. fclose (f);
  103. Pointfile_Next ();
  104. }
  105. void Pointfile_Draw( void )
  106. {
  107. int i;
  108. glColor3f( 1.0F, 0.0F, 0.0F );
  109. glDisable(GL_TEXTURE_2D);
  110. glDisable(GL_TEXTURE_1D);
  111. glLineWidth (4);
  112. glBegin(GL_LINE_STRIP);
  113. for ( i = 0; i < s_num_points; i++ )
  114. {
  115. glVertex3fv( s_pointvecs[i] );
  116. }
  117. glEnd();
  118. glLineWidth( 1 );
  119. }
  120. void Pointfile_Clear (void)
  121. {
  122. if (!g_qeglobals.d_pointfile_display_list)
  123. return;
  124. glDeleteLists (g_qeglobals.d_pointfile_display_list, 1);
  125. g_qeglobals.d_pointfile_display_list = 0;
  126. Sys_UpdateWindows (W_ALL);
  127. }