diff --git a/.github/workflows/action.yml b/.github/workflows/action.yml deleted file mode 100644 index 8b137891..00000000 --- a/.github/workflows/action.yml +++ /dev/null @@ -1 +0,0 @@ - diff --git a/runtime/language/en.uitxt b/runtime/language/en.uitxt index 00112cf9..d381c41f 100644 --- a/runtime/language/en.uitxt +++ b/runtime/language/en.uitxt @@ -221,6 +221,7 @@ $BGCOL 0 +configdlg/opengl #OpenGL +common/setdefault #Set Default +configdlg/environment #Environment ++configdlg/daylength #Day length (mins) +configdlg/light #Light Direction +configdlg/aircraft #Aircraft +configdlg/blackout #Black Out diff --git a/runtime/language/ja.uitxt b/runtime/language/ja.uitxt index 366dbb23..a4f6f04d 100644 --- a/runtime/language/ja.uitxt +++ b/runtime/language/ja.uitxt @@ -224,6 +224,7 @@ $BGCOL 0 +configdlg/opengl #OpenGL +common/setdefault #デフォルトに戻す +configdlg/environment #環境 ++configdlg/daylength #日の長さ(分) +configdlg/light #光源方向 +configdlg/aircraft #航空機 +configdlg/blackout #ブラックアウト diff --git a/runtime/misc/moon.srf b/runtime/misc/moon.srf new file mode 100644 index 00000000..c90b4f1a --- /dev/null +++ b/runtime/misc/moon.srf @@ -0,0 +1,132 @@ +Surf +VER 4.700 10.000 -0.100 R +VER 3.700 9.800 -0.100 R +VER 2.800 9.800 -0.100 R +VER 2.900 9.200 -0.100 R +VER 1.000 9.200 -0.100 R +VER 2.100 8.300 -0.100 R +VER -0.600 8.300 -0.100 R +VER 1.300 7.100 -0.100 R +VER -2.100 7.100 -0.100 R +VER 0.800 5.600 -0.100 R +VER -3.300 5.600 -0.100 R +VER 0.300 3.800 -0.100 R +VER -4.200 3.800 -0.100 R +VER 0.100 2.000 -0.100 R +VER -4.700 2.000 -0.100 R +VER -0.000 0.000 -0.100 R +VER -4.900 0.000 -0.100 R +VER 0.100 -2.000 -0.100 R +VER -4.700 -2.000 -0.100 R +VER 0.300 -3.800 -0.100 R +VER -4.200 -3.800 -0.100 R +VER 0.800 -5.600 -0.100 R +VER -3.300 -5.600 -0.100 R +VER 1.300 -7.100 -0.100 R +VER -2.100 -7.100 -0.100 R +VER 2.100 -8.300 -0.100 R +VER -0.600 -8.300 -0.100 R +VER 2.900 -9.200 -0.100 R +VER 1.000 -9.200 -0.100 R +VER 3.700 -9.800 -0.100 R +VER 2.800 -9.800 -0.100 R +VER 4.700 -10.000 -0.100 R +FAC +BRI +COL 255 255 255 +NOR 3.733 9.867 -0.100 -0.000 0.000 1.000 +VER 0 2 1 +END +FAC +BRI +COL 255 255 255 +NOR 2.600 9.500 -0.100 -0.000 0.000 1.000 +VER 1 2 4 3 +END +FAC +BRI +COL 255 255 255 +NOR 1.350 8.750 -0.100 -0.000 0.000 1.000 +VER 3 4 6 5 +END +FAC +BRI +COL 255 255 255 +NOR 0.175 7.700 -0.100 -0.000 0.000 1.000 +VER 5 6 8 7 +END +FAC +BRI +COL 255 255 255 +NOR -0.825 6.350 -0.100 -0.000 0.000 1.000 +VER 7 8 10 9 +END +FAC +BRI +COL 255 255 255 +NOR -1.600 4.700 -0.100 -0.000 0.000 1.000 +VER 9 10 12 11 +END +FAC +BRI +COL 255 255 255 +NOR -2.125 2.900 -0.100 -0.000 0.000 1.000 +VER 11 12 14 13 +END +FAC +BRI +COL 255 255 255 +NOR -2.375 1.000 -0.100 -0.000 0.000 1.000 +VER 13 14 16 15 +END +FAC +BRI +COL 255 255 255 +NOR -2.375 -1.000 -0.100 -0.000 0.000 1.000 +VER 15 16 18 17 +END +FAC +BRI +COL 255 255 255 +NOR -2.125 -2.900 -0.100 -0.000 0.000 1.000 +VER 17 18 20 19 +END +FAC +BRI +COL 255 255 255 +NOR -1.600 -4.700 -0.100 -0.000 0.000 1.000 +VER 19 20 22 21 +END +FAC +BRI +COL 255 255 255 +NOR -0.825 -6.350 -0.100 -0.000 0.000 1.000 +VER 21 22 24 23 +END +FAC +BRI +COL 255 255 255 +NOR 0.175 -7.700 -0.100 -0.000 0.000 1.000 +VER 23 24 26 25 +END +FAC +BRI +COL 255 255 255 +NOR 1.350 -8.750 -0.100 -0.000 0.000 1.000 +VER 25 26 28 27 +END +FAC +BRI +COL 255 255 255 +NOR 2.600 -9.500 -0.100 -0.000 0.000 1.000 +VER 27 28 30 29 +END +FAC +BRI +COL 255 255 255 +NOR 3.733 -9.867 -0.100 -0.000 0.000 1.000 +VER 29 30 31 +END +END + + diff --git a/runtime/misc/sun.srf b/runtime/misc/sun.srf new file mode 100644 index 00000000..b4635827 --- /dev/null +++ b/runtime/misc/sun.srf @@ -0,0 +1,117 @@ +Surf +VER 0.000 0.000 0.000 R +VER 10.000 0.000 0.000 R +VER 9.200 -3.800 0.000 R +VER 7.100 -7.100 0.000 R +VER 3.800 -9.200 0.000 R +VER 0.000 -10.000 0.000 R +VER -3.800 -9.200 -0.000 R +VER -7.100 -7.100 -0.000 R +VER -9.200 -3.800 -0.000 R +VER -10.000 0.000 -0.000 R +VER -9.200 3.800 -0.000 R +VER -7.100 7.100 -0.000 R +VER -3.800 9.200 -0.000 R +VER 0.000 10.000 0.000 R +VER 3.800 9.200 0.000 R +VER 7.100 7.100 0.000 R +VER 9.200 3.800 0.000 R +FAC +BRI +COL 255 255 255 +NOR 6.400 -1.267 0.000 -0.000 0.000 1.000 +VER 0 2 1 +END +FAC +BRI +COL 255 255 255 +NOR 5.433 -3.633 0.000 -0.000 0.000 1.000 +VER 0 3 2 +END +FAC +BRI +COL 255 255 255 +NOR 3.633 -5.433 0.000 -0.000 0.000 1.000 +VER 0 4 3 +END +FAC +BRI +COL 255 255 255 +NOR 1.267 -6.400 0.000 -0.000 0.000 1.000 +VER 0 5 4 +END +FAC +BRI +COL 255 255 255 +NOR -1.267 -6.400 -0.000 -0.000 0.000 1.000 +VER 0 6 5 +END +FAC +BRI +COL 255 255 255 +NOR -3.633 -5.433 -0.000 -0.000 0.000 1.000 +VER 0 7 6 +END +FAC +BRI +COL 255 255 255 +NOR -5.433 -3.633 -0.000 -0.000 0.000 1.000 +VER 0 8 7 +END +FAC +BRI +COL 255 255 255 +NOR -6.400 -1.267 -0.000 -0.000 0.000 1.000 +VER 0 9 8 +END +FAC +BRI +COL 255 255 255 +NOR -6.400 1.267 -0.000 -0.000 0.000 1.000 +VER 0 10 9 +END +FAC +BRI +COL 255 255 255 +NOR -5.433 3.633 -0.000 -0.000 0.000 1.000 +VER 0 11 10 +END +FAC +BRI +COL 255 255 255 +NOR -3.633 5.433 -0.000 -0.000 0.000 1.000 +VER 0 12 11 +END +FAC +BRI +COL 255 255 255 +NOR -1.267 6.400 -0.000 -0.000 0.000 1.000 +VER 0 13 12 +END +FAC +BRI +COL 255 255 255 +NOR 1.267 6.400 0.000 -0.000 0.000 1.000 +VER 0 14 13 +END +FAC +BRI +COL 255 255 255 +NOR 3.633 5.433 0.000 -0.000 0.000 1.000 +VER 0 15 14 +END +FAC +BRI +COL 255 255 255 +NOR 5.433 3.633 0.000 -0.000 0.000 1.000 +VER 0 16 15 +END +FAC +BRI +COL 255 255 255 +NOR 6.400 1.267 0.000 -0.000 0.000 1.000 +VER 0 1 16 +END +END + + diff --git a/src/common/fstextresource.h b/src/common/fstextresource.h index 6eeff684..fc309396 100644 --- a/src/common/fstextresource.h +++ b/src/common/fstextresource.h @@ -246,6 +246,7 @@ inline const wchar_t *FsGetTextResource(const char *key,const wchar_t *alternati #define FSGUI_CFGDLG_SETDEFAULT FsGetTextResource("common/setdefault",L"Set Default") #define FSGUI_CFGDLG_ENVIRONMENT FsGetTextResource("configdlg/environment",L"Environment") #define FSGUI_CFGDLG_LIGHT FsGetTextResource("configdlg/light",L"Light Direction") +#define FSGUI_CFGDLG_DAYLENGTH FsGetTextResource("configdlg/daylength",L"Day Length (min)") #define FSGUI_CFGDLG_AIRCRAFT FsGetTextResource("configdlg/aircraft",L"Aircraft") #define FSGUI_CFGDLG_FIELD FsGetTextResource("common/field",L"Field") #define FSGUI_CFGDLG_STP FsGetTextResource("common/startpos",L"Start Position") diff --git a/src/config/fsconfig.cpp b/src/config/fsconfig.cpp index efdc62e9..81b497ce 100644 --- a/src/config/fsconfig.cpp +++ b/src/config/fsconfig.cpp @@ -91,6 +91,9 @@ void FsFlightConfig::SetDefault(void) aircraftReliability=95; aircraftTroubleFrequency=0.1; + + dayLength=120; + dayTime=0.0; } void FsFlightConfig::SetDetailedMode(void) @@ -230,8 +233,13 @@ const char *const FsFlightConfig::keyWordSource[]= "CONSTWIND", // 2023/07/29 "CLOUDLAYER", // 2023/07/29 + "CENTERCAM", // 2023/08/15 + "DAYLENG", // 2023/09/03 + + "DAYTIME", // 2023/09/03 + NULL }; YsKeyWordList FsFlightConfig::keyWordList; @@ -553,8 +561,15 @@ YSRESULT FsFlightConfig::SendCommand(const char cmd[]) } case 64: // CENTERCAM return FsGetBool(centerCameraPerspective, av[1]); - - } + + case 65: // "DAYLENG", // 2023/09/03 + dayLength=atoi(av[1]); + return YSOK; + + case 66: // "DAYTIME", // 2023/09/03 + dayTime = atof(av[1]); + return YSOK; + } } else { @@ -577,7 +592,7 @@ YSRESULT FsFlightConfig::Load(const wchar_t fn[]) { if(SendCommand(buf)!=YSOK) { - // fsStderr.Printf("Unrecognizable Line : %s\n",buf); + //printf("Unrecognizable Line : %s\n",buf); res=YSERR; } } @@ -733,6 +748,11 @@ YSRESULT FsFlightConfig::Save(const wchar_t fn[]) cloudLayer[i].y0, cloudLayer[i].y1); } + + fprintf(fp,"DAYLENG %d\n",dayLength); + + fprintf(fp,"DAYTIME %lf\n",dayTime); + fclose(fp); return YSOK; } diff --git a/src/config/fsconfig.h b/src/config/fsconfig.h index 03761a24..09575f63 100644 --- a/src/config/fsconfig.h +++ b/src/config/fsconfig.h @@ -98,8 +98,11 @@ class FsFlightConfig double radarAltitudeLimit; YSBOOL noExtAirView; + int dayLength; + double dayTime; YsVec3 lightSourceDirection; + YSBOOL accurateTime; void SetDefault(void); diff --git a/src/core/fscloud.cpp b/src/core/fscloud.cpp index 85627726..7e35ebf5 100644 --- a/src/core/fscloud.cpp +++ b/src/core/fscloud.cpp @@ -3,6 +3,9 @@ #include #include #include +#include +#include +#include #include @@ -10,6 +13,9 @@ #include "fsdef.h" #include "graphics/common/fsopengl.h" #include "fscloud.h" +#include "fsvisual.h" +#include +#include @@ -672,9 +678,8 @@ static double sphere_e2_nom[]= 0.176784,0.942245,-0.284469 }; -FsSolidCloud::FsSolidCloud() : ltc(1) +FsSolidCloud::FsSolidCloud() { - ltc.DisablePolygonToCellHashTable(); CreateGraphicCache(); } @@ -691,6 +696,11 @@ void FsSolidCloud::Initialize(void) } const YsShell &FsSolidCloud::GetShell(void) const +{ + return shl.Conv(); +} + +FsVisualSrf &FsSolidCloud::GetSrf(void) { return shl; } @@ -703,6 +713,7 @@ const YsVec3 &FsSolidCloud::GetCenter(void) const void FsSolidCloud::Make(const YsVec3 &mov,const double &sizeX,const double &sizeZ,const double &y0,const double &y1) { YsArray vtHdList; + YsShellExt shell; YsShellPolygonHandle plHd; YsShellVertexHandle vtHd; YsVec3 diagon; @@ -714,7 +725,8 @@ void FsSolidCloud::Make(const YsVec3 &mov,const double &sizeX,const double &size { YsVec3 pos; pos.Set(sphere_e2_vtx[i*3],sphere_e2_vtx[i*3+1],sphere_e2_vtx[i*3+2]); - vtHd=shl.AddVertexH(pos); + vtHd=shell.AddVertex(pos); + shell.SetVertexRoundFlag(vtHd,YSTRUE); vtHdList.Append(vtHd); } @@ -727,17 +739,20 @@ void FsSolidCloud::Make(const YsVec3 &mov,const double &sizeX,const double &size plVtHd[0]=vtHdList[sphere_e2_idx[i*3]]; plVtHd[1]=vtHdList[sphere_e2_idx[i*3+1]]; plVtHd[2]=vtHdList[sphere_e2_idx[i*3+2]]; - plHd=shl.AddPolygonH(3,plVtHd); - shl.SetNormalOfPolygon(plHd,plNom); + plHd=shell.AddPolygon(3,plVtHd); + shell.SetPolygonNormal(plHd,plNom); + YsColor col; + col.SetIntRGBA(255,255,255,125); + shell.SetPolygonColor(plHd,col); } - shl.GetBoundingBox(bbx[0],bbx[1]); + shell.GetBoundingBox(bbx[0],bbx[1]); diagon=bbx[1]-bbx[0]; bump=diagon.GetLength()/20.0; plHd=NULL; - while((plHd=shl.FindNextPolygon(plHd))!=NULL) + while((plHd=shell.FindNextPolygon(plHd))!=NULL) { if(rand()%100<50) { @@ -745,23 +760,23 @@ void FsSolidCloud::Make(const YsVec3 &mov,const double &sizeX,const double &size const YsShellVertexHandle *plVtHd; double t; YsVec3 nom,pos; - shl.GetNormalOfPolygon(nom,plHd); - shl.GetVertexListOfPolygon(nPlVt,plVtHd,plHd); + shell.GetNormalOfPolygon(nom,plHd); + shell.GetVertexListOfPolygon(nPlVt,plVtHd,plHd); t=(double)(rand()%100-50)/50.0; for(i=0; i *itm; - itm=cloudContainer.Create(); - itm->dat.Initialize(); - itm->dat.shl.BeginReadSrf(); - while(str.Fgets(fp)!=NULL) - { - if(state==0) - { - if(str[0]=='F' || str[0]=='f') - { - state=1; - } - else if(str[0]=='E' || str[0]=='e') - { - break; - } - } - else - { - if(str[0]=='E' || str[0]=='e') - { - state=0; - } - } - itm->dat.shl.ReadSrfOneLine(str); - } - itm->dat.shl.EndReadSrf(); - - itm->dat.shl.GetBoundingBox(itm->dat.bbx[0],itm->dat.bbx[1]); - itm->dat.cen=(itm->dat.bbx[0]+itm->dat.bbx[1])/2.0; - - itm->dat.shl.AutoComputeVertexNormalAll(YSTRUE); - itm->dat.ltc.SetDomain(itm->dat.shl,1024); - - itm->dat.ScatterParticle(400); - } - } - break; - } + return YSOK; } @@ -1095,12 +1072,22 @@ void FsSolidClouds::Make( } } +void FsSolidClouds::Move(const double dv, const YsVec3 &wind) +{ + YsVec3 winddv = wind * dv; + YsListItem *itm=NULL; + while((itm=cloudContainer.FindNext(itm))!=NULL) + { + itm->dat.Move(winddv); + } +} + void FsSolidClouds::AddToParticleManager( class YsGLParticleManager &partMan, - FSENVIRONMENT env,const class FsWeather &weather, - const YsVec3 &viewDir,const YsMatrix4x4 &viewMdlTfm,const double &nearZ,const double &farZ,const double &tanFov) + double lightIntensity,const class FsWeather &weather, + const YsVec3 &viewDir,const YsMatrix4x4 &viewMdlTfm,const double &nearZ,const double &farZ,const double &tanFov,const YsVec3 &viewPoint) { - const double baseBrightness=(FSDAYLIGHT==env ? 0.7 : 0.15); + const double baseBrightness=lightIntensity*.75; YsListItem *itm=NULL; while((itm=cloudContainer.FindNext(itm))!=NULL) @@ -1115,7 +1102,7 @@ void FsSolidClouds::AddToParticleManager( col.SetDoubleRGBA(brightness,brightness,brightness,0.5); float s=(float)particle.particleType*0.125f; - partMan.Add(particle.pos,col,particle.rad*2.0,s,0); + partMan.Add(particle.pos+itm->dat.cen,col,particle.rad*2.0,s,0); } } } @@ -1123,13 +1110,21 @@ void FsSolidClouds::AddToParticleManager( void FsSolidClouds::Draw( FSENVIRONMENT env,const FsWeather &weather, - const YsMatrix4x4 &viewMdlTfm,const double &nearZ,const double &farZ,const double &tanFov) + const YsMatrix4x4 &viewMdlTfm,const double &nearZ,const double &farZ,const double &tanFov,const YsMatrix4x4 &projTfm) { YsArray dist; YsArray toDraw; BeginDrawCloud(); + YsVec3 cameraPos,pos; + pos.Set(0.0,0.0,0.0); + cameraPos = viewMdlTfm * pos; + + + printf("CameraPos: %lf %lf %lf\n",cameraPos.x(),cameraPos.y(),cameraPos.z()); + + YsListItem *itm; itm=NULL; while((itm=cloudContainer.FindNext(itm))!=NULL) @@ -1146,9 +1141,52 @@ void FsSolidClouds::Draw( for(int i=0; iDraw(env,weather); + FsVisualSrf srf; + YsAtt3 atti = YsAtt3(0.0,0,0); + srf = toDraw[i]->GetSrf(); + srf.Draw(*&viewMdlTfm,*&projTfm,toDraw[i]->cen, *&atti, FSVISUAL_DRAWTRANSPARENT); } EndDrawCloud(); } + double FsSolidCloud::perlinNoise(double x, double y, int seed){ + std::default_random_engine generator(seed); + + std::vector p(256); + + for (int i= 0; i < 256; ++i) { + p[i] = i; + } + + std::shuffle(p.begin(), p.end(), generator); + + double noise = 0.0; + double fade = 1.0; + + for (int i = 0; i < 4; ++i) { + int X = (int)floor(x) & 255; + int Y = (int)floor(y) & 255; + + double u = x - floor(x); + double v = y - floor(y); + + int A = p[X] + Y; + int AA = p[A]; + int AB = p[A + 1]; + int B = p[X + 1] + Y; + int BA = p[B]; + int BB = p[B + 1]; + + noise += fade * ((1 - u) * (1 - v) * AA + (1 - u) * v * AB + u * (1 - v) * BA + u * v * BB); + + x *= 2.0; + y *= 2.0; + fade *= 0.5; + } + + return noise; + +} + + diff --git a/src/core/fscloud.h b/src/core/fscloud.h index 0f349272..a18615a0 100644 --- a/src/core/fscloud.h +++ b/src/core/fscloud.h @@ -3,6 +3,7 @@ /* { */ #include +#include "fsvisual.h" class FsCloud { @@ -83,9 +84,8 @@ friend class FsSolidCloudGraphicCache; YsArray particle; - YsShell shl; - YsShellLattice ltc; - YsVec3 bbx[2],cen; + mutable class FsVisualSrf shl; + YsVec3 bbx[2],cen, position; YsGLBufferManager::Handle vboHd; public: @@ -94,6 +94,7 @@ friend class FsSolidCloudGraphicCache; void Initialize(void); const YsShell &GetShell(void) const; + FsVisualSrf &GetSrf(void); const YsVec3 &GetCenter(void) const; // Cloud rendering is view-direction dependent. @@ -102,9 +103,11 @@ friend class FsSolidCloudGraphicCache; void MakeOpenGlList(void); void Make(const YsVec3 &cen,const double &sizeX,const double &sizeZ,const double &y0,const double &y1); + void Move(const YsVec3 &wind); YSBOOL IsInCloud(const YsVec3 &pos) const; void ScatterParticle(int nParticle); + double perlinNoise(double x, double y, int seed); }; class FsSolidClouds @@ -126,8 +129,8 @@ class FsSolidClouds void AddToParticleManager( class YsGLParticleManager &partMan, - FSENVIRONMENT env,const class FsWeather &weather, - const YsVec3 &viewDir,const YsMatrix4x4 &viewMdlTfm,const double &nearZ,const double &farZ,const double &tanFov); + double lightIntensity,const class FsWeather &weather, + const YsVec3 &viewDir,const YsMatrix4x4 &viewMdlTfm,const double &nearZ,const double &farZ,const double &tanFov,const YsVec3 &viewPoint); void MakeOpenGlList(void); @@ -136,7 +139,8 @@ class FsSolidClouds void BeginDrawCloud(void); void Draw( FSENVIRONMENT env,const class FsWeather &weather, - const YsMatrix4x4 &viewMdlTfm,const double &nearZ,const double &farZ,const double &tanFov); + const YsMatrix4x4 &viewMdlTfm,const double &nearZ,const double &farZ,const double &tanFov, const YsMatrix4x4 &projTfm); + void Move(const double dv, const YsVec3 &wind); void EndDrawCloud(void); void ReduceVisibilityByPolygon(const YsMatrix4x4 &viewTfm,const YsColor &col,YSBOOL transparency); void Make(int n,const YsVec3 &cen,const double &range,const double &sizeX,const double &y0,const double &y1); diff --git a/src/core/fsgroundsky.h b/src/core/fsgroundsky.h index 1931cbc9..5ecc2286 100644 --- a/src/core/fsgroundsky.h +++ b/src/core/fsgroundsky.h @@ -14,6 +14,8 @@ class FsGroundSky int nLayer; double nDeg; + FsVisualSrf *sun,*moon; + class FsGroundSkyGraphicCache *res; public: @@ -25,11 +27,13 @@ class FsGroundSky const double &farZ,YSBOOL specular); void DrawByFog (const YsVec3 &pos,const YsAtt3 &att,const YsColor &gnd,const YsColor &sky,const YsColor &horizon, - const double &farZ,YSBOOL specular); + const double &farZ,YSBOOL specular, YsVec3 sunPos, YsColor sunColor); void DrawCrappy (const YsVec3 &pos,const YsColor &ignd,const YsColor &isky, const double &farZ,YSBOOL specular); + void LoadSunAndMoon(void); + void DrawGroundMesh(const YsVec3 &pos,const YsAtt3 &att,const YsColor &ignd,int div,YSBOOL specular); void DrawGroundMesh(const YsVec3& pos, const YsAtt3& att, const YsColor& ignd, int div, YSBOOL specular, YSBOOL useOpenGlGroundTexture); }; diff --git a/src/core/fsguiconfigdlg.cpp b/src/core/fsguiconfigdlg.cpp index 8a0e03de..e3d80073 100644 --- a/src/core/fsguiconfigdlg.cpp +++ b/src/core/fsguiconfigdlg.cpp @@ -97,7 +97,7 @@ void FsGuiConfigDialog::MakeDefaultsDialog(FsWorld *world,FsFlightConfig &cfg) - FsGuiStatic *label; + FsGuiStatic *label, *label2; FsGuiGroupBox *grpBox; @@ -109,12 +109,25 @@ void FsGuiConfigDialog::MakeDefaultsDialog(FsWorld *world,FsFlightConfig &cfg) dayOrNightBtn[0]=AddTextButton(MkId("day") ,FSKEY_NULL,FSGUI_RADIOBUTTON,L"DAY",YSTRUE); dayOrNightBtn[1]=AddTextButton(MkId("night"),FSKEY_NULL,FSGUI_RADIOBUTTON,L"NIGHT",YSFALSE); SetRadioButtonGroup(2,dayOrNightBtn); + + const char *const startTimeStr[] = {"Dawn","Noon","Dusk","Midnight"}; + label2 = AddStaticText(1,FSKEY_NULL,"Start time",16,1,YSTRUE); + startTimeList=AddDropList(MkId("startTime"),FSKEY_NULL,"Start Time",4,startTimeStr,4,32,32,YSTRUE); grpBox=AddGroupBox(); grpBox->AddGuiItem(label); grpBox->AddGuiItem(dayOrNightBtn[0]); grpBox->AddGuiItem(dayOrNightBtn[1]); + grpBox->AddGuiItem(label2); + grpBox->AddGuiItem(startTimeList); + + daylengthNBox = AddTextBox(1,FSKEY_NULL,FSGUI_CFGDLG_DAYLENGTH,"",8,YSTRUE); + daylengthNBox->SetTextType(FSGUI_INTEGER); + + grpBox = AddGroupBox(); + grpBox->AddGuiItem(daylengthNBox); + label=AddStaticText(1,FSKEY_NULL,FSGUI_NEWFLTDLG_WEATHER,16,1,YSTRUE); label->SetFill(YSFALSE); @@ -472,6 +485,35 @@ void FsGuiConfigDialog::InitializeDialog(FsWorld *,FsFlightConfig &cfg) dayOrNightBtn[1]->SetCheck(YSTRUE); break; } + + double dayTime = cfg.dayTime; + // Noon is 0, Dusk is pi*.4, Midnight is pi, Dawn is 3pi/2 + + if (dayTime >= 0 && dayTime < YsPi*.3) + { + startTimeList->Select(1); + } + else if (dayTime >= YsPi*.3 && dayTime < YsPi) + { + startTimeList->Select(2); + } + else if (dayTime >= YsPi && dayTime < 3*YsPi/2) + { + startTimeList->Select(3); + } + else if (dayTime >= 3*YsPi/2 && dayTime < 2*YsPi) + { + startTimeList->Select(0); + } + else + { + startTimeList->Select(0); + } + + printf("dayLength = %d\n", cfg.dayLength); + + daylengthNBox->SetInteger(cfg.dayLength); + double windDirval = YsRadToDeg(-atan2(cfg.constWind.x(), -cfg.constWind.z())); windDir->SetNumber(windDirval); @@ -636,6 +678,28 @@ void FsGuiConfigDialog::RetrieveConfig(FsFlightConfig &cfg) cfg.env=FSNIGHT; } + double dayTime = 0.0; + + switch(startTimeList->GetSelection()) + { + case 0: + dayTime = 3*YsPi/2; + break; + case 1: + dayTime = 0.0; + break; + case 2: + dayTime = YsPi*0.4; + break; + case 3: + dayTime = YsPi; + break; + } + + cfg.dayTime = dayTime; + + cfg.dayLength = YsBound(daylengthNBox->GetInteger(),1,1445); + double windDirVal = windDir->GetNumber()/(180/YsPi); //In rads double windSpdVal = YsUnitConv::KTtoMPS(windSpd->GetNumber()); YsVec3 windVec; diff --git a/src/core/fsguiconfigdlg.h b/src/core/fsguiconfigdlg.h index b54e32db..4d42bb31 100644 --- a/src/core/fsguiconfigdlg.h +++ b/src/core/fsguiconfigdlg.h @@ -17,6 +17,9 @@ class FsGuiConfigDialog : public FsGuiDialog FsGuiButton *okBtn,*cancelBtn,*resetBtn; FsGuiButton *dayOrNightBtn[2]; + FsGuiDropList *startTimeList; + FsGuiTextBox *daylengthNBox; + FsGuiStatic *daylengthText; FsGuiButton *lightSrcBtn[5]; FsGuiNumberBox *windDir; FsGuiNumberBox *windSpd; diff --git a/src/core/fshud2.cpp b/src/core/fshud2.cpp index 17a9ae92..eadde761 100644 --- a/src/core/fshud2.cpp +++ b/src/core/fshud2.cpp @@ -129,6 +129,11 @@ void FsHud2::SetColor(const YsColor &col) this->hudCol=col; } +YsColor FsHud2::GetColor(void) const +{ + return hudCol; +} + void FsHud2::DrawCrossHair(const double &lx,const double &ly,const double ¢erBlank) { const float crsHairVtx[3*8]= diff --git a/src/core/fshud2.h b/src/core/fshud2.h index 1db240a4..813c0ed4 100644 --- a/src/core/fshud2.h +++ b/src/core/fshud2.h @@ -38,6 +38,8 @@ class FsHud2 void SetColor(const YsColor &col); + YsColor GetColor(void) const; + void DrawBank(const double &bank); void DrawHSI( diff --git a/src/core/fsnetwork.cpp b/src/core/fsnetwork.cpp index e1a36b1a..045cf24a 100644 --- a/src/core/fsnetwork.cpp +++ b/src/core/fsnetwork.cpp @@ -47,6 +47,7 @@ typedef int SOCKET; #include #include "fstextresource.h" +#include "fsweather.h" YSBOOL FsVerboseMode=YSFALSE; @@ -465,6 +466,8 @@ void FsNetworkUser::Initialize(void) controlShowUserNameReadBack=YSFALSE; environmentReadBack=YSFALSE; preparationReadBack=YSFALSE; + + usingYSCE=YSFALSE; //Switch to decide whether to send them the new packets, if and when they come. } @@ -1942,17 +1945,9 @@ YSRESULT FsSocketServer::BroadcastFogColor(YsColor col) return BroadcastPacket(7,dat,20040618); } -YSRESULT FsSocketServer::BroadcastForceJoin(void) -{ - unsigned char dat[16]; - FsSetInt(dat,FSNETCMD_SERVER_FORCE_JOIN); - return BroadcastPacket(4,dat,2040618); -} - -YSRESULT FsSocketServer::BroadcastEnvironment(void) -{ +YSRESULT FsSocketServer::BroadcastEnvironmentUpdate(void){ int i; - for (i=0; i= 20150425) { versionCheck=YSOK; } @@ -3770,8 +3771,12 @@ YSRESULT FsSocketServer::ReceiveTextMessage(int clientId,unsigned char dat[],uns } } -YSRESULT FsSocketServer::ReceiveEnvironmentRequest(int clientId,unsigned char [],unsigned ) +YSRESULT FsSocketServer::ReceiveEnvironmentRequest(int clientId,unsigned char dat[],unsigned packetLength ) { + if (packetLength>4){ + //We've got a packet from a YSCE client. + user[clientId].usingYSCE=YSTRUE; + } return SendEnvironment(clientId); } @@ -4203,6 +4208,7 @@ YSRESULT FsSocketServer::SendVersionNotify(int clientId) ptr=dat; FsPushInt(ptr,FSNETCMD_VERSIONNOTIFY); FsPushInt(ptr,YSFLIGHT_NETVERSION); + FsPushInt(ptr,1); //Push a 1, this will let the client know if they're connecting to a YSCE server. return SendPacket(clientId,ptr-dat,dat); } return YSOK; @@ -4274,10 +4280,22 @@ YSRESULT FsSocketServer::SendEnvironment(int clientId) YSBOOL fog; double visibility; unsigned flags; + int cloudLayerCount; + int dayLength; + float dayTime; + int version = 1; + if (user[clientId].usingYSCE == YSTRUE) + { + version = 2; + } + wind=sim->GetWeather().GetWind(); fog=sim->GetWeather().GetFog(); visibility=sim->GetWeather().GetFogVisibility(); + dayLength = sim->GetDayLength(); + dayTime = sim->GetDayTime(); + cloudLayerCount = sim->GetWeather().GetCloudLayerCount(); flags=0; if(fog==YSTRUE) @@ -4344,13 +4362,25 @@ YSRESULT FsSocketServer::SendEnvironment(int clientId) ptr=dat; FsPushInt (ptr,FSNETCMD_ENVIRONMENT); - FsPushShort(ptr,1); // Version 1:Env, Flags, Wind, Visibility + FsPushShort(ptr,version); // Version 1:Env, Flags, Wind, Visibility FsPushShort(ptr,(short)sim->GetEnvironment()); FsPushInt (ptr,flags); FsPushFloat(ptr,(float)wind.x()); FsPushFloat(ptr,(float)wind.y()); FsPushFloat(ptr,(float)wind.z()); FsPushFloat(ptr,(float)visibility); + + if (version==2){ //YSCE version, cloud layers. + FsPushInt(ptr,sim->GetDayLength()); + FsPushFloat(ptr,(float)sim->GetDayTime()); + FsPushInt(ptr,cloudLayerCount); + for (int i = 0; i < cloudLayerCount; i++){ + const FsWeatherCloudLayer* layer; + sim->GetWeather().GetCloudLayer(i,layer); + FsPushInt(ptr, layer->y0); + FsPushInt(ptr, layer->y1); + } + } return SendPacket(clientId,ptr-dat,dat); } @@ -4955,6 +4985,7 @@ FsSocketClient::FsSocketClient(const char username[],const int port,FsSimulation sideWindowAssigned=YSFALSE; reportedServerVersion=0; + ysceServer=YSFALSE; svrUseMissile=YSTRUE; svrUseUnguidedWeapon=YSTRUE; @@ -5090,7 +5121,7 @@ YSRESULT FsSocketClient::Received(YSSIZE_T nBytes,unsigned char dat[]) ReceiveAssignSideWindow(cmdTop); break; case FSNETCMD_VERSIONNOTIFY: - ReceiveVersionNotify(cmdTop); + ReceiveVersionNotify(packetLength,cmdTop); break; case FSNETCMD_AIRCMD: ReceiveAirCmd(cmdTop); @@ -5718,9 +5749,10 @@ YSRESULT FsSocketClient::SendTextMessage(const char txt[]) YSRESULT FsSocketClient::SendEnvironmentRequest(void) { - unsigned char dat[4]; + unsigned char dat[8]; FsSetInt(dat,FSNETCMD_ENVIRONMENT); - return SendPacket(4,dat); + FsSetInt(dat+4,1); //Send a 1 to indicate that this a request from a YSCE client. + return SendPacket(8,dat); } YSRESULT FsSocketClient::SendResendJoinApproval(void) @@ -6417,13 +6449,22 @@ YSRESULT FsSocketClient::ReceiveAssignSideWindow(unsigned char dat[]) return YSOK; } -YSRESULT FsSocketClient::ReceiveVersionNotify(unsigned char dat[]) +YSRESULT FsSocketClient::ReceiveVersionNotify(unsigned int packetLength, unsigned char dat[]) { int svrVersion; + char str[256]; - - svrVersion=FsGetInt(dat+4); - + const unsigned char *ptr=dat; + FsPopInt(ptr); // Skip FSNETCMD_VERSIONNOTIFY + svrVersion=FsPopInt(ptr); + printf("PacketLength is %d\n",packetLength); + if (packetLength>=8){ + int ysceVersion=FsPopInt(ptr); + if (ysceVersion >0){ + ysceServer=YSTRUE; + } + } + AddMessage("Version check"); sprintf(str," SERVER NET-VERSION : %d",svrVersion); AddMessage(str); @@ -6870,7 +6911,10 @@ YSRESULT FsSocketClient::ReceiveEnvironment(int ,unsigned char dat[]) FSENVIRONMENT env; unsigned flags; YSBOOL fog; - double visibility,wx,wy,wz; + int cloudLayers, dayLength; + double visibility,wx,wy,wz, dayTime; + YsArray cloudLayer; + FsPopInt(ptr); version=FsPopShort(ptr); @@ -6882,9 +6926,22 @@ YSRESULT FsSocketClient::ReceiveEnvironment(int ,unsigned char dat[]) wz=FsPopFloat(ptr); visibility=FsPopFloat(ptr); - // if(2<=version) - // { - // } + if(2<=version) + { + dayLength=FsPopInt(ptr); + dayTime = FsPopFloat(ptr); + + sim->SetDayLength(dayLength); + sim->SetDayTime(dayTime); + cloudLayers=FsPopInt(ptr); + + for (int i=0;i < cloudLayers; i++){ + FsWeatherCloudLayer layer; + layer.Overcast(FsPopInt(ptr),FsPopInt(ptr)); + cloudLayer.Append(layer); + } + sim->GetWeather().SetCloudLayer(cloudLayers,cloudLayer); + } if(env!=sim->GetEnvironment()) // This check has been added 2015/04/17 { @@ -7510,8 +7567,6 @@ FSNET_CONSOLE_COMMAND FsTranslateKeyToServerCommand(int ky) return FSNCC_SVR_STARTENDURANCEMODE_WW2; case FSKEY_P: return FSNCC_SVR_STARTCLOSEAIRSUPPORTMISSION; - case FSKEY_N: - return FSNCC_SVR_SETDAY; case FSKEY_T: return FSNCC_SVR_TERMINATEMISSION; case FSKEY_R: @@ -7878,8 +7933,6 @@ class FsGuiServerDialog : public FsGuiDialog FsGuiButton *whoKilledMeBtn,*whomHaveIKilledBtn; - FsGuiButton *setDayBtn; - FsGuiStatic *multiIpWarningTxt; FsGuiButton *endServerBtn,*confirmEndServerBtn; @@ -7973,8 +8026,6 @@ void FsGuiServerDialog::MakeDialog(FsSimulation *sim,FsSocketServer *server) startInterceptMissionBtn=AddTextButton(0,FSKEY_NULL,FSGUI_PUSHBUTTON,FSGUI_NETCONSOLE_INTERCEPT,YSTRUE); startCloseAirSupportBtn=AddTextButton(0,FSKEY_NULL,FSGUI_PUSHBUTTON,FSGUI_NETCONSOLE_CLOSEAIRSUPPORT,YSFALSE); - setDayBtn=AddTextButton(0,FSKEY_NULL,FSGUI_PUSHBUTTON,FSGUI_NETCONSOLE_SETENVIRONMENT,YSTRUE); - multiIpWarningTxt=AddStaticText(0,FSKEY_NULL,"",16,2,YSTRUE); endServerBtn=AddTextButton(0,FSKEY_NULL,FSGUI_PUSHBUTTON,FSGUI_NETCONSOLE_ENDSERVER,YSTRUE); @@ -8091,9 +8142,6 @@ void FsGuiServerDialog::OnButtonClick(FsGuiButton *btn) { svr->commandQueue.push(FSNCC_SVR_STARTCLOSEAIRSUPPORTMISSION); } - else if(btn==setDayBtn){ - svr->commandQueue.push(FSNCC_SVR_SETDAY); - } else if(btn==endServerBtn) { confirmEndServerBtn->Enable(); @@ -8269,7 +8317,7 @@ static void FsPrintServerMenu( fsConsole.Printf("[C]...Lock Server [K]...Join-Lock"); fsConsole.Printf("[1][2][3][4]...Choose IFF [V].....Observer mode"); fsConsole.Printf("[E]...Start Endurance Mode (Jet) [W].....Start Endurance Mode (WwII)"); - fsConsole.Printf("[B].....Start Intercept Mission [N].....Toggle Day/Night"); + fsConsole.Printf("[B].....Start Intercept Mission"); fsConsole.Printf("[P]...Start Close Air Support Mission"); fsConsole.Printf("[T]...Terminate Endurance Mode/Intercept Mission"); fsConsole.Printf("[R]...Revive Ground Objects"); @@ -8283,7 +8331,7 @@ static void FsPrintServerMenu( fsConsole.Printf("[L]...List Players [D]...Dispell User"); fsConsole.Printf("[C]...Lock Server [K]...Join-Lock"); fsConsole.Printf("[E]...Start Endurance Mode (Jet) [W].....Start Endurance Mode (WwII)"); - fsConsole.Printf("[B].....Start Intercept Mission [N].....Toggle Day/Night"); + fsConsole.Printf("[B].....Start Intercept Mission"); fsConsole.Printf("[P]...Start Close Air Support Mission"); fsConsole.Printf("[T]...Terminate Endurance Mode/Intercept Mission"); fsConsole.Printf("[R]...Revive Ground Objects"); @@ -8689,19 +8737,6 @@ YSRESULT FsSimulation::ServerState_StandBy( DestroyAutoGeneratedAirAndGnd(); - break; - case FSNCC_SVR_SETDAY: - FSENVIRONMENT env; - env = GetEnvironment(); - switch(env){ - case FSDAYLIGHT: - SetEnvironment(FSNIGHT); - break; - case FSNIGHT: - SetEnvironment(FSDAYLIGHT); - break; - } - svr.BroadcastEnvironment(); break; case FSNCC_SVR_REVIVEGROUND: ReviveGround(); @@ -10729,5 +10764,4 @@ FsServerRunLoop::~FsServerRunLoop() delete chooseStartPosition; delete opt; delete svrDlg; -} - +} \ No newline at end of file diff --git a/src/core/fsnetwork.h b/src/core/fsnetwork.h index aad01dac..5dcb9589 100644 --- a/src/core/fsnetwork.h +++ b/src/core/fsnetwork.h @@ -187,6 +187,7 @@ class FsNetworkUser YsArray gndToSend,airToSend; YSBOOL useMissileReadBack,useUnguidedWeaponReadBack,controlShowUserNameReadBack; YSBOOL environmentReadBack,preparationReadBack; + YSBOOL usingYSCE; YsArray gndRmvToSend,airRmvToSend; int joinSequence; // 0:Not in process 1:Waiting for Airplane Read Back 2:Waiting for SetPlayer Read Back @@ -253,7 +254,6 @@ enum FSNET_CONSOLE_COMMAND FSNCC_SVR_STARTENDURANCEMODE_JET, FSNCC_SVR_STARTENDURANCEMODE_WW2, FSNCC_SVR_STARTCLOSEAIRSUPPORTMISSION, - FSNCC_SVR_SETDAY, FSNCC_SVR_TERMINATEMISSION, FSNCC_SVR_REVIVEGROUND, @@ -380,8 +380,8 @@ class FsSocketServer : public YsSocketServer, public FsServerVariable YSRESULT BroadcastSkyColor(YsColor col); YSRESULT BroadcastGroundColor(YsColor col); YSRESULT BroadcastFogColor(YsColor col); + YSRESULT BroadcastEnvironmentUpdate(void); YSRESULT BroadcastForceJoin(void); - YSRESULT BroadcastEnvironment(void); YSRESULT RectifyIllegalMissiles(void); @@ -535,6 +535,7 @@ class FsSocketClient : public YsSocketClient, public FsClientVariable YSBOOL connectionClosedByServer; // Will be set YSTRUE if the connection was closed from the server side. int lastErrorFromServer; unsigned int reportedServerVersion; + YSBOOL ysceServer; FsSocketClient(const char username[],const int port,class FsSimulation *associatedSimulation,class FsNetConfig *cfg); @@ -610,7 +611,7 @@ class FsSocketClient : public YsSocketClient, public FsClientVariable YSRESULT ReceiveGetDamage(unsigned char dat[]); YSRESULT ReceiveSetTestAutopilot(unsigned char dat[]); YSRESULT ReceiveAssignSideWindow(unsigned char dat[]); - YSRESULT ReceiveVersionNotify(unsigned char dat[]); + YSRESULT ReceiveVersionNotify(unsigned int packetLength,unsigned char dat[]); YSRESULT ReceiveAirCmd(unsigned char dat[]); YSRESULT ReceiveGndCmd(unsigned char dat[]); YSRESULT ReceiveTextMessage(unsigned char dat[]); @@ -787,4 +788,4 @@ class FsServerRunLoop }; /* } */ -#endif +#endif \ No newline at end of file diff --git a/src/core/fsradar.cpp b/src/core/fsradar.cpp index 6ea170f2..a5c8b7a2 100644 --- a/src/core/fsradar.cpp +++ b/src/core/fsradar.cpp @@ -115,7 +115,7 @@ void FsHorizontalRadar::DrawBasic( //draw radar bounding box FsDrawRect(x1,y1,x2,y2,YsGreen(),YSFALSE); - + printf("x1,y1,x2,y2: %d,%d,%d,%d\n", x1, y1, x2, y2); //draw radar range string char str[256]; sprintf(str,"%d NM",int(rangeInX)); diff --git a/src/core/fssimulation.cpp b/src/core/fssimulation.cpp index ee7a36b1..49d968b8 100644 --- a/src/core/fssimulation.cpp +++ b/src/core/fssimulation.cpp @@ -173,6 +173,9 @@ FsSimulation::FsSimulation(FsWorld *w) : airplaneList(FsAirplaneAllocator),groun currentTime=0.0; aircraftTroubleTimer=0.0; lastTime=0; + dayTime = 0; + dayLength = 0; + lightPositionVector = YsVec3(-1.0, 1, 0.0); mainWindowViewmode=FSCOCKPITVIEW; mainWindowAdditionalAirplaneViewId=0; mainWindowActualViewMode.viewPoint=YsOrigin(); @@ -234,6 +237,7 @@ FsSimulation::FsSimulation(FsWorld *w) : airplaneList(FsAirplaneAllocator),groun subMenu.CleanUp(); env=FSDAYLIGHT; + lastEnv = FSDAYLIGHT; airplaneSearch=new YsHashTable (128); groundSearch=new YsHashTable (128); @@ -1480,22 +1484,43 @@ void FsSimulation::EnforceEnvironment(void) { case FSDAYLIGHT: field.ApplyColorScale(1.0,1.0,0.7); - fogColor.SetDoubleRGB(0.6,0.6,0.6); YsScenery::lightPointSizePix=1; break; case FSNIGHT: field.ApplyColorScale(0.1,0.1,1.0); - fogColor.SetDoubleRGB(0.1,0.1,0.1); YsScenery::lightPointSizePix=4; break; } } +void FsSimulation::SendServerEnvironment(FSENVIRONMENT env){ + if (netServer != NULL){ + netServer->BroadcastEnvironmentUpdate(); + } + +} FSENVIRONMENT FsSimulation::GetEnvironment(void) const { return env; } +//Implement the following functions: +int FsSimulation::GetDayLength(void) const{ + return dayLength / 60; //Convert to minutes +} + +double FsSimulation::GetDayTime(void) const{ + return dayTime; +} + +void FsSimulation::SetDayLength(int dayLength){ + this->dayLength = dayLength*60; //Convert to seconds +} + +void FsSimulation::SetDayTime(double dayTime){ + this->dayTime = dayTime; +} + YSRESULT FsSimulation::SendConfigString(const char str[]) { return cfgPtr->SendCommand(str); @@ -2309,7 +2334,7 @@ void FsSimulation::PrepareRunSimulation(void) { if(solidCloud->IsReady()!=YSTRUE) { - solidCloud->Make(12,cloudCenter,30000.0,6000.0,cfgPtr->ceiling-400.0,cfgPtr->ceiling+400.0); + solidCloud->Make(20,cloudCenter,30000.0,6000.0,cfgPtr->ceiling-400.0,cfgPtr->ceiling+400.0); } } } @@ -3878,7 +3903,22 @@ void FsSimulation::SimMove(const double &dt) particleStore.Move(dt,weather->GetWind()); weather->WeatherTransition(dt); - + //Cloud movement if we bring that in, goes here! + solidCloud->Move(dt,weather->GetWind()); + + env = weather->GetDayTime(dayTime,dt,dayLength); + // If the environment has changed, ensure it is forwarded to the server. + if (env != lastEnv){ + SetEnvironment(env); + lastEnv = env; + SendServerEnvironment(env); + } + weather->GetDayTimeHours(dayTime); + + lightColour = weather->GetLightColour(dayTime); + lightIntensity = weather->GetLightIntensity(dayTime); + weather->SetSunPosition(lightPositionVector,dayTime); + fogColor.SetDoubleRGB(0.6*lightIntensity*lightColour.Rd(),0.6*lightIntensity * lightColour.Gd(), 0.6*lightIntensity * lightColour.Bd()); airplane=NULL; while((airplane=FindNextAirplane(airplane))!=NULL) { @@ -4625,7 +4665,7 @@ void FsSimulation::SimControlByUser(const double &dt,FSUSERCONTROL userControl) { // Skip all mouse-move events. } - + auto inFltDlg=GetCurrentInFlightDialog(); if(NULL!=inFltDlg) @@ -6400,7 +6440,7 @@ void FsSimulation::SimDrawScreen( particleStore.AddToParticleManager(partMan); if(YSTRUE==cfgPtr->useParticle) { - solidCloud->AddToParticleManager(partMan,env,*weather,actualViewMode.viewAttitude.GetForwardVector(),actualViewMode.viewMat,prj.nearz,prj.farz,prj.tanFov); + solidCloud->AddToParticleManager(partMan,lightIntensity,*weather,actualViewMode.viewAttitude.GetForwardVector(),actualViewMode.viewMat,prj.nearz,prj.farz,prj.tanFov,actualViewMode.viewPoint); bulletHolder.AddToParticleManager(partMan,currentTime); for(FsAirplane *seeker=nullptr; nullptr!=(seeker=FindNextAirplane(seeker)); ) @@ -6723,15 +6763,7 @@ void FsSimulation::SimDrawScreenZBufferSensitive( #endif YsColor fogColor; - switch(env) - { - case FSDAYLIGHT: - fogColor.SetDoubleRGB(0.6,0.6,0.6); - break; - case FSNIGHT: - fogColor.SetDoubleRGB(0.1,0.1,0.1); - break; - } + fogColor.SetDoubleRGB(0.6*lightIntensity*lightColour.Rd(),0.6*lightIntensity * lightColour.Gd(), 0.6*lightIntensity * lightColour.Bd()); #ifdef CRASHINVESTIGATION_SIMDRAWSCREENZBUFFERSENSITIVE printf("SimDrawScreenZBufferSensitive %d\n",__LINE__); @@ -6803,7 +6835,7 @@ void FsSimulation::SimDrawScreenZBufferSensitive( if(YSTRUE!=cfgPtr->useParticle) { - solidCloud->Draw(env,*weather,actualViewMode.viewMat,proj.nearz,proj.farz,proj.tanFov); + solidCloud->Draw(env,*weather,actualViewMode.viewMat,proj.nearz,proj.farz,proj.tanFov,proj.GetMatrix()); } #ifdef CRASHINVESTIGATION_SIMDRAWSCREENZBUFFERSENSITIVE @@ -6901,7 +6933,8 @@ FsProjection FsSimulation::SimDrawPrepare(const ActualViewMode &actualViewMode) printf("SIMDRAW-2.6\n"); #endif - FsSetDirectionalLight(actualViewMode.viewPoint,cfgPtr->lightSourceDirection,env); + + FsSetDirectionalLight(actualViewMode.viewPoint,lightPositionVector,FSDAYLIGHT,lightColour,lightIntensity); sizx=hei*4/3; sizy=hei; @@ -6993,25 +7026,21 @@ void FsSimulation::SimDrawBackground(const ActualViewMode &actualViewMode,const { auto gnd=gndColor; auto sky=skyColor; + sky = weather->GetLightColour(sky, dayTime); YSBOOL gndSpecular=this->gndSpecular; YsColor horizonColor; - switch(env) - { - case FSNIGHT: - gnd.SetDoubleRGB(gnd.Rd()*0.1,gnd.Gd()*0.1,gnd.Bd()*0.1); - sky.SetDoubleRGB(sky.Rd()*0.1,sky.Gd()*0.1,sky.Bd()*0.1); - horizonColor=YsGrayScale(0.1); - gndSpecular=YSFALSE; - break; - case FSDAYLIGHT: - horizonColor.SetDoubleRGB(0.7,0.7,0.7); - break; + gnd.SetDoubleRGB(gnd.Rd()*lightIntensity,gnd.Gd()*lightIntensity,gnd.Bd()*lightIntensity); + sky.SetDoubleRGB(sky.Rd()*lightIntensity,sky.Gd()*lightIntensity,sky.Bd()*lightIntensity); + horizonColor=YsGrayScale(lightIntensity); + if (env == FSNIGHT){ + gndSpecular = YSFALSE; } + if(weather->GetFog()==YSTRUE) { - groundSky->DrawByFog(actualViewMode.viewPoint,actualViewMode.viewAttitude,gnd,sky,horizonColor,farZ,gndSpecular); + groundSky->DrawByFog(actualViewMode.viewPoint,actualViewMode.viewAttitude,gnd,sky,horizonColor,farZ,gndSpecular, lightPositionVector, lightColour); } else if(cfgPtr->horizonGradation==YSTRUE) { @@ -7055,17 +7084,17 @@ void FsSimulation::SimDrawBackground(const ActualViewMode &actualViewMode,const void FsSimulation::SimDrawMap(const ActualViewMode &actualViewMode,const FsProjection &proj,const double &elvMin,const double &elvMax) const { // >>>> Map and shadow - YSBOOL drawPset=YSFALSE; - if(FSDAYLIGHT!=GetEnvironment()) - { - drawPset=YSTRUE; - } - else if(FSDAYLIGHT==GetEnvironment() && - cfgPtr->drawLightsInDaylight==YSTRUE && - weather->GetFogVisibility()drawLightsInDaylightVisibilityThr) - { - drawPset=YSTRUE; - } + YSBOOL drawPset=YSTRUE; + // if(FSDAYLIGHT!=GetEnvironment()) + // { + // drawPset=YSTRUE; + // } + // else if(FSDAYLIGHT==GetEnvironment() && + // cfgPtr->drawLightsInDaylight==YSTRUE && + // weather->GetFogVisibility()drawLightsInDaylightVisibilityThr) + // { + // drawPset=YSTRUE; + // } YsScenery::numSceneryDrawn=0; field.CacheMapDrawingOrder(); @@ -7271,10 +7300,8 @@ void FsSimulation::SimDrawField(const ActualViewMode &actualViewMode,const class { field.DrawVisual(actualViewMode.viewPoint,actualViewMode.viewAttitude,proj.GetMatrix(),YSFALSE, cfgPtr->useOpenGlGroundTexture); // forShadowMap=YSFALSE - if(cfgPtr->drawCloud==YSTRUE && env!=FSNIGHT) - { - cloud->Draw(); - } + cloud->Draw(); + } void FsSimulation::SimDrawShadow(const ActualViewMode &actualViewMode,const class FsProjection &proj) const // For OpenGL/Direct3D, not for BlueImpulseSDK @@ -8024,19 +8051,24 @@ void FsSimulation::SimDrawRadar(const ActualViewMode &actualViewMode) const double radarRange; radarRange=playerPlane->Prop().GetCurrentRadarRange(); + int wid,hei; + FsGetWindowSize(wid,hei); - if(YsEqual(radarRange,0.0)!=YSTRUE) - { - int wid,hei; - FsGetWindowSize(wid,hei); - - long radarSize = wid / 5; + long radarSize = wid / 5; - long x1 = wid - radarSize - 10; - long y1 = 10; - long x2 = wid - 10; - long y2 = 10 + radarSize; + long x1 = wid - radarSize - 10; + long y1 = 10; + long x2 = wid - 10; + long y2 = 10 + radarSize; + YsString timeString; + YsArray timeArray; + timeArray = weather->GetDayTimeHours(dayTime); + timeString.Printf("Clock: %02d:%02d", timeArray[0], timeArray[1]); + if(YsEqual(radarRange,0.0)!=YSTRUE) + { + + FsDrawString(x1,y2+16,timeString, hud2->GetColor()); switch(playerPlane->Prop().GetWeaponOfChoice()) { default: @@ -8086,6 +8118,10 @@ void FsSimulation::SimDrawRadar(const ActualViewMode &actualViewMode) const break; } } + else{ + //Radar is off. Draw the clock at the top: + FsDrawString(wid*.9,y1+16, timeString, hud2->GetColor()); + } } if(NULL!=GetPlayerGround()) @@ -8331,10 +8367,10 @@ void FsSimulation::SimDrawHud3d(const YsVec3 &fakeViewPos,const YsAtt3 &instView double radarRange = playerPlane->Prop().GetCurrentRadarRange(); if (YsEqual(radarRange, 0.0) != YSTRUE && cfgPtr->drawRWR == YSTRUE) - { - hud2->DrawRWRHUD(this, GetPlayerAirplane(), cfgPtr->radarAltitudeLimit, radarRange * 1852, 0.0, 0.0, 0.4); + { + hud2->DrawRWRHUD(this, GetPlayerAirplane(), cfgPtr->radarAltitudeLimit, radarRange * 1852, 0.0, 0.0, 0.4); + } } - } //draw HUD warnings if (playerPlane != NULL && playerPlane->Prop().IsActive()) @@ -10053,7 +10089,7 @@ void FsSimulation::SimDecideViewpointAndCheckIsInCloud(ActualViewMode &actualVie const auto cameraEv=actualViewMode.viewAttitude.GetForwardVector(); const auto cameraUv=actualViewMode.viewAttitude.GetUpVector(); - const YsVec3 lightEv=-YsUnitVector(cfgPtr->lightSourceDirection); + const YsVec3 lightEv=-YsUnitVector(lightPositionVector); const double cameraEvSimilarity=fabs(lightEv*cameraEv); const double cameraUvSimilarity=fabs(lightEv*cameraUv); const YsVec3 lightUv=(cameraEvSimilaritylightSourceDirection); + const YsVec3 lightEv=-YsUnitVector(lightPositionVector); const double cosTheata=cameraEv*lightEv; const double sinTheata=sqrt(1.0-YsSmaller(1.0,cosTheata*cosTheata)); @@ -12495,7 +12531,7 @@ YSRESULT FsSimulation::LoadConfigFile(const wchar_t fn[],YSBOOL changeEnvironmen if(changeEnvironment==YSTRUE) { - env=cfgPtr->env; + //env=cfgPtr->env; weather->SetFog(cfgPtr->drawFog); weather->SetFogVisibility(cfgPtr->fogVisibility); for(int i=0; icloudLayer.GetN(); i++) @@ -12504,6 +12540,9 @@ YSRESULT FsSimulation::LoadConfigFile(const wchar_t fn[],YSBOOL changeEnvironmen } weather->SetWind(cfgPtr->constWind); + SetDayTime(cfgPtr->dayTime); + SetDayLength(cfgPtr->dayLength); + } return r; diff --git a/src/core/fssimulation.h b/src/core/fssimulation.h index 4abf4524..e4b25cfc 100644 --- a/src/core/fssimulation.h +++ b/src/core/fssimulation.h @@ -289,9 +289,20 @@ class FsSimulation : public FsHasInFlightDialog FSENVIRONMENT env; YsColor fogColor; - YsColor skyColor,gndColor; + YsColor skyColor,gndColor; //These are the original sky/ground colours, set by the field. We won't modify them too much. YSBOOL gndSpecular; + YsVec3 lightPositionVector = YsVec3(-1.0, 1, 0.0); + YsColor dayColour = YsColor(1,1,1); + YsColor sunColour = YsColor(1,1,1); + YsColor nightColour = YsColor(0.1,0.1,0.1); + YsColor sunriseColour = YsColor(1,0.5,0); + mutable int dayLength = 60; + mutable double dayTime = YsPi; + mutable double lightIntensity = 1; + mutable YsColor lightColour = YsColor(1,1,1); + FSENVIRONMENT lastEnv; + class ActualViewMode { public: @@ -476,7 +487,13 @@ class FsSimulation : public FsHasInFlightDialog void SetEnvironment(FSENVIRONMENT env); void EnforceEnvironment(void); + void SendServerEnvironment(FSENVIRONMENT env); FSENVIRONMENT GetEnvironment(void) const; + int GetDayLength(void) const; + double GetDayTime(void) const; + void SetDayLength(int dayLength); + void SetDayTime(double dayTime); + YSRESULT SendConfigString(const char str[]); diff --git a/src/core/fssimulationfileio.cpp b/src/core/fssimulationfileio.cpp index f6d3d174..2e51707e 100644 --- a/src/core/fssimulationfileio.cpp +++ b/src/core/fssimulationfileio.cpp @@ -83,6 +83,8 @@ YSRESULT FsSimulation::Save( fprintf(fp,"ENVIRONM NIGHT\n"); } + fprintf(fp,"DAYLENG %d\n",GetDayLength()); + fprintf(fp,"DAYTIME %lf\n",dayTime); fprintf(fp,"ALLOWGUN %s\n",((allowedWeaponType & FSWEAPON_ALLOWGUN) ? "TRUE" : "FALSE")); fprintf(fp,"ALLOWAAM %s\n",((allowedWeaponType & FSWEAPON_ALLOWAAM) ? "TRUE" : "FALSE")); fprintf(fp,"ALLOWAGM %s\n",((allowedWeaponType & FSWEAPON_ALLOWAGM) ? "TRUE" : "FALSE")); diff --git a/src/core/fsweather.cpp b/src/core/fsweather.cpp index f89c9af2..d7e40f08 100644 --- a/src/core/fsweather.cpp +++ b/src/core/fsweather.cpp @@ -6,6 +6,7 @@ #include #include + #include #include "fs.h" @@ -35,6 +36,13 @@ int FsWeatherCloudLayer::CloudLayerTypeFromString(const char str[]) return FSCLOUDLAYER_NONE; } +FsWeatherCloudLayer FsWeatherCloudLayer::Overcast(double y0,double y1) +{ + this->y0=y0; + this->y1=y1; + this->cloudLayerType=FSCLOUDLAYER_OVERCAST; + return *this; +} @@ -175,6 +183,144 @@ YSBOOL FsWeather::IsInCloudLayer(const YsVec3 &pos) const return YSFALSE; } +int FsWeather::GetCloudLayerCount() const +{ + return (int)cloudLayer.GetN(); +} +//Day/Night cycle functions + + +YsColor FsWeather::GetLightColour(const double dayTime) const{ + YsColor lightColour = daylightColour; + if (IsDuskOrDawn(dayTime) == YSTRUE) + { + //Which colour are we transitioning from? Day or night? + if (IsDay(dayTime) == YSTRUE){ + lightColour = daylightColour; + } + else{ + lightColour = nightColour; + } + //If it's dusk or dawn, then we need to fade the colour. + lightColour.SetRd(ColourInterpolate(lightColour.Rd(),dawnColour.Rd(),DuskIntensity(dayTime))); + lightColour.SetGd(ColourInterpolate(lightColour.Gd(),dawnColour.Gd(),DuskIntensity(dayTime))); + lightColour.SetBd(ColourInterpolate(lightColour.Bd(),dawnColour.Bd(),DuskIntensity(dayTime))); + } + else if (IsDay(dayTime) == YSFALSE){ + lightColour = nightColour; + } + + return lightColour; +}; + +YsColor FsWeather::GetLightColour(YsColor skyColour, const double dayTime) const{ + YsColor lightColour = skyColour; + if (IsDuskOrDawn(dayTime) == YSTRUE){ + //If it's dusk or dawn, then we need to fade the colour. + lightColour.SetRd(ColourInterpolate(skyColour.Rd(),dawnColour.Rd(),DuskIntensity(dayTime))); + lightColour.SetGd(ColourInterpolate(skyColour.Gd(),dawnColour.Gd(),DuskIntensity(dayTime))); + lightColour.SetBd(ColourInterpolate(skyColour.Bd(),dawnColour.Bd(),DuskIntensity(dayTime))); + + } + + return lightColour; + +}; + +double FsWeather::GetLightIntensity(const double dayTime) const{ + double lightIntensity = 1.0; + lightIntensity = sin(dayTime+YsPi/2); + if (lightIntensity<=0.1){ + lightIntensity = 0.1; + } + // if (IsDuskOrDawn(dayTime) == YSTRUE){ //Then it's dusk/dawn + // lightIntensity = DuskIntensity(dayTime); + // } + // if (IsDay(dayTime) == YSFALSE){ + // lightIntensity = 0.1; + // } + return lightIntensity; +}; + +double FsWeather::ColourInterpolate(const double colour2, const double colour1, const double i) const { + return colour1 + (colour2 - colour1) * i; +}; + +YSBOOL FsWeather::IsDay(const double dayTime) const{ + if (dayTime < YsPi/2 || dayTime > 3*YsPi/2){ + return YSTRUE; + } + else{ + return YSFALSE; + } +}; + +YSBOOL FsWeather::IsDuskOrDawn(const double dayTime) const{ + if (sin(dayTime+YsPi/2)<0.2 && sin(dayTime+YsPi/2)>-0.2){ + return YSTRUE; + } + else{ + return YSFALSE; + } + +}; + +double FsWeather::DuskIntensity(const double dayTime) const{ + //Scale the dusk intensity. Dusk is between sin(dayTime+YsPi/2) = 0.2 and -0.2. + double lightIntensity = abs(sin(dayTime+YsPi/2))*5; + if (lightIntensity<=0.1){ + lightIntensity = 0.1; + } + return lightIntensity; + +}; + +//Increments the dayTime by deltaTime (in seconds) and the dayLength (in seconds) +//Returns the dayTime - which is the time of day * 2*PI. +// 0 is mid day, PI is midnight, 2*PI is mid day again. +FSENVIRONMENT FsWeather::GetDayTime(double& daytime, double dt, int dayLength) const{ + int totalSteps = dayLength/dt; + double step = 2 * YsPi / totalSteps; + daytime = daytime + step; + if (daytime > 2 * YsPi){ + daytime = 0; + } + if (IsDay(daytime) == YSTRUE){ + return FSDAYLIGHT; + } + else{ + return FSNIGHT; + } +}; + +void FsWeather::SetSunPosition(YsVec3& lightPosition, double dayTime) const{ + // if (IsDay(dayTime) == YSTRUE){ + lightPosition.SetX(cos(dayTime+YsPi/2)); + lightPosition.SetY((sin(dayTime+YsPi/2))); +}; + +YsArray FsWeather::GetDayTimeHours(double dayTime) const{ + if (dayTime >= YsPi){ + dayTime = dayTime - YsPi; + } + else{ + dayTime = dayTime + YsPi; + } + int hours = (int)(dayTime/(2*YsPi)*24); + int minutes = (int)((dayTime/(2*YsPi)*24 - hours)*60); + int seconds = (int)((((dayTime/(2*YsPi)*24 - hours)*60) - minutes)*60); + YsArray time; + time.Append(hours); + time.Append(minutes); + time.Append(seconds); + return time; +}; + + + + +//Save cloud functions - to review whether these continue to be used with new clouds in future. + YSRESULT FsWeather::Save(FILE *fp) const { fprintf(fp,"WEATHERX\n"); diff --git a/src/core/fsweather.h b/src/core/fsweather.h index 3308354b..66a789bd 100644 --- a/src/core/fsweather.h +++ b/src/core/fsweather.h @@ -15,6 +15,7 @@ class FsWeatherCloudLayer static const char *CloudLayerTypeString(int cloudLayerType); static int CloudLayerTypeFromString(const char str[]); + FsWeatherCloudLayer Overcast(double y0,double y1); // Returns an overcast }; @@ -31,6 +32,10 @@ class FsWeather YsArray cloudLayer; + YsColor daylightColour = YsColor(1.0,1.0,1.0); //Because it is spelled colour. Not color... uncultured swines. + YsColor nightColour = YsColor(0.1,0.1,0.3); + YsColor dawnColour = YsColor(1,0.5,0.0); + public: FsWeather(); ~FsWeather(); @@ -52,12 +57,27 @@ class FsWeather void SetCloudLayer(YSSIZE_T nLayer,const FsWeatherCloudLayer layer[]); void AddCloudLayer(const FsWeatherCloudLayer &layer); void GetCloudLayer(int &nLayer,const FsWeatherCloudLayer *&layer) const; + int GetCloudLayerCount() const; YSBOOL IsInCloudLayer(const YsVec3 &pos) const; YSRESULT Save(FILE *fp) const; YSRESULT Load(FILE *fp); void DrawCloudLayer(const YsVec3 &cameraPos) const; + + //Day/Night cycle functions + + YsColor GetLightColour(const double dayTime) const; + YsColor GetLightColour(YsColor skyColour, const double dayTime) const; + double GetLightIntensity(const double dayTime) const; + double ColourInterpolate(const double colour1, const double colour2, const double i) const; + YSBOOL IsDay(const double dayTime) const; + YSBOOL IsDuskOrDawn(const double dayTime) const; + double DuskIntensity(const double dayTime) const; + FSENVIRONMENT GetDayTime(double& daytime, double dt, int dayLength) const; + void SetSunPosition(YsVec3& lightPosition, double dayTime) const; + YsArray GetDayTimeHours(double dayTime) const; + }; diff --git a/src/core/fsworld.cpp b/src/core/fsworld.cpp index 0fb5071e..92b1f43e 100644 --- a/src/core/fsworld.cpp +++ b/src/core/fsworld.cpp @@ -998,6 +998,9 @@ static const char *const ysflightCommand[]= // Added 2017/12/17 "EXTENSIO", + //Added 2023/09/03 + "DAYLENG", + "DAYTIME", NULL }; @@ -1979,6 +1982,16 @@ YSRESULT FsWorld::LoadInternal(const wchar_t fn[],const YsVec3 &fieldPos,const Y } } break; + case 53: // "DAYLENG" + int dayLength; + dayLength = atoi(args[1]); + sim->SetDayLength(dayLength); + break; + case 54: // "DAYTIME" + double dayTime; + dayTime = atof(args[1]); + sim->SetDayTime(dayTime); + break; default: fsStderr.Printf("Unrecognized:%s\n",readBuf.Txt()); @@ -3889,6 +3902,26 @@ FSENVIRONMENT FsWorld::GetEnvironment(void) return FSDAYLIGHT; } +YSRESULT FsWorld::SetDayTime(double t) +{ + if(NULL!=sim) + { + sim->SetDayTime(t); + return YSERR; + } + return YSOK; +} + +YSRESULT FsWorld::SetDayLength(int dayLength) +{ + if(NULL!=sim) + { + sim->SetDayLength(dayLength); + return YSERR; + } + return YSOK; +} + FsAirplane *FsWorld::AddAirplane(const char idName[],YSBOOL isPlayerPlane,unsigned netSearchKey) { if(NULL!=sim) diff --git a/src/core/fsworld.h b/src/core/fsworld.h index dad4addb..1c28895b 100644 --- a/src/core/fsworld.h +++ b/src/core/fsworld.h @@ -364,6 +364,8 @@ class FsWorld YSRESULT DisableGroundFire(void); YSRESULT SetEnvironment(FSENVIRONMENT env); FSENVIRONMENT GetEnvironment(void); + YSRESULT SetDayTime(double time); + YSRESULT SetDayLength(int dayLength); FsAirplane *AddAirplane(const char idName[],YSBOOL isPlayerPlane,unsigned netSearchKey=0); FsAirplane *ResetAirplane(FsAirplane *air); FsAirplane *AddMatchingAirplane( diff --git a/src/core/sun.cpp b/src/core/sun.cpp new file mode 100644 index 00000000..035349f3 --- /dev/null +++ b/src/core/sun.cpp @@ -0,0 +1,68 @@ +static const int sunnVtx=9; +static const int sunPlg = 8; +static double sunvtx[] = { +0.000,0.000,0.000, +0.000,0.000,2.280, +-1.612,0.000,1.612, +-2.280,0.000,-0.000, +-1.612,0.000,-1.612, +0.000,0.000,-2.280, +1.612,0.000,-1.612, +2.280,0.000,0.000, +1.612,0.000,1.612}; + +static int sunidx[] = { + 0, 2, 1, + 0, 3, 2, + 0, 4, 3, + 0, 5, 4, + 0, 6, 5, + 0, 7, 6, + 0, 8, 7, + 0, 1, 8 + }; + +static double sunnorm[]={ + -0.537,0.000,1.297, + -1.297,0.000,0.537, + -1.297,0.000,-0.537, + -0.537,0.000,-1.297, + 0.537,0.000,-1.297, + 1.297,0.000,-0.537, + 1.297,0.000,0.537, + 0.537,0.000,1.297 + +}; + +YsArray vtHdList; +YsShellExt shell; +YsShellPolygonHandle plHd; +YsShellVertexHandle vtHd; + +for(int i=0; id3dDev->SetLight(0,&light); + ysD3dDev->d3dDev->LightEnable(0,TRUE); + ysD3dDev->d3dDev->SetRenderState(D3DRS_LIGHTING,TRUE); + } +} + void FsFogOn(const YsColor &col,const double &visibility) { auto ysD3dDev=YsD3dDevice::GetCurrent(); diff --git a/src/graphics/gl/fsgroundskygl.cpp b/src/graphics/gl/fsgroundskygl.cpp index 9e80d4f2..e7be5a7a 100644 --- a/src/graphics/gl/fsgroundskygl.cpp +++ b/src/graphics/gl/fsgroundskygl.cpp @@ -63,7 +63,7 @@ FsGroundSky::~FsGroundSky() void FsGroundSky::DrawByFog (const YsVec3 &pos,const YsAtt3 &viewAtt,const YsColor &ignd,const YsColor &isky,const YsColor &horizon, - const double &farZ,YSBOOL specular) + const double &farZ,YSBOOL specular, YsVec3 sunPos, YsColor sunColor) { int i; YsAtt3 att; diff --git a/src/graphics/gl/fsopengl.cpp b/src/graphics/gl/fsopengl.cpp index d7130005..543e1707 100644 --- a/src/graphics/gl/fsopengl.cpp +++ b/src/graphics/gl/fsopengl.cpp @@ -367,6 +367,48 @@ void FsSetDirectionalLight(const YsVec3 &cameraPosition,const YsVec3 &lightDirec FsResetMaterial(); } +void FsSetDirectionalLight(const YsVec3 &/*cameraPosition*/, const YsVec3 &lightDirection, FSENVIRONMENT env, const YsColor &lightColor, const double &lightLevel){ + float light[4]; +#ifdef YSOGLERRORCHECK + FsOpenGlShowError("FsSetDirectionalLight In"); +#endif + + light[0]=(float)lightDirection.x(); + light[1]=(float)lightDirection.y(); + light[2]=(float)lightDirection.z(); + light[3]=0.0; + glLightfv(GL_LIGHT0,GL_POSITION,light); + + GLfloat dif[4]; + GLfloat amb[4]; + GLfloat spc[4]; + + dif[0]=(float) 0.6 * lightColor.Rd() * lightLevel; + dif[1]=(float) 0.6 * lightColor.Gd() * lightLevel; + dif[2]=(float) 0.6 * lightColor.Bd() * lightLevel; + dif[3]=1.0F; + + amb[0]=0.3F * lightColor.Rd() * lightLevel; + amb[1]=0.3F * lightColor.Gd() * lightLevel; + amb[2]=0.3F * lightColor.Bd() * lightLevel; + amb[3]=1.0F; + + spc[0]=0.9F * lightColor.Rd() * lightLevel; + spc[1]=0.9F * lightColor.Gd() * lightLevel; + spc[2]=0.9F * lightColor.Bd() * lightLevel; + spc[3]=1.0F; + + glLightfv(GL_LIGHT0,GL_DIFFUSE,dif); + glLightfv(GL_LIGHT0,GL_AMBIENT,amb); + glLightfv(GL_LIGHT0,GL_SPECULAR,spc); + +#ifdef YSOGLERRORCHECK + FsOpenGlShowError("FsSetDirectionalLight Out"); +#endif + + FsResetMaterial(); +} + void FsFogOn(const YsColor &col,const double &visibility) { float fogColor[]={0.7F,0.7F,0.7F,0.0F}; diff --git a/src/graphics/gl2.0/CMakeLists.txt b/src/graphics/gl2.0/CMakeLists.txt index fc10913f..a3d4c13f 100644 --- a/src/graphics/gl2.0/CMakeLists.txt +++ b/src/graphics/gl2.0/CMakeLists.txt @@ -17,6 +17,7 @@ fsopengl2.0.cpp fsparticlegl2.0.cpp fsweapongl2.0.cpp fsweathergl2.0.cpp +fssunsetcolour.cpp ) set(HEADERS diff --git a/src/graphics/gl2.0/fsgroundskygl2.0.cpp b/src/graphics/gl2.0/fsgroundskygl2.0.cpp index c28fb04f..49cb678f 100644 --- a/src/graphics/gl2.0/fsgroundskygl2.0.cpp +++ b/src/graphics/gl2.0/fsgroundskygl2.0.cpp @@ -21,7 +21,7 @@ class FsGroundSkyGraphicCache FsGroundSky::FsGroundSky() { res=new FsGroundSkyGraphicCache; - + LoadSunAndMoon(); nLayer=8; nDeg=30.0; @@ -64,7 +64,7 @@ FsGroundSky::~FsGroundSky() void FsGroundSky::DrawByFog( const YsVec3 &pos,const YsAtt3 &viewAtt,const YsColor &ignd,const YsColor &isky,const YsColor & /*horizon*/, - const double &farZ,YSBOOL specular) + const double &farZ,YSBOOL specular, YsVec3 sunPos, YsColor sunCol) { glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP); @@ -77,9 +77,9 @@ void FsGroundSky::DrawByFog( glDepthFunc(GL_ALWAYS); glDepthMask(GL_FALSE); - + YsAtt3 att; - att.Set(viewAtt.h(),0.0,0.0); + att.Set(viewAtt.h(),viewAtt.p(),viewAtt.b()); const GLfloat fogDensity=YsGLSLGet3DRendererFogDensity(renderer); @@ -94,8 +94,8 @@ void FsGroundSky::DrawByFog( } const GLfloat cylRad=(GLfloat)farZ/10.0f; - const GLfloat x0=-cylRad*3.0f; // Actually, I have to draw a infinitely long cylinder. - const GLfloat x1= cylRad*3.0f; // So, x0 and x1 must be sufficiently long, but not too long to cause numerical shit. + const GLfloat x0=-cylRad*5.0f; // Actually, I have to draw a infinitely long cylinder. + const GLfloat x1= cylRad*5.0f; // So, x0 and x1 must be sufficiently long, but not too long to cause numerical shit. GLfloat tfm[16]; YsGLCopyMatrixfv(tfm,prevTfm); @@ -132,14 +132,21 @@ void FsGroundSky::DrawByFog( res->vtxBuf.AddColor(ignd.Rf(),ignd.Gf(),ignd.Bf(),1.0f); res->vtxBuf.AddVertex(x1, 0.0f, cylRad); - + GLuint fragment = glCreateShader(GL_FRAGMENT_SHADER); + for(int i=0; ivtxBuf.AddColor(isky.Rf(),isky.Gf(),isky.Bf(),1.0f); + g= ((128*pow(2,(-0.0056*pow((1.5*a0-6),2)))-(a0/3)+53-50/(a0+0.5)))/255; + + b= ((105-75/(1+pow((a0+5)/7,7))-a0/1.5))/255; + + res->vtxBuf.AddColor(r,g,b,1.0f); res->vtxBuf.AddVertex(x0,cylRad*(GLfloat)sin(a0)/10.0f,cylRad*(GLfloat)cos(a0)); - res->vtxBuf.AddColor(isky.Rf(),isky.Gf(),isky.Bf(),1.0f); + res->vtxBuf.AddColor(r,g,b,1.0f); res->vtxBuf.AddVertex(x1,cylRad*(GLfloat)sin(a0)/10.0f,cylRad*(GLfloat)cos(a0)); } @@ -147,6 +154,7 @@ void FsGroundSky::DrawByFog( { const double a0=(YsPi/2.0)*double(i)/double(nLayer); + res->vtxBuf.AddColor(isky.Rf(),isky.Gf(),isky.Bf(),1.0f); res->vtxBuf.AddVertex(x0,cylRad*(GLfloat)sin(a0)/10.0f,-cylRad*(GLfloat)cos(a0)); res->vtxBuf.AddColor(isky.Rf(),isky.Gf(),isky.Bf(),1.0f); @@ -156,51 +164,86 @@ void FsGroundSky::DrawByFog( YsGLSLDrawPrimitiveVtxColfv(renderer,GL_TRIANGLE_STRIP,res->vtxBuf.nVtx,res->vtxBuf.vtxArray,res->vtxBuf.colArray); YsGLSLSet3DRendererUniformFogDensity(renderer,fogDensity); - YsGLSLSet3DRendererModelViewfv(renderer,prevTfm); YsGLSLEndUse3DRenderer(renderer); + YsMatrix4x4 viewTransform; + + viewTransform.CreateFromOpenGlCompatibleMatrix(prevTfm); + YsMatrix4x4 invViewTransform; + invViewTransform+=viewTransform; + // invViewTransform.Invert(); + + // invViewTransform.Translate(pos.x(),pos.y(),pos.z()); + // invViewTransform.Rotate(viewAtt); + // invViewTransform.RotateXZ(att.h()); + // invViewTransform.RotateZY(att.p()); + // invViewTransform.RotateXY(att.b()); + // invViewTransform.Translate(0,0,-50); + // invViewTransform.RotateZX(viewAtt.h()); + + //XZ is yaw + //ZY is pitch + //XY is roll + + // invViewTransform.RotateXZ(sunPos.x()); + // invViewTransform.RotateZY(-sunPos.y()); + YsMatrix4x4 modelTransform; + + modelTransform.RotateXZ(YsPi); //Because it is backwards... + modelTransform.Translate(10,pos.y(),-pos.z()); + modelTransform.RotateZX(att.h()); + modelTransform.RotateZY(att.p()); + modelTransform.RotateXY(att.b()); + + sun->SetMatrix(modelTransform); + + + + // moon->SetMatrix(modelTransform); + + + + + sun->Draw(invViewTransform,FSVISUAL_DRAWALL); + glDepthMask(GL_TRUE); glDepthFunc(GL_LEQUAL); glStencilOp(GL_KEEP,GL_KEEP,GL_INCR); } void FsGroundSky::DrawGradation - (const YsVec3 &pos,const YsAtt3 &att,const YsColor &ignd,const YsColor &isky,const YsColor &horizon, - const double & /*farZ*/,YSBOOL specular) + (const YsVec3 &pos,const YsAtt3 &viewAtt,const YsColor &ignd,const YsColor &isky,const YsColor &horizon, + const double &farZ,YSBOOL specular) { glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP); + + + YsGLSL3DRenderer *renderer=YsGLSLSharedVariColor3DRenderer(); + YsGLSLUse3DRenderer(renderer); + + GLfloat prevTfm[16]; + YsGLSLGet3DRendererModelViewfv(prevTfm,renderer); glDisable(GL_DEPTH_TEST); glDepthFunc(GL_ALWAYS); glDepthMask(GL_FALSE); - glEnable(GL_CULL_FACE); + YsAtt3 att; + att.Set(viewAtt.h(),0.0,0.0); - GLfloat groundFadeAngle=0.0f; - // if(YsEqual(att.p(),YsPi/2.0)!=YSTRUE && YsEqual(att.p(),-YsPi/2.0)!=YSTRUE) - // { - // double groundFadeZ; // Distance that maps fade - // groundFadeZ=farZ*cos(att.p())+(farZ*sin(att.p())+pos.y())*tan(att.p()); - // groundFadeAngle=atan2(pos.y(),groundFadeZ); - // } - // else - // { - // groundFadeAngle=0.0; - // } - - + GLfloat groundFadeAngle=1.0f; + if(YsEqual(viewAtt.p(),YsPi/2.0)!=YSTRUE && YsEqual(viewAtt.p(),-YsPi/2.0)!=YSTRUE) + { + GLfloat groundFadeZ; // Distance that maps fade + groundFadeZ=(GLfloat)(farZ*cos(viewAtt.p())+(farZ*sin(viewAtt.p())+pos.y())*tan(viewAtt.p())); + groundFadeAngle=(GLfloat)atan2((GLfloat)pos.y(),groundFadeZ); + } - const GLfloat cylRad=5000.0f; + const GLfloat cylRad=(GLfloat)farZ/10.0f; const GLfloat x0=-cylRad*3.0f; // Actually, I have to draw a infinitely long cylinder. const GLfloat x1= cylRad*3.0f; // So, x0 and x1 must be sufficiently long, but not too long to cause numerical shit. - YsGLSL3DRenderer *renderer=YsGLSLSharedVariColor3DRenderer(); - YsGLSLUse3DRenderer(renderer); - - GLfloat prevTfm[16]; - YsGLSLGet3DRendererModelViewfv(prevTfm,renderer); - GLfloat tfm[16]; YsGLCopyMatrixfv(tfm,prevTfm); YsGLMultMatrixTranslationfv(tfm,(GLfloat)pos.x(),(GLfloat)pos.y(),(GLfloat)pos.z()); @@ -209,40 +252,42 @@ void FsGroundSky::DrawGradation res->vtxBuf.CleanUp(); - res->vtxBuf.AddColor(ignd.Rf(),ignd.Gf(),ignd.Bf(),1.0f); - res->vtxBuf.AddVertex(x0,-cylRad*sinf(groundFadeAngle),-cylRad*cosf(groundFadeAngle)); - res->vtxBuf.AddColor(ignd.Rf(),ignd.Gf(),ignd.Bf(),1.0f); - res->vtxBuf.AddVertex(x1,-cylRad*sinf(groundFadeAngle),-cylRad*cosf(groundFadeAngle)); - res->vtxBuf.AddColor(ignd.Rf(),ignd.Gf(),ignd.Bf(),1.0f); - res->vtxBuf.AddVertex(x1,-cylRad , 0.0f); - - res->vtxBuf.AddColor(ignd.Rf(),ignd.Gf(),ignd.Bf(),1.0f); - res->vtxBuf.AddVertex(x1,-cylRad , 0.0f); - res->vtxBuf.AddColor(ignd.Rf(),ignd.Gf(),ignd.Bf(),1.0f); - res->vtxBuf.AddVertex(x0,-cylRad , 0.0f); - res->vtxBuf.AddColor(ignd.Rf(),ignd.Gf(),ignd.Bf(),1.0f); - res->vtxBuf.AddVertex(x0,-cylRad*sinf(groundFadeAngle),-cylRad*cosf(groundFadeAngle)); + const GLfloat y0=-cylRad*sinf(groundFadeAngle); res->vtxBuf.AddColor(ignd.Rf(),ignd.Gf(),ignd.Bf(),1.0f); - res->vtxBuf.AddVertex(x0,-cylRad , 0.0f); - res->vtxBuf.AddColor(ignd.Rf(),ignd.Gf(),ignd.Bf(),1.0f); - res->vtxBuf.AddVertex(x1,-cylRad , 0.0f); - res->vtxBuf.AddColor(ignd.Rf(),ignd.Gf(),ignd.Bf(),1.0f); - res->vtxBuf.AddVertex(x1,-cylRad*sinf(groundFadeAngle), cylRad*cosf(groundFadeAngle)); - + res->vtxBuf.AddVertex(x0, 0.0f, -cylRad); res->vtxBuf.AddColor(ignd.Rf(),ignd.Gf(),ignd.Bf(),1.0f); - res->vtxBuf.AddVertex(x1,-cylRad*sinf(groundFadeAngle), cylRad*cosf(groundFadeAngle)); + res->vtxBuf.AddVertex(x1, 0.0f, -cylRad); + for(int i=-32; i>=1; i/=2) + { + const GLfloat z=cylRad*cosf(groundFadeAngle)*(GLfloat)i/32.0f; + res->vtxBuf.AddColor(ignd.Rf(),ignd.Gf(),ignd.Bf(),1.0f); + res->vtxBuf.AddVertex(x0,y0,z); + res->vtxBuf.AddColor(ignd.Rf(),ignd.Gf(),ignd.Bf(),1.0f); + res->vtxBuf.AddVertex(x1,y0,z); + } + for(int i=1; i<=32; i*=2) + { + const GLfloat z=cylRad*cosf(groundFadeAngle)*(GLfloat)i/32.0f; + res->vtxBuf.AddColor(ignd.Rf(),ignd.Gf(),ignd.Bf(),1.0f); + res->vtxBuf.AddVertex(x0,y0,z); + res->vtxBuf.AddColor(ignd.Rf(),ignd.Gf(),ignd.Bf(),1.0f); + res->vtxBuf.AddVertex(x1,y0,z); + } res->vtxBuf.AddColor(ignd.Rf(),ignd.Gf(),ignd.Bf(),1.0f); - res->vtxBuf.AddVertex(x0,-cylRad*sinf(groundFadeAngle), cylRad*cosf(groundFadeAngle)); + res->vtxBuf.AddVertex(x0, 0.0f, cylRad); res->vtxBuf.AddColor(ignd.Rf(),ignd.Gf(),ignd.Bf(),1.0f); - res->vtxBuf.AddVertex(x0,-cylRad , 0.0f); + res->vtxBuf.AddVertex(x1, 0.0f, cylRad); + res->vtxBuf.AddVertex(x1, 0.0f, cylRad); res->vtxBuf.AddColor(horizon.Rf(),horizon.Gf(),horizon.Bf(),1.0f); - res->vtxBuf.AddVertex(x0,-cylRad*sinf(groundFadeAngle), cylRad*cosf(groundFadeAngle)); + res->vtxBuf.AddVertex(x1, 0.0f, cylRad); res->vtxBuf.AddColor(horizon.Rf(),horizon.Gf(),horizon.Bf(),1.0f); - res->vtxBuf.AddVertex(x1,-cylRad*sinf(groundFadeAngle), cylRad*cosf(groundFadeAngle)); + res->vtxBuf.AddVertex(x0, 0.0f, cylRad); res->vtxBuf.AddColor(horizon.Rf(),horizon.Gf(),horizon.Bf(),1.0f); - res->vtxBuf.AddVertex(x1, 0.0f, cylRad); + res->vtxBuf.AddVertex(x0,-cylRad*sinf(groundFadeAngle), cylRad*cosf(groundFadeAngle)); + + res->vtxBuf.AddVertex(x1, 0.0f, cylRad); res->vtxBuf.AddColor(horizon.Rf(),horizon.Gf(),horizon.Bf(),1.0f); res->vtxBuf.AddVertex(x1, 0.0f, cylRad); @@ -252,59 +297,38 @@ void FsGroundSky::DrawGradation res->vtxBuf.AddVertex(x0,-cylRad*sinf(groundFadeAngle), cylRad*cosf(groundFadeAngle)); - int k; - YsColor col0,col1; - GLfloat a0,a1; - const GLfloat nRadianf=(GLfloat)YsDegToRad(nDeg); - for(int i=0; ivtxBuf.AddColor(col0.Rf(),col0.Gf(),col0.Bf(),1.0f); - res->vtxBuf.AddVertex(x0,cylRad*sinf(a0),cylRad*(cosf(a0))); - res->vtxBuf.AddColor(col0.Rf(),col0.Gf(),col0.Bf(),1.0f); - res->vtxBuf.AddVertex(x1,cylRad*sinf(a0),cylRad*(cosf(a0))); - res->vtxBuf.AddColor(col1.Rf(),col1.Gf(),col1.Bf(),1.0f); - res->vtxBuf.AddVertex(x1,cylRad*sinf(a1),cylRad*(cosf(a1))); - - res->vtxBuf.AddColor(col1.Rf(),col1.Gf(),col1.Bf(),1.0f); - res->vtxBuf.AddVertex(x1,cylRad*sinf(a1),cylRad*(cosf(a1))); - res->vtxBuf.AddColor(col1.Rf(),col1.Gf(),col1.Bf(),1.0f); - res->vtxBuf.AddVertex(x0,cylRad*sinf(a1),cylRad*(cosf(a1))); - res->vtxBuf.AddColor(col0.Rf(),col0.Gf(),col0.Bf(),1.0f); - res->vtxBuf.AddVertex(x0,cylRad*sinf(a0),cylRad*(cosf(a0))); + const double a0=(YsPi/2.0)*double(i)/double(nLayer); + float r,g,b; + r= (205/(1+pow((a0/30+0.55),7))-(a0/10)+15)/255; + + g= ((128*pow(2,(-0.0056*pow((1.5*a0-6),2)))-(a0/3)+53-50/(a0+0.5)))/255; + + b= ((105-75/(1+pow((a0+5)/7,7))-a0/1.5))/255; + + res->vtxBuf.AddColor(r,g,b,1.0f); + res->vtxBuf.AddVertex(x0,cylRad*(GLfloat)sin(a0)/10.0f,cylRad*(GLfloat)cos(a0)); + res->vtxBuf.AddColor(r,g,b,1.0f); + res->vtxBuf.AddVertex(x1,cylRad*(GLfloat)sin(a0)/10.0f,cylRad*(GLfloat)cos(a0)); } - a1=nRadianf; - res->vtxBuf.AddColor(col0.Rf(),col0.Gf(),col0.Bf(),1.0f); - res->vtxBuf.AddVertex(x0,cylRad*sinf(a1), cylRad*cosf(a1)); - res->vtxBuf.AddColor(col0.Rf(),col0.Gf(),col0.Bf(),1.0f); - res->vtxBuf.AddVertex(x1,cylRad*sinf(a1), cylRad*cosf(a1)); - res->vtxBuf.AddColor(col0.Rf(),col0.Gf(),col0.Bf(),1.0f); - res->vtxBuf.AddVertex(x1,cylRad*sinf(a1),-cylRad*cosf(a1)); + for(int i=nLayer; 0<=i; --i) + { + const double a0=(YsPi/2.0)*double(i)/double(nLayer); - res->vtxBuf.AddColor(col0.Rf(),col0.Gf(),col0.Bf(),1.0f); - res->vtxBuf.AddVertex(x1,cylRad*sinf(a1),-cylRad*cosf(a1)); - res->vtxBuf.AddColor(col0.Rf(),col0.Gf(),col0.Bf(),1.0f); - res->vtxBuf.AddVertex(x0,cylRad*sinf(a1),-cylRad*cosf(a1)); - res->vtxBuf.AddColor(col0.Rf(),col0.Gf(),col0.Bf(),1.0f); - res->vtxBuf.AddVertex(x0,cylRad*sinf(a1), cylRad*cosf(a1)); + res->vtxBuf.AddColor(isky.Rf(),isky.Gf(),isky.Bf(),1.0f); + res->vtxBuf.AddVertex(x0,cylRad*(GLfloat)sin(a0)/10.0f,-cylRad*(GLfloat)cos(a0)); + res->vtxBuf.AddColor(isky.Rf(),isky.Gf(),isky.Bf(),1.0f); + res->vtxBuf.AddVertex(x1,cylRad*(GLfloat)sin(a0)/10.0f,-cylRad*(GLfloat)cos(a0)); + } - YsGLSLDrawPrimitiveVtxColfv(renderer,GL_TRIANGLES,res->vtxBuf.nVtx,res->vtxBuf.vtxArray,res->vtxBuf.colArray); + YsGLSLDrawPrimitiveVtxColfv(renderer,GL_TRIANGLE_STRIP,res->vtxBuf.nVtx,res->vtxBuf.vtxArray,res->vtxBuf.colArray); YsGLSLSet3DRendererModelViewfv(renderer,prevTfm); YsGLSLEndUse3DRenderer(renderer); + glDepthMask(GL_TRUE); + glDepthFunc(GL_LEQUAL); glStencilOp(GL_KEEP,GL_KEEP,GL_INCR); } @@ -539,3 +563,17 @@ void FsGroundSky::DrawCrappy(const YsVec3 &pos,const YsColor &ignd,const YsColor glDepthMask(GL_TRUE); glStencilOp(GL_KEEP,GL_KEEP,GL_INCR); } + +void FsGroundSky::LoadSunAndMoon(void){ + sun = new FsVisualSrf; + if(sun->Load(L"misc/sun.srf")!=YSOK) + { + printf("Error loading sun srf\n"); + + } + moon = new FsVisualSrf; + if(moon->Load(L"misc/moon.srf")!= YSOK){ + printf("Error loading moon srf\n"); + } + +} \ No newline at end of file diff --git a/src/graphics/gl2.0/fsopengl2.0.cpp b/src/graphics/gl2.0/fsopengl2.0.cpp index 00693512..87179d18 100644 --- a/src/graphics/gl2.0/fsopengl2.0.cpp +++ b/src/graphics/gl2.0/fsopengl2.0.cpp @@ -460,6 +460,66 @@ void FsSetDirectionalLight(const YsVec3 &/*cameraPosition*/ ,const YsVec3 &light #endif } + +void FsSetDirectionalLight(const YsVec3 &/*cameraPosition*/, const YsVec3 &lightDirection, FSENVIRONMENT env, const YsColor &lightColor, const double &lightLevel){ +#ifdef YSOGLERRORCHECK + FsOpenGlShowError("FsSetDirectionalLight In"); +#endif + + const GLfloat light[4]= + { + (GLfloat)lightDirection.x(), + (GLfloat)lightDirection.y(), + (GLfloat)lightDirection.z(), + 0.0f + }; + + GLfloat dif[4]; + GLfloat amb[4]; + GLfloat spc[4]; + + dif[0]=(float) 0.6 * lightColor.Rd() * lightLevel; + dif[1]=(float) 0.6 * lightColor.Gd() * lightLevel; + dif[2]=(float) 0.6 * lightColor.Bd() * lightLevel; + dif[3]=1.0F; + + amb[0]=0.3F * lightColor.Rd() * lightLevel; + amb[1]=0.3F * lightColor.Gd() * lightLevel; + amb[2]=0.3F * lightColor.Bd() * lightLevel; + amb[3]=1.0F; + + spc[0]=0.9F * lightColor.Rd() * lightLevel; + spc[1]=0.9F * lightColor.Gd() * lightLevel; + spc[2]=0.9F * lightColor.Bd() * lightLevel; + spc[3]=1.0F; + + + YsGLSLSetShared3DRendererDirectionalLightfv(0,light); + YsGLSLSetShared3DRendererLightColor(0,dif); + YsGLSLSetShared3DRendererAmbientColor(amb); + YsGLSLSetShared3DRendererSpecularColor(spc); + + YsGLSLUse3DRenderer(YsGLSLSharedFlash3DRenderer()); + switch(env) + { + case FSDAYLIGHT: + YsGLSLSet3DRendererUniformFlashSize(YsGLSLSharedFlash3DRenderer(),0.1f); + YsGLSLSet3DRendererFlashRadius(YsGLSLSharedFlash3DRenderer(),0.6f,1.0f); + break; + case FSNIGHT: + YsGLSLSet3DRendererUniformFlashSize(YsGLSLSharedFlash3DRenderer(),1.0f); + YsGLSLSet3DRendererFlashRadius(YsGLSLSharedFlash3DRenderer(),0.2f,1.0f); + break; + } + YsGLSLEndUse3DRenderer(YsGLSLSharedFlash3DRenderer()); + + +#ifdef YSOGLERRORCHECK + FsOpenGlShowError("FsSetDirectionalLight Out"); +#endif + +} + void FsFogOn(const YsColor &col,const double &visibility) { #ifdef YSOGLERRORCHECK diff --git a/src/graphics/gl2.0/fssunsetcolour.cpp b/src/graphics/gl2.0/fssunsetcolour.cpp new file mode 100644 index 00000000..d4b24830 --- /dev/null +++ b/src/graphics/gl2.0/fssunsetcolour.cpp @@ -0,0 +1,9 @@ +#include + +#include "fssunsetcolour.h" + +#include + +void SunsetColourGenerator::GetColourByAngle(double angle, double dayTime, double &r, double &g, double &b) const{ + +} \ No newline at end of file diff --git a/src/graphics/gl2.0/fssunsetcolour.h b/src/graphics/gl2.0/fssunsetcolour.h new file mode 100644 index 00000000..e277d447 --- /dev/null +++ b/src/graphics/gl2.0/fssunsetcolour.h @@ -0,0 +1,58 @@ +class SunsetColourGenerator +{ + public: + void GetColourByAngle(double angle, double dayTime, double &r, double &g, double &b) const; + + void GetColourByAngleAndAlt(double angle, double alt, double dayTime, double &r, double &g, double &b) const; + private: + const float dayHorizonR = 0.706; + const float dayHorizonG = 0.765; + const float dayHorizonB = 0.843; + const float dayLowerR = 0.314; + const float dayLowerG = 0.647; + const float dayLowerB = 0.902; + const float dayMiddleR = 0.314; + const float dayMiddleG = 0.647; + const float dayMiddleB = 0.902; + const float dayUpperR = 0.314; + const float dayUpperG = 0.647;; + const float dayUpperB = 0.902; + const float dayZenithR = 0.129; + const float dayZenithG = 0.310; + const float dayZenithB = 0.651; + + const float sunsetHorizonR = 0.92; + const float sunsetHorizonG = 0.756; + const float sunsetHorizonB = 0.118; + const float sunsetLowerR = 0.843; + const float sunsetLowerG = 0.47; + const float sunsetLowerB = 0.157; + const float sunsetMiddleR = 0.078; + const float sunsetMiddleG = 0.250; + const float sunsetMiddleB = 0.392; + const float sunsetUpperR = 0.04; + const float sunsetUpperG = 0.1; + const float sunsetUpperB = 0.2; + const float sunsetZenithR = 0.059; + const float sunsetZenithG = 0.065; + const float sunsetZenithB = 0.200; + const float sunsetOpposition; + + const float nightHorizonR = 0.08; + const float nightHorizonG = 0.15; + const float nightHorizonB = 0.25; + const float nightLowerR = 0.08; + const float nightLowerG = 0.15; + const float nightLowerB = 0.25; + const float nightMiddleR = 0.08; + const float nightMiddleG = 0.15; + const float nightMiddleB = 0.25; + const float nightUpperR = 0.08; + const float nightUpperG = 0.1; + const float nightUpperB = 0.2; + const float nightZenithR = 0.04; + const float nightZenithG = 0.05; + const float nightZenithB = 0.1; + + +}; \ No newline at end of file diff --git a/src/graphics/null/fsgroundskynownd.cpp b/src/graphics/null/fsgroundskynownd.cpp index e6a5d246..ed0bfa60 100644 --- a/src/graphics/null/fsgroundskynownd.cpp +++ b/src/graphics/null/fsgroundskynownd.cpp @@ -14,7 +14,7 @@ FsGroundSky::~FsGroundSky() void FsGroundSky::DrawByFog( const YsVec3 &,const YsAtt3 &,const YsColor &,const YsColor &,const YsColor &, - const double &,YSBOOL) + const double &,YSBOOL, YsVec3, YsColor) { } diff --git a/src/graphics/null/fsnownd.cpp b/src/graphics/null/fsnownd.cpp index 5e2b48c2..1ad0e879 100644 --- a/src/graphics/null/fsnownd.cpp +++ b/src/graphics/null/fsnownd.cpp @@ -93,6 +93,9 @@ void FsSetDirectionalLight(const YsVec3 &cameraPosition,const YsVec3 &lightDirec { } +void FsSetDirectionalLight(const YsVec3 &/*cameraPosition*/, const YsVec3 &lightDirection, FSENVIRONMENT env, const YsColor &lightColor, const double &lightLevel){ +} + void FsFogOn(const YsColor &fogColor,const double &visibility) { } diff --git a/src/platform/linux/fsnullnetwork.cpp b/src/platform/linux/fsnullnetwork.cpp index fa8053bf..de340a1d 100644 --- a/src/platform/linux/fsnullnetwork.cpp +++ b/src/platform/linux/fsnullnetwork.cpp @@ -643,7 +643,7 @@ YSRESULT FsSocketClient::ReceiveAssignSideWindow(unsigned char dat[]) return YSERR; } -YSRESULT FsSocketClient::ReceiveVersionNotify(unsigned char dat[]) +YSRESULT FsSocketClient::ReceiveVersionNotify(unsigned packetLength, unsigned char dat[]) { return YSERR; }