Khaotic Engine Reborn
Loading...
Searching...
No Matches
Skybox Class Reference

Public Member Functions

 Skybox ()
 Constructor for the Skybox class. Initializes the skybox with a reference to the d_3d_class instance.
 
void Initialize (d_3d_class *d3dClassRef)
 
objectConstructSkybox (application_class *app)
 

Public Attributes

std::vector< ID3D11ShaderResourceView * > textures
 
std::vector< XMMATRIX > translations
 

Detailed Description

Definition at line 7 of file Skybox.h.

Constructor & Destructor Documentation

◆ Skybox()

Skybox::Skybox ( )

Constructor for the Skybox class. Initializes the skybox with a reference to the d_3d_class instance.

Definition at line 3 of file Skybox.cpp.

4{
5}

◆ ~Skybox()

Skybox::~Skybox ( )

Definition at line 7 of file Skybox.cpp.

8{
9 for (auto& texture : textures)
10 {
11 if (texture)
12 {
13 texture->Release();
14 texture = nullptr;
15 }
16 }
17 textures.clear();
18 translations.clear();
19}

Member Function Documentation

◆ ConstructSkybox()

object * Skybox::ConstructSkybox ( application_class * app)

Create the skybox object.

Parameters
app
Returns
Pointer to the created skybox object.

Definition at line 26 of file Skybox.cpp.

27{
28 Logger::Get().Log("Construct skybox", __FILE__, __LINE__, Logger::LogLevel::Initialize);
29
30 char modelFilename[128];
31 strcpy_s(modelFilename, "assets/Model/OBJ/skysphere.obj");
32
33 std::vector<std::wstring> skyboxTextures = {
34 L"assets/Skybox/skybox.png",
35 };
36
37 TextureContainer SkyboxTextures;
38
39 // Load the textures
40 for (const auto& textureFilename : skyboxTextures)
41 {
42 ID3D11ShaderResourceView* texture = nullptr;
43 HRESULT result = DirectX::CreateWICTextureFromFile(m_d3dClassRef->get_device(), m_d3dClassRef->get_device_context(), textureFilename.c_str(), nullptr, &texture);
44 if (FAILED(result))
45 {
46 Logger::Get().Log("Failed to load texture: " + std::string(textureFilename.begin(), textureFilename.end()), __FILE__, __LINE__, Logger::LogLevel::Error);
47 return nullptr;
48 }
49 SkyboxTextures.diffuse.push_back(texture);
50
51 }
52
53 // Create the model object
54 m_Skybox = new object(*app);
55 HRESULT result = m_Skybox->Initialize(m_d3dClassRef->get_device(), m_d3dClassRef->get_device_context(), modelFilename, SkyboxTextures);
56 if (!result)
57 {
58 Logger::Get().Log("Could not initialize the skybox model object", __FILE__, __LINE__, Logger::LogLevel::Error);
59 delete m_Skybox;
60 return nullptr;
61 }
62 m_Skybox->SetTranslateMatrix(XMMatrixTranslation(0.0f, 0.0f, 0.0f)); // Set the initial translation of the skybox
63 m_Skybox->SetActiveShader(ShaderType::SKYBOX);
64
65 return m_Skybox; // Return the constructed skybox object
66}
static Logger & Get()
Definition Logger.h:20
void Log(const std::string &message, const std::string &fileName, int lineNumber, LogLevel level=LogLevel::Info)
Definition Logger.h:158
ID3D11Device * get_device()
Gets the Direct3D device.
ID3D11DeviceContext * get_device_context()
Gets the Direct3D device context.

◆ Initialize()

void Skybox::Initialize ( d_3d_class * d3dClassRef)

Initializes the Skybox with the given d_3d_class reference.

Parameters
d3dClassRef

Definition at line 21 of file Skybox.cpp.

22{
23 m_d3dClassRef = d3dClassRef;
24}

Member Data Documentation

◆ textures

std::vector<ID3D11ShaderResourceView*> Skybox::textures

Definition at line 34 of file Skybox.h.

◆ translations

std::vector<XMMATRIX> Skybox::translations

Definition at line 35 of file Skybox.h.


The documentation for this class was generated from the following files: