Esempio n. 1
0
 /// <summary>
 /// Ticks the region, including all primary calculations and lighting updates.
 /// </summary>
 public void TickWorld(double delta)
 {
     rTicks++;
     if (rTicks >= CVars.r_shadowpace.ValueI)
     {
         Vector3i playerChunkPos = TheRegion.ChunkLocFor(Player.GetPosition());
         if (playerChunkPos != SunChunkPos) // TODO: Or sun/planet angle changed!
         {
             SunChunkPos = playerChunkPos;
             Location corPos = (SunChunkPos.ToLocation() * Constants.CHUNK_WIDTH) + new Location(Constants.CHUNK_WIDTH * 0.5);
             TheSun.Direction = Utilities.ForwardVector_Deg(SunAngle.Yaw, SunAngle.Pitch);
             TheSun.Reposition(corPos - TheSun.Direction * 30 * 6);
             TheSunClouds.Direction = TheSun.Direction;
             TheSunClouds.Reposition(TheSun.EyePos);
             PlanetDir           = Utilities.ForwardVector_Deg(PlanetAngle.Yaw, PlanetAngle.Pitch);
             ThePlanet.Direction = PlanetDir;
             ThePlanet.Reposition(corPos - ThePlanet.Direction * 30 * 6);
             Vector3 tsd = TheSun.Direction.ToBVector();
             Vector3 tpd = PlanetDir.ToBVector();
             Quaternion.GetQuaternionBetweenNormalizedVectors(ref tsd, ref tpd, out Quaternion diff);
             PlanetSunDist = (float)Quaternion.GetAngleFromQuaternion(ref diff) / (float)Utilities.PI180;
             if (PlanetSunDist < 75)
             {
                 TheSun.InternalLights[0].color = new OpenTK.Vector3((float)Math.Min(SunLightDef.X * (PlanetSunDist / 15), 1),
                                                                     (float)Math.Min(SunLightDef.Y * (PlanetSunDist / 20), 1), (float)Math.Min(SunLightDef.Z * (PlanetSunDist / 60), 1));
                 TheSunClouds.InternalLights[0].color = new OpenTK.Vector3((float)Math.Min(CloudSunLightDef.X * (PlanetSunDist / 15), 1),
                                                                           (float)Math.Min(CloudSunLightDef.Y * (PlanetSunDist / 20), 1), (float)Math.Min(CloudSunLightDef.Z * (PlanetSunDist / 60), 1));
                 //ThePlanet.InternalLights[0].color = new OpenTK.Vector3(0, 0, 0);
             }
             else
             {
                 TheSun.InternalLights[0].color       = ClientUtilities.Convert(SunLightDef);
                 TheSunClouds.InternalLights[0].color = ClientUtilities.Convert(CloudSunLightDef);
                 //ThePlanet.InternalLights[0].color = ClientUtilities.Convert(PlanetLightDef * Math.Min((PlanetSunDist / 180f), 1f));
             }
             PlanetLight = PlanetSunDist / 180f;
             if (SunAngle.Pitch < 10 && SunAngle.Pitch > -30)
             {
                 float rel = 30 + (float)SunAngle.Pitch;
                 if (rel == 0)
                 {
                     rel = 0.00001f;
                 }
                 rel = 1f - (rel / 40f);
                 rel = Math.Max(Math.Min(rel, 1f), 0f);
                 float rel2 = Math.Max(Math.Min(rel * 1.5f, 1f), 0f);
                 TheSun.InternalLights[0].color       = new OpenTK.Vector3(TheSun.InternalLights[0].color.X * rel2, TheSun.InternalLights[0].color.Y * rel, TheSun.InternalLights[0].color.Z * rel);
                 TheSunClouds.InternalLights[0].color = new OpenTK.Vector3(TheSunClouds.InternalLights[0].color.X * rel2, TheSunClouds.InternalLights[0].color.Y * rel, TheSunClouds.InternalLights[0].color.Z * rel);
                 MainWorldView.DesaturationAmount     = (1f - rel) * 0.75f;
                 MainWorldView.ambient = BaseAmbient * ((1f - rel) * 0.5f + 0.5f);
                 sl_min   = 0.2f - (1f - rel) * (0.2f - 0.05f);
                 sl_max   = 0.8f - (1f - rel) * (0.8f - 0.15f);
                 SkyColor = SkyApproxColDefault * rel;
             }
             else if (SunAngle.Pitch >= 10)
             {
                 TheSun.InternalLights[0].color       = new OpenTK.Vector3(0, 0, 0);
                 TheSunClouds.InternalLights[0].color = new OpenTK.Vector3(0, 0, 0);
                 MainWorldView.DesaturationAmount     = 0.75f;
                 MainWorldView.ambient = BaseAmbient * 0.5f;
                 sl_min   = 0.05f;
                 sl_max   = 0.15f;
                 SkyColor = Location.Zero;
             }
             else
             {
                 sl_min = 0.2f;
                 sl_max = 0.8f;
                 MainWorldView.DesaturationAmount     = 0f;
                 MainWorldView.ambient                = BaseAmbient;
                 TheSun.InternalLights[0].color       = ClientUtilities.Convert(SunLightDef);
                 TheSunClouds.InternalLights[0].color = ClientUtilities.Convert(CloudSunLightDef);
                 SkyColor = SkyApproxColDefault;
             }
             shouldRedrawShadows = true;
         }
         rTicks = 0;
     }
     TheRegion.TickWorld(delta);
 }
Esempio n. 2
0
 public void TickWorld(double delta)
 {
     rTicks++;
     if (rTicks >= CVars.r_shadowpace.ValueI)
     {
         // TODO: Z+ -> max view rad + 30
         TheSun.Direction = Utilities.ForwardVector_Deg(SunAngle.Yaw, SunAngle.Pitch);
         TheSun.Reposition(Player.GetPosition().GetBlockLocation() - TheSun.Direction * 30 * 6);
         TheSunClouds.Direction = TheSun.Direction;
         TheSunClouds.Reposition(TheSun.EyePos);
         PlanetDir           = Utilities.ForwardVector_Deg(PlanetAngle.Yaw, PlanetAngle.Pitch);
         ThePlanet.Direction = PlanetDir;
         TheSunClouds.Reposition(Player.GetPosition().GetBlockLocation() - ThePlanet.Direction * 30 * 6);
         Quaternion diff;
         Vector3    tsd = TheSun.Direction.ToBVector();
         Vector3    tpd = PlanetDir.ToBVector();
         Quaternion.GetQuaternionBetweenNormalizedVectors(ref tsd, ref tpd, out diff);
         PlanetSunDist = (float)Quaternion.GetAngleFromQuaternion(ref diff) / (float)Utilities.PI180;
         if (PlanetSunDist < 75)
         {
             TheSun.InternalLights[0].color = new OpenTK.Vector3((float)Math.Min(SunLightDef.X * (PlanetSunDist / 15), 1),
                                                                 (float)Math.Min(SunLightDef.Y * (PlanetSunDist / 20), 1), (float)Math.Min(SunLightDef.Z * (PlanetSunDist / 60), 1));
             TheSunClouds.InternalLights[0].color = new OpenTK.Vector3((float)Math.Min(CloudSunLightDef.X * (PlanetSunDist / 15), 1),
                                                                       (float)Math.Min(CloudSunLightDef.Y * (PlanetSunDist / 20), 1), (float)Math.Min(CloudSunLightDef.Z * (PlanetSunDist / 60), 1));
             ThePlanet.InternalLights[0].color = new OpenTK.Vector3(0, 0, 0);
         }
         else
         {
             TheSun.InternalLights[0].color       = ClientUtilities.Convert(SunLightDef);
             TheSunClouds.InternalLights[0].color = ClientUtilities.Convert(CloudSunLightDef);
             ThePlanet.InternalLights[0].color    = ClientUtilities.Convert(PlanetLightDef * Math.Min((PlanetSunDist / 180f), 1f));
         }
         PlanetLight = PlanetSunDist / 180f;
         if (SunAngle.Pitch < 10 && SunAngle.Pitch > -30)
         {
             float rel = 30 + (float)SunAngle.Pitch;
             if (rel == 0)
             {
                 rel = 0.00001f;
             }
             rel = 1f - (rel / 40f);
             rel = Math.Max(Math.Min(rel, 1f), 0f);
             float rel2 = Math.Max(Math.Min(rel * 1.5f, 1f), 0f);
             TheSun.InternalLights[0].color       = new OpenTK.Vector3(TheSun.InternalLights[0].color.X * rel2, TheSun.InternalLights[0].color.Y * rel, TheSun.InternalLights[0].color.Z * rel);
             TheSunClouds.InternalLights[0].color = new OpenTK.Vector3(TheSunClouds.InternalLights[0].color.X * rel2, TheSunClouds.InternalLights[0].color.Y * rel, TheSunClouds.InternalLights[0].color.Z * rel);
             MainWorldView.DesaturationAmount     = (1f - rel) * 0.75f;
             MainWorldView.ambient = BaseAmbient * ((1f - rel) * 0.5f + 0.5f);
             sl_min = 0.2f - (1f - rel) * (0.2f - 0.05f);
             sl_max = 0.8f - (1f - rel) * (0.8f - 0.15f);
         }
         else if (SunAngle.Pitch >= 10)
         {
             TheSun.InternalLights[0].color       = new OpenTK.Vector3(0, 0, 0);
             TheSunClouds.InternalLights[0].color = new OpenTK.Vector3(0, 0, 0);
             MainWorldView.DesaturationAmount     = 0.75f;
             MainWorldView.ambient = BaseAmbient * 0.5f;
             sl_min = 0.05f;
             sl_max = 0.15f;
         }
         else
         {
             sl_min = 0.2f;
             sl_max = 0.8f;
             MainWorldView.DesaturationAmount     = 0f;
             MainWorldView.ambient                = BaseAmbient;
             TheSun.InternalLights[0].color       = ClientUtilities.Convert(SunLightDef);
             TheSunClouds.InternalLights[0].color = ClientUtilities.Convert(CloudSunLightDef);
         }
         rTicks = 0;
         shouldRedrawShadows = true;
     }
     TheRegion.TickWorld(delta);
 }