/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
- using Delta.Rendering.Cameras;
- using Delta.Utilities.Datatypes;
-
- namespace Delta.Rendering.Models
- {
- /// <summary>
- /// Helper to render the sky dome. A model with the name "Skydome" must
- /// exist for the current project. You can set or replace the sky mesh also
- /// for different levels or different needs. The mesh will be rendered
- /// normally (at the end of the frame) and should be inside out and only
- /// using the simple and fast TexturedShader3D.
- /// Note: At 1-10 million meters away from the origin you will run into
- /// floating point errors, you should use a different rendering technique
- /// there (not the camera position). Games should be centered around the
- /// camera anyway for the best floating point precision and optimizations.
- /// </summary>
- public static class Sky
- {
- #region Draw (Static)
- /// <summary>
- /// Draw
- /// </summary>
- public static void Draw()
- {
- // Use the far plane to render at the end of the z buffer and move
- // the sky box to the camera position (always centered). Note: We want
- // to use as much as possible of the depth buffer, if you want to
- // increase the zoom range, reduce 0.99 to 0.9 for really big zoom
- // distances (1 million and more meters away) with an if condition.
- Matrix rotationMatrix = Matrix.CreateRotationZ(30); //-80);
- BaseCamera currentCam = BaseCamera.Current;
- Matrix positionMatrix = Matrix.CreateScaleAndTranslation(
- currentCam.FarPlane, currentCam.Position);
- Matrix.Multiply(ref rotationMatrix, ref positionMatrix,
- ref positionMatrix);
- SkyMesh.Draw(ref positionMatrix);
- }
- #endregion
-
- #region SkyMesh (Static)
- /// <summary>
- /// Sky mesh
- /// </summary>
- public static Mesh SkyMesh
- {
- get
- {
- if (usedSkyMesh == null)
- {
- usedSkyMesh = new Mesh("Skydome");
- }
- return usedSkyMesh;
- }
- set
- {
- usedSkyMesh = value;
- }
- }
- #endregion
-
- #region Private
-
- #region usedSkyMesh (Private)
- /// <summary>
- /// Used sky mesh
- /// </summary>
- private static Mesh usedSkyMesh;
- #endregion
-
- #endregion
- }
- }