Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // SkyBox.hpp
- class SkyBox
- {
- public:
- SkyBox(const wchar_t *cubeMapFilePath);
- ~SkyBox();
- XMFLOAT4X4 const &GetWorldMatrix() const;
- Model const &GetModel() const;
- void SetRotation(XMFLOAT3 const &rotation);
- static Model CreateSkyBox(const wchar_t *cubeMapFilePath); // static member function called from constructor
- private:
- Model mModel; // the member with no def-ctor
- XMFLOAT3 mRotation;
- mutable XMFLOAT4X4 mWorldMatrix;
- mutable bool mDirtyFlag = true;
- };
- // SkyBox.cpp
- #include "SkyBox.h"
- SkyBox::SkyBox(const wchar_t *cubeMapFilePath) : mModel(CreateSkyBox(cubeMapFilePath)), mRotation(0.0f, 0.0f, 0.0f)
- {
- }
- SkyBox::~SkyBox()
- {
- }
- Model SkyBox::CreateSkyBox(const wchar_t *cubeMapFilePath)
- {
- Mesh mesh;
- std::vector<XMFLOAT3> positions;
- positions.push_back(XMFLOAT3(-0.5f, 0.5f, -0.5f));
- positions.push_back(XMFLOAT3(0.5f, 0.5f, -0.5f));
- positions.push_back(XMFLOAT3(0.5f, -0.5f, -0.5f));
- positions.push_back(XMFLOAT3(-0.5f, -0.5f, -0.5f));
- positions.push_back(XMFLOAT3(-0.5f, 0.5f, 0.5f));
- positions.push_back(XMFLOAT3(0.5f, 0.5f, 0.5f));
- positions.push_back(XMFLOAT3(0.5f, -0.5f, 0.5f));
- positions.push_back(XMFLOAT3(-0.5f, -0.5f, 0.5f));
- 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 };
- mesh.LoadAttribute("POSITION", &positions[0], positions.size());
- mesh.LoadIndexBuffer(indices);
- std::vector<Texture> cubeMap;
- Texture texture(Texture::CUBE_MAP);
- texture.LoadCubeMap(cubeMapFilePath);
- cubeMap.push_back(texture);
- Material material = {};
- return Model(mesh, cubeMap, material);
- }
- // .... other members
Add Comment
Please, Sign In to add comment