From 84c9fe38b027912381fb03f53e898e024f204789 Mon Sep 17 00:00:00 2001 From: Skipper Date: Sat, 2 Sep 2023 22:25:34 +0100 Subject: [PATCH 1/8] Working prototype of day/night cycle. Todo: * Add in config menu options for cycle length * Currently set to 60 minutes. * Review shading during night time, as ground seems lighter than the aircraft --- src/core/fsnetwork.cpp | 130 ++++++++++++++++----------- src/core/fsnetwork.h | 8 +- src/core/fssimulation.cpp | 59 ++++++++---- src/core/fssimulation.h | 16 +++- src/core/fsweather.cpp | 109 ++++++++++++++++++++++ src/core/fsweather.h | 18 ++++ src/graphics/common/fsopengl.h | 1 + src/graphics/d3d9/fsd3d.cpp | 56 ++++++++++++ src/graphics/gl/fsopengl.cpp | 43 +++++++++ src/graphics/gl2.0/fsopengl2.0.cpp | 60 +++++++++++++ src/graphics/null/fsnownd.cpp | 3 + src/platform/linux/fsnullnetwork.cpp | 2 +- 12 files changed, 426 insertions(+), 79 deletions(-) diff --git a/src/core/fsnetwork.cpp b/src/core/fsnetwork.cpp index e1a36b1a..f6d44a66 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. } @@ -1949,20 +1952,6 @@ YSRESULT FsSocketServer::BroadcastForceJoin(void) return BroadcastPacket(4,dat,2040618); } -YSRESULT FsSocketServer::BroadcastEnvironment(void) -{ - int i; - for (i=0; i= 20150425) { versionCheck=YSOK; } @@ -3770,8 +3759,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 +4196,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 +4268,22 @@ YSRESULT FsSocketServer::SendEnvironment(int clientId) YSBOOL fog; double visibility; unsigned flags; + int cloudLayerCount; + int dayLength; + float dayCycle; + 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(); + dayCycle = sim->GetDayCycle(); + cloudLayerCount = sim->GetWeather().GetCloudLayerCount(); flags=0; if(fog==YSTRUE) @@ -4344,13 +4350,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->GetDayCycle()); + 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 +4973,7 @@ FsSocketClient::FsSocketClient(const char username[],const int port,FsSimulation sideWindowAssigned=YSFALSE; reportedServerVersion=0; + ysceServer=YSFALSE; svrUseMissile=YSTRUE; svrUseUnguidedWeapon=YSTRUE; @@ -5090,7 +5109,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 +5737,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 +6437,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 +6899,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, dayCycle; + YsArray cloudLayer; + FsPopInt(ptr); version=FsPopShort(ptr); @@ -6882,9 +6914,22 @@ YSRESULT FsSocketClient::ReceiveEnvironment(int ,unsigned char dat[]) wz=FsPopFloat(ptr); visibility=FsPopFloat(ptr); - // if(2<=version) - // { - // } + if(2<=version) + { + dayLength=FsPopInt(ptr); + dayCycle = FsPopFloat(ptr); + + sim->SetDayLength(dayLength); + sim->SetDayCycle(dayCycle); + 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 +7555,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 +7921,6 @@ class FsGuiServerDialog : public FsGuiDialog FsGuiButton *whoKilledMeBtn,*whomHaveIKilledBtn; - FsGuiButton *setDayBtn; - FsGuiStatic *multiIpWarningTxt; FsGuiButton *endServerBtn,*confirmEndServerBtn; @@ -7973,8 +8014,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 +8130,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 +8305,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 +8319,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 +8725,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 +10752,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..a8db9fd6 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, @@ -381,7 +381,6 @@ class FsSocketServer : public YsSocketServer, public FsServerVariable YSRESULT BroadcastGroundColor(YsColor col); YSRESULT BroadcastFogColor(YsColor col); YSRESULT BroadcastForceJoin(void); - YSRESULT BroadcastEnvironment(void); YSRESULT RectifyIllegalMissiles(void); @@ -535,6 +534,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 +610,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 +787,4 @@ class FsServerRunLoop }; /* } */ -#endif +#endif \ No newline at end of file diff --git a/src/core/fssimulation.cpp b/src/core/fssimulation.cpp index ee7a36b1..18b5630f 100644 --- a/src/core/fssimulation.cpp +++ b/src/core/fssimulation.cpp @@ -173,6 +173,7 @@ FsSimulation::FsSimulation(FsWorld *w) : airplaneList(FsAirplaneAllocator),groun currentTime=0.0; aircraftTroubleTimer=0.0; lastTime=0; + daycycle = 0; mainWindowViewmode=FSCOCKPITVIEW; mainWindowAdditionalAirplaneViewId=0; mainWindowActualViewMode.viewPoint=YsOrigin(); @@ -1476,16 +1477,16 @@ void FsSimulation::SetEnvironment(FSENVIRONMENT env) void FsSimulation::EnforceEnvironment(void) { + fogColor.SetDoubleRGB(0.6*lightIntensity*lightColour.Rd(),0.6*lightIntensity * lightColour.Gd(), 0.6*lightIntensity * lightColour.Bd()); + //The day/night switch may be removed, as this is all being handled via day/night cycle. switch(env) { 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; } @@ -1495,6 +1496,22 @@ FSENVIRONMENT FsSimulation::GetEnvironment(void) const { return env; } +//Implement the following functions: +int FsSimulation::GetDayLength(void) const{ + return dayLength; +} + +double FsSimulation::GetDayCycle(void) const{ + return daycycle; +} + +void FsSimulation::SetDayLength(int dayLength){ + dayLength = dayLength; +} + +void FsSimulation::SetDayCycle(double dayCycle){ + daycycle = dayCycle; +} YSRESULT FsSimulation::SendConfigString(const char str[]) { @@ -3878,7 +3895,18 @@ void FsSimulation::SimMove(const double &dt) particleStore.Move(dt,weather->GetWind()); weather->WeatherTransition(dt); + //Cloud movement if we bring that in, goes here! + //TODO: Set this is a config variable, day/night cycle length + int totalSteps = dayLength/dt; + double step = 2 * YsPi / totalSteps; + weather->GetDayTime(daycycle,dt,dayLength); + + lightColour = weather->GetLightColour(daycycle); + lightIntensity = weather->GetLightIntensity(daycycle); + weather->SetSunPosition(lightPositionVector,daycycle); + SetEnvironment(FSNIGHT); //Shouldnt matter, this is currently for testing. + airplane=NULL; while((airplane=FindNextAirplane(airplane))!=NULL) { @@ -6723,15 +6751,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,0.6*lightIntensity,0.6*lightIntensity); #ifdef CRASHINVESTIGATION_SIMDRAWSCREENZBUFFERSENSITIVE printf("SimDrawScreenZBufferSensitive %d\n",__LINE__); @@ -6901,8 +6921,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); + printf("Light intensity: %f\n", lightIntensity); sizx=hei*4/3; sizy=hei; if (cfgPtr->centerCameraPerspective == YSFALSE) @@ -6993,19 +7013,20 @@ void FsSimulation::SimDrawBackground(const ActualViewMode &actualViewMode,const { auto gnd=gndColor; auto sky=skyColor; + sky = weather->GetLightColour(sky, daycycle); YSBOOL gndSpecular=this->gndSpecular; YsColor horizonColor; + gnd.SetDoubleRGB(gnd.Rd()*lightIntensity,gnd.Gd()*lightIntensity,gnd.Bd()*lightIntensity); + sky.SetDoubleRGB(sky.Rd()*lightIntensity,sky.Gd()*lightIntensity,sky.Bd()*lightIntensity); 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); + horizonColor=YsGrayScale(lightIntensity); gndSpecular=YSFALSE; break; case FSDAYLIGHT: - horizonColor.SetDoubleRGB(0.7,0.7,0.7); + horizonColor=YsGrayScale(lightIntensity); break; } @@ -10053,7 +10074,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)); diff --git a/src/core/fssimulation.h b/src/core/fssimulation.h index 4abf4524..8526cb75 100644 --- a/src/core/fssimulation.h +++ b/src/core/fssimulation.h @@ -289,9 +289,18 @@ 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 nightColour = YsColor(0.1,0.1,0.1); + YsColor sunriseColour = YsColor(1,0.5,0); + mutable int dayLength = 60; + mutable double daycycle = YsPi; + mutable double lightIntensity = 1; + mutable YsColor lightColour = YsColor(1,1,1); + class ActualViewMode { public: @@ -477,6 +486,11 @@ class FsSimulation : public FsHasInFlightDialog void SetEnvironment(FSENVIRONMENT env); void EnforceEnvironment(void); FSENVIRONMENT GetEnvironment(void) const; + int GetDayLength(void) const; + double GetDayCycle(void) const; + void SetDayLength(int dayLength); + void SetDayCycle(double dayCycle); + YSRESULT SendConfigString(const char str[]); diff --git a/src/core/fsweather.cpp b/src/core/fsweather.cpp index f89c9af2..8687e258 100644 --- a/src/core/fsweather.cpp +++ b/src/core/fsweather.cpp @@ -35,6 +35,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 +182,108 @@ 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){ + //If it's dusk or dawn, then we need to fade the colour. + lightColour.SetRd(ColourInterpolate(daylightColour.Rd(),dawnColour.Rd(),DuskIntensity(dayTime))); + lightColour.SetGd(ColourInterpolate(daylightColour.Gd(),dawnColour.Gd(),DuskIntensity(dayTime))); + lightColour.SetBd(ColourInterpolate(daylightColour.Bd(),dawnColour.Bd(),DuskIntensity(dayTime))); + } + 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; + 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.1 and -0.1. + //return sin(dayTime+YsPi/2)*5+0.5; + return abs(sin(dayTime+YsPi/2))*5; + +}; + +//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. +void 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; + } +}; + +void FsWeather::SetSunPosition(YsVec3& lightPosition, double dayTime) const{ + if (IsDay(dayTime) == YSTRUE){ + lightPosition.SetX(cos(dayTime+YsPi/2)); + lightPosition.SetY(abs(sin(dayTime+YsPi/2))); + } + else{ + lightPosition.SetX(-cos(dayTime+YsPi/2)); + lightPosition.SetY(abs(sin(dayTime+YsPi/2))); + } +}; + +//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..b53a9018 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,25 @@ 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; + void GetDayTime(double& daytime, double dt, int dayLength) const; + void SetSunPosition(YsVec3& lightPosition, double dayTime) const; }; diff --git a/src/graphics/common/fsopengl.h b/src/graphics/common/fsopengl.h index 9af725d7..a30e2b2d 100644 --- a/src/graphics/common/fsopengl.h +++ b/src/graphics/common/fsopengl.h @@ -59,6 +59,7 @@ void FsClearStencilBuffer(void); void FsSetPerPixelShading(YSBOOL perPix); void FsSetPointLight(const YsVec3 &cameraPosition,const YsVec3 &lightPosition,FSENVIRONMENT env); void FsSetDirectionalLight(const YsVec3 &cameraPosition,const YsVec3 &lightDirection,FSENVIRONMENT env); +void FsSetDirectionalLight(const YsVec3 &cameraPosition, const YsVec3 &lightDirection, FSENVIRONMENT env, const YsColor &lightColor, const double &lightLevel); void FsFogOn(const YsColor &fogColor,const double &visibility); void FsFogOff(void); diff --git a/src/graphics/d3d9/fsd3d.cpp b/src/graphics/d3d9/fsd3d.cpp index c54f4ee5..fd3da6ee 100644 --- a/src/graphics/d3d9/fsd3d.cpp +++ b/src/graphics/d3d9/fsd3d.cpp @@ -269,6 +269,62 @@ void FsSetDirectionalLight(const YsVec3 &cameraPosition,const YsVec3 &lightDirec } } +void FsSetDirectionalLight(const YsVec3 &/*cameraPosition*/, const YsVec3 &lightDirection, FSENVIRONMENT env, const YsColor &lightColor, const int &lightLevel){ + auto ysD3dDev=YsD3dDevice::GetCurrent(); + if(ysD3dDev!=NULL) + { + D3DVECTOR lightDir; + D3DLIGHT9 light; + ZeroMemory(&light,sizeof(light)); + light.Type=D3DLIGHT_DIRECTIONAL; + + switch(env) + { + case FSDAYLIGHT: + light.Diffuse.r=0.6F; + light.Diffuse.g=0.6F; + light.Diffuse.b=0.6F; + light.Diffuse.a=1.0; + + light.Ambient.r=0.3F; + light.Ambient.g=0.3F; + light.Ambient.b=0.3F; + light.Ambient.a=1.0F; + + light.Specular.r=0.9F; + light.Specular.g=0.9F; + light.Specular.b=0.9F; + light.Specular.a=1.0F; + break; + case FSNIGHT: + light.Diffuse.r=0.05F; + light.Diffuse.g=0.05F; + light.Diffuse.b=0.05F; + light.Diffuse.a=1.0; + + light.Ambient.r=0.05F; + light.Ambient.g=0.05F; + light.Ambient.b=0.05F; + light.Ambient.a=1.0F; + + light.Specular.r=0.0F; + light.Specular.g=0.0F; + light.Specular.b=0.0F; + light.Specular.a=1.0F; + break; + } + + lightDir.x=(float)-lightDirection.x(); + lightDir.y=(float)-lightDirection.y(); + lightDir.z=(float)-lightDirection.z(); + YsD3dNormalize(light.Direction,lightDir); + light.Range=100.0F; + ysD3dDev->d3dDev->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/fsopengl.cpp b/src/graphics/gl/fsopengl.cpp index d7130005..cd1668d5 100644 --- a/src/graphics/gl/fsopengl.cpp +++ b/src/graphics/gl/fsopengl.cpp @@ -367,6 +367,49 @@ 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]; +//TODO - Need to apply the light level and colour here to DAYLIGHT. +#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/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/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; } From 1b3c8c996748e69347e45946ef7d238d5db9fbdb Mon Sep 17 00:00:00 2001 From: Skipper Date: Sun, 3 Sep 2023 07:36:25 +0100 Subject: [PATCH 2/8] Fixed lightvec type --- src/core/fssimulation.cpp | 1 + src/core/fssimulation.h | 2 +- src/core/fsweather.cpp | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/fssimulation.cpp b/src/core/fssimulation.cpp index 18b5630f..8d0a4999 100644 --- a/src/core/fssimulation.cpp +++ b/src/core/fssimulation.cpp @@ -174,6 +174,7 @@ FsSimulation::FsSimulation(FsWorld *w) : airplaneList(FsAirplaneAllocator),groun aircraftTroubleTimer=0.0; lastTime=0; daycycle = 0; + lightPositionVector = YsVec3(-1.0, 1, 0.0); mainWindowViewmode=FSCOCKPITVIEW; mainWindowAdditionalAirplaneViewId=0; mainWindowActualViewMode.viewPoint=YsOrigin(); diff --git a/src/core/fssimulation.h b/src/core/fssimulation.h index 8526cb75..746a400a 100644 --- a/src/core/fssimulation.h +++ b/src/core/fssimulation.h @@ -292,7 +292,7 @@ class FsSimulation : public FsHasInFlightDialog 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); + YsVec3 lightPositionVector = YsVec3(-1.0, 1, 0.0); YsColor dayColour = YsColor(1,1,1); YsColor nightColour = YsColor(0.1,0.1,0.1); YsColor sunriseColour = YsColor(1,0.5,0); diff --git a/src/core/fsweather.cpp b/src/core/fsweather.cpp index 8687e258..a77748f9 100644 --- a/src/core/fsweather.cpp +++ b/src/core/fsweather.cpp @@ -253,7 +253,7 @@ YSBOOL FsWeather::IsDuskOrDawn(const double dayTime) const{ }; double FsWeather::DuskIntensity(const double dayTime) const{ - //Scale the dusk intensity. Dusk is between sin(dayTime+YsPi/2) = 0.1 and -0.1. + //Scale the dusk intensity. Dusk is between sin(dayTime+YsPi/2) = 0.2 and -0.2. //return sin(dayTime+YsPi/2)*5+0.5; return abs(sin(dayTime+YsPi/2))*5; From fe44da9891bce95b85507ad56c63300c09a58ee5 Mon Sep 17 00:00:00 2001 From: Skipper Date: Sun, 3 Sep 2023 16:58:15 +0100 Subject: [PATCH 3/8] Additional functionality: * Config menu options for cycle length and start time * Netcode for sending time updates, and day/night switch to keep classic up to date * Function to convert YS pi time to hours/mins/secs --- runtime/language/en.uitxt | 1 + runtime/language/ja.uitxt | 1 + src/common/fstextresource.h | 1 + src/config/fsconfig.cpp | 26 +++++++++++++-- src/config/fsconfig.h | 3 ++ src/core/fsguiconfigdlg.cpp | 66 ++++++++++++++++++++++++++++++++++++- src/core/fsguiconfigdlg.h | 3 ++ src/core/fsnetwork.cpp | 11 +++++++ src/core/fsnetwork.h | 1 + src/core/fssimulation.cpp | 45 ++++++++++++++++--------- src/core/fssimulation.h | 4 ++- src/core/fsweather.cpp | 26 ++++++++++++++- src/core/fsweather.h | 3 +- src/core/fsworld.cpp | 20 +++++++++++ src/core/fsworld.h | 2 ++ 15 files changed, 191 insertions(+), 22 deletions(-) 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/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/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/fsnetwork.cpp b/src/core/fsnetwork.cpp index f6d44a66..d3ba75ca 100644 --- a/src/core/fsnetwork.cpp +++ b/src/core/fsnetwork.cpp @@ -1945,6 +1945,17 @@ YSRESULT FsSocketServer::BroadcastFogColor(YsColor col) return BroadcastPacket(7,dat,20040618); } +YSRESULT FsSocketServer::BroadcastEnvironmentUpdate(void){ + for(i=0; i (128); groundSearch=new YsHashTable (128); @@ -1493,25 +1495,31 @@ void FsSimulation::EnforceEnvironment(void) } } +void FsSimulation::SendServerEnvironment(FSENVIRONMENT env){ + if (netServer != NULL){ + netServer->SendEnvironment(env); + } + +} FSENVIRONMENT FsSimulation::GetEnvironment(void) const { return env; } //Implement the following functions: int FsSimulation::GetDayLength(void) const{ - return dayLength; + return dayLength / 60; //Convert to minutes } double FsSimulation::GetDayCycle(void) const{ - return daycycle; + return dayTime; } void FsSimulation::SetDayLength(int dayLength){ - dayLength = dayLength; + this->dayLength = dayLength*60; //Convert to seconds } void FsSimulation::SetDayCycle(double dayCycle){ - daycycle = dayCycle; + this->dayTime = dayCycle; } YSRESULT FsSimulation::SendConfigString(const char str[]) @@ -3898,15 +3906,18 @@ void FsSimulation::SimMove(const double &dt) weather->WeatherTransition(dt); //Cloud movement if we bring that in, goes here! - //TODO: Set this is a config variable, day/night cycle length - int totalSteps = dayLength/dt; - double step = 2 * YsPi / totalSteps; - weather->GetDayTime(daycycle,dt,dayLength); + 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(daycycle); - lightIntensity = weather->GetLightIntensity(daycycle); - weather->SetSunPosition(lightPositionVector,daycycle); - SetEnvironment(FSNIGHT); //Shouldnt matter, this is currently for testing. + lightColour = weather->GetLightColour(dayTime); + lightIntensity = weather->GetLightIntensity(dayTime); + weather->SetSunPosition(lightPositionVector,dayTime); airplane=NULL; while((airplane=FindNextAirplane(airplane))!=NULL) @@ -6922,8 +6933,9 @@ FsProjection FsSimulation::SimDrawPrepare(const ActualViewMode &actualViewMode) printf("SIMDRAW-2.6\n"); #endif + FsSetDirectionalLight(actualViewMode.viewPoint,lightPositionVector,FSDAYLIGHT,lightColour,lightIntensity); - printf("Light intensity: %f\n", lightIntensity); + sizx=hei*4/3; sizy=hei; if (cfgPtr->centerCameraPerspective == YSFALSE) @@ -7014,7 +7026,7 @@ void FsSimulation::SimDrawBackground(const ActualViewMode &actualViewMode,const { auto gnd=gndColor; auto sky=skyColor; - sky = weather->GetLightColour(sky, daycycle); + sky = weather->GetLightColour(sky, dayTime); YSBOOL gndSpecular=this->gndSpecular; YsColor horizonColor; @@ -12526,6 +12538,9 @@ YSRESULT FsSimulation::LoadConfigFile(const wchar_t fn[],YSBOOL changeEnvironmen } weather->SetWind(cfgPtr->constWind); + SetDayCycle(cfgPtr->dayTime); + SetDayLength(cfgPtr->dayLength); + } return r; diff --git a/src/core/fssimulation.h b/src/core/fssimulation.h index 746a400a..d2dc960c 100644 --- a/src/core/fssimulation.h +++ b/src/core/fssimulation.h @@ -297,9 +297,10 @@ class FsSimulation : public FsHasInFlightDialog YsColor nightColour = YsColor(0.1,0.1,0.1); YsColor sunriseColour = YsColor(1,0.5,0); mutable int dayLength = 60; - mutable double daycycle = YsPi; + mutable double dayTime = YsPi; mutable double lightIntensity = 1; mutable YsColor lightColour = YsColor(1,1,1); + FSENVIRONMENT lastEnv; class ActualViewMode { @@ -485,6 +486,7 @@ class FsSimulation : public FsHasInFlightDialog void SetEnvironment(FSENVIRONMENT env); void EnforceEnvironment(void); + void SendServerEnvironment(FSENVIRONMENT env); FSENVIRONMENT GetEnvironment(void) const; int GetDayLength(void) const; double GetDayCycle(void) const; diff --git a/src/core/fsweather.cpp b/src/core/fsweather.cpp index a77748f9..445e9082 100644 --- a/src/core/fsweather.cpp +++ b/src/core/fsweather.cpp @@ -262,13 +262,19 @@ double FsWeather::DuskIntensity(const double dayTime) const{ //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. -void FsWeather::GetDayTime(double& daytime, double dt, int dayLength) const{ +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{ @@ -282,6 +288,24 @@ void FsWeather::SetSunPosition(YsVec3& lightPosition, double dayTime) const{ } }; +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); + printf("Hours: %d, Minutes: %d, Seconds: %d\n", hours, minutes, seconds); + 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 diff --git a/src/core/fsweather.h b/src/core/fsweather.h index b53a9018..6f927d59 100644 --- a/src/core/fsweather.h +++ b/src/core/fsweather.h @@ -74,8 +74,9 @@ class FsWeather YSBOOL IsDay(const double dayTime) const; YSBOOL IsDuskOrDawn(const double dayTime) const; double DuskIntensity(const double dayTime) const; - void GetDayTime(double& daytime, double dt, int dayLength) 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..890136bb 100644 --- a/src/core/fsworld.cpp +++ b/src/core/fsworld.cpp @@ -3889,6 +3889,26 @@ FSENVIRONMENT FsWorld::GetEnvironment(void) return FSDAYLIGHT; } +YSRESULT FsWorld::SetDayTime(double t) +{ + if(NULL!=sim) + { + sim->SetDayCycle(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( From ad749034c8afdc3503a5d32d7ff027325782ed5e Mon Sep 17 00:00:00 2001 From: Skipper Date: Tue, 5 Sep 2023 21:44:53 +0100 Subject: [PATCH 4/8] * Network functionality working * Day/night switch no longer making clouds flash --- src/core/fscloud.cpp | 4 +- src/core/fscloud.h | 2 +- src/core/fshud2.cpp | 5 ++ src/core/fshud2.h | 2 + src/core/fsnetwork.cpp | 13 +++-- src/core/fsradar.cpp | 2 +- src/core/fssimulation.cpp | 97 +++++++++++++++++---------------- src/core/fssimulation.h | 4 +- src/core/fssimulationfileio.cpp | 2 + src/core/fsweather.cpp | 26 ++++++--- src/core/fsworld.cpp | 15 ++++- 11 files changed, 103 insertions(+), 69 deletions(-) diff --git a/src/core/fscloud.cpp b/src/core/fscloud.cpp index 85627726..8f4ac86a 100644 --- a/src/core/fscloud.cpp +++ b/src/core/fscloud.cpp @@ -1097,10 +1097,10 @@ void FsSolidClouds::Make( void FsSolidClouds::AddToParticleManager( class YsGLParticleManager &partMan, - FSENVIRONMENT env,const class FsWeather &weather, + double lightIntensity,const class FsWeather &weather, const YsVec3 &viewDir,const YsMatrix4x4 &viewMdlTfm,const double &nearZ,const double &farZ,const double &tanFov) { - const double baseBrightness=(FSDAYLIGHT==env ? 0.7 : 0.15); + const double baseBrightness=lightIntensity*.75; YsListItem *itm=NULL; while((itm=cloudContainer.FindNext(itm))!=NULL) diff --git a/src/core/fscloud.h b/src/core/fscloud.h index 0f349272..790139ca 100644 --- a/src/core/fscloud.h +++ b/src/core/fscloud.h @@ -126,7 +126,7 @@ class FsSolidClouds void AddToParticleManager( class YsGLParticleManager &partMan, - FSENVIRONMENT env,const class FsWeather &weather, + double lightIntensity,const class FsWeather &weather, const YsVec3 &viewDir,const YsMatrix4x4 &viewMdlTfm,const double &nearZ,const double &farZ,const double &tanFov); 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 d3ba75ca..045cf24a 100644 --- a/src/core/fsnetwork.cpp +++ b/src/core/fsnetwork.cpp @@ -1946,6 +1946,7 @@ YSRESULT FsSocketServer::BroadcastFogColor(YsColor col) } YSRESULT FsSocketServer::BroadcastEnvironmentUpdate(void){ + int i; for(i=0; iGetWeather().GetFog(); visibility=sim->GetWeather().GetFogVisibility(); dayLength = sim->GetDayLength(); - dayCycle = sim->GetDayCycle(); + dayTime = sim->GetDayTime(); cloudLayerCount = sim->GetWeather().GetCloudLayerCount(); flags=0; @@ -4371,7 +4372,7 @@ YSRESULT FsSocketServer::SendEnvironment(int clientId) if (version==2){ //YSCE version, cloud layers. FsPushInt(ptr,sim->GetDayLength()); - FsPushFloat(ptr,(float)sim->GetDayCycle()); + FsPushFloat(ptr,(float)sim->GetDayTime()); FsPushInt(ptr,cloudLayerCount); for (int i = 0; i < cloudLayerCount; i++){ const FsWeatherCloudLayer* layer; @@ -6911,7 +6912,7 @@ YSRESULT FsSocketClient::ReceiveEnvironment(int ,unsigned char dat[]) unsigned flags; YSBOOL fog; int cloudLayers, dayLength; - double visibility,wx,wy,wz, dayCycle; + double visibility,wx,wy,wz, dayTime; YsArray cloudLayer; @@ -6928,10 +6929,10 @@ YSRESULT FsSocketClient::ReceiveEnvironment(int ,unsigned char dat[]) if(2<=version) { dayLength=FsPopInt(ptr); - dayCycle = FsPopFloat(ptr); + dayTime = FsPopFloat(ptr); sim->SetDayLength(dayLength); - sim->SetDayCycle(dayCycle); + sim->SetDayTime(dayTime); cloudLayers=FsPopInt(ptr); for (int i=0;i < cloudLayers; i++){ 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 b5dca10f..ee98106f 100644 --- a/src/core/fssimulation.cpp +++ b/src/core/fssimulation.cpp @@ -1480,8 +1480,6 @@ void FsSimulation::SetEnvironment(FSENVIRONMENT env) void FsSimulation::EnforceEnvironment(void) { - fogColor.SetDoubleRGB(0.6*lightIntensity*lightColour.Rd(),0.6*lightIntensity * lightColour.Gd(), 0.6*lightIntensity * lightColour.Bd()); - //The day/night switch may be removed, as this is all being handled via day/night cycle. switch(env) { case FSDAYLIGHT: @@ -1497,7 +1495,7 @@ void FsSimulation::EnforceEnvironment(void) void FsSimulation::SendServerEnvironment(FSENVIRONMENT env){ if (netServer != NULL){ - netServer->SendEnvironment(env); + netServer->BroadcastEnvironmentUpdate(); } } @@ -1505,12 +1503,13 @@ FSENVIRONMENT FsSimulation::GetEnvironment(void) const { return env; } + //Implement the following functions: int FsSimulation::GetDayLength(void) const{ return dayLength / 60; //Convert to minutes } -double FsSimulation::GetDayCycle(void) const{ +double FsSimulation::GetDayTime(void) const{ return dayTime; } @@ -1518,8 +1517,8 @@ void FsSimulation::SetDayLength(int dayLength){ this->dayLength = dayLength*60; //Convert to seconds } -void FsSimulation::SetDayCycle(double dayCycle){ - this->dayTime = dayCycle; +void FsSimulation::SetDayTime(double dayTime){ + this->dayTime = dayTime; } YSRESULT FsSimulation::SendConfigString(const char str[]) @@ -3918,7 +3917,7 @@ void FsSimulation::SimMove(const double &dt) 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) { @@ -4665,7 +4664,7 @@ void FsSimulation::SimControlByUser(const double &dt,FSUSERCONTROL userControl) { // Skip all mouse-move events. } - + auto inFltDlg=GetCurrentInFlightDialog(); if(NULL!=inFltDlg) @@ -6440,7 +6439,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); bulletHolder.AddToParticleManager(partMan,currentTime); for(FsAirplane *seeker=nullptr; nullptr!=(seeker=FindNextAirplane(seeker)); ) @@ -6763,7 +6762,7 @@ void FsSimulation::SimDrawScreenZBufferSensitive( #endif YsColor fogColor; - fogColor.SetDoubleRGB(0.6*lightIntensity,0.6*lightIntensity,0.6*lightIntensity); + 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__); @@ -7032,16 +7031,11 @@ void FsSimulation::SimDrawBackground(const ActualViewMode &actualViewMode,const YsColor horizonColor; gnd.SetDoubleRGB(gnd.Rd()*lightIntensity,gnd.Gd()*lightIntensity,gnd.Bd()*lightIntensity); sky.SetDoubleRGB(sky.Rd()*lightIntensity,sky.Gd()*lightIntensity,sky.Bd()*lightIntensity); - switch(env) - { - case FSNIGHT: - horizonColor=YsGrayScale(lightIntensity); - gndSpecular=YSFALSE; - break; - case FSDAYLIGHT: - horizonColor=YsGrayScale(lightIntensity); - break; + horizonColor=YsGrayScale(lightIntensity); + if (env == FSNIGHT){ + gndSpecular = YSFALSE; } + if(weather->GetFog()==YSTRUE) { @@ -7089,17 +7083,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(); @@ -7305,10 +7299,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 @@ -8058,19 +8050,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: @@ -8120,6 +8117,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()) @@ -8365,10 +8366,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()) @@ -12538,7 +12539,7 @@ YSRESULT FsSimulation::LoadConfigFile(const wchar_t fn[],YSBOOL changeEnvironmen } weather->SetWind(cfgPtr->constWind); - SetDayCycle(cfgPtr->dayTime); + SetDayTime(cfgPtr->dayTime); SetDayLength(cfgPtr->dayLength); } diff --git a/src/core/fssimulation.h b/src/core/fssimulation.h index d2dc960c..97c1de0c 100644 --- a/src/core/fssimulation.h +++ b/src/core/fssimulation.h @@ -489,9 +489,9 @@ class FsSimulation : public FsHasInFlightDialog void SendServerEnvironment(FSENVIRONMENT env); FSENVIRONMENT GetEnvironment(void) const; int GetDayLength(void) const; - double GetDayCycle(void) const; + double GetDayTime(void) const; void SetDayLength(int dayLength); - void SetDayCycle(double dayCycle); + 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 445e9082..24198f00 100644 --- a/src/core/fsweather.cpp +++ b/src/core/fsweather.cpp @@ -191,13 +191,21 @@ int FsWeather::GetCloudLayerCount() const YsColor FsWeather::GetLightColour(const double dayTime) const{ YsColor lightColour = daylightColour; - if (IsDuskOrDawn(dayTime) == YSTRUE){ + 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(daylightColour.Rd(),dawnColour.Rd(),DuskIntensity(dayTime))); - lightColour.SetGd(ColourInterpolate(daylightColour.Gd(),dawnColour.Gd(),DuskIntensity(dayTime))); - lightColour.SetBd(ColourInterpolate(daylightColour.Bd(),dawnColour.Bd(),DuskIntensity(dayTime))); + 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))); } - if (IsDay(dayTime) == YSFALSE){ + else if (IsDay(dayTime) == YSFALSE){ lightColour = nightColour; } @@ -254,8 +262,11 @@ YSBOOL FsWeather::IsDuskOrDawn(const double dayTime) const{ double FsWeather::DuskIntensity(const double dayTime) const{ //Scale the dusk intensity. Dusk is between sin(dayTime+YsPi/2) = 0.2 and -0.2. - //return sin(dayTime+YsPi/2)*5+0.5; - return abs(sin(dayTime+YsPi/2))*5; + double lightIntensity = abs(sin(dayTime+YsPi/2))*5; + if (lightIntensity<=0.1){ + lightIntensity = 0.1; + } + return lightIntensity; }; @@ -298,7 +309,6 @@ YsArray FsWeather::GetDayTimeHours(double dayTime) const{ 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); - printf("Hours: %d, Minutes: %d, Seconds: %d\n", hours, minutes, seconds); YsArray time; time.Append(hours); time.Append(minutes); diff --git a/src/core/fsworld.cpp b/src/core/fsworld.cpp index 890136bb..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()); @@ -3893,7 +3906,7 @@ YSRESULT FsWorld::SetDayTime(double t) { if(NULL!=sim) { - sim->SetDayCycle(t); + sim->SetDayTime(t); return YSERR; } return YSOK; From a25232725a2a747d2bb221d9f96e377c7b18ab8a Mon Sep 17 00:00:00 2001 From: Skipper Date: Fri, 8 Sep 2023 22:44:13 +0100 Subject: [PATCH 5/8] * Remade cloud movements * Test implementation of Wasp's sunset formula --- .github/workflows/action.yml | 1 - src/core/fscloud.cpp | 150 +++++++++----------- src/core/fscloud.h | 11 +- src/core/fssimulation.cpp | 7 +- src/core/fsweather.cpp | 43 ++++++ src/core/fsweather.h | 3 + src/graphics/gl/fsopengl.cpp | 1 - src/graphics/gl2.0/fsgroundskygl2.0.cpp | 174 +++++++++++------------- 8 files changed, 205 insertions(+), 185 deletions(-) delete mode 100644 .github/workflows/action.yml 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/src/core/fscloud.cpp b/src/core/fscloud.cpp index 8f4ac86a..73d28e52 100644 --- a/src/core/fscloud.cpp +++ b/src/core/fscloud.cpp @@ -10,6 +10,9 @@ #include "fsdef.h" #include "graphics/common/fsopengl.h" #include "fscloud.h" +#include "fsvisual.h" +#include +#include @@ -672,9 +675,8 @@ static double sphere_e2_nom[]= 0.176784,0.942245,-0.284469 }; -FsSolidCloud::FsSolidCloud() : ltc(1) +FsSolidCloud::FsSolidCloud() { - ltc.DisablePolygonToCellHashTable(); CreateGraphicCache(); } @@ -691,6 +693,11 @@ void FsSolidCloud::Initialize(void) } const YsShell &FsSolidCloud::GetShell(void) const +{ + return shl.Conv(); +} + +FsVisualSrf &FsSolidCloud::GetSrf(void) { return shl; } @@ -703,6 +710,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 +722,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 +736,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 +757,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,6 +1069,16 @@ 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, double lightIntensity,const class FsWeather &weather, @@ -1123,7 +1107,7 @@ 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; @@ -1146,7 +1130,9 @@ void FsSolidClouds::Draw( for(int i=0; iDraw(env,weather); + FsVisualSrf srf; + srf = toDraw[i]->GetSrf(); + srf.Draw(*&viewMdlTfm,*&projTfm,toDraw[i]->cen, *&YsAtt3(0.0,0,0), FSVISUAL_DRAWTRANSPARENT); } EndDrawCloud(); diff --git a/src/core/fscloud.h b/src/core/fscloud.h index 790139ca..257a6d84 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,6 +103,7 @@ 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); @@ -136,7 +138,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/fssimulation.cpp b/src/core/fssimulation.cpp index ee98106f..a156fb31 100644 --- a/src/core/fssimulation.cpp +++ b/src/core/fssimulation.cpp @@ -3904,6 +3904,7 @@ void FsSimulation::SimMove(const double &dt) 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. @@ -3917,6 +3918,8 @@ void FsSimulation::SimMove(const double &dt) lightColour = weather->GetLightColour(dayTime); lightIntensity = weather->GetLightIntensity(dayTime); weather->SetSunPosition(lightPositionVector,dayTime); + double randomNoise = weather->perlinNoise(1,1,1); + printf("Random Noise: %f\n",randomNoise); fogColor.SetDoubleRGB(0.6*lightIntensity*lightColour.Rd(),0.6*lightIntensity * lightColour.Gd(), 0.6*lightIntensity * lightColour.Bd()); airplane=NULL; while((airplane=FindNextAirplane(airplane))!=NULL) @@ -6834,7 +6837,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 @@ -12530,7 +12533,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++) diff --git a/src/core/fsweather.cpp b/src/core/fsweather.cpp index 24198f00..a8192013 100644 --- a/src/core/fsweather.cpp +++ b/src/core/fsweather.cpp @@ -5,6 +5,8 @@ #include #include #include +#include +#include #include @@ -316,6 +318,47 @@ YsArray FsWeather::GetDayTimeHours(double dayTime) const{ return time; }; +double FsWeather::perlinNoise(double x, double y, int seed) const{ + std::default_random_engine generator(seed); + + std::vector p(256); + + for (int i= 0; i < 256; ++i) { + p[i] = i; + } + + 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; + +} + + + //Save cloud functions - to review whether these continue to be used with new clouds in future. YSRESULT FsWeather::Save(FILE *fp) const diff --git a/src/core/fsweather.h b/src/core/fsweather.h index 6f927d59..170b87b5 100644 --- a/src/core/fsweather.h +++ b/src/core/fsweather.h @@ -77,6 +77,9 @@ class FsWeather FSENVIRONMENT GetDayTime(double& daytime, double dt, int dayLength) const; void SetSunPosition(YsVec3& lightPosition, double dayTime) const; YsArray GetDayTimeHours(double dayTime) const; + + double perlinNoise(double x, double y, int seed) const; + }; diff --git a/src/graphics/gl/fsopengl.cpp b/src/graphics/gl/fsopengl.cpp index cd1668d5..543e1707 100644 --- a/src/graphics/gl/fsopengl.cpp +++ b/src/graphics/gl/fsopengl.cpp @@ -369,7 +369,6 @@ void FsSetDirectionalLight(const YsVec3 &cameraPosition,const YsVec3 &lightDirec void FsSetDirectionalLight(const YsVec3 &/*cameraPosition*/, const YsVec3 &lightDirection, FSENVIRONMENT env, const YsColor &lightColor, const double &lightLevel){ float light[4]; -//TODO - Need to apply the light level and colour here to DAYLIGHT. #ifdef YSOGLERRORCHECK FsOpenGlShowError("FsSetDirectionalLight In"); #endif diff --git a/src/graphics/gl2.0/fsgroundskygl2.0.cpp b/src/graphics/gl2.0/fsgroundskygl2.0.cpp index c28fb04f..6e465b92 100644 --- a/src/graphics/gl2.0/fsgroundskygl2.0.cpp +++ b/src/graphics/gl2.0/fsgroundskygl2.0.cpp @@ -136,10 +136,16 @@ void FsGroundSky::DrawByFog( 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 +153,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); @@ -165,42 +172,38 @@ void FsGroundSky::DrawByFog( } 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 +212,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 +257,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); } From 0b58b604d0e4e7c4fbfb67b1e4fc6ed91549c5b4 Mon Sep 17 00:00:00 2001 From: Skipper Date: Fri, 8 Sep 2023 23:11:59 +0100 Subject: [PATCH 6/8] Fixing some linux bugs --- src/core/fscloud.cpp | 3 ++- src/core/fsweather.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/fscloud.cpp b/src/core/fscloud.cpp index 73d28e52..31fc1554 100644 --- a/src/core/fscloud.cpp +++ b/src/core/fscloud.cpp @@ -1131,8 +1131,9 @@ void FsSolidClouds::Draw( for(int i=0; iGetSrf(); - srf.Draw(*&viewMdlTfm,*&projTfm,toDraw[i]->cen, *&YsAtt3(0.0,0,0), FSVISUAL_DRAWTRANSPARENT); + srf.Draw(*&viewMdlTfm,*&projTfm,toDraw[i]->cen, *&atti, FSVISUAL_DRAWTRANSPARENT); } EndDrawCloud(); diff --git a/src/core/fsweather.cpp b/src/core/fsweather.cpp index a8192013..dc106c4f 100644 --- a/src/core/fsweather.cpp +++ b/src/core/fsweather.cpp @@ -327,7 +327,7 @@ double FsWeather::perlinNoise(double x, double y, int seed) const{ p[i] = i; } - shuffle(p.begin(), p.end(), generator); + std::shuffle(p.begin(), p.end(), generator); double noise = 0.0; double fade = 1.0; From cee3097940a805390a6bc6647678f623631c6971 Mon Sep 17 00:00:00 2001 From: Skipper Date: Sat, 9 Sep 2023 08:49:34 +0100 Subject: [PATCH 7/8] Including algorithm for perlin --- src/core/fsweather.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/fsweather.cpp b/src/core/fsweather.cpp index dc106c4f..01ccc176 100644 --- a/src/core/fsweather.cpp +++ b/src/core/fsweather.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include From 42ca154dbbc1c9a15a304250a847e19a9e74ab4b Mon Sep 17 00:00:00 2001 From: Skipper Date: Sat, 7 Oct 2023 20:19:19 +0100 Subject: [PATCH 8/8] progress on moon etc, currently not functioning! --- runtime/misc/moon.srf | 132 ++++++++++++++++++++++++ runtime/misc/sun.srf | 117 +++++++++++++++++++++ src/core/fscloud.cpp | 67 ++++++++++-- src/core/fscloud.h | 3 +- src/core/fsgroundsky.h | 6 +- src/core/fssimulation.cpp | 8 +- src/core/fssimulation.h | 1 + src/core/fsweather.cpp | 63 ++--------- src/core/fsweather.h | 2 - src/core/sun.cpp | 68 ++++++++++++ src/graphics/gl/fsgroundskygl.cpp | 2 +- src/graphics/gl2.0/CMakeLists.txt | 1 + src/graphics/gl2.0/fsgroundskygl2.0.cpp | 70 +++++++++++-- src/graphics/gl2.0/fssunsetcolour.cpp | 9 ++ src/graphics/gl2.0/fssunsetcolour.h | 58 +++++++++++ src/graphics/null/fsgroundskynownd.cpp | 2 +- 16 files changed, 530 insertions(+), 79 deletions(-) create mode 100644 runtime/misc/moon.srf create mode 100644 runtime/misc/sun.srf create mode 100644 src/core/sun.cpp create mode 100644 src/graphics/gl2.0/fssunsetcolour.cpp create mode 100644 src/graphics/gl2.0/fssunsetcolour.h 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/core/fscloud.cpp b/src/core/fscloud.cpp index 31fc1554..7e35ebf5 100644 --- a/src/core/fscloud.cpp +++ b/src/core/fscloud.cpp @@ -3,6 +3,9 @@ #include #include #include +#include +#include +#include #include @@ -814,12 +817,12 @@ void FsSolidCloud::Move(const YsVec3 &wind){ //Moves each cloud by wind * delta YsMatrix4x4 mat; mat.Translate(wind); shl.SetMatrix(mat); - for(auto &p : particle){ - p.pos += wind; - if (p.pos.y() < 0){ - p.pos.SetY(cen.y()); - } - } + // for(auto &p : particle){ + // p.pos += wind; + // if (p.pos.y() < 0){ + // p.pos.SetY(cen.y()); + // } + // } } void FsSolidClouds::MakeOpenGlList(void) @@ -1082,7 +1085,7 @@ void FsSolidClouds::Move(const double dv, const YsVec3 &wind) void FsSolidClouds::AddToParticleManager( class YsGLParticleManager &partMan, double lightIntensity,const class FsWeather &weather, - const YsVec3 &viewDir,const YsMatrix4x4 &viewMdlTfm,const double &nearZ,const double &farZ,const double &tanFov) + const YsVec3 &viewDir,const YsMatrix4x4 &viewMdlTfm,const double &nearZ,const double &farZ,const double &tanFov,const YsVec3 &viewPoint) { const double baseBrightness=lightIntensity*.75; @@ -1099,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); } } } @@ -1114,6 +1117,14 @@ void FsSolidClouds::Draw( 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) @@ -1139,3 +1150,43 @@ void FsSolidClouds::Draw( 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 257a6d84..a18615a0 100644 --- a/src/core/fscloud.h +++ b/src/core/fscloud.h @@ -107,6 +107,7 @@ friend class FsSolidCloudGraphicCache; YSBOOL IsInCloud(const YsVec3 &pos) const; void ScatterParticle(int nParticle); + double perlinNoise(double x, double y, int seed); }; class FsSolidClouds @@ -129,7 +130,7 @@ class FsSolidClouds void AddToParticleManager( class YsGLParticleManager &partMan, double lightIntensity,const class FsWeather &weather, - const YsVec3 &viewDir,const YsMatrix4x4 &viewMdlTfm,const double &nearZ,const double &farZ,const double &tanFov); + const YsVec3 &viewDir,const YsMatrix4x4 &viewMdlTfm,const double &nearZ,const double &farZ,const double &tanFov,const YsVec3 &viewPoint); void MakeOpenGlList(void); 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/fssimulation.cpp b/src/core/fssimulation.cpp index a156fb31..49d968b8 100644 --- a/src/core/fssimulation.cpp +++ b/src/core/fssimulation.cpp @@ -2334,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); } } } @@ -3918,8 +3918,6 @@ void FsSimulation::SimMove(const double &dt) lightColour = weather->GetLightColour(dayTime); lightIntensity = weather->GetLightIntensity(dayTime); weather->SetSunPosition(lightPositionVector,dayTime); - double randomNoise = weather->perlinNoise(1,1,1); - printf("Random Noise: %f\n",randomNoise); fogColor.SetDoubleRGB(0.6*lightIntensity*lightColour.Rd(),0.6*lightIntensity * lightColour.Gd(), 0.6*lightIntensity * lightColour.Bd()); airplane=NULL; while((airplane=FindNextAirplane(airplane))!=NULL) @@ -6442,7 +6440,7 @@ void FsSimulation::SimDrawScreen( particleStore.AddToParticleManager(partMan); if(YSTRUE==cfgPtr->useParticle) { - solidCloud->AddToParticleManager(partMan,lightIntensity,*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)); ) @@ -7042,7 +7040,7 @@ void FsSimulation::SimDrawBackground(const ActualViewMode &actualViewMode,const 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) { diff --git a/src/core/fssimulation.h b/src/core/fssimulation.h index 97c1de0c..e4b25cfc 100644 --- a/src/core/fssimulation.h +++ b/src/core/fssimulation.h @@ -294,6 +294,7 @@ class FsSimulation : public FsHasInFlightDialog 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; diff --git a/src/core/fsweather.cpp b/src/core/fsweather.cpp index 01ccc176..d7e40f08 100644 --- a/src/core/fsweather.cpp +++ b/src/core/fsweather.cpp @@ -5,9 +5,7 @@ #include #include #include -#include -#include -#include + #include @@ -231,12 +229,16 @@ YsColor FsWeather::GetLightColour(YsColor skyColour, const double dayTime) const double FsWeather::GetLightIntensity(const double dayTime) const{ double lightIntensity = 1.0; - if (IsDuskOrDawn(dayTime) == YSTRUE){ //Then it's dusk/dawn - lightIntensity = DuskIntensity(dayTime); - } - if (IsDay(dayTime) == YSFALSE){ + 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; }; @@ -292,14 +294,9 @@ FSENVIRONMENT FsWeather::GetDayTime(double& daytime, double dt, int dayLength) c }; void FsWeather::SetSunPosition(YsVec3& lightPosition, double dayTime) const{ - if (IsDay(dayTime) == YSTRUE){ + // if (IsDay(dayTime) == YSTRUE){ lightPosition.SetX(cos(dayTime+YsPi/2)); - lightPosition.SetY(abs(sin(dayTime+YsPi/2))); - } - else{ - lightPosition.SetX(-cos(dayTime+YsPi/2)); - lightPosition.SetY(abs(sin(dayTime+YsPi/2))); - } + lightPosition.SetY((sin(dayTime+YsPi/2))); }; YsArray FsWeather::GetDayTimeHours(double dayTime) const{ @@ -319,44 +316,6 @@ YsArray FsWeather::GetDayTimeHours(double dayTime) const{ return time; }; -double FsWeather::perlinNoise(double x, double y, int seed) const{ - 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/fsweather.h b/src/core/fsweather.h index 170b87b5..66a789bd 100644 --- a/src/core/fsweather.h +++ b/src/core/fsweather.h @@ -78,8 +78,6 @@ class FsWeather void SetSunPosition(YsVec3& lightPosition, double dayTime) const; YsArray GetDayTimeHours(double dayTime) const; - double perlinNoise(double x, double y, int seed) const; - }; 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; ivtxBuf.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.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); @@ -523,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/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) { }