AireEngine
A 3D Open-World Game Engine
Loading...
Searching...
No Matches
scene.h
1#pragma once
2
3#include <json.h>
4#include <fstream>
5#include "../utils/rigidbodyHandler.h"
6#include "../utils/ai.h"
7
8#include "../rendering/shaderProgram.h"
9#include "../rendering/camera.h"
10#include "../rendering/shadows.h"
11#include "../rendering/skybox.h"
12#include "../rendering/billboard.h"
13#include "../rendering/water.h"
14#include "../rendering/hud.h"
15#include "../rendering/particle.h"
16
17#include "../audio/audioEngine.h"
18#include "../audio/audioSource.h"
19
20#include "terrain.h"
21#include "texManager.h"
22#include "meshManager.h"
23#include "model.h"
24#include "light.h"
25#include "animator.h"
26
27namespace Aire
28{
32 class Scene
33 {
34 public:
46 Scene(Window* window, Camera& camera, TextureManager& texManager, MeshManager& meshManager,
47 Clock& clock, RigidbodyHandler* rigidbodyHandler, HUD* hudManager);
48
52 ~Scene();
53
54 // Setters for shaders
55
61 void setTerrainShader(ShaderProgram& shader) { terrainShader = &shader; }
62
68 void setModelShader(ShaderProgram& shader) { modelShader = &shader; }
69
75 void setAnimationShader(ShaderProgram& shader) { animationShader = &shader; }
76
82 void setBillboardShader(ShaderProgram& shader) { billboardShader = &shader; }
83
84 // Boid Manager
85
91 void setBoidManager(BoidManager* boidManager) { this->boidManager = boidManager; }
92
98 BoidManager* getBoidManager() { return boidManager; }
99
100 // Particle Generator
101
107 void setParticleGenerator(ParticleGenerator* particleGenerator) { this->particleGenerator = particleGenerator; }
108
114 ParticleGenerator* getParticleGenerator() { return particleGenerator; }
115
116 // Audio Engine
117
123 void setAudioEngine(AudioEngine* audioEngine) { this->audioEngine = audioEngine; }
124
130 AudioEngine* getAudioEngine() { return audioEngine; }
131
137 void setBoidSounds(const std::string& soundPath);
138
144 void updateBoidSounds(const std::string& soundPath);
145
146 // Scene elements setters
147
153 void setSkybox(Skybox* skybox) { this->skybox = skybox; }
154
160 void setDirectionalLight(Light& light) { directionalLight = light; }
161
167 void setPointLights(std::vector<Light>& lights) { pointLights = lights; }
168
174 void addPointLight(Light& light) { pointLights.push_back(light); }
175
176 // Shadow mapping
177
182
186 void enablePointShadows();
187
188 // Scene elements management
189
196 void addTerrain(Terrain* terrain);
197
203 std::vector<Terrain*> getTerrains() { return terrains; }
204
212 Terrain* getTerrain(int index);
213
214
220 void addModel(Model* model) { models.push_back(model); }
221
227 std::vector<Model*> getModels() { return models; }
228
236 Model* getModel(int index);
237
243 void addAnimator(Animator* animator) { animators.push_back(animator); }
244
250 std::vector<Animator*> getAnimators() { return animators; }
251
259 Animator* getAnimator(int index);
260
266 void addBillboard(Billboard* billboard) { billboards.push_back(billboard); }
267
273 std::vector<Billboard*> getBillboards() { return billboards; }
274
282 Billboard* getBillboard(int index);
283
290 void bindTerrainToRigidbody(int index);
291
297 void load(const char* scenePath);
298
307 void render(bool debug, bool pause);
308
312 void update();
313
322 void computeBillboardInstances(std::vector<Billboard*> billboards, Terrain* terrain, int numBillboards);
323
330 void renderBillboards(ShaderProgram& shader, Camera& camera);
331
332 private:
333 Aire::Window* window = nullptr;
334 Aire::Camera* camera = nullptr;
335 Aire::Clock* clock = nullptr;
336 Aire::RigidbodyHandler* rigidbodyHandler = nullptr;
337 Aire::TextureManager* textureManager = nullptr;
338 Aire::MeshManager* meshManager = nullptr;
339 Aire::BoidManager* boidManager = nullptr;
340 Aire::ParticleGenerator* particleGenerator = nullptr;
341 Aire::HUD* hudManager = nullptr;
342 Aire::AudioEngine* audioEngine = nullptr;
343 std::vector<Aire::AudioSource*> boidSounds;
345 Aire::HUD::HUD_TEXT* debugText = nullptr;
346 Aire::HUD::HUD_TEXT* pauseText = nullptr;
348 float currentFrame = 0.0f;
349 float deltaTime = 0.0f;
350 float lastFrame = 0.0f;
352 Aire::ShaderProgram* terrainShader = nullptr;
353 Aire::ShaderProgram* modelShader = nullptr;
354 Aire::ShaderProgram* animationShader = nullptr;
355 Aire::ShaderProgram* billboardShader = nullptr;
357 Aire::ShaderProgram* pointShadowShader = nullptr;
358 Aire::ShaderProgram* directionalShadowShader = nullptr;
360 Aire::ShaderProgram* animationPointShadowShader = nullptr;
361 Aire::ShaderProgram* animationDirectionalShadowShader = nullptr;
363 Aire::Skybox* skybox = nullptr;
365 Light directionalLight = Light{ glm::vec3(1.f, 1.f, 1.f), glm::vec3(1, 1, 1) };
366 std::vector<Light> pointLights;
368 // Collisions and physics
369 std::vector<Rigidbody*> obstacles;
370 std::vector<Rigidbody*> enemies;
372 // Debug
373 bool debug = false;
374 Aire::ShaderProgram* debugShader = nullptr;
375 Model* sphere = nullptr;
376 Model* box = nullptr;
378 std::vector<Terrain*> terrains;
379 std::vector<Model*> models;
380 std::vector<Animator*> animators;
381 std::vector<Billboard*> billboards;
382 std::vector<BillboardInstance> billboardInstances;
384 Aire::PointShadows* pShadows = nullptr;
385 Aire::DirectionalShadows* dShadows = nullptr;
387 bool dirShadowsEnabled = false;
388 bool pointShadowsEnabled = false;
396 void setSceneUniforms(ShaderProgram* shader);
397 };
398
399}; // namespace Aire
Class for playing the animation.
Definition animator.h:18
The AudioEngine class manages the audio system.
Definition audioEngine.h:20
Class for billboard rendering.
Definition billboard.h:15
Manager for the boids.
Definition ai.h:159
Definition camera.h:9
Simple clock class.
Definition clock.h:6
Class to handle directional light shadows using shadow mapping with a depth map.
Definition shadows.h:57
Class to render HUD elements on the screen.
Definition hud.h:15
Mesh manager. Handles mesh creation, storage, and deletion.
Definition meshManager.h:28
Definition Model.h:30
Definition Particle.h:97
Class to handle point light shadows using shadow mapping with cubemaps.
Definition shadows.h:15
A singleton class used to handle all rigid bodies in the scene.
Definition rigidbodyHandler.h:13
Represents a 3D scene environment.
Definition scene.h:33
void enablePointShadows()
Enables point light shadow mapping.
Definition scene.cpp:95
void setModelShader(ShaderProgram &shader)
Sets the shader for rendering models.
Definition scene.h:68
void setBillboardShader(ShaderProgram &shader)
Sets the shader for rendering billboards.
Definition scene.h:82
std::vector< Model * > getModels()
Retrieves all models in the scene.
Definition scene.h:227
void renderBillboards(ShaderProgram &shader, Camera &camera)
Renders the billboards in the scene using the billboard instances.
Definition scene.cpp:1068
void setSkybox(Skybox *skybox)
Sets the skybox for the scene.
Definition scene.h:153
void setAnimationShader(ShaderProgram &shader)
Sets the shader for animation rendering.
Definition scene.h:75
void setAudioEngine(AudioEngine *audioEngine)
Sets the AudioEngine for handling audio playback.
Definition scene.h:123
~Scene()
Destructor.
Definition scene.cpp:40
void setBoidManager(BoidManager *boidManager)
Sets the BoidManager for handling AI boid behaviors.
Definition scene.h:91
std::vector< Terrain * > getTerrains()
Retrieves all terrains in the scene.
Definition scene.h:203
Terrain * getTerrain(int index)
Retrieves a specific terrain in the scene by index.
Definition scene.cpp:138
ParticleGenerator * getParticleGenerator()
Retrieves the ParticleGenerator used in the scene.
Definition scene.h:114
void addBillboard(Billboard *billboard)
Adds a billboard to the scene.
Definition scene.h:266
void addPointLight(Light &light)
Adds a point light to the scene.
Definition scene.h:174
void setPointLights(std::vector< Light > &lights)
Sets the point lights for the scene.
Definition scene.h:167
std::vector< Animator * > getAnimators()
Retrieves all animators in the scene.
Definition scene.h:250
void bindTerrainToRigidbody(int index)
Binds a terrain to the RigidbodyHandler based on its index.
Definition scene.cpp:178
Billboard * getBillboard(int index)
Retrieves a specific billboard in the scene by index.
Definition scene.cpp:168
BoidManager * getBoidManager()
Retrieves the BoidManager used in the scene.
Definition scene.h:98
void addAnimator(Animator *animator)
Adds an animator to the scene.
Definition scene.h:243
void addTerrain(Terrain *terrain)
Adds a terrain to the scene. The first terrain loaded is automatically bound to the rigidbody.
Definition scene.cpp:118
Animator * getAnimator(int index)
Retrieves a specific animator in the scene by index.
Definition scene.cpp:158
void setParticleGenerator(ParticleGenerator *particleGenerator)
Sets the ParticleGenerator for handling particle effects.
Definition scene.h:107
void render(bool debug, bool pause)
Renders the scene.
Definition scene.cpp:745
Scene(Window *window, Camera &camera, TextureManager &texManager, MeshManager &meshManager, Clock &clock, RigidbodyHandler *rigidbodyHandler, HUD *hudManager)
Constructor.
Definition scene.cpp:6
void update()
Updates the scene animations and physics.
Definition scene.cpp:1016
void updateBoidSounds(const std::string &soundPath)
Updates the audio sources vector for boid sounds.
Definition scene.cpp:1094
void load(const char *scenePath)
Loads scene data from a JSON file.
Definition scene.cpp:215
Model * getModel(int index)
Retrieves a specific model in the scene by index.
Definition scene.cpp:148
AudioEngine * getAudioEngine()
Retrieves the AudioEngine used in the scene.
Definition scene.h:130
std::vector< Billboard * > getBillboards()
Retrieves all billboards in the scene.
Definition scene.h:273
void addModel(Model *model)
Adds a model to the scene.
Definition scene.h:220
void setDirectionalLight(Light &light)
Sets the directional light for the scene.
Definition scene.h:160
void setBoidSounds(const std::string &soundPath)
Sets the audio sources vector for boid sounds.
Definition scene.cpp:1075
void enableDirectionalShadows()
Enables directional light shadow mapping.
Definition scene.cpp:78
void computeBillboardInstances(std::vector< Billboard * > billboards, Terrain *terrain, int numBillboards)
Computes random locations and billboard textures and saves them in the billboardInstances vector.
Definition scene.cpp:1036
void setTerrainShader(ShaderProgram &shader)
Sets the shader for rendering terrain.
Definition scene.h:61
A linked OpenGL program.
Definition shaderProgram.h:16
Definition skybox.h:10
A class that represents a terrain object.
Definition terrain.h:28
Texture manager. Handles texture creation, storage, and deletion.
Definition texManager.h:20
Definition window.h:13
Class to display text on the screen.
Definition hud.h:47
A point light.
Definition light.h:7