a few more changes on sun position
							parent
							
								
									13ed40d9f6
								
							
						
					
					
						commit
						c6fcc33e49
					
				|  | @ -1240,20 +1240,20 @@ namespace OpenSim.Framework | |||
|             moonrot = Quaternion.Identity; | ||||
| 
 | ||||
|             List<DayCycle.TrackEntry> track = null; | ||||
|             if(altitude < Altitudes[0]) | ||||
|             if (altitude < Altitudes[0]) | ||||
|                 track = Cycle.skyTrack0; | ||||
|             else | ||||
|             { | ||||
|                 int altindx = 2; | ||||
|                 for(;altindx > 0; --altindx) | ||||
|                 for (; altindx > 0; --altindx) | ||||
|                 { | ||||
|                     if(Altitudes[altindx] < altitude) | ||||
|                     if (Altitudes[altindx] < altitude) | ||||
|                         break; | ||||
|                 } | ||||
| 
 | ||||
|                 while(altindx >= 0) | ||||
|                 while (altindx >= 0) | ||||
|                 { | ||||
|                     switch(altindx) | ||||
|                     switch (altindx) | ||||
|                     { | ||||
|                         case 2: | ||||
|                             track = Cycle.skyTrack3; | ||||
|  | @ -1265,24 +1265,194 @@ namespace OpenSim.Framework | |||
|                             track = Cycle.skyTrack1; | ||||
|                             break; | ||||
|                     } | ||||
|                     if(track != null) | ||||
|                     if (track != null) | ||||
|                         break; | ||||
|                     --altindx; | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             if(track == null || track.Count == 0) | ||||
|             if (track == null || track.Count == 0) | ||||
|                 return false; | ||||
| 
 | ||||
|             if(track.Count == 1) | ||||
|             if (track.Count == 1 || track[0].time < 0) | ||||
|             { | ||||
|                 if(!Cycle.skyframes.TryGetValue(track[0].frameName, out SkyData sky) || sky == null) | ||||
|                 if (!Cycle.skyframes.TryGetValue(track[0].frameName, out SkyData sky) || sky == null) | ||||
|                     return false; | ||||
|                 moonrot = sky.moon_rotation; | ||||
|                 moondir = Xrot(moonrot); | ||||
|                 sunrot = sky.sun_rotation; | ||||
|                 sundir = Xrot(sunrot); | ||||
|                 return true; | ||||
|             } | ||||
|             int i = 0; | ||||
|             while (i < track.Count) | ||||
|             { | ||||
|                 if (track[i].time > dayfrac) | ||||
|                     break; | ||||
|                 ++i; | ||||
|             } | ||||
| 
 | ||||
|             float firstFrac; | ||||
|             float secondFrac; | ||||
|             string first; | ||||
|             string second; | ||||
|             int ntracks = track.Count; | ||||
|             if (i == 0 || i == ntracks) | ||||
|             { | ||||
|                 --ntracks; | ||||
|                 firstFrac = track[ntracks].time; | ||||
|                 secondFrac = track[0].time + 1f; | ||||
|                 first = track[ntracks].frameName; | ||||
|                 second = track[0].frameName; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 secondFrac = track[i].time; | ||||
|                 second = track[i].frameName; | ||||
|                 --i; | ||||
|                 firstFrac = track[i].time; | ||||
|                 first = track[i].frameName; | ||||
|             } | ||||
| 
 | ||||
|             if (!Cycle.skyframes.TryGetValue(first, out SkyData sky1) || sky1 == null) | ||||
|                 firstFrac = -1; | ||||
|             if (!Cycle.skyframes.TryGetValue(second, out SkyData sky2) || sky2 == null) | ||||
|                 secondFrac = -1; | ||||
| 
 | ||||
|             if (firstFrac < 0) | ||||
|             { | ||||
|                 if (secondFrac < 0) | ||||
|                     return false; | ||||
|                 moonrot = sky2.moon_rotation; | ||||
|                 moondir = Xrot(moonrot); | ||||
|                 sunrot = sky2.sun_rotation; | ||||
|                 sundir = Xrot(sunrot); | ||||
|                 return true; | ||||
|             } | ||||
|             if (secondFrac < 0 || secondFrac == firstFrac) | ||||
|             { | ||||
|                 moonrot = sky1.moon_rotation; | ||||
|                 moondir = Xrot(moonrot); | ||||
|                 sunrot = sky1.sun_rotation; | ||||
|                 sundir = Xrot(sunrot); | ||||
|                 return true; | ||||
|             } | ||||
| 
 | ||||
|             dayfrac -= firstFrac; | ||||
|             secondFrac -= firstFrac; | ||||
|             dayfrac /= secondFrac; | ||||
| 
 | ||||
|             moonrot = Quaternion.Slerp(sky1.moon_rotation, sky2.moon_rotation, dayfrac); | ||||
|             moondir = Xrot(moonrot); | ||||
| 
 | ||||
|             sunrot = Quaternion.Slerp(sky1.sun_rotation, sky2.sun_rotation, dayfrac); | ||||
|             sundir = Xrot(sunrot); | ||||
|             return true; | ||||
|         } | ||||
|         public bool getWLPositions(float altitude, float dayfrac, out Vector3 sundir) | ||||
|         { | ||||
|             sundir = Vector3.Zero; | ||||
| 
 | ||||
|             List<DayCycle.TrackEntry> track = null; | ||||
|             if (altitude < Altitudes[0]) | ||||
|                 track = Cycle.skyTrack0; | ||||
|             else | ||||
|             { | ||||
|                 int altindx = 2; | ||||
|                 for (; altindx > 0; --altindx) | ||||
|                 { | ||||
|                     if (Altitudes[altindx] < altitude) | ||||
|                         break; | ||||
|                 } | ||||
| 
 | ||||
|                 while (altindx >= 0) | ||||
|                 { | ||||
|                     switch (altindx) | ||||
|                     { | ||||
|                         case 2: | ||||
|                             track = Cycle.skyTrack3; | ||||
|                             break; | ||||
|                         case 1: | ||||
|                             track = Cycle.skyTrack2; | ||||
|                             break; | ||||
|                         case 0: | ||||
|                             track = Cycle.skyTrack1; | ||||
|                             break; | ||||
|                     } | ||||
|                     if (track != null) | ||||
|                         break; | ||||
|                     --altindx; | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             if (track == null || track.Count == 0) | ||||
|                 return false; | ||||
| 
 | ||||
|             Quaternion sunrot; | ||||
|             if (track.Count == 1 || track[0].time < 0) | ||||
|             { | ||||
|                 if (!Cycle.skyframes.TryGetValue(track[0].frameName, out SkyData sky) || sky == null) | ||||
|                     return false; | ||||
|                 sunrot = sky.sun_rotation; | ||||
|                 sundir = Xrot(sunrot); | ||||
|                 return true; | ||||
|             } | ||||
|             int i = 0; | ||||
|             while (i < track.Count) | ||||
|             { | ||||
|                 if (track[i].time > dayfrac) | ||||
|                     break; | ||||
|                 ++i; | ||||
|             } | ||||
| 
 | ||||
|             float firstFrac; | ||||
|             float secondFrac; | ||||
|             string first; | ||||
|             string second; | ||||
|             int ntracks = track.Count; | ||||
|             if (i == 0 || i == ntracks) | ||||
|             { | ||||
|                 --ntracks; | ||||
|                 firstFrac = track[ntracks].time; | ||||
|                 secondFrac = track[0].time + 1f; | ||||
|                 first = track[ntracks].frameName; | ||||
|                 second = track[0].frameName; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 secondFrac = track[i].time; | ||||
|                 second = track[i].frameName; | ||||
|                 --i; | ||||
|                 firstFrac = track[i].time; | ||||
|                 first = track[i].frameName; | ||||
|             } | ||||
| 
 | ||||
|             if (!Cycle.skyframes.TryGetValue(first, out SkyData sky1) || sky1 == null) | ||||
|                 firstFrac = -1; | ||||
|             if (!Cycle.skyframes.TryGetValue(second, out SkyData sky2) || sky2 == null) | ||||
|                 secondFrac = -1; | ||||
| 
 | ||||
|             if (firstFrac < 0) | ||||
|             { | ||||
|                 if (secondFrac < 0) | ||||
|                     return false; | ||||
|                 sunrot = sky2.sun_rotation; | ||||
|                 sundir = Xrot(sunrot); | ||||
|                 return true; | ||||
|             } | ||||
|             if (secondFrac < 0 || secondFrac == firstFrac) | ||||
|             { | ||||
|                 sunrot = sky1.sun_rotation; | ||||
|                 sundir = Xrot(sunrot); | ||||
|                 return true; | ||||
|             } | ||||
| 
 | ||||
|             dayfrac -= firstFrac; | ||||
|             secondFrac -= firstFrac; | ||||
|             dayfrac /= secondFrac; | ||||
| 
 | ||||
|             sunrot = Quaternion.Slerp(sky1.sun_rotation, sky2.sun_rotation, dayfrac); | ||||
|             sundir = Xrot(sunrot); | ||||
|             return true; | ||||
|         } | ||||
|     } | ||||
|  |  | |||
|  | @ -144,7 +144,7 @@ namespace OpenSim.Region.CoreModules.World.LightShare | |||
|                 return; | ||||
|             } | ||||
| 
 | ||||
|             if(m_DefaultEnv == null) | ||||
|             if (m_DefaultEnv == null) | ||||
|             { | ||||
|                 AssetBase defEnv = m_assetService.Get(m_defaultDayAssetID); | ||||
|                 if(defEnv != null) | ||||
|  | @ -163,6 +163,8 @@ namespace OpenSim.Region.CoreModules.World.LightShare | |||
|                     } | ||||
|                 } | ||||
|             } | ||||
|             if (m_DefaultEnv == null) | ||||
|                 m_DefaultEnv = new ViewerEnviroment(); | ||||
| 
 | ||||
|             string senv = scene.SimulationDataService.LoadRegionEnvironmentSettings(scene.RegionInfo.RegionID); | ||||
|             if(!string.IsNullOrEmpty(senv)) | ||||
|  | @ -385,7 +387,7 @@ namespace OpenSim.Region.CoreModules.World.LightShare | |||
| 
 | ||||
|             ViewerEnviroment VEnv = m_scene.RegionEnviroment; | ||||
|             if (VEnv == null) | ||||
|                 VEnv = m_DefaultEnv == null ? new ViewerEnviroment() : m_DefaultEnv; | ||||
|                 VEnv = m_DefaultEnv; | ||||
| 
 | ||||
|             OSDMap map = new OpenMetaverse.StructuredData.OSDMap(); | ||||
|             map["environment"] = VEnv.ToOSD(); | ||||
|  | @ -453,7 +455,16 @@ namespace OpenSim.Region.CoreModules.World.LightShare | |||
|                         { | ||||
|                             ViewerEnviroment VEnv = m_scene.RegionEnviroment; | ||||
|                             if (VEnv == null) | ||||
|                             { | ||||
|                                 VEnv = new ViewerEnviroment(); | ||||
|                                 if (m_DefaultEnv != null) | ||||
|                                 { | ||||
|                                     OSD otmp = m_DefaultEnv.ToOSD(); | ||||
|                                     byte[] btmp = OSDParser.SerializeLLSDXmlToBytes(otmp); | ||||
|                                     otmp = OSDParser.DeserializeLLSDXml(btmp); | ||||
|                                     VEnv.FromOSD(otmp); | ||||
|                                 } | ||||
|                             } | ||||
|                             OSDMap evmap = (OSDMap)env; | ||||
|                             if(evmap.TryGetValue("day_asset", out OSD tmp) && !evmap.ContainsKey("day_cycle")) | ||||
|                             { | ||||
|  | @ -539,16 +550,12 @@ namespace OpenSim.Region.CoreModules.World.LightShare | |||
|             // m_log.DebugFormat("[{0}]: Environment GET handle for agentID {1} in region {2}", | ||||
|             //      Name, agentID, caps.RegionName); | ||||
| 
 | ||||
|             string env = String.Empty; | ||||
|             ViewerEnviroment VEnv = m_scene.RegionEnviroment; | ||||
|             if (VEnv == null) | ||||
|                 VEnv = m_DefaultEnv; | ||||
| 
 | ||||
|             if (VEnv != null) | ||||
|             { | ||||
|                 OSD d = VEnv.ToWLOSD(UUID.Zero, regionID); | ||||
|                 env = OSDParser.SerializeLLSDXmlString(d); | ||||
|             } | ||||
|   | ||||
|             OSD d = VEnv.ToWLOSD(UUID.Zero, regionID); | ||||
|             string env = OSDParser.SerializeLLSDXmlString(d); | ||||
| 
 | ||||
|             if (String.IsNullOrEmpty(env)) | ||||
|             { | ||||
|  | @ -760,16 +767,9 @@ namespace OpenSim.Region.CoreModules.World.LightShare | |||
|             ViewerEnviroment env = m_scene.RegionEnviroment; | ||||
|             if(env == null) | ||||
|                 env = m_DefaultEnv; | ||||
|             if(env == null) | ||||
|             { | ||||
|                 m_dayOffset = 57600f; | ||||
|                 m_dayOffset = 14400f; | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 m_dayOffset = env.DayOffset; | ||||
|                 m_dayLen = env.DayLength; | ||||
|             } | ||||
| 
 | ||||
|             m_dayOffset = env.DayOffset; | ||||
|             m_dayLen = env.DayLength; | ||||
| 
 | ||||
|             m_currentTime = Util.UnixTimeSinceEpoch() + m_dayOffset; | ||||
|             float dayFrac = (m_currentTime % m_dayLen) / m_dayLen; | ||||
|  | @ -777,31 +777,45 @@ namespace OpenSim.Region.CoreModules.World.LightShare | |||
| 
 | ||||
|             m_sunAngle = Utils.TWO_PI * dayFrac; | ||||
| 
 | ||||
|             bool r = env.getPositions(0, dayFrac, out m_sunDir, out Vector3 moondir, out m_sunVel, | ||||
|                 out Quaternion sunrot, out Quaternion moonrot); | ||||
| 
 | ||||
|             ++m_frame; | ||||
|             if(m_frame % 50 == 0) | ||||
|                 UpdateClientsSunTime(); | ||||
|                 UpdateClientsSunTime(env, dayFrac); | ||||
|         } | ||||
| 
 | ||||
|         private void UpdateClientsSunTime() | ||||
|         private void UpdateClientsSunTime(ViewerEnviroment env, float dayFrac) | ||||
|         { | ||||
|             m_scene.ForEachClient(delegate (IClientAPI client) | ||||
|             float wldayFrac = dayFrac; | ||||
|             if (wldayFrac < 0.25f) | ||||
|                 wldayFrac += 1.5f; | ||||
|             else if (wldayFrac > 0.75) | ||||
|                 wldayFrac += 0.5f; | ||||
|             else if (wldayFrac > 0.33) | ||||
|                 wldayFrac = 3 * wldayFrac - 1; | ||||
|             else | ||||
|                 wldayFrac = 3 * wldayFrac + 1; | ||||
| 
 | ||||
|             wldayFrac = Utils.Clamp(wldayFrac, 0, 2); | ||||
|             wldayFrac *= Utils.PI; | ||||
| 
 | ||||
|             m_scene.ForEachRootScenePresence(delegate (ScenePresence sp) | ||||
|             { | ||||
|                 if (!client.IsActive) | ||||
|                 if(sp.IsDeleted || sp.IsInTransit || sp.IsNPC) | ||||
|                     return; | ||||
| 
 | ||||
|                 /* | ||||
|                 IClientAPI client = sp.ControllingClient; | ||||
|                 uint vflags = client.GetViewerCaps(); | ||||
| 
 | ||||
|                 if ((vflags & 0x8000) != 0) | ||||
|                     m_estateModule.HandleRegionInfoRequest(client); | ||||
|                 { | ||||
|                     client.SendSunPos(Vector3.Zero, Vector3.Zero, m_sunAngle); | ||||
|                     return; | ||||
|                 } | ||||
| 
 | ||||
|                 else if ((vflags & 0x4000) != 0) | ||||
|                     m_eventQueue.WindlightRefreshEvent(interpolate, client.AgentId); | ||||
|                 */ | ||||
|                 client.SendSunPos(m_sunDir, m_sunVel, m_sunAngle); | ||||
|                 float z = sp.AbsolutePosition.Z; | ||||
|                 if (z < 0) | ||||
|                     z = 0; | ||||
|                 env.getWLPositions(z, dayFrac, out m_sunDir); | ||||
|                 client.SendSunPos(m_sunDir, Vector3.Zero, wldayFrac); | ||||
|             }); | ||||
|         } | ||||
|     } | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	 UbitUmarov
						UbitUmarov