Advertisement
Guest User

Untitled

a guest
Feb 11th, 2021
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Microsoft.Xna.Framework;
  6. using Microsoft.Xna.Framework.Graphics;
  7. using Microsoft.Xna.Framework.Content;
  8. using BootHillHeroes.Components;
  9. using BootHillHeroes.GameScreens;
  10.  
  11. namespace Skyboxes
  12. {
  13. /// <summary>
  14. /// Handles all of the aspects of working with a skybox.
  15. /// </summary>
  16. public class Skybox
  17. {
  18. /// <summary>
  19. /// The skybox model, which will just be a cube
  20. /// </summary>
  21. private Model skyBox;
  22.  
  23. /// <summary>
  24. /// The actual skybox texture
  25. /// </summary>
  26. private TextureCube skyBoxTextureCube;
  27.  
  28. /// <summary>
  29. /// The effect file that the skybox will use to render
  30. /// </summary>
  31. private Effect skyBoxEffect;
  32.  
  33. /// <summary>
  34. /// The size of the cube, used so that we can resize the box
  35. /// for different sized environments.
  36. /// </summary>
  37. private float size = 50f;
  38.  
  39.  
  40. public TextureCube SkyBoxTextureCube
  41. {
  42. get
  43. {
  44. return skyBoxTextureCube;
  45. }
  46. }
  47.  
  48. /// <summary>
  49. /// Creates a new skybox
  50. /// </summary>
  51. /// <param name="skyboxTexture">the name of the skybox texture to use</param>
  52. public Skybox()
  53. {
  54.  
  55. skyBox = DataManager.GetModel("cube3", BaseGameState.PlayerContent);
  56. skyBoxTextureCube = DataManager.GetSkybox("Sunset", BaseGameState.PlayerContent);
  57. skyBoxEffect = DataManager.GetEffect("Skybox", BaseGameState.PlayerContent);
  58. }
  59.  
  60. /// <summary>
  61. /// Does the actual drawing of the skybox with our skybox effect.
  62. /// There is no world matrix, because we're assuming the skybox won't
  63. /// be moved around. The size of the skybox can be changed with the size
  64. /// variable.
  65. /// </summary>
  66. /// <param name="view">The view matrix for the effect</param>
  67. /// <param name="projection">The projection matrix for the effect</param>
  68. /// <param name="cameraPosition">The position of the camera</param>
  69. public void Draw(Matrix view, Matrix projection, Vector3 cameraPosition)
  70. {
  71. // Go through each pass in the effect, but we know there is only one...
  72. foreach (EffectPass pass in skyBoxEffect.CurrentTechnique.Passes)
  73. {
  74. // Draw all of the components of the mesh, but we know the cube really
  75. // only has one mesh
  76. foreach (ModelMesh mesh in skyBox.Meshes)
  77. {
  78. // Assign the appropriate values to each of the parameters
  79. foreach (ModelMeshPart part in mesh.MeshParts)
  80. {
  81. part.Effect = skyBoxEffect;
  82. part.Effect.Parameters["World"].SetValue(
  83. Matrix.CreateScale(size) * Matrix.CreateTranslation(cameraPosition));
  84. part.Effect.Parameters["View"].SetValue(view);
  85. part.Effect.Parameters["Projection"].SetValue(projection);
  86. part.Effect.Parameters["SkyBoxTexture"].SetValue(SkyBoxTextureCube);
  87. part.Effect.Parameters["CameraPosition"].SetValue(cameraPosition);
  88. }
  89.  
  90. // Draw the mesh with the skybox effect
  91. mesh.Draw();
  92. }
  93. }
  94. }
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement