Sky.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //-----------------------------------------------------------------------------
  2. // Sky.cs
  3. //
  4. // Microsoft XNA Community Game Platform
  5. // Copyright (C) Microsoft Corporation. All rights reserved.
  6. //-----------------------------------------------------------------------------
  7. using Microsoft.Xna.Framework;
  8. using Microsoft.Xna.Framework.Content;
  9. using Microsoft.Xna.Framework.Graphics;
  10. namespace GeneratedGeometry
  11. {
  12. /// <summary>
  13. /// Runtime class for loading and rendering a textured skydome
  14. /// that was created during the build process by the SkyProcessor.
  15. /// </summary>
  16. public class Sky
  17. {
  18. /// <summary>
  19. /// Gets or sets the skydome model.
  20. /// </summary>
  21. public Model Model;
  22. /// <summary>
  23. /// Gets or sets the texture applied to the skydome.
  24. /// </summary>
  25. public Texture2D Texture;
  26. /// <summary>
  27. /// Helper for drawing the skydome mesh with the specified view and projection matrices.
  28. /// </summary>
  29. /// <param name="view">The view matrix.</param>
  30. /// <param name="projection">The projection matrix.</param>
  31. public void Draw(Matrix view, Matrix projection)
  32. {
  33. /// <summary>
  34. /// Draws the skydome mesh with the specified view and projection matrices.
  35. /// </summary>
  36. /// <param name="view">The view matrix.</param>
  37. /// <param name="projection">The projection matrix.</param>
  38. GraphicsDevice GraphicsDevice = Texture.GraphicsDevice;
  39. GraphicsDevice.BlendState = BlendState.Opaque;
  40. GraphicsDevice.RasterizerState = RasterizerState.CullNone;
  41. GraphicsDevice.DepthStencilState = DepthStencilState.None;
  42. GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;
  43. view.Translation = Vector3.Zero;
  44. foreach (ModelMesh mesh in Model.Meshes)
  45. {
  46. foreach (BasicEffect effect in mesh.Effects)
  47. {
  48. effect.View = view;
  49. effect.Projection = projection;
  50. effect.Texture = Texture;
  51. effect.TextureEnabled = true;
  52. }
  53. mesh.Draw();
  54. }
  55. }
  56. }
  57. }