Difference between revisions of "LlGetSunDirection"

From Second Life Wiki
Jump to navigation Jump to search
(Add new related function.)
 
(12 intermediate revisions by 7 users not shown)
Line 1: Line 1:
{{LSL_Function
{{LSL_Function
|func_id=177|func_sleep=0.0|func_energy=10.0
|func=llGetSunDirection|return_type=vector
|func=llGetSunDirection|return_type=vector
|func_footnote=The sun position can be dynamic or static depending upon the wishes of the sim owner.
|func_desc=Returns a normalized vector to the current sun position at the location of object containing the script. [[llGetSunDirection]] is the vector to the parcel's sun, [[llGetRegionSunDirection]] is the vector to region's sun. If there is no custom environment set for the current parcel [[llGetSunDirection]] returns the direction to the region's sun. These functions are altitude aware.
|func_desc
 
|return_text=that is the direction of the sun in the region
|spec
|caveats
|constants
|examples
|helpers
|also_functions=
|also_functions=
{{LSL DefineRow||[[llGetTimeOfDay]]|}}
{{LSL DefineRow||[[llGetEnvironment]]}} Newer function that consolidates many environment-based settings.
|also_events
{{LSL DefineRow||[[llGetDayLength]]}}
|also_tests
{{LSL DefineRow||[[llGetDayOffset]]}}
|also_articles
{{LSL DefineRow||[[llGetMoonDirection]]}}
|notes=
{{LSL DefineRow||[[llGetMoonRotation]]}}
<pre>AVERAGE_SUN_TILT = -.25 * pi
{{LSL DefineRow||[[llGetSunDirection]]}}
SEASONAL_SUN_TILT = .03 * pi
{{LSL DefineRow||[[llGetSunRotation]]}}
SUN_NORMALIZED_OFFSET = .45
{{LSL DefineRow||[[llGetRegionDayLength]]}}
</pre>
{{LSL DefineRow||[[llGetRegionDayOffset]]}}
This is how mSunOffset is calculated:
{{LSL DefineRow||[[llGetRegionMoonDirection]]}}
<pre>
{{LSL DefineRow||[[llGetRegionMoonRotation]]}}
F64 daily_phase  = DAILY_OMEGA * U64_to_F64(local_time / USEC_PER_SEC);
{{LSL DefineRow||[[llGetRegionSunDirection]]}}
F32 sun_phase = (F32)fmod(daily_phase, 2.0*F_PI);
{{LSL DefineRow||[[llGetRegionSunRotation]]}}
sun_hour -= 6.f;
mSunOffset = HOURS_TO_RADIANS * sun_hour - (0.25f * F_PI) * cosf(HOURS_TO_RADIANS * sun_hour) - sun_phase;
 
And here's how sun direction is calculated:
 
void LLRegion::calculateSunInfo(
      U64 current_time,
      LLVector3& directionp,
      LLVector3& ang_velocityp,
      F32& sun_phase)
{
  U64 local_time = current_time;
  if(getSunFixed())
  {
      local_time = 0;
  }
    // Sun moves (once a day) about a circle that lies on a tilted plane.
    // The angle of the plane cycles (once a year) a few radians about
    // some average.
    // These are F64's, otherwise we get rounding errors over time
  F64 daily_phase  = DAILY_OMEGA * U64_to_F64(local_time / USEC_PER_SEC) + mSunOffset;
  F64 yearly_phase = YEARLY_OMEGA * U64_to_F64(local_time / USEC_PER_SEC);
  F32 tilt = AVERAGE_SUN_TILT + SEASONAL_SUN_TILT_AMPLITUDE * (F32)sin(yearly_phase);
 
  sun_phase = (F32)fmod(daily_phase, 2.0*F_PI);
    // move sun around a circle
  directionp.setVec((F32)cos(-daily_phase), (F32)sin(-daily_phase), 0.0f);
    //tilt the circle about X-axis (due east) 
  directionp.rotVec(tilt, 1.0f, 0.0f, 0.0f);
 
    // calculate angular velocity (radians per second)
  ang_velocityp.setVec(0.0f, 0.0f, (F32)DAILY_OMEGA);
  ang_velocityp.rotVec((F32)tilt, 1.0f, 0.0f, 0.0f);
 
    // James wanted the night to be shorter than the day.
    // We can do this by offsetting the center of the sun's orbit in the positive
    // z-direction and normalizing the new vector.
  directionp.mV[VZ] += SUN_NORMALIZED_OFFSET;
  F32 R = directionp.normVec();
 
    // We also need to correct the angular velocity
    //
    // V = W % R
    // V has constant magnitude
    // As R goes up, W must go down
    // W and R are always perpendicular
    // ===>
    // W *= 1 / |R|
  ang_velocityp *= 1.0f / R;
}
</pre>
Source: [https://lists.secondlife.com/pipermail/secondlifescripters/2007-July/001288.html Zyzzy Zarf]
|permission
|negative_index
|source
|sort=GetSunDirection
|cat1=Region
|cat2=Time
|cat3=Light
|cat4
|cat5
|cat6
}}
}}

Latest revision as of 08:47, 23 August 2022

Summary

Function: vector llGetSunDirection( );

Returns a normalized vector to the current sun position at the location of object containing the script. llGetSunDirection is the vector to the parcel's sun, llGetRegionSunDirection is the vector to region's sun. If there is no custom environment set for the current parcel llGetSunDirection returns the direction to the region's sun. These functions are altitude aware.
Returns a vector

Examples

See Also

Functions

•  llGetEnvironment Newer function that consolidates many environment-based settings.
•  llGetDayLength
•  llGetDayOffset
•  llGetMoonDirection
•  llGetMoonRotation
•  llGetSunDirection
•  llGetSunRotation
•  llGetRegionDayLength
•  llGetRegionDayOffset
•  llGetRegionMoonDirection
•  llGetRegionMoonRotation
•  llGetRegionSunDirection
•  llGetRegionSunRotation

Deep Notes

Search JIRA for related Issues

Signature

function vector llGetSunDirection();