Guest User

Untitled

a guest
Jul 17th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. // SkyBox.hpp
  2.  
  3. class SkyBox
  4. {
  5. public:
  6. SkyBox(const wchar_t *cubeMapFilePath);
  7. ~SkyBox();
  8. XMFLOAT4X4 const &GetWorldMatrix() const;
  9. Model const &GetModel() const;
  10. void SetRotation(XMFLOAT3 const &rotation);
  11. static Model CreateSkyBox(const wchar_t *cubeMapFilePath); // static member function called from constructor
  12. private:
  13. Model mModel; // the member with no def-ctor
  14. XMFLOAT3 mRotation;
  15. mutable XMFLOAT4X4 mWorldMatrix;
  16. mutable bool mDirtyFlag = true;
  17. };
  18.  
  19.  
  20. // SkyBox.cpp
  21.  
  22. #include "SkyBox.h"
  23.  
  24. SkyBox::SkyBox(const wchar_t *cubeMapFilePath) : mModel(CreateSkyBox(cubeMapFilePath)), mRotation(0.0f, 0.0f, 0.0f)
  25. {
  26. }
  27.  
  28. SkyBox::~SkyBox()
  29. {
  30. }
  31.  
  32. Model SkyBox::CreateSkyBox(const wchar_t *cubeMapFilePath)
  33. {
  34. Mesh mesh;
  35. std::vector<XMFLOAT3> positions;
  36. positions.push_back(XMFLOAT3(-0.5f, 0.5f, -0.5f));
  37. positions.push_back(XMFLOAT3(0.5f, 0.5f, -0.5f));
  38. positions.push_back(XMFLOAT3(0.5f, -0.5f, -0.5f));
  39. positions.push_back(XMFLOAT3(-0.5f, -0.5f, -0.5f));
  40. positions.push_back(XMFLOAT3(-0.5f, 0.5f, 0.5f));
  41. positions.push_back(XMFLOAT3(0.5f, 0.5f, 0.5f));
  42. positions.push_back(XMFLOAT3(0.5f, -0.5f, 0.5f));
  43. positions.push_back(XMFLOAT3(-0.5f, -0.5f, 0.5f));
  44.  
  45. std::vector<unsigned int> indices{ 0, 1, 3, 3, 1, 2, 5, 4, 6, 6, 4, 7, 4, 0, 7, 7, 0, 3, 1, 5, 2, 2, 5, 6, 4, 5, 0, 0, 5, 1, 3, 2, 7, 7, 2, 6 };
  46.  
  47. mesh.LoadAttribute("POSITION", &positions[0], positions.size());
  48. mesh.LoadIndexBuffer(indices);
  49.  
  50. std::vector<Texture> cubeMap;
  51. Texture texture(Texture::CUBE_MAP);
  52. texture.LoadCubeMap(cubeMapFilePath);
  53. cubeMap.push_back(texture);
  54.  
  55. Material material = {};
  56.  
  57. return Model(mesh, cubeMap, material);
  58. }
  59.  
  60. // .... other members
Add Comment
Please, Sign In to add comment