/* * Copyright (C) Volition, Inc. 1999. All rights reserved. * * All source code herein is the property of Volition, Inc. You may not sell * or otherwise commercially exploit the source or things you created based on the * source. * */ #include "starfield/nebula.h" #include "math/vecmat.h" #include "render/3d.h" #include "mission/missionparse.h" #include "nebula/neb.h" #include "cfile/cfile.h" #include "debugconsole/console.h" #define MAX_TRIS 200 #define MAX_POINTS 300 static int num_pts = 0; static vec3d nebula_vecs[MAX_POINTS]; static vertex nebula_verts[MAX_POINTS]; static float scale_factor = 1.0f; static int num_tris = 0; static int tri[MAX_TRIS][3]; static int Nebula_loaded = 0; static angles Nebula_pbh; static matrix Nebula_orient; int Nebula_pitch; int Nebula_bank; int Nebula_heading; void nebula_close() { if (!Nebula_loaded) return; Nebula_loaded = 0; } #define NEBULA_FILE_ID NOX("NEBU") #define NEBULA_MAJOR_VERSION 1 // Can be 1-? #define NEBULA_MINOR_VERSION 0 // Can be 0-99 // given: // u,v in range 0-1 void project_2d_onto_sphere( vec3d *pnt, float u, float v ) { float a,x,y,z,s; a = PI * (2.0f * u - 1.0f ); z = 2.0f * v - 1.0f; s = scale_factor * fl_sqrt( 1.0f - z*z ); x = s * (float)cos(a); y = s * (float)sin(a); pnt->xyz.x = x; pnt->xyz.y = y; pnt->xyz.z = z; } // Version 199 mean major version=1, minor=99. // Changing major means no longer compatible. // Revision history: // 1.00 - initial version // returns 0 if failed int load_nebula_sub(char *filename) { CFILE *fp; char id[16]; int version, major; fp = cfopen(filename, "rb"); if ( !fp ) { return 0; } // ID of NEBU cfread( id, 4, 1, fp ); if ( strncmp( id, NEBULA_FILE_ID, 4)) { mprintf(( "Not a valid nebula file.\n" )); return 0; } cfread( &version, sizeof(int), 1, fp ); major = version / 100; if ( major != NEBULA_MAJOR_VERSION ) { mprintf(( "An out of date nebula file.\n" )); return 0; } cfread( &num_pts, sizeof(int), 1, fp ); Assert( num_pts < MAX_POINTS ); cfread( &num_tris, sizeof(int), 1, fp ); Assert( num_tris < MAX_TRIS ); int i; for (i=0; i