1 // cloud.cxx -- model a single cloud layer
3 // Written by Curtis Olson, started June 2000.
5 // Copyright (C) 2000 Curtis L. Olson - curt@flightgear.org
7 // This program is distributed in the hope that it will be useful, but
8 // WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // General Public License for more details.
12 // You should have received a copy of the GNU General Public License
13 // along with this program; if not, write to the Free Software
14 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include <simgear/constants.h>
34 SGCloudLayer::SGCloudLayer( void ) {
39 SGCloudLayer::~SGCloudLayer( void ) {
43 // build the moon object
44 ssgBranch * SGCloudLayer::build( FGPath path, double size, double asl ) {
48 // set up the cloud state
49 path.append( "cloud.rgba" );
50 layer_state = new ssgSimpleState();
51 layer_state->setTexture( (char *)path.c_str() );
52 layer_state->setShadeModel( GL_SMOOTH );
53 layer_state->disable( GL_LIGHTING );
54 layer_state->disable( GL_CULL_FACE );
55 layer_state->enable( GL_TEXTURE_2D );
56 layer_state->enable( GL_COLOR_MATERIAL );
57 layer_state->setColourMaterial( GL_AMBIENT_AND_DIFFUSE );
58 layer_state->setMaterial( GL_EMISSION, 0, 0, 0, 1 );
59 layer_state->setMaterial( GL_SPECULAR, 0, 0, 0, 1 );
60 layer_state->enable( GL_BLEND );
61 layer_state->enable( GL_ALPHA_TEST );
62 layer_state->setAlphaClamp( 0.01 );
64 cl = new ssgColourArray( 4 );
65 vl = new ssgVertexArray( 4 );
66 tl = new ssgTexCoordArray( 4 );
68 // build the cloud layer
72 sgSetVec4( color, 1.0f, 1.0f, 1.0f, 1.0f );
74 sgSetVec3( vertex, -size, -size, 0.0f );
75 sgSetVec2( tc, 0.0f, 0.0f );
80 sgSetVec3( vertex, size, -size, 0.0f );
81 sgSetVec2( tc, size / 1000.0f, 0.0f );
86 sgSetVec3( vertex, -size, size, 0.0f );
87 sgSetVec2( tc, 0.0f, size / 1000.0f );
92 sgSetVec3( vertex, size, size, 0.0f );
93 sgSetVec2( tc, size / 1000.0f, size / 1000.0f );
99 new ssgVtxTable ( GL_TRIANGLE_STRIP, vl, NULL, tl, cl );
100 layer->setState( layer_state );
102 // force a repaint of the moon colors with arbitrary defaults
105 // build the ssg scene graph sub tree for the sky and connected
106 // into the provide scene graph branch
107 layer_transform = new ssgTransform;
109 // moon_transform->addKid( halo );
110 layer_transform->addKid( layer );
112 return layer_transform;
116 // repaint the cloud layer colors
117 bool SGCloudLayer::repaint( sgVec3 fog_color ) {
120 for ( int i = 0; i < 4; ++i ) {
121 color = cl->get( i );
122 sgCopyVec4( color, fog_color );
129 // reposition the cloud layer at the specified origin and orientation
130 // lon specifies a rotation about the Z axis
131 // lat specifies a rotation about the new Y axis
132 // spin specifies a rotation about the new Z axis (and orients the
133 // sunrise/set effects
134 bool SGCloudLayer::reposition( sgVec3 p, sgVec3 up, double lon, double lat ) {
138 // combine p and asl (meters) to get translation offset
140 sgCopyVec3( asl_offset, up );
141 sgNormalizeVec3( asl_offset );
142 sgScaleVec3( asl_offset, layer_asl );
143 // cout << "asl_offset = " << asl_offset[0] << "," << asl_offset[1]
144 // << "," << asl_offset[2] << endl;
145 sgAddVec3( asl_offset, p );
146 // cout << " asl_offset = " << asl_offset[0] << "," << asl_offset[1]
147 // << "," << asl_offset[2] << endl;
149 // Translate to zero elevation
150 // Point3D zero_elev = current_view.get_cur_zero_elev();
151 // xglTranslatef( zero_elev.x(), zero_elev.y(), zero_elev.z() );
152 sgMakeTransMat4( T1, asl_offset );
154 // printf(" Translated to %.2f %.2f %.2f\n",
155 // zero_elev.x, zero_elev.y, zero_elev.z );
157 // Rotate to proper orientation
158 // printf(" lon = %.2f lat = %.2f\n", FG_Longitude * RAD_TO_DEG,
159 // FG_Latitude * RAD_TO_DEG);
160 // xglRotatef( f->get_Longitude() * RAD_TO_DEG, 0.0, 0.0, 1.0 );
161 sgSetVec3( axis, 0.0, 0.0, 1.0 );
162 sgMakeRotMat4( LON, lon * RAD_TO_DEG, axis );
164 // xglRotatef( 90.0 - f->get_Latitude() * RAD_TO_DEG, 0.0, 1.0, 0.0 );
165 sgSetVec3( axis, 0.0, 1.0, 0.0 );
166 sgMakeRotMat4( LAT, 90.0 - lat * RAD_TO_DEG, axis );
170 sgCopyMat4( TRANSFORM, T1 );
171 sgPreMultMat4( TRANSFORM, LON );
172 sgPreMultMat4( TRANSFORM, LAT );
175 sgSetCoord( &layerpos, TRANSFORM );
177 layer_transform->setTransform( &layerpos );