// Description: // Starfield with nebulas. // // Copyright (C) 2001 Frank Becker // // This program is free software; you can redistribute it and/or modify it under // the terms of the GNU General Public License as published by the Free Software // Foundation; either version 2 of the License, or (at your option) any later // version. // // This program is distributed in the hope that it will be useful, but WITHOUT // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details // #include #include #include #include #include #include #include #include Starfield::Starfield( void) { XTRACE(); _nebula = BitmapManagerS::instance()->getBitmap( "bitmaps/nebula"); if( !_nebula) { LOG_ERROR << "Unable to load nebula" << endl; } _nebulaIndex = _nebula->getIndex( "Nebula"); _nebulaHalfWidth = (float)(_nebula->getWidth( _nebulaIndex))/2.0f; _nebulaHalfHeight= (float)(_nebula->getHeight( _nebulaIndex))/2.0f; } Starfield::~Starfield() { XTRACE(); } void Starfield::init( float z) { XTRACE(); for( int i=0; iDrawC( _nebulaIndex, 0, 0, _nebulaInfo[i].sizeX, _nebulaInfo[i].sizeY); glPopMatrix(); } glDisable(GL_TEXTURE_2D); } glEnable(GL_LIGHTING); // glEnable(GL_DEPTH_TEST); } void Starfield::pickSize( Nebula &n) { n.sizeX = Random::rangef0_1()*1.2f + 0.4f; n.sizeY = Random::rangef0_1()*1.2f + 0.4f; } void Starfield::findMax( Nebula &n) { float sina = _nebulaHalfWidth *n.sizeX*sin( n.rot * ((float)M_PI/180.0f)); float cosa = _nebulaHalfHeight*n.sizeY*cos( n.rot * ((float)M_PI/180.0f)); float t1 = fabs(-sina + cosa); float t2 = fabs(+sina + cosa); n.max = max(t1,t2); } void Starfield::pickColor( Nebula &n) { //only use 2 color components float r1 = Random::rangef0_1()+0.1f; float r2 = Random::rangef0_1()+0.1f; float d = 1.8f/(r1+r2); r1 = r1*d; r2 = r2*d; int r = Random::random() % 3; switch( r) { case 0: n.r = r1; n.g = r2; n.b = 0.0; break; case 1: n.r = 0.0; n.g = r1; n.b = r2; break; default: case 2: n.r = r1; n.g = 0.0; n.b = r2; break; } }