public void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime) { // Adjust dome position so the bottom edge is not visible Vector3 ViewerXNAPosition = new Vector3(Viewer.Camera.Location.X, Viewer.Camera.Location.Y - 100, -Viewer.Camera.Location.Z); Matrix XNASkyWorldLocation = Matrix.CreateTranslation(ViewerXNAPosition); if (worldLoc == null) { // First time around, initialize the following items: worldLoc = new WorldLatLon(); skySteps.OldClockTime = Viewer.Simulator.ClockTime % 86400; while (skySteps.OldClockTime < 0) { skySteps.OldClockTime += 86400; } skySteps.Step1 = skySteps.Step2 = (int)(skySteps.OldClockTime / 1200); skySteps.Step2 = skySteps.Step2 < skySteps.MaxSteps - 1 ? skySteps.Step2 + 1 : 0; // limit to max. steps in case activity starts near midnight // Get the current latitude and longitude coordinates worldLoc.ConvertWTC(Viewer.Camera.TileX, Viewer.Camera.TileZ, Viewer.Camera.Location, ref latitude, ref longitude); if (seasonType != (int)Viewer.Simulator.Season) { seasonType = (int)Viewer.Simulator.Season; date.ordinalDate = latitude >= 0 ? 82 + seasonType * 91 : (82 + (seasonType + 2) * 91) % 365; // TODO: Set the following three externally from ORTS route files (future) date.month = 1 + date.ordinalDate / 30; date.day = 21; date.year = 2017; } // Fill in the sun- and moon-position lookup tables for (int i = 0; i < skySteps.MaxSteps; i++) { solarPosArray[i] = SunMoonPos.SolarAngle(latitude, longitude, ((float)i / skySteps.MaxSteps), date); lunarPosArray[i] = SunMoonPos.LunarAngle(latitude, longitude, ((float)i / skySteps.MaxSteps), date); } // Phase of the moon is generated at random moonPhase = Viewer.Random.Next(8); if (moonPhase == 6 && date.ordinalDate > 45 && date.ordinalDate < 330) { moonPhase = 3; // Moon dog only occurs in winter } } skySteps.SetSunAndMoonDirection(ref solarDirection, ref lunarDirection, ref solarPosArray, ref lunarPosArray, Viewer.Simulator.ClockTime); frame.AddPrimitive(Material, Primitive, RenderPrimitiveGroup.Sky, ref XNASkyWorldLocation); }
public void LoadPrep() { mstsskyworldLoc = new WorldLatLon(); // Get the current latitude and longitude coordinates mstsskyworldLoc.ConvertWTC(MSTSSkyViewer.Camera.TileX, MSTSSkyViewer.Camera.TileZ, MSTSSkyViewer.Camera.Location, ref mstsskylatitude, ref mstsskylongitude); mstsskyseasonType = (int)MSTSSkyViewer.Simulator.Season; date.ordinalDate = mstsskylatitude >= 0 ? 82 + mstsskyseasonType * 91 : (82 + (mstsskyseasonType + 2) * 91) % 365; date.month = 1 + date.ordinalDate / 30; date.day = 21; date.year = 2017; float fractClockTime = (float)MSTSSkyViewer.Simulator.ClockTime / 86400; mstsskysolarDirection = SunMoonPos.SolarAngle(mstsskylatitude, mstsskylongitude, fractClockTime, date); mstsskyworldLoc = null; mstsskylatitude = 0; mstsskylongitude = 0; }
public void LoadPrep() { worldLoc = new WorldLatLon(); // Get the current latitude and longitude coordinates worldLoc.ConvertWTC(Viewer.Camera.TileX, Viewer.Camera.TileZ, Viewer.Camera.Location, ref latitude, ref longitude); seasonType = (int)Viewer.Simulator.Season; date.ordinalDate = latitude >= 0 ? 82 + seasonType * 91 : (82 + (seasonType + 2) * 91) % 365; date.month = 1 + date.ordinalDate / 30; date.day = 21; date.year = 2017; float fractClockTime = (float)Viewer.Simulator.ClockTime / 86400; solarDirection = SunMoonPos.SolarAngle(latitude, longitude, fractClockTime, date); worldLoc = null; latitude = 0; longitude = 0; }
/// <summary> /// Used to update information affecting the SkyMesh /// </summary> public void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime) { // Adjust dome position so the bottom edge is not visible Vector3 ViewerXNAPosition = new Vector3(MSTSSkyViewer.Camera.Location.X, MSTSSkyViewer.Camera.Location.Y - 100, -MSTSSkyViewer.Camera.Location.Z); Matrix XNASkyWorldLocation = Matrix.CreateTranslation(ViewerXNAPosition); if (mstsskyworldLoc == null) { // First time around, initialize the following items: mstsskyworldLoc = new WorldLatLon(); mstsskyoldClockTime = MSTSSkyViewer.Simulator.ClockTime % 86400; while (mstsskyoldClockTime < 0) { mstsskyoldClockTime += 86400; } step1 = step2 = (int)(mstsskyoldClockTime / 1200); step2 = step2 < maxSteps - 1 ? step2 + 1 : 0; // limit to max. steps in case activity starts near midnight // Get the current latitude and longitude coordinates mstsskyworldLoc.ConvertWTC(MSTSSkyViewer.Camera.TileX, MSTSSkyViewer.Camera.TileZ, MSTSSkyViewer.Camera.Location, ref mstsskylatitude, ref mstsskylongitude); if (mstsskyseasonType != (int)MSTSSkyViewer.Simulator.Season) { mstsskyseasonType = (int)MSTSSkyViewer.Simulator.Season; date.ordinalDate = mstsskylatitude >= 0 ? 82 + mstsskyseasonType * 91 : (82 + (mstsskyseasonType + 2) * 91) % 365; // TODO: Set the following three externally from ORTS route files (future) date.month = 1 + date.ordinalDate / 30; date.day = 21; date.year = 2017; } // Fill in the sun- and moon-position lookup tables for (int i = 0; i < maxSteps; i++) { mstsskysolarPosArray[i] = SunMoonPos.SolarAngle(mstsskylatitude, mstsskylongitude, ((float)i / maxSteps), date); mstsskylunarPosArray[i] = SunMoonPos.LunarAngle(mstsskylatitude, mstsskylongitude, ((float)i / maxSteps), date); } // Phase of the moon is generated at random mstsskymoonPhase = Viewer.Random.Next(8); if (mstsskymoonPhase == 6 && date.ordinalDate > 45 && date.ordinalDate < 330) { mstsskymoonPhase = 3; // Moon dog only occurs in winter } // Overcast factor: 0.0=almost no clouds; 0.1=wispy clouds; 1.0=total overcast //mstsskyovercastFactor = MSTSSkyViewer.World.WeatherControl.overcastFactor; mstsskyfogDistance = MSTSSkyViewer.Simulator.Weather.FogDistance; } MPManager manager = MPManager.Instance(); if (MPManager.IsClient() && manager.weatherChanged) { //received message about weather change if (manager.overcastFactor >= 0) { mstsskyovercastFactor = manager.overcastFactor; } //received message about weather change if (manager.fogDistance > 0) { mstsskyfogDistance = manager.fogDistance; } if (manager.overcastFactor >= 0 || manager.fogDistance > 0) { manager.weatherChanged = false; manager.overcastFactor = -1; manager.fogDistance = -1; } } ////////////////////// T E M P O R A R Y /////////////////////////// // The following keyboard commands are used for viewing sky and weather effects in "demo" mode. // Control- and Control+ for overcast, Shift- and Shift+ for fog and - and + for time. // Don't let multiplayer clients adjust the weather. if (!MPManager.IsClient()) { // Overcast ranges from 0 (completely clear) to 1 (completely overcast). if (UserInput.IsDown(UserCommand.DebugOvercastIncrease)) { mstsskyovercastFactor = MathHelper.Clamp(mstsskyovercastFactor + elapsedTime.RealSeconds / 10, 0, 1); } if (UserInput.IsDown(UserCommand.DebugOvercastDecrease)) { mstsskyovercastFactor = MathHelper.Clamp(mstsskyovercastFactor - elapsedTime.RealSeconds / 10, 0, 1); } // Fog ranges from 10m (can't see anything) to 100km (clear arctic conditions). if (UserInput.IsDown(UserCommand.DebugFogIncrease)) { mstsskyfogDistance = MathHelper.Clamp(mstsskyfogDistance - elapsedTime.RealSeconds * mstsskyfogDistance, 10, 100000); } if (UserInput.IsDown(UserCommand.DebugFogDecrease)) { mstsskyfogDistance = MathHelper.Clamp(mstsskyfogDistance + elapsedTime.RealSeconds * mstsskyfogDistance, 10, 100000); } } // Don't let clock shift if multiplayer. if (!MPManager.IsMultiPlayer()) { // Shift the clock forwards or backwards at 1h-per-second. if (UserInput.IsDown(UserCommand.DebugClockForwards)) { MSTSSkyViewer.Simulator.ClockTime += elapsedTime.RealSeconds * 3600; } if (UserInput.IsDown(UserCommand.DebugClockBackwards)) { MSTSSkyViewer.Simulator.ClockTime -= elapsedTime.RealSeconds * 3600; } } // Server needs to notify clients of weather changes. if (MPManager.IsServer()) { if (UserInput.IsReleased(UserCommand.DebugOvercastIncrease) || UserInput.IsReleased(UserCommand.DebugOvercastDecrease) || UserInput.IsReleased(UserCommand.DebugFogIncrease) || UserInput.IsReleased(UserCommand.DebugFogDecrease)) { manager.SetEnvInfo(mstsskyovercastFactor, mstsskyfogDistance); MPManager.Notify(new MSGWeather(-1, mstsskyovercastFactor, -1, mstsskyfogDistance).ToString()); } } //////////////////////////////////////////////////////////////////// // Current solar and lunar position are calculated by interpolation in the lookup arrays. // Using the Lerp() function, so need to calculate the in-between differential float diff = (float)(MSTSSkyViewer.Simulator.ClockTime - mstsskyoldClockTime) / 1200; // The rest of this increments/decrements the array indices and checks for overshoot/undershoot. if (MSTSSkyViewer.Simulator.ClockTime >= (mstsskyoldClockTime + 1200)) // Plus key, or normal forward in time { step1++; step2++; mstsskyoldClockTime = MSTSSkyViewer.Simulator.ClockTime; diff = 0; if (step2 >= maxSteps) // Midnight. { step2 = 0; } if (step1 >= maxSteps) // Midnight. { step1 = 0; } } if (MSTSSkyViewer.Simulator.ClockTime <= (mstsskyoldClockTime - 1200)) // Minus key { step1--; step2--; mstsskyoldClockTime = MSTSSkyViewer.Simulator.ClockTime; diff = 0; if (step1 < 0) // Midnight. { step1 = maxSteps - 1; } if (step2 < 0) // Midnight. { step2 = maxSteps - 1; } } mstsskysolarDirection.X = MathHelper.Lerp(mstsskysolarPosArray[step1].X, mstsskysolarPosArray[step2].X, diff); mstsskysolarDirection.Y = MathHelper.Lerp(mstsskysolarPosArray[step1].Y, mstsskysolarPosArray[step2].Y, diff); mstsskysolarDirection.Z = MathHelper.Lerp(mstsskysolarPosArray[step1].Z, mstsskysolarPosArray[step2].Z, diff); mstsskylunarDirection.X = MathHelper.Lerp(mstsskylunarPosArray[step1].X, mstsskylunarPosArray[step2].X, diff); mstsskylunarDirection.Y = MathHelper.Lerp(mstsskylunarPosArray[step1].Y, mstsskylunarPosArray[step2].Y, diff); mstsskylunarDirection.Z = MathHelper.Lerp(mstsskylunarPosArray[step1].Z, mstsskylunarPosArray[step2].Z, diff); frame.AddPrimitive(MSTSSkyMaterial, MSTSSkyMesh, RenderPrimitiveGroup.Sky, ref XNASkyWorldLocation); }
/// <summary> /// Constructor /// </summary> /// <param name="xLowerLeft">Lower left x-value where to print the location in pixels</param> /// <param name="yLowerLeft">Lower left y-value where to print the location in pixels</param> public DrawLongitudeLatitude(int xLowerLeft, int yLowerLeft) { worldLoc = new WorldLatLon(); lowerLeft = new Vector2(xLowerLeft, yLowerLeft); }
public void PrepareFrame(RenderFrame frame, ElapsedTime elapsedTime) { // Adjust dome position so the bottom edge is not visible Vector3 ViewerXNAPosition = new Vector3(Viewer.Camera.Location.X, Viewer.Camera.Location.Y - 100, -Viewer.Camera.Location.Z); Matrix XNASkyWorldLocation = Matrix.CreateTranslation(ViewerXNAPosition); if (worldLoc == null) { // First time around, initialize the following items: worldLoc = new WorldLatLon(); oldClockTime = Viewer.Simulator.ClockTime % 86400; while (oldClockTime < 0) { oldClockTime += 86400; } step1 = step2 = (int)(oldClockTime / 1200); step2 = step2 < maxSteps - 1 ? step2 + 1 : 0; // limit to max. steps in case activity starts near midnight // Get the current latitude and longitude coordinates worldLoc.ConvertWTC(Viewer.Camera.TileX, Viewer.Camera.TileZ, Viewer.Camera.Location, ref latitude, ref longitude); if (seasonType != (int)Viewer.Simulator.Season) { seasonType = (int)Viewer.Simulator.Season; date.ordinalDate = latitude >= 0 ? 82 + seasonType * 91 : (82 + (seasonType + 2) * 91) % 365; // TODO: Set the following three externally from ORTS route files (future) date.month = 1 + date.ordinalDate / 30; date.day = 21; date.year = 2017; } // Fill in the sun- and moon-position lookup tables for (int i = 0; i < maxSteps; i++) { solarPosArray[i] = SunMoonPos.SolarAngle(latitude, longitude, ((float)i / maxSteps), date); lunarPosArray[i] = SunMoonPos.LunarAngle(latitude, longitude, ((float)i / maxSteps), date); } // Phase of the moon is generated at random moonPhase = Viewer.Random.Next(8); if (moonPhase == 6 && date.ordinalDate > 45 && date.ordinalDate < 330) { moonPhase = 3; // Moon dog only occurs in winter } } // Current solar and lunar position are calculated by interpolation in the lookup arrays. // The arrays have intervals of 1200 secs or 20 mins. // Using the Lerp() function, so need to calculate the in-between differential float diff = GetCelestialDiff(); // The rest of this increments/decrements the array indices and checks for overshoot/undershoot. while (Viewer.Simulator.ClockTime >= (oldClockTime + 1200)) // Plus key, or normal forward in time; <CSComment> better so in case of fast forward { oldClockTime = oldClockTime + 1200; diff = GetCelestialDiff(); step1++; step2++; if (step2 >= maxSteps) // Midnight. { step2 = 0; } if (step1 >= maxSteps) // Midnight. { step1 = 0; } } if (Viewer.Simulator.ClockTime <= (oldClockTime - 1200)) // Minus key { oldClockTime = Viewer.Simulator.ClockTime; diff = 0; step1--; step2--; if (step1 < 0) // Midnight. { step1 = maxSteps - 1; } if (step2 < 0) // Midnight. { step2 = maxSteps - 1; } } solarDirection.X = MathHelper.Lerp(solarPosArray[step1].X, solarPosArray[step2].X, diff); solarDirection.Y = MathHelper.Lerp(solarPosArray[step1].Y, solarPosArray[step2].Y, diff); solarDirection.Z = MathHelper.Lerp(solarPosArray[step1].Z, solarPosArray[step2].Z, diff); lunarDirection.X = MathHelper.Lerp(lunarPosArray[step1].X, lunarPosArray[step2].X, diff); lunarDirection.Y = MathHelper.Lerp(lunarPosArray[step1].Y, lunarPosArray[step2].Y, diff); lunarDirection.Z = MathHelper.Lerp(lunarPosArray[step1].Z, lunarPosArray[step2].Z, diff); frame.AddPrimitive(Material, Primitive, RenderPrimitiveGroup.Sky, ref XNASkyWorldLocation); }