00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <sky/SkyDome.h>
00022 #include <sky/Sky.h>
00023 #include <sky/Hemisphere.h>
00024 #include <landscape/Landscape.h>
00025 #include <landscapemap/LandscapeMaps.h>
00026 #include <landscapedef/LandscapeTex.h>
00027 #include <landscapedef/LandscapeDefinition.h>
00028 #include <GLEXT/GLState.h>
00029 #include <GLEXT/GLCamera.h>
00030 #include <image/ImageFactory.h>
00031 #include <client/ScorchedClient.h>
00032 #include <graph/OptionsDisplay.h>
00033 #include <common/OptionsTransient.h>
00034 #include <common/Defines.h>
00035
00036 SkyDome::SkyDome() :
00037 xy_(0.0f),
00038 cloudSpeed_(500.0f),
00039 flashTime_(0.0f)
00040 {
00041 }
00042
00043 SkyDome::~SkyDome()
00044 {
00045 }
00046
00047 void SkyDome::flash()
00048 {
00049 flashTime_ = 0.25f;
00050 }
00051
00052 void SkyDome::generate()
00053 {
00054 LandscapeTex *tex = ScorchedClient::instance()->
00055 getLandscapeMaps().getDefinitions().getTex();
00056
00057
00058 std::string ctex(S3D::getDataFile(tex->skytexture.c_str()));
00059 std::string ctexm(S3D::getDataFile(tex->skytexturemask.c_str()));
00060 ImageHandle bitmapCloud = ImageFactory::loadImageHandle(ctex.c_str(), ctexm.c_str(), false);
00061 DIALOG_ASSERT(cloudTexture_.replace(bitmapCloud));
00062 skyColorsMap_ = ImageFactory::loadImageHandle(S3D::getDataFile(tex->skycolormap.c_str()));
00063
00064
00065 useStarTexture_ = false;
00066 if (!tex->skytexturestatic.empty())
00067 {
00068 useStarTexture_ = true;
00069 std::string stex(S3D::getDataFile(tex->skytexturestatic.c_str()));
00070 ImageHandle bitmapStars = ImageFactory::loadImageHandle(stex.c_str(), stex.c_str(), false);
00071 DIALOG_ASSERT(starTexture_.replace(bitmapStars));
00072 }
00073 noSunFog_ = tex->nosunfog;
00074 horizonGlow_ = !tex->nohorizonglow;
00075
00076
00077 skyLine1_.clear();
00078 useSkyLine_ = false;
00079 if (!tex->skyline.empty())
00080 {
00081 useSkyLine_ = true;
00082 std::string stex(S3D::getDataFile(tex->skyline.c_str()));
00083 std::string stexa(S3D::getDataFile(tex->skylinemask.c_str()));
00084 ImageHandle bitmapSkyLine = ImageFactory::loadImageHandle(stex.c_str(), stexa.c_str());
00085 DIALOG_ASSERT(skyLineTexture_.replace(bitmapSkyLine));
00086 }
00087
00088
00089 colors_.clear();
00090 }
00091
00092 void SkyDome::simulate(float frameTime)
00093 {
00094 if (OptionsDisplay::instance()->getNoSkyMovement()) return;
00095
00096 float fastSpeed = 100;
00097 float slowSpeed = 500;
00098 float currentSpeed = ScorchedClient::instance()->getOptionsTransient().getWindSpeed().asFloat();
00099 float wantedAngle = ScorchedClient::instance()->getOptionsTransient().getWindAngle().asFloat();
00100 float wantedSpeed = (((5.0f - currentSpeed) / 5.0f) * (slowSpeed - fastSpeed)) + fastSpeed;
00101
00102
00103 cloudSpeed_ = wantedSpeed;
00104 cloudDirection_ = -ScorchedClient::instance()->getOptionsTransient().getWindDirection().asVector();
00105 xy_ += frameTime / cloudSpeed_;
00106
00107
00108 flashTime_ -= frameTime;
00109 }
00110
00111 void SkyDome::drawBackdrop()
00112 {
00113 Vector &pos = GLCamera::getCurrentCamera()->getCurrentPos();
00114 Vector sunDir =
00115 Landscape::instance()->getSky().getSun().getPosition().Normalize();
00116 LandscapeTex &tex =
00117 *ScorchedClient::instance()->getLandscapeMaps().getDefinitions().getTex();
00118
00119
00120
00121 glPushMatrix();
00122
00123 glTranslatef(pos[0], pos[1], -15.0f);
00124
00125
00126 GLState mainState2(GLState::TEXTURE_OFF | GLState::BLEND_OFF);
00127 colors_.drawColored(2000, 225, skyColorsMap_, sunDir, tex.skytimeofday, horizonGlow_);
00128
00129
00130 if (useStarTexture_)
00131 {
00132 glDisable(GL_FOG);
00133
00134 glColor4f(1.0f, 1.0f, 1.0f, 0.7f);
00135 GLState currentState(GLState::TEXTURE_ON | GLState::BLEND_ON);
00136 starTexture_.draw();
00137
00138 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
00139
00140 glMatrixMode(GL_TEXTURE);
00141 glLoadIdentity();
00142 glScalef(9.0f, 9.0f, 0.0f);
00143 glMatrixMode(GL_MODELVIEW);
00144
00145 stars_.draw(1990, 215, Hemisphere::eWidthTexture);
00146 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00147
00148 glMatrixMode(GL_TEXTURE);
00149 glLoadIdentity();
00150 glMatrixMode(GL_MODELVIEW);
00151 }
00152
00153 glPopMatrix();
00154
00155 if (!OptionsDisplay::instance()->getNoFog())
00156 {
00157 glEnable(GL_FOG);
00158 }
00159
00160
00161 if (noSunFog_) glDisable(GL_FOG);
00162 Landscape::instance()->getSky().getSun().draw();
00163
00164 if (!OptionsDisplay::instance()->getNoFog())
00165 {
00166 glEnable(GL_FOG);
00167 }
00168 }
00169
00170 void SkyDome::drawLayers()
00171 {
00172 Vector &pos = GLCamera::getCurrentCamera()->getCurrentPos();
00173
00174 glPushMatrix();
00175
00176 glTranslatef(pos[0], pos[1], -15.0f);
00177
00178
00179 if (useSkyLine_)
00180 {
00181
00182
00183 skyLineTexture_.draw();
00184 skyLine1_.draw(1000.0f, 1000.0f, 200.0f);
00185
00186
00187 }
00188
00189
00190 if (!OptionsDisplay::instance()->getNoSkyLayers())
00191 {
00192
00193 float slowXY = (xy_ + 45.5f) / 1.5f;
00194 GLState currentState(GLState::TEXTURE_ON | GLState::BLEND_ON);
00195 glColor4f(1.0f, 1.0f, 1.0f, 0.7f);
00196
00197
00198 cloudTexture_.draw();
00199
00200
00201 glMatrixMode(GL_TEXTURE);
00202 glLoadIdentity();
00203 glTranslatef(xy_ * cloudDirection_[0],
00204 xy_ * cloudDirection_[1], 0.0f);
00205 glMatrixMode(GL_MODELVIEW);
00206
00207 clouds1_.draw(1980, 210, Hemisphere::eWidthTexture);
00208
00209
00210 glMatrixMode(GL_TEXTURE);
00211 glLoadIdentity();
00212 glTranslatef((slowXY) * (cloudDirection_[0] + cloudDirection_[1] * 0.3f),
00213 (slowXY) * (cloudDirection_[1] - cloudDirection_[0] * 0.3f), 0.0f);
00214 glMatrixMode(GL_MODELVIEW);
00215
00216 clouds2_.draw(1980, 170, Hemisphere::eWidthTexture);
00217
00218
00219 glMatrixMode(GL_TEXTURE);
00220 glLoadIdentity();
00221 glMatrixMode(GL_MODELVIEW);
00222 }
00223
00224 glPopMatrix();
00225 }