Updates to cloud code to add different basic cloud types. This isn't the

final list of cloud types, but servers as an example / template for someone
who wants to tweak this out and do it right.
This commit is contained in:
curt 2000-06-23 02:55:57 +00:00
parent 0468b315d4
commit 6cf2716615
4 changed files with 91 additions and 20 deletions

View File

@ -30,6 +30,8 @@
#include <simgear/math/point3d.hxx>
#include <simgear/math/polar3d.hxx>
#include <Objects/matlib.hxx>
#include "cloud.hxx"
@ -45,7 +47,7 @@ SGCloudLayer::~SGCloudLayer( void ) {
// build the moon object
void SGCloudLayer::build( FGPath path, double s, double asl, double thickness,
double transition )
double transition, SGCloudType type )
{
scale = 4000.0;
@ -56,21 +58,27 @@ void SGCloudLayer::build( FGPath path, double s, double asl, double thickness,
size = s;
last_lon = last_lat = -999.0f;
// set up the cloud state
path.append( "cloud.rgba" );
layer_state = new ssgSimpleState();
layer_state->setTexture( (char *)path.c_str() );
layer_state->setShadeModel( GL_SMOOTH );
layer_state->disable( GL_LIGHTING );
layer_state->disable( GL_CULL_FACE );
layer_state->enable( GL_TEXTURE_2D );
layer_state->enable( GL_COLOR_MATERIAL );
layer_state->setColourMaterial( GL_AMBIENT_AND_DIFFUSE );
layer_state->setMaterial( GL_EMISSION, 0, 0, 0, 1 );
layer_state->setMaterial( GL_SPECULAR, 0, 0, 0, 1 );
layer_state->enable( GL_BLEND );
layer_state->enable( GL_ALPHA_TEST );
layer_state->setAlphaClamp( 0.01 );
// look up the appropriate cloud state
FGNewMat *m;
switch ( type ) {
case SG_CLOUD_OVERCAST:
m = material_lib.find( "CloudOvercast" );
layer_state = m->get_state();
break;
case SG_CLOUD_MOSTLY_CLOUDY:
m = material_lib.find( "CloudMostlyCloudy" );
layer_state = m->get_state();
break;
case SG_CLOUD_MOSTLY_SUNNY:
m = material_lib.find( "CloudMostlySunny" );
layer_state = m->get_state();
break;
case SG_CLOUD_CIRRUS:
m = material_lib.find( "CloudCirrus" );
layer_state = m->get_state();
break;
}
cl = new ssgColourArray( 4 );
vl = new ssgVertexArray( 4 );
@ -247,3 +255,24 @@ bool SGCloudLayer::reposition( sgVec3 p, sgVec3 up, double lon, double lat,
void SGCloudLayer::draw() {
ssgCullAndDraw( layer_root );
}
// make an ssgSimpleState for a cloud layer given the named texture
ssgSimpleState *SGCloudMakeState( const string &path ) {
ssgSimpleState *state = new ssgSimpleState();
state->setTexture( (char *)path.c_str() );
state->setShadeModel( GL_SMOOTH );
state->disable( GL_LIGHTING );
state->disable( GL_CULL_FACE );
state->enable( GL_TEXTURE_2D );
state->enable( GL_COLOR_MATERIAL );
state->setColourMaterial( GL_AMBIENT_AND_DIFFUSE );
state->setMaterial( GL_EMISSION, 0, 0, 0, 1 );
state->setMaterial( GL_SPECULAR, 0, 0, 0, 1 );
state->enable( GL_BLEND );
state->enable( GL_ALPHA_TEST );
state->setAlphaClamp( 0.01 );
return state;
}

View File

@ -30,8 +30,18 @@
#include <simgear/misc/fgpath.hxx>
enum SGCloudType {
SG_CLOUD_OVERCAST = 0,
SG_CLOUD_MOSTLY_CLOUDY,
SG_CLOUD_MOSTLY_SUNNY,
SG_CLOUD_CIRRUS,
};
class SGCloudLayer {
private:
ssgRoot *layer_root;
ssgTransform *layer_transform;
ssgSimpleState *layer_state;
@ -63,7 +73,7 @@ public:
// build the cloud object
void build( FGPath path, double size, double asl, double thickness,
double transition );
double transition, SGCloudType type );
// repaint the cloud colors based on current value of sun_angle,
// sky, and fog colors. This updates the color arrays for
@ -91,4 +101,8 @@ public:
};
// make an ssgSimpleState for a cloud layer given the named texture
ssgSimpleState *SGCloudMakeState( const string &path );
#endif // _SG_CLOUD_HXX_

View File

@ -31,6 +31,8 @@
#include <simgear/constants.h>
#include <simgear/math/fg_random.h>
#include <Objects/matlib.hxx>
#include "sky.hxx"
@ -93,6 +95,30 @@ void SGSky::build( double sun_size, double moon_size,
pre_root->addKid( pre_selector );
post_root->addKid( post_selector );
// add the cloud ssgStates to the material lib
FGPath cloud_path;
ssgSimpleState *cloud_state;
cloud_path.set( tex_path.str() );
cloud_path.append( "cirrus.rgba" );
cloud_state = SGCloudMakeState( cloud_path.str() );
material_lib.add_item( "CloudCirrus", cloud_state );
cloud_path.set( tex_path.str() );
cloud_path.append( "mostlycloudy.rgba" );
cloud_state = SGCloudMakeState( cloud_path.str() );
material_lib.add_item( "CloudMostlyCloudy", cloud_state );
cloud_path.set( tex_path.str() );
cloud_path.append( "mostlysunny.rgba" );
cloud_state = SGCloudMakeState( cloud_path.str() );
material_lib.add_item( "CloudMostlySunny", cloud_state );
cloud_path.set( tex_path.str() );
cloud_path.append( "overcast.rgb" );
cloud_state = SGCloudMakeState( cloud_path.str() );
material_lib.add_item( "CloudOvercast", cloud_state );
}
@ -201,9 +227,10 @@ void SGSky::draw_scene( float alt ) {
}
void SGSky::add_cloud_layer( double asl, double thickness, double transition ) {
void SGSky::add_cloud_layer( double asl, double thickness, double transition,
SGCloudType type ) {
SGCloudLayer *layer = new SGCloudLayer;
layer->build(tex_path, 40000.0f, asl, thickness, transition);
layer->build(tex_path, 40000.0f, asl, thickness, transition, type );
layer_list_iterator current = cloud_layers.begin();
layer_list_iterator last = cloud_layers.end();

View File

@ -150,7 +150,8 @@ public:
}
// add a cloud layer (above sea level in meters)
void add_cloud_layer( double asl, double thickness, double transition );
void add_cloud_layer( double asl, double thickness, double transition,
SGCloudType type );
inline int get_num_layers() const { return cloud_layers.size(); }
inline SGCloudLayer *get_cloud_layer( int i ) const {