-
-
-
-
-void SGNewCloud::drawContainers() {
-
-
-}
-
-
-
-// sort on distance to eye because of transparency
-void SGNewCloud::sortSprite( sgVec3 eye ) {
- list_of_spriteDef::iterator iSprite;
-
- // compute distance from sprite to eye
- for( iSprite = list_spriteDef.begin() ; iSprite != list_spriteDef.end() ; iSprite++ ) {
- sgVec3 dist;
- sgSubVec3( dist, iSprite->pos, eye );
- iSprite->dist = -(dist[0]*dist[0] + dist[1]*dist[1] + dist[2]*dist[2]);
- }
- std::sort( list_spriteDef.begin(), list_spriteDef.end() );
-}
-
-// render the cloud on screen or on the RTT texture to build the impostor
-void SGNewCloud::Render3Dcloud( bool drawBB, sgVec3 FakeEyePos, sgVec3 deltaPos, float dist_center ) {
-
- float step = ( list_spriteDef.size() * (direction ? fadetimer : duration-fadetimer)) / duration;
- int clrank = (int) step;
- float clfadeinrank = (step - clrank);
- last_step = step;
-
- float CloudVisFade = 1.0 / (0.7f * SGCloudField::get_CloudVis());
- // blend clouds with sky based on distance to limit the contrast of distant cloud
- float t = 1.0f - dist_center * CloudVisFade;
-// if ( t < 0.0f )
-// return;
-
- computeSimpleLight( FakeEyePos );
-
- // view point sort, we sort because of transparency
- sortSprite( FakeEyePos );
-
- float dark = (familly == CLFamilly_cb ? 0.9f : 1.0f);
-
- GLint previousTexture = -1, thisTexture;
- list_of_spriteDef::iterator iSprite;
- for( iSprite = list_spriteDef.begin() ; iSprite != list_spriteDef.end() ; iSprite++ ) {
- // skip this sprite if faded
- if(iSprite->rank > clrank)
- continue;
- // choose texture to use depending on sprite type
- switch(iSprite->sprite_type) {
- case CLbox_stratus:
- thisTexture = CLTexture_stratus;
- break;
- default:
- thisTexture = CLTexture_cumulus;
- break;
- }
- // in practice there is no texture switch (atm)
- if( previousTexture != thisTexture ) {
- previousTexture = thisTexture;
- // OSGFIXME
-// glBindTexture(GL_TEXTURE_2D, cloudTextures[thisTexture]->getHandle());
- }
-
- sgVec3 translate;
- sgSubVec3( translate, iSprite->pos, deltaPos);
-
-
- // flipx and flipy are random texture flip flags, this gives more random clouds
- float flipx = (float) ( iSprite->rank & 1 );
- float flipy = (float) ( (iSprite->rank >> 1) & 1 );
- // cu texture have a flat bottom so we can't do a vertical flip
- if( iSprite->sprite_type == CLbox_cumulus )
- flipy = 0.0f;
-// if( iSprite->sprite_type == CLbox_stratus )
-// flipx = 0.0f;
- // adjust colors depending on cloud type
- // TODO : rewrite that later, still experimental
- switch(iSprite->sprite_type) {
- case CLbox_cumulus:
- // dark bottom
- sgScaleVec3(iSprite->l0, 0.8f * dark);
- sgScaleVec3(iSprite->l1, 0.8f * dark);
- sgScaleVec3(iSprite->l2, dark);
- sgScaleVec3(iSprite->l3, dark);
- break;
- case CLbox_stratus:
- // usually dark grey
- if( familly == CLFamilly_st ) {
- sgScaleVec3(iSprite->l0, 0.8f);
- sgScaleVec3(iSprite->l1, 0.8f);
- sgScaleVec3(iSprite->l2, 0.8f);
- sgScaleVec3(iSprite->l3, 0.8f);
- } else {
- sgScaleVec3(iSprite->l0, 0.7f);
- sgScaleVec3(iSprite->l1, 0.7f);
- sgScaleVec3(iSprite->l2, 0.7f);
- sgScaleVec3(iSprite->l3, 0.7f);
- }
- break;
- default:
- // darker bottom than top
- sgScaleVec3(iSprite->l0, 0.8f);
- sgScaleVec3(iSprite->l1, 0.8f);
- break;
- }
- float r = iSprite->r * 0.5f;
-
- sgVec4 l0, l1, l2, l3;
- sgCopyVec4 ( l0, iSprite->l0 );
- sgCopyVec4 ( l1, iSprite->l1 );
- sgCopyVec4 ( l2, iSprite->l2 );
- sgCopyVec4 ( l3, iSprite->l3 );
- if( ! drawBB ) {
- // now clouds at the far plane are half blended
- sgScaleVec4( l0, t );
- sgScaleVec4( l1, t );
- sgScaleVec4( l2, t );
- sgScaleVec4( l3, t );
- }
- if( iSprite->rank == clrank ) {
- sgScaleVec4( l0, clfadeinrank );
- sgScaleVec4( l1, clfadeinrank );
- sgScaleVec4( l2, clfadeinrank );
- sgScaleVec4( l3, clfadeinrank );
- }
- // compute the rotations so that the quad is facing the camera
- sgVec3 pos;
- sgSetVec3( pos, translate[SG_X], translate[SG_Z], translate[SG_Y] );
- sgCopyVec3( translate, pos );
- translate[2] -= FakeEyePos[1];
-// sgNormaliseVec3( translate );
- float dist_sprite = sgLengthVec3 ( translate );
- sgScaleVec3 ( translate, SG_ONE / dist_sprite ) ;
- sgVec3 x, y, up = {0.0f, 0.0f, 1.0f};
- if( dist_sprite > 2*r ) {
- sgVectorProductVec3(x, translate, up);
- sgVectorProductVec3(y, x, translate);
- } else {
- sgCopyVec3( x, SGCloudField::view_X );
- sgCopyVec3( y, SGCloudField::view_Y );
- }
- sgScaleVec3(x, r);
- sgScaleVec3(y, r);
-
- sgVec3 left, right;
- if( drawBB )
- sgSetVec3( left, iSprite->pos[SG_X], iSprite->pos[SG_Z], iSprite->pos[SG_Y]);
- else
- sgCopyVec3( left, pos );
- sgSubVec3 (left, y);
- sgAddVec3 (right, left, x);
- sgSubVec3 (left, x);
-
- glBegin(GL_QUADS);
- glColor4fv(l0);
- glTexCoord2f(flipx, 1.0f - flipy);
- glVertex3fv(left);
- glColor4fv(l1);
- glTexCoord2f(1.0f - flipx, 1.0f - flipy);
- glVertex3fv(right);
- sgScaleVec3( y, 2.0 );
- sgAddVec3( left, y);
- sgAddVec3( right, y);
- glColor4fv(l2);
- glTexCoord2f(1.0f - flipx, flipy);
- glVertex3fv(right);
- glColor4fv(l3);
- glTexCoord2f(flipx, flipy);
- glVertex3fv(left);
-
- glEnd();
-
- }
-}
-
-
-// compute rotations so that a quad is facing the camera
-// TODO:change obsolete code because we dont use glrotate anymore
-void SGNewCloud::CalcAngles(sgVec3 refpos, sgVec3 FakeEyePos, float *angleY, float *angleX) {
- sgVec3 upAux, lookAt, objToCamProj, objToCam;
- float angle, angle2;
-
- sgSetVec3(objToCamProj, -FakeEyePos[SG_X] + refpos[SG_X], -FakeEyePos[SG_Z] + refpos[SG_Z], 0.0f);
- sgNormaliseVec3(objToCamProj);
-
- sgSetVec3(lookAt, 0.0f, 1.0f, 0.0f);
- sgVectorProductVec3(upAux, lookAt, objToCamProj);
- angle = sgScalarProductVec3(lookAt, objToCamProj);
- if( (angle < 0.9999f) && (angle > -0.9999f) ) {
- angle = acos(angle) * 180.0f / SG_PI;
- if( upAux[2] < 0.0f )
- angle = -angle;
- } else
- angle = 0.0f;
-
- sgSetVec3(objToCam, -FakeEyePos[SG_X] + refpos[SG_X], -FakeEyePos[SG_Z] + refpos[SG_Z], -FakeEyePos[SG_Y] + refpos[SG_Y]);
- sgNormaliseVec3(objToCam);
-
- angle2 = sgScalarProductVec3(objToCamProj, objToCam);
- if( (angle2 < 0.9999f) && (angle2 > -0.9999f) ) {
- angle2 = -acos(angle2) * 180.0f / SG_PI;
- if( objToCam[2] > 0.0f )
- angle2 = -angle2;
- } else
- angle2 = 0.0f;
-
- angle2 += 90.0f;
-
- *angleY = angle;
- *angleX = angle2;
-}
-
-// draw a cloud but this time we use the impostor texture
-void SGNewCloud::RenderBB(sgVec3 deltaPos, bool first_time, float dist_center) {
-
- sgVec3 translate;
- sgSubVec3( translate, center, deltaPos);
-
- // blend clouds with sky based on distance to limit the contrast of distant cloud
- float CloudVisFade = (1.0f * SGCloudField::get_CloudVis());
-
- float t = 1.0f - (dist_center - 1.0*radius) / CloudVisFade;
- if ( t < 0.0f )
- return;
- if( t > 1.0f )
- t = 1.0f;
- if( t > 0.50f )
- t *= 1.1f;
- glColor4f(t, t, t, t);
- float r = radius;
- // compute the rotations so that the quad is facing the camera
- sgVec3 pos;
- sgSetVec3( pos, translate[SG_X], translate[SG_Z], translate[SG_Y] );
- sgCopyVec3( translate, pos );
- pos[2] += deltaPos[1];
-
- sgNormaliseVec3( translate );
- sgVec3 x, y, up = {0.0f, 0.0f, 1.0f};
- sgVectorProductVec3(x, translate, up);
- sgVectorProductVec3(y, x, translate);
- if(first_time) {
- sgCopyVec3( rotX, x );
- sgCopyVec3( rotY, y );
- } else if(fabs(sgScalarProductVec3(rotX, x)) < 0.93f || fabs(sgScalarProductVec3(rotY, y)) < 0.93f ) {
- // ask for a redraw of this impostor if the view angle changed too much
- sgCopyVec3( rotX, x );
- sgCopyVec3( rotY, y );
- cldCache->invalidate(cloudId, bbId);
- }
- sgScaleVec3(x, r);
- sgScaleVec3(y, r);
-
- sgVec3 left, right;
- sgCopyVec3( left, pos );
- sgSubVec3 (left, y);
- sgAddVec3 (right, left, x);
- sgSubVec3 (left, x);
-
- glBegin(GL_QUADS);
- glTexCoord2f(0.0f, 0.0f);
- glVertex3fv(left);
- glTexCoord2f(1.0f, 0.0f);
- glVertex3fv(right);
- sgScaleVec3( y, 2.0 );
- sgAddVec3( left, y);
- sgAddVec3( right, y);
- glTexCoord2f(1.0f, 1.0f);
- glVertex3fv(right);
- glTexCoord2f(0.0f, 1.0f);
- glVertex3fv(left);
- glEnd();
-
-#if 0 // debug only
- int age = cldCache->queryImpostorAge(bbId);
- // draw a red border for the newly generated BBs else draw a white border
- if( age < 200 )
- glColor3f(1, 0, 0);
- else
- glColor3f(1, 1, 1);
-
- glBindTexture(GL_TEXTURE_2D, 0);
- glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
- glBegin(GL_QUADS);
- glVertex2f(-r, -r);
- glVertex2f(r, -r);
- glVertex2f(r, r);
- glVertex2f(-r, r);
- glEnd();
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
-