PageRenderTime 124ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/Rendering/Models/Sky.cs

#
C# | 72 lines | 42 code | 5 blank | 25 comment | 2 complexity | 9c6584b9563e711161908f0ec9cf6dda MD5 | raw file
Possible License(s): Apache-2.0
  1. using Delta.Rendering.Cameras;
  2. using Delta.Utilities.Datatypes;
  3. namespace Delta.Rendering.Models
  4. {
  5. /// <summary>
  6. /// Helper to render the sky dome. A model with the name "Skydome" must
  7. /// exist for the current project. You can set or replace the sky mesh also
  8. /// for different levels or different needs. The mesh will be rendered
  9. /// normally (at the end of the frame) and should be inside out and only
  10. /// using the simple and fast TexturedShader3D.
  11. /// Note: At 1-10 million meters away from the origin you will run into
  12. /// floating point errors, you should use a different rendering technique
  13. /// there (not the camera position). Games should be centered around the
  14. /// camera anyway for the best floating point precision and optimizations.
  15. /// </summary>
  16. public static class Sky
  17. {
  18. #region Draw (Static)
  19. /// <summary>
  20. /// Draw
  21. /// </summary>
  22. public static void Draw()
  23. {
  24. // Use the far plane to render at the end of the z buffer and move
  25. // the sky box to the camera position (always centered). Note: We want
  26. // to use as much as possible of the depth buffer, if you want to
  27. // increase the zoom range, reduce 0.99 to 0.9 for really big zoom
  28. // distances (1 million and more meters away) with an if condition.
  29. Matrix rotationMatrix = Matrix.CreateRotationZ(30); //-80);
  30. BaseCamera currentCam = BaseCamera.Current;
  31. Matrix positionMatrix = Matrix.CreateScaleAndTranslation(
  32. currentCam.FarPlane, currentCam.Position);
  33. Matrix.Multiply(ref rotationMatrix, ref positionMatrix,
  34. ref positionMatrix);
  35. SkyMesh.Draw(ref positionMatrix);
  36. }
  37. #endregion
  38. #region SkyMesh (Static)
  39. /// <summary>
  40. /// Sky mesh
  41. /// </summary>
  42. public static Mesh SkyMesh
  43. {
  44. get
  45. {
  46. if (usedSkyMesh == null)
  47. {
  48. usedSkyMesh = new Mesh("Skydome");
  49. }
  50. return usedSkyMesh;
  51. }
  52. set
  53. {
  54. usedSkyMesh = value;
  55. }
  56. }
  57. #endregion
  58. #region Private
  59. #region usedSkyMesh (Private)
  60. /// <summary>
  61. /// Used sky mesh
  62. /// </summary>
  63. private static Mesh usedSkyMesh;
  64. #endregion
  65. #endregion
  66. }
  67. }