How to simulate morning,noon,afternoon,night on NeL?

Added by wangxuan2730 almost 4 years ago

Recently, I'm working on the NeL about the Light. And I want to simulate morning,noon,afternoon,night. But I have no idea to do it, I don't know where to start it.

Is there someone have done this? Or someone could give some guidance about the Light operation. And I think I need some principle about this work!

My mind is : write a time class which is used to control the rate of the change,  and the variable of the light changes according to the game_time.

At first , thanks for your reading.


Replies (4)

RE: How to simulate morning,noon,afternoon,night on NeL? - Added by kervala almost 4 years ago

You can check code/ryzom/client/src/light_cycle_manager.cpp for that :) That's the class which implements light colors depending on game time :)

For more control on weather, you can also check all weather*.cpp files.

RE: How to simulate morning,noon,afternoon,night on NeL? - Added by wangxuan2730 almost 4 years ago

Thanks for your information so quickly!

RE: How to simulate morning,noon,afternoon,night on NeL? - Added by wangxuan2730 almost 4 years ago

hi ~~~

I have read the light_cycle_manager, and I have written my own class on it(My demo doesn't have landscape,it's just used for some shapes).in the light_cycle_manager.cpp ,It has many params,
where is the config file?
I don't know how to set these param.

RE: How to simulate morning,noon,afternoon,night on NeL? - Added by wangxuan2730 almost 4 years ago

Hi kervala!

namespace MYCLIENT{
//Description of the hours for days/night
struct CLightCycleDesc{
float RealDayLength; // real length of the day(seconds)
float NumHours; //number of game hours in a day
float NightTransitionStartHour; //start of night transition
float NightTransitionEndHour; //End of night transition
float DuskRatio; //ratio for dusk transition. e.g. when set to 0.5f, that means that the dusk colors are taken when the day->night transition is at its half
float DawnTransitionStartHour; //start of day transition
float DawnTransitionEndHour; //end of day transition
uint MaxNumColorSteps; //the max number of color steps
CLightCycleDesc()
{
RealDayLength = 300;
NumHours = 24;
NightTransitionStartHour = 19;
NightTransitionEndHour = 21;
DuskRatio = 0.5;
DawnTransitionStartHour = 5;
DawnTransitionEndHour = 7;
MaxNumColorSteps = 128;
}
float getNightTransitionLength() const;  //get the hours between the start and the end
float getDawnTransitionLength() const;
};

class CLightManager {
public:
enum TLightState{Day = 0, Night, DayToNight, NightToDay, StateUnknown};
public:
CLightManager();

/** Set the description of the light cycle
  * This also reset the hour to 0
  * \param desc description of lighting intervals
  * \return true If the desc was valid (not overlapping transitions..)
*/
bool setLightDesc(const CLightCycleDesc &desc);
const CLightCycleDesc &getLightDesc() const {return _Desc;};
/** Set the current hour for your game, and change the color if necessary
  * The caller can provide an additional lighting color if he want
*/
void setHour(float hour);
float getHour() const {return _Hour;};
// Get the last computed light level in a call to setHour(0 for day,1 for night)
float getLightLevel() const {return _LightLevel;};
//Return a string to describe the current state(day,night....)
std::string getStateString() const;
//Return an enum that describ the current state
TLightState getState() const {
return _State;
}
//To tells if a day->night or night->day transition is currently occuring
bool isInTransition() const;
//Get the light level at the given hour
float getLightLevel(float hour) const;

//////////////////////////////////////////////////////////////////////////////////////////////
public:
float _Hour;
bool _ValidDesc;
NLMISC::CRGBA _LastDiffuse,_LastAmbient;
CLightCycleDesc _Desc;
float _LightLevel;
TLightState _State;
TLightState _PrevState;
public:
//to know the given hour is in which state
static bool isInInterval(float start, float end, float value);
static bool isInDayInterval(float startHour, float endHour, float dayDuration, float hour, float &ratio);
// set the directional light
void setDirLight(const CDirLightSetup &setup0, const CDirLightSetup &setup1, float level, float intensity, NL3D::UScene &scene);
//Setup light for canopy or main scene
void setupDayToNightLight(NL3D::UScene &scene, const CDirLightSetup &daylight, const CDirLightSetup &duskLight, const CDirLightSetup &nightLight, float lightIntensity);
//update the state which the hour is in which interval
void updateState();
};
}

this is my class on light_cycle_manager.cpp, But it doesn't work well. Need I write a time class ? I don't know how to control it!!!

MYCLIENT::CLightManager LightManager;
CLightCycleDesc desc;
LightManager.setHour(5);
LightManager.setLightDesc(desc);
CDirLightSetup daylight(CRGBA(255,255,255),CRGBA(255,255,255),CRGBA(255,255,255),CVector(0,0,0));
CDirLightSetup dusklight(CRGBA(0,20,0),CRGBA(50,100,150),CRGBA(0,0,0),CVector(0,0,-20));
CDirLightSetup nightlight(CRGBA(0,0,0),CRGBA(0,0,0),CRGBA(0,0,0),CVector(0,0,0));
LightManager.setDirLight(daylight,dusklight,0,255,*Scene);
LightManager.setupDayToNightLight(*Scene,daylight,dusklight,nightlight,30);
Driver->enableLight(0,true);
It doesn't work!

(1-4/4)