home *** CD-ROM | disk | FTP | other *** search
/ Freelog Special Issue 2 / Freelog_HS_3_Setp_Oct_Nov_2000_CD2.mdx / Arcade / Orbit / src / stars.c < prev    next >
C/C++ Source or Header  |  1999-09-24  |  3KB  |  152 lines

  1. /*
  2.  
  3. ORBIT, a freeware space combat simulator
  4. Copyright (C) 1999  Steve Belczyk <steve1@genesis.nred.ma.us>
  5.  
  6. This program is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU General Public License
  8. as published by the Free Software Foundation; either version 2
  9. of the License, or (at your option) any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  19.  
  20. */
  21.  
  22. #include "orbit.h"
  23. #include "stars.h"
  24.  
  25. /*
  26.  *  Stuff for the background starfield
  27.  */
  28.  
  29. ReadStars()
  30. /*
  31.  *  Read in the stellar database
  32.  */
  33. {
  34.     int i;
  35.     double magmin, magmax;
  36.  
  37.     for (i=0; i<NSTARS; i++)
  38.     {
  39.         star[i].x = stars[i][0];
  40.         star[i].y = stars[i][1];
  41.         star[i].z = stars[i][2];
  42.         star[i].mag = stars[i][3];
  43.  
  44.         /* Reverse "magnitude" of magnitude (smaller mag means brighter star!) */
  45.         star[i].mag = 0.0 - star[i].mag;
  46.  
  47.         if (i == 0)
  48.         {
  49.             magmin = magmax = star[i].mag;
  50.         }
  51.         else
  52.         {
  53.             if (star[i].mag < magmin) magmin = star[i].mag;
  54.             if (star[i].mag > magmax) magmax = star[i].mag;
  55.         }
  56.     }
  57.  
  58.     /* Set the magnitudes */
  59.     for (i=0; i<NSTARS; i++)
  60.     {
  61.         star[i].bright = (star[i].mag - magmin) / (magmax - magmin);
  62.     }
  63.  
  64.     /* Find magnitude limits for sparse list */
  65.     for (i=0; i<NSTARS/10; i++)
  66.     {
  67.         if (i == 0)
  68.         {
  69.             magmin = magmax = star[i].mag;
  70.         }
  71.         else
  72.         {
  73.             if (star[i].mag < magmin) magmin = star[i].mag;
  74.             if (star[i].mag > magmax) magmax = star[i].mag;
  75.         }
  76.     }
  77.  
  78.     for (i=0; i<NSTARS/10; i++)
  79.     {
  80.         star[i].bright2 = (star[i].mag - magmin) / (magmax - magmin);
  81.     }
  82. }
  83.  
  84. DrawStars()
  85. /*
  86.  *  "My god.  It's full of stars."
  87.  */
  88. {
  89.     /* Turn off 3D stuff */
  90.     glDisable (GL_DEPTH_TEST);
  91. /*    glDisable (GL_CULL_FACE);    */
  92.     glDisable (GL_LIGHTING);
  93.     glDepthMask (GL_FALSE);
  94. /*    glDisable (GL_LIGHT0);    */
  95.  
  96.     glPointSize (1);
  97.  
  98.     glCallList (star_list);
  99.  
  100.     /* Re-enable three-D stuff */
  101.     glEnable (GL_DEPTH_TEST);
  102. /*    glEnable (GL_CULL_FACE);    */
  103.     glEnable (GL_LIGHTING);
  104.     glDepthMask (GL_TRUE);
  105. /*    glEnable (GL_LIGHT0);    */
  106. }
  107.  
  108. MakeStarList()
  109. /*
  110.  *  Construct display list for starfield
  111.  */
  112. {
  113.     int i, j;
  114.  
  115.     /* Make dense star field list */
  116.     star_list_dense = glGenLists (1);
  117.     glNewList (star_list_dense, GL_COMPILE);
  118.     glBegin (GL_POINTS);
  119.  
  120.     for (j=0; j<NSTARS; j++)
  121.     {
  122.         /* Plot stars backwards so bright ones plotted last */
  123.         i = (NSTARS - j) - 1;
  124.  
  125.         glColor3d (star[i].bright, star[i].bright, star[i].bright);
  126. /*        glVertex4d (star[i].x, star[i].y, star[i].z, 0.00000); */
  127.         glVertex4d (star[i].x, star[i].y, star[i].z, 0.001);
  128.     }
  129.  
  130.     glEnd ();
  131.     glEndList();
  132.  
  133.     /* Make sparse list */
  134.     star_list_sparse = glGenLists (1);
  135.     glNewList (star_list_sparse, GL_COMPILE);
  136.     glBegin (GL_POINTS);
  137.  
  138.     for (j=0; j<(NSTARS/10); j++)
  139.     {
  140.         i = (NSTARS/10 - j) - 1;
  141.         glColor3d (star[i].bright2, star[i].bright2, star[i].bright2);
  142.         glVertex4d (star[i].x, star[i].y, star[i].z, 0.001);
  143.     }
  144.  
  145.     glEnd ();
  146.     glEndList();
  147.  
  148.     star_list = star_list_sparse;
  149.     if (starfield == 2) star_list = star_list_dense;
  150. }
  151.  
  152.