PageRenderTime 175ms CodeModel.GetById 169ms app.highlight 2ms RepoModel.GetById 2ms app.codeStats 0ms

/Rendering/Models/Sky.cs

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