hey all,
sorry if in the wrong section
have come to a road block and could really do with some help, so any would be appreciated and thanks before hand.
Now how to explain this
looking at this really awesome best drawing in the world how would i go about finding a value on the green line if i supply the hour and minute of the hour?
thanks for any help
diagram.jpg (80.2 kB)
1 Like
First off I would convert your hours/minutes into a single value between 0.0 and 24.0 - you could do this using:
int Hours = 15;
int Mins = 48;
float TimeValue = (float)Hours + ((float)Mins / 60.0f );
Then you have 4 quadrants so I would divide that value by 6 to get it between 0.0 and 4.0
TimeValue /= 6.0f;
You could then do an If->Then statement to work out which quadrant it’s in.
float OutputValue;
if( TimeValue <= 1.0f )
{
// 1st Quadrant - return value between 0.5 and 1.0
OutputValue = 0.5f + ( TimeValue / 2.0f );
}
else if( TimeValue <= 2.0f )
{
// 2nd Quadrant - return value between 0.0 and 1.0
OutputValue = TimeValue - 1.0f;
}
else if( TimeValue <= 3.0f )
{
// 3rd Quadrant - return value between 0.0 and 1.0
OutputValue = TimeValue - 2.0f;
}
else
{
// 4th Quadrant - return value between 0.0 and 0.5
OutputValue = ( TimeValue - 3.0f ) / 2.0f;
}
tonemcbride:
First off I would convert your hours/minutes into a single value between 0.0 and 24.0 - you could do this using:
int Hours = 15;
int Mins = 48;
float TimeValue = (float)Hours + ((float)Mins / 60.0f );
Then you have 4 quadrants so I would divide that value by 6 to get it between 0.0 and 4.0
TimeValue /= 6.0f;
You could then do an If->Then statement to work out which quadrant it’s in.
float OutputValue;
if( TimeValue <= 1.0f )
{
// 1st Quadrant - return value between 0.5 and 1.0
OutputValue = 0.5f + ( TimeValue / 2.0f );
}
else if( TimeValue <= 2.0f )
{
// 2nd Quadrant - return value between 0.0 and 1.0
OutputValue = TimeValue - 1.0f;
}
else if( TimeValue <= 3.0f )
{
// 3rd Quadrant - return value between 0.0 and 1.0
OutputValue = TimeValue - 2.0f;
}
else
{
// 4th Quadrant - return value between 0.0 and 0.5
OutputValue = ( TimeValue - 3.0f ) / 2.0f;
}
thanks for your help much appreciated but i still seem to be any closer. i implemented that code in but i still cant get any good of it.
heres the forementioned part of the script.
public void LerpSkySetting(float h,float min)
{
float TimeValue = (float)h + ((float)min / 60.0f);
TimeValue /= 6.0f;
float OutputValue;
int hour;
int nextHour;
if (TimeValue <= 1.0f)
{
// 1st Quadrant - return value between 0.5 and 1.0
hour = 0;
nextHour = 3;
OutputValue = TimeValue - 0.5f;
}
else if (TimeValue <= 2.0f)
{
hour = 1;
nextHour = 2;
// 2nd Quadrant - return value between 0.0 and 1.0
OutputValue = TimeValue - 1.0f;
}
else if (TimeValue <= 3.0f)
{
hour = 2;
nextHour = 3;
// 3rd Quadrant - return value between 0.0 and 1.0
OutputValue = TimeValue - 2.0f;
}
else
{
hour = 3;
nextHour = 0;
// 4th Quadrant - return value between 0.0 and 0.5
OutputValue = (TimeValue - 3.0f) / 2.0f;
}
float t = OutputValue;
currentSkySettings.directionalLightColor = Color.Lerp(TODGroups[0].timeSettings[hour].directionalLightColor, TODGroups[0].timeSettings[nextHour].directionalLightColor, t );
currentSkySettings.directionalLightIntensity = Mathf.Lerp(TODGroups[0].timeSettings[hour].directionalLightIntensity,TODGroups[0].timeSettings[nextHour].directionalLightIntensity, t);
currentSkySettings.sunSize = Mathf.Lerp(TODGroups[0].timeSettings[hour].sunSize, TODGroups[0].timeSettings[hour].sunSize, t);
currentSkySettings.shadowIntensity = Mathf.Lerp(TODGroups[0].timeSettings[hour].shadowIntensity,TODGroups[0].timeSettings[nextHour].shadowIntensity, t);
currentSkySettings.ambientIntensity = Mathf.Lerp(TODGroups[0].timeSettings[hour].ambientIntensity,TODGroups[0].timeSettings[nextHour].ambientIntensity, t);
currentSkySettings.skyTint = Color.Lerp(TODGroups[0].timeSettings[hour].skyTint,TODGroups[0].timeSettings[nextHour].skyTint, t);
currentSkySettings.skyGround = Color.Lerp(TODGroups[0].timeSettings[hour].skyGround, TODGroups[0].timeSettings[nextHour].skyGround, t);
currentSkySettings.exposure = Mathf.Lerp(TODGroups[0].timeSettings[hour].exposure,TODGroups[0].timeSettings[nextHour].exposure, t);
currentSkySettings.atmosphereThickness = Mathf.Lerp(TODGroups[0].timeSettings[hour].atmosphereThickness,TODGroups[0].timeSettings[nextHour].atmosphereThickness, t);
InputSetting();
}
Trexug
September 14, 2017, 3:33pm
4
public static float Convert(int hour, int minute)
{
float q = (hour / 6f + minute / 360f + 1) % 4;
return q < 2 ? q / 2f : q % 1;
}
im not sure how to implement that trexug
i have it 90% working now the only problem now is the lerping to and from the first quadrant
public void LerpSkySetting(float h, float min)
{
float TimeValue = (float)h + ((float)min / 60.0f);
TimeValue /= 6.0f;
float OutputValue;
int hour;
int nextHour;
if (TimeValue <= 1.0f)
{
// 1st Quadrant - return value between 0.5 and 1.0
hour = 0;
nextHour = 1;
OutputValue = TimeValue - 0.5f;
}
else if (TimeValue <= 2.0f)
{
hour = 1;
nextHour = 2;
// 2nd Quadrant - return value between 0.0 and 1.0
OutputValue = TimeValue - 1.0f;
}
else if (TimeValue <= 3.0f)
{
hour = 2;
nextHour = 3;
// 3rd Quadrant - return value between 0.0 and 1.0
OutputValue = TimeValue - 2.0f;
}
else
{
hour = 3;
nextHour = 0;
// 4th Quadrant - return value between 0.0 and 0.5
OutputValue = (TimeValue - 3.0f) / 2.0f;
}
float t = OutputValue;
print(t);
currentSkySettings.directionalLightColor = Color.Lerp(TODGroups[0].timeSettings[hour].directionalLightColor, TODGroups[0].timeSettings[nextHour].directionalLightColor, t);
currentSkySettings.directionalLightIntensity = Mathf.Lerp(TODGroups[0].timeSettings[hour].directionalLightIntensity, TODGroups[0].timeSettings[nextHour].directionalLightIntensity, t);
currentSkySettings.sunSize = Mathf.Lerp(TODGroups[0].timeSettings[hour].sunSize, TODGroups[0].timeSettings[hour].sunSize, t);
currentSkySettings.shadowIntensity = Mathf.Lerp(TODGroups[0].timeSettings[hour].shadowIntensity, TODGroups[0].timeSettings[nextHour].shadowIntensity, t);
currentSkySettings.ambientIntensity = Mathf.Lerp(TODGroups[0].timeSettings[hour].ambientIntensity, TODGroups[0].timeSettings[nextHour].ambientIntensity, t);
currentSkySettings.skyTint = Color.Lerp(TODGroups[0].timeSettings[hour].skyTint, TODGroups[0].timeSettings[nextHour].skyTint, t);
currentSkySettings.skyGround = Color.Lerp(TODGroups[0].timeSettings[hour].skyGround, TODGroups[0].timeSettings[nextHour].skyGround, t);
currentSkySettings.exposure = Mathf.Lerp(TODGroups[0].timeSettings[hour].exposure, TODGroups[0].timeSettings[nextHour].exposure, t);
currentSkySettings.atmosphereThickness = Mathf.Lerp(TODGroups[0].timeSettings[hour].atmosphereThickness, TODGroups[0].timeSettings[nextHour].atmosphereThickness, t);
InputSetting();
}
Trexug
September 15, 2017, 4:19pm
6
I was suggesting just calling convert and using the returned value as your OutputValue, but it is possible that I did not quite understand the issue you are having.
public static float Convert(int hour, int minute)
{
float q = (hour / 6f + minute / 360f + 1) % 4;
return q < 2 ? q / 2f : q % 1;
}
public void LerpSkySetting(int h, int min)
{
float t = Convert(h, min);;
/// The rest of your code
}