PGR Copakond OpenGL Engine - Bowling
Loading...
Searching...
No Matches
scene.h
Go to the documentation of this file.
1#ifndef PGR_SEM_COPAKOND_SCENE_H
2#define PGR_SEM_COPAKOND_SCENE_H
3
4#include <iostream>
5#include <algorithm>
6#include "../pgr-portable.h"
7#include "../meshes/mesh.h"
11#include "../geometry/camera.h"
12#include "../light/light.h"
13#include "../parser/input.h"
14#include "../shaders/shader.h"
15#include "../animation/spline.h"
17#include "../animation/bezier.h"
25
26namespace copakond {
29 extern StencilSelect stencilMode; // only declare once
30
32 class Scene {
33 protected:
34 const char *WIN_TITLE;
37
39 std::vector<Mesh*> meshes = std::vector<Mesh*>();
40 std::vector<Light*> lights = std::vector<Light*>();
41 std::vector<Spline*> splines = std::vector<Spline*>();
42 std::vector<CollisionShape*> colliders = std::vector<CollisionShape*>();
43
44 Light* sun = nullptr;
45 Skybox* skybox = nullptr;
46
47 uint64_t time = 0;
48 int winWidth = 0;
49 int winHeight = 0;
50 float skyboxBlendingCoeff = 0.0f;
51
52 void addToScene(Mesh* mesh);
53 void addToScene(Light* light);
54 void addToScene(Spline* spline);
55
56 public:
57 Scene(const char *sceneName, Input* engineInput, Shader* engineShader, int winWidth, int winHeight) : input(engineInput), shader
58 (engineShader), winWidth(winWidth), winHeight(winHeight) {
59 WIN_TITLE = sceneName;
60 camera = new Camera(glm::vec3(0.0f),glm::vec3(0.0f), 1000.0f); // sample camera
61 }
62
63 virtual ~Scene() = default;
64
65 // getters for main
66 const std::vector<Mesh*>& getMeshes() const { return meshes; }
67 const std::vector<Light*>& getLights() const { return lights; }
68 const std::vector<Spline*>& getSplines() const { return splines; }
69 const std::vector<CollisionShape*>& getColliders() const { return colliders; }
70 Skybox* getSkybox() const { return skybox; }
71 Light* getSun() const { return sun; }
72 Camera& getCamera() { return *camera; }
73 Shader* getShader() const { return shader; }
74 Input* getInput() const { return input; }
75
77 float updateTime();
78 float getSkyboxBlendingCoeff() { return skyboxBlendingCoeff; } // each scene can overwrite it with custom logic
79 const char* getSceneName() { return WIN_TITLE; }
80
81 // functions for scene
82 virtual void init() {};
83 virtual void update(float deltaTime) {};
84
86 virtual void physics_update(float deltaTime) {};
87
88 virtual void onKeyboardEvent(unsigned char key, int x, int y, bool isDown) {}
89
90 virtual void onMouseButtonEvent(int button, int state, int x, int y) {}
91 virtual void onMouseWheelEvent(int wheel, int direction, int x, int y) {}
92 virtual void onMouseMoveEvent(int x, int y) {}
93
95 virtual void onScreenResizeEvent(int width, int height) {}
96
97 virtual void onMenuEvent(int option) {}
98 };
99}
100
101#endif // PGR_SEM_COPAKOND_SCENE_H
Camera for generating view and projection matrices.
Definition camera.h:20
Global input manager tracking keyboard states and mouse deltas.
Definition input.h:20
Base class for scene lighting calculations.
Definition light.h:23
Base drawable 3D object containing geometry and material data.
Definition mesh.h:19
virtual void onKeyboardEvent(unsigned char key, int x, int y, bool isDown)
Definition scene.h:88
virtual ~Scene()=default
const std::vector< Light * > & getLights() const
Definition scene.h:67
float getSkyboxBlendingCoeff()
Definition scene.h:78
Shader * shader
Definition scene.h:36
Light * sun
Definition scene.h:44
virtual void onMouseWheelEvent(int wheel, int direction, int x, int y)
Definition scene.h:91
Scene(const char *sceneName, Input *engineInput, Shader *engineShader, int winWidth, int winHeight)
Definition scene.h:57
Input * input
Definition scene.h:35
virtual void onScreenResizeEvent(int width, int height)
Handles viewport and projection matrix updates on window resize.
Definition scene.h:95
std::vector< Mesh * > meshes
Definition scene.h:39
Input * getInput() const
Definition scene.h:74
float updateTime()
Calculates delta time since the last frame.
Definition scene.cpp:6
virtual void init()
Definition scene.h:82
std::vector< CollisionShape * > colliders
Definition scene.h:42
Shader * getShader() const
Definition scene.h:73
int winWidth
Definition scene.h:48
void addToScene(Mesh *mesh)
Definition scene.cpp:13
const std::vector< Mesh * > & getMeshes() const
Definition scene.h:66
const char * WIN_TITLE
Definition scene.h:34
virtual void onMouseButtonEvent(int button, int state, int x, int y)
Definition scene.h:90
virtual void onMenuEvent(int option)
Definition scene.h:97
Skybox * skybox
Definition scene.h:45
int winHeight
Definition scene.h:49
Skybox * getSkybox() const
Definition scene.h:70
std::vector< Spline * > splines
Definition scene.h:41
virtual void update(float deltaTime)
Definition scene.h:83
const std::vector< CollisionShape * > & getColliders() const
Definition scene.h:69
Camera & getCamera()
Definition scene.h:72
virtual void physics_update(float deltaTime)
Fixed-step physics update loop for resolving collisions and forces.
Definition scene.h:86
Light * getSun() const
Definition scene.h:71
std::vector< Light * > lights
Definition scene.h:40
uint64_t time
Definition scene.h:47
const char * getSceneName()
Definition scene.h:79
float skyboxBlendingCoeff
Definition scene.h:50
const std::vector< Spline * > & getSplines() const
Definition scene.h:68
Camera * camera
Definition scene.h:38
virtual void onMouseMoveEvent(int x, int y)
Definition scene.h:92
Core manager for shader program compilation, uniform binding, and rendering.
Definition shader.h:13
Environmental background cube map with day/night cycle blending.
Definition skybox.h:10
Base class for parameterized spline animations.
Definition spline.h:9
PGR Semestral work with sample scenes and bowling. doxygen was generated with a help of LLM.
Definition bezier.cpp:3
StencilSelect stencilMode
Definition scene.cpp:4
StencilSelect
Determines which objects are written to the stencil buffer for mouse picking.
Definition scene.h:28
@ ALL
Definition scene.h:28
@ MESHES
Definition scene.h:28
@ COLLISION
Definition scene.h:28