diff --git a/src/Camera.cpp b/src/Camera.cpp index 542df91..0e7bae1 100644 --- a/src/Camera.cpp +++ b/src/Camera.cpp @@ -91,3 +91,33 @@ void Camera::updateDirectionFromMouseInput(double *cameraMouseActionRegister) direction.z = sin(glm::radians(yaw)) * cos(glm::radians(pitch)); frontVec = glm::normalize(direction); } + +void Camera::setPosition(glm::vec3 position) +{ + this->position = position; +} + +glm::mat4 Camera::getView() +{ + return viewMatrix; +} + +glm::mat4 Camera::getProj() +{ + return projectionMatrix; +} + +glm::mat4 Camera::getViewProj() +{ + return viewProjectionMatrix; +} + +glm::vec3 Camera::getPosition() +{ + return position; +} + +glm::vec3 Camera::getDirection() +{ + return frontVec; +} diff --git a/src/Camera.h b/src/Camera.h index bdfb675..3b830b5 100644 --- a/src/Camera.h +++ b/src/Camera.h @@ -16,39 +16,20 @@ public: void translate(glm::vec3 translateVector); - void setPosition(glm::vec3 position) - { - this->position = position; - } - void lookAtTarget(glm::vec3 target); void lookForward(); - glm::mat4 getView() - { - return viewMatrix; - } - glm::mat4 getProj() - { - return projectionMatrix; - } - glm::mat4 getViewProj() - { - return viewProjectionMatrix; - } - glm::vec3 getPosition() - { - return position; - } - glm::vec3 getDirection() - { - return frontVec; - } + glm::mat4 getView(); + glm::mat4 getProj(); + glm::mat4 getViewProj(); + glm::vec3 getPosition(); + glm::vec3 getDirection(); + + void setPosition(glm::vec3 position); private: glm::mat4 viewMatrix; glm::mat4 projectionMatrix; - glm::mat4 viewProjectionMatrix; glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.0f); diff --git a/src/Controller.cpp b/src/Controller.cpp index f621915..ad0dddf 100644 --- a/src/Controller.cpp +++ b/src/Controller.cpp @@ -39,10 +39,6 @@ Controller::Controller() glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); -#ifndef _DEBUG - glfwWindowHint(GLFW_MAXIMIZED, GL_TRUE); -#endif - gameWindow = new Window(); gameEventHandler = new EventHandler(gameWindow->getGLFWwindow()); @@ -55,6 +51,7 @@ Controller::Controller() menu = new Menu(pp_framebuffer, getShaderProgramByName("menuProgram")); #ifdef _DEBUG + glfwWindowHint(GLFW_MAXIMIZED, GL_TRUE); glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); glfwSetErrorCallback(error_callback); diff --git a/src/Controller.h b/src/Controller.h index 32fbd4b..ac3c465 100644 --- a/src/Controller.h +++ b/src/Controller.h @@ -35,6 +35,7 @@ private: void renderImGui(World &world, PointLight *pointLight, glm::vec3 *lightColor, bool *rotateEntity, bool *rotateLightSource, ShaderProgram *postProcessingProgram, float *intensity, bool *drawShadows); +private: Window *gameWindow; EventHandler *gameEventHandler; Camera *camera; @@ -48,7 +49,5 @@ private: const uint16_t MAX_FPS = 60; double deltaTime; - bool wireFrameMode = 0; - float exposure = 1.0f; }; diff --git a/src/Entity.cpp b/src/Entity.cpp index 875bc82..4e703f2 100644 --- a/src/Entity.cpp +++ b/src/Entity.cpp @@ -112,7 +112,40 @@ void Entity::updateModelMatrix() modelMatrix = translationMatrix * rotationMatrix * scaleMatrix; } +void Entity::setIsLightSource(bool temp) +{ + isLightSource = temp; +} +void Entity::setId(uint32_t id) +{ + this->id = id; +} + +uint32_t Entity::getId() +{ + return id; +} + +std::string Entity::getUniqueName() +{ + return unique_name; +} + +glm::vec3 Entity::getPosition() +{ + return position; +} + +glm::mat4 Entity::getModelMatrix() +{ + return modelMatrix; +} + +bool Entity::getIsLightSource() +{ + return isLightSource; +} Skybox::Skybox(Model *cubeModel, ShaderProgram *shaderProgram, const char *texturePseudoPath) : cubeModel(cubeModel), diff --git a/src/Entity.h b/src/Entity.h index 87c9175..9a3772f 100644 --- a/src/Entity.h +++ b/src/Entity.h @@ -24,59 +24,35 @@ public: void setRotation(glm::vec3 eulerAngles); void setRotation(glm::vec3 axis, float radians); void setScale(float scaleFactor); + void setIsLightSource(bool temp); + void setId(uint32_t id); - void setIsLightSource(bool temp) - { - isLightSource = temp; - } - - void setId(uint32_t id) - { - this->id = id; - } - uint32_t getId() - { - return id; - } - std::string getUniqueName() - { - return unique_name; - } - - glm::vec3 getPosition() - { - return position; - } - glm::mat4 getModelMatrix() - { - return modelMatrix; - } - bool getIsLightSource() - { - return isLightSource; - } + uint32_t getId(); + std::string getUniqueName(); + glm::vec3 getPosition(); + glm::mat4 getModelMatrix(); + bool getIsLightSource(); private: void updateModelMatrix(); - static uint32_t id_counter; +private: uint32_t id; + static uint32_t id_counter; std::string unique_name; + Model *model; + ShaderProgram *shaderProgram; + bool isLightSource = false; + glm::mat4 modelMatrix = glm::mat4(1.0f); + glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.0f); glm::quat quaternion; glm::vec3 velocity = glm::vec3(0.0f, 0.0f, 0.0f); - float modelScale = 1.0f; - - Model *model; - - glm::mat4 modelMatrix = glm::mat4(1.0f); - - ShaderProgram *shaderProgram; }; class Skybox diff --git a/src/EventHandler.cpp b/src/EventHandler.cpp index 5e66ec1..082ba50 100644 --- a/src/EventHandler.cpp +++ b/src/EventHandler.cpp @@ -116,3 +116,23 @@ void EventHandler::mouse_callback(GLFWwindow *window, double xpos, double ypos) cameraMouseActionRegister[cameraMouseDeltaX] = deltaCursorPosX; cameraMouseActionRegister[cameraMouseDeltaY] = deltaCursorPosY; } + +bool * EventHandler::getCameraActionRegister() +{ + return cameraActionRegister; +} + +bool * EventHandler::getWindowActionRegister() +{ + return windowActionRegister; +} + +double * EventHandler::getCursorDelta() +{ + return cameraMouseActionRegister; +} + +void EventHandler::setFirstMouseInput(bool val) +{ + firstMouseInput = val; +} diff --git a/src/EventHandler.h b/src/EventHandler.h index 7f09d44..be3de19 100644 --- a/src/EventHandler.h +++ b/src/EventHandler.h @@ -12,24 +12,10 @@ public: void handleEvents(); - bool *getCameraActionRegister() - { - return cameraActionRegister; - } - bool *getWindowActionRegister() - { - return windowActionRegister; - } - - double *getCursorDelta() - { - return cameraMouseActionRegister; - } - - void setFirstMouseInput(bool val) - { - firstMouseInput = val; - } + bool *getCameraActionRegister(); + bool *getWindowActionRegister(); + double *getCursorDelta(); + void setFirstMouseInput(bool val); private: void clearActionRegisters(); @@ -37,6 +23,7 @@ private: static void key_callback(GLFWwindow *window, int key, int scancode, int action, int mods); static void mouse_callback(GLFWwindow *window, double xpos, double ypos); +private: static bool cameraActionRegister[CAMERA_ACTION_NUM_ITEMS]; static double cameraMouseActionRegister[CAMERA_MOUSE_ACTION_NUM_ITEMS]; static bool windowActionRegister[WINDOW_ACTION_NUM_ITEMS]; @@ -44,6 +31,5 @@ private: GLFWwindow *window; static float mouseSensitivity; - static bool firstMouseInput; }; diff --git a/src/Framebuffer.cpp b/src/Framebuffer.cpp index a047445..e9f666f 100644 --- a/src/Framebuffer.cpp +++ b/src/Framebuffer.cpp @@ -91,6 +91,11 @@ void Framebuffer::setExposureCorrection(bool exposureCorrection) shaderProgram->unbind(); } +GLuint Framebuffer::getTextureId() +{ + return textures[0]; +} + DepthMap::DepthMap(int TYPE, int RESOLUTION) : cubeMap(RESOLUTION) { @@ -134,3 +139,18 @@ void DepthMap::unbind() { glBindFramebuffer(GL_FRAMEBUFFER, 0); } + +GLuint DepthMap::getFBO() +{ + return depthMapFBO; +} + +GLuint DepthMap::getDepthMap() +{ + return depthMap; +} + +GLuint DepthMap::getCubeMapId() +{ + return cubeMap.getTextureId(); +} diff --git a/src/Framebuffer.h b/src/Framebuffer.h index 584bb04..547728e 100644 --- a/src/Framebuffer.h +++ b/src/Framebuffer.h @@ -17,15 +17,13 @@ public: void changeDimensions(uint32_t width, uint32_t height); - GLuint getTextureId() - { - return textures[0]; - } + GLuint getTextureId(); void setExposureCorrection(bool exposureCorrection); private: void generateTextures(uint32_t width, uint32_t height); +private: GLuint FBO; GLuint textures[2]; @@ -44,18 +42,9 @@ public: void bind(); void unbind(); - GLuint getFBO() - { - return depthMapFBO; - } - GLuint getDepthMap() - { - return depthMap; - } - GLuint getCubeMapId() - { - return cubeMap.getTextureId(); - } + GLuint getFBO(); + GLuint getDepthMap(); + GLuint getCubeMapId(); private: GLuint depthMapFBO; diff --git a/src/Light.cpp b/src/Light.cpp index 76ebe04..34c4a39 100644 --- a/src/Light.cpp +++ b/src/Light.cpp @@ -2,6 +2,34 @@ #include +// Light + +glm::vec3 Light::getColor() +{ + return lightColor; +} + +void Light::setShaderProgram(ShaderProgram* shaderProgram) +{ + this->shaderProgram = shaderProgram; + update(); +} + +void Light::setColor(glm::vec3 color) +{ + lightColor = color; + diffuseColor = lightColor * glm::vec3(1.0f); + ambientColor = diffuseColor * glm::vec3(0.002f); + specularColor = lightColor * glm::vec3(1.0f); + update(); +} + +void Light::setActive(bool active) +{ + isActive = active; + update(); +} + // PointLight PointLight::PointLight(ShaderProgram *shaderProgram) : @@ -14,22 +42,42 @@ void PointLight::update() { shaderProgram->bind(); - shaderProgram->setUniform((_getStructMemberName() + "isActive").c_str(), isActive); - shaderProgram->setUniform((_getStructMemberName() + "position").c_str(), position); - shaderProgram->setUniform((_getStructMemberName() + "ambient").c_str(), ambientColor); - shaderProgram->setUniform((_getStructMemberName() + "diffuse").c_str(), diffuseColor); - shaderProgram->setUniform((_getStructMemberName() + "specular").c_str(), specularColor); - shaderProgram->setUniform((_getStructMemberName() + "K_q").c_str(), K_q); + shaderProgram->setUniform((getStructMemberName() + "isActive").c_str(), isActive); + shaderProgram->setUniform((getStructMemberName() + "position").c_str(), position); + shaderProgram->setUniform((getStructMemberName() + "ambient").c_str(), ambientColor); + shaderProgram->setUniform((getStructMemberName() + "diffuse").c_str(), diffuseColor); + shaderProgram->setUniform((getStructMemberName() + "specular").c_str(), specularColor); + shaderProgram->setUniform((getStructMemberName() + "K_q").c_str(), K_q); shaderProgram->unbind(); } -std::string PointLight::_getStructMemberName() +std::string PointLight::getStructMemberName() { std::string temp = "u_pointLight[" + std::to_string(lightId) + "]."; return temp; } +glm::vec3 PointLight::getPosition() +{ + return position; +} + +void PointLight::setPosition(glm::vec3 position) +{ + this->position = position; + update(); +} + +void PointLight::setParameters(float K_q) +{ + this->K_q = K_q; +} + +void PointLight::setId(unsigned int id) +{ + this->lightId = id; +} // DirectionalLight @@ -51,3 +99,9 @@ void DirectionalLight::update() shaderProgram->unbind(); } + +void DirectionalLight::setDirection(glm::vec3 direction) +{ + this->direction = direction; + update(); +} diff --git a/src/Light.h b/src/Light.h index f056ac2..ad147e9 100644 --- a/src/Light.h +++ b/src/Light.h @@ -13,34 +13,16 @@ public: virtual void update() = 0; - void setActive(bool active) - { - isActive = active; - update(); - } - void setColor(glm::vec3 color) - { - lightColor = color; - diffuseColor = lightColor * glm::vec3(1.0f); - ambientColor = diffuseColor * glm::vec3(0.002f); - specularColor = lightColor * glm::vec3(1.0f); - update(); - } + void setActive(bool active); + void setColor(glm::vec3 color); + void setShaderProgram(ShaderProgram *shaderProgram); - void setShaderProgram(ShaderProgram *shaderProgram) - { - this->shaderProgram = shaderProgram; - update(); - } - - glm::vec3 getColor() - { - return lightColor; - } + glm::vec3 getColor(); protected: Light(ShaderProgram *shaderProgram) : shaderProgram(shaderProgram) {} +protected: ShaderProgram *shaderProgram; bool isActive = false; @@ -59,30 +41,17 @@ public: PointLight(ShaderProgram *shaderProgram); ~PointLight() = default; - void setPosition(glm::vec3 position) - { - this->position = position; - update(); - } + void setPosition(glm::vec3 position); + void setParameters(float K_q); + void setId(unsigned int id); - void setParameters(float K_q) - { - this->K_q = K_q; - } - - void setId(unsigned int id) - { - lightId = id; - } - - glm::vec3 getPosition() - { - return position; - } + glm::vec3 getPosition(); private: void update() override; - std::string _getStructMemberName(); + std::string getStructMemberName(); + +private: unsigned int lightId; glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.0f); @@ -95,14 +64,11 @@ class DirectionalLight : public Light public: DirectionalLight(ShaderProgram *shaderProgram); - void setDirection(glm::vec3 direction) - { - this->direction = direction; - update(); - } + void setDirection(glm::vec3 direction); private: void update() override; +private: glm::vec3 direction; }; diff --git a/src/Mesh.cpp b/src/Mesh.cpp index 6d267be..16e692a 100644 --- a/src/Mesh.cpp +++ b/src/Mesh.cpp @@ -40,3 +40,8 @@ void Mesh::drawWithoutTextures() glDrawElements(GL_TRIANGLES, numElements, GL_UNSIGNED_INT, 0); vertexArray.unbind(); } + +VertexArray* Mesh::getVertexArray() +{ + return &vertexArray; +} diff --git a/src/Mesh.h b/src/Mesh.h index c0cadc3..b5fa53b 100644 --- a/src/Mesh.h +++ b/src/Mesh.h @@ -16,16 +16,14 @@ public: void draw(ShaderProgram *shaderProgram); void drawWithoutTextures(); - VertexArray *getVertexArray() - { - return &vertexArray; - } + VertexArray *getVertexArray(); + +private: + void setupMesh(); private: uint32_t numElements; std::vector textures; VertexArray vertexArray; - - void setupMesh(); }; diff --git a/src/Model.cpp b/src/Model.cpp index 634ff4b..49ea3cb 100644 --- a/src/Model.cpp +++ b/src/Model.cpp @@ -115,3 +115,13 @@ void Model::loadModel(std::string &pathToModel) input.close(); } + +Mesh* Model::getMesh(unsigned int index) +{ + return meshes[index]; +} + +std::string Model::getUniqueName() +{ + return unique_name; +} diff --git a/src/Model.h b/src/Model.h index 03b4086..03e35f4 100644 --- a/src/Model.h +++ b/src/Model.h @@ -14,21 +14,14 @@ public: void draw(ShaderProgram *shaderProgram); void drawWithoutTextures(); - Mesh *getMesh(unsigned int index) - { - return meshes[index]; - } - - std::string getUniqueName() - { - return unique_name; - } + Mesh *getMesh(unsigned int index); + std::string getUniqueName(); private: void loadModel(std::string &pathToModel); +private: std::vector meshes; - std::vector loadedTextures; std::string directory; diff --git a/src/ShaderProgram.cpp b/src/ShaderProgram.cpp index 436e48b..cef509a 100644 --- a/src/ShaderProgram.cpp +++ b/src/ShaderProgram.cpp @@ -162,3 +162,13 @@ void ShaderProgram::setUniform(const char *name, glm::mat4 matrix) const GLint location = glGetUniformLocation(shaderProgramId, name); glUniformMatrix4fv(location, 1, GL_FALSE, glm::value_ptr(matrix)); } + +GLuint ShaderProgram::getShaderProgramId() +{ + return shaderProgramId; +} + +std::string ShaderProgram::getUniqueName() +{ + return unique_name; +} diff --git a/src/ShaderProgram.h b/src/ShaderProgram.h index 8069e2d..edd9c7b 100644 --- a/src/ShaderProgram.h +++ b/src/ShaderProgram.h @@ -22,20 +22,15 @@ public: void setUniform(const char *name, glm::mat3 matrix) const; void setUniform(const char *name, glm::mat4 matrix) const; - GLuint getShaderProgramId() - { - return shaderProgramId; - } - - std::string getUniqueName() - { - return unique_name; - } +public: + GLuint getShaderProgramId(); + std::string getUniqueName(); private: std::string parse(const char *filename); GLuint compile(std::string shaderSource, GLenum type); +private: GLuint shaderProgramId; std::string unique_name; }; diff --git a/src/Texture.cpp b/src/Texture.cpp index ed10b02..23d7fcf 100644 --- a/src/Texture.cpp +++ b/src/Texture.cpp @@ -80,6 +80,21 @@ void Texture::unbind() glBindTexture(GL_TEXTURE_2D, 0); } +uint8_t Texture::getTextureType() +{ + return textureType; +} + +std::string Texture::getPath() +{ + return texturePath; +} + +GLuint Texture::getTextureId() +{ + return textureId; +} + CubeMap::CubeMap(const char *texturePseudoPath) { // Reserve space in vector so that elements can be accessed explicitly. @@ -167,3 +182,8 @@ void CubeMap::fillTexturePathVector(const char *texturePseudoPath) texturePaths[cm_right] = std::string(texturePseudoPath) + "right.png"; } } + +GLuint CubeMap::getTextureId() +{ + return textureId; +} diff --git a/src/Texture.h b/src/Texture.h index 3aa08b8..e8ef1a6 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -21,18 +21,9 @@ public: void bind(uint8_t textureUnit, ShaderProgram *shaderProgram, uint8_t textureTypeNum); void unbind(); - uint8_t getTextureType() - { - return textureType; - } - std::string getPath() - { - return texturePath; - } - GLuint getTextureId() - { - return textureId; - } + uint8_t getTextureType(); + std::string getPath(); + GLuint getTextureId(); private: std::string texturePath; @@ -57,14 +48,12 @@ public: void bind(ShaderProgram *shaderProgram); void unbind(); - GLuint getTextureId() - { - return textureId; - } + GLuint getTextureId(); private: void fillTexturePathVector(const char *texturePseudoPath); +private: std::vector texturePaths; GLuint textureId; diff --git a/src/Window.cpp b/src/Window.cpp index 244c6a2..2d36d38 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -137,3 +137,28 @@ void Window::openGLDebugCallback(GLenum source, GLenum type, GLuint id, GLenum s << "Severity: " << severity << std::endl << std::endl; } + +GLFWwindow* Window::getGLFWwindow() +{ + return window; +} + +int Window::getWindowWidth() +{ + return width; +} + +int Window::getWindowHeight() +{ + return height; +} + +float Window::getWindowAspectRatio() +{ + return (float) width / (float) height; +} + +bool Window::getMouseIsCatched() +{ + return mouseCatched; +} diff --git a/src/Window.h b/src/Window.h index 0ba621b..d3d41b2 100644 --- a/src/Window.h +++ b/src/Window.h @@ -8,28 +8,12 @@ public: Window(); ~Window(); - GLFWwindow *getGLFWwindow() - { - return window; - } + GLFWwindow *getGLFWwindow(); - int getWindowWidth() - { - return width; - } - int getWindowHeight() - { - return height; - } - float getWindowAspectRatio() - { - return (float) width / (float) height; - } - - bool getMouseIsCatched() - { - return mouseCatched; - } + int getWindowWidth(); + int getWindowHeight(); + float getWindowAspectRatio(); + bool getMouseIsCatched(); // side effect! bool checkWindowWasResized(); @@ -39,9 +23,9 @@ public: private: static void framebuffer_size_callback(GLFWwindow *window, int width, int height); static void openGLDebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam); - void setCatchedCursor(bool value); +private: GLFWwindow *window; int posX, posY; diff --git a/src/World.cpp b/src/World.cpp index b5e326b..0e73ba8 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -223,3 +223,18 @@ Entity* World::getEntityById(uint32_t id) std::cout << "[Warning] Entity could not be found by ID \"" << id << "\"" << std::endl; return nullptr; } + +PointLight* World::getPointLights() +{ + return pointLights.data(); +} + +std::vector< Entity* > World::getEntities() +{ + return entities; +} + +Skybox* World::getSkybox() +{ + return skybox; +} diff --git a/src/World.h b/src/World.h index 67a1883..558af74 100644 --- a/src/World.h +++ b/src/World.h @@ -21,20 +21,9 @@ public: void updatePointLight(unsigned int lightId, bool active, glm::vec3 position, glm::vec3 color); void updateDirectionalLight(bool active, glm::vec3 direction, glm::vec3 color); - std::vector getEntities() - { - return entities; - } - - PointLight *getPointLights() - { - return pointLights.data(); - } - Skybox *getSkybox() - { - return skybox; - } - + std::vector getEntities(); + PointLight *getPointLights(); + Skybox *getSkybox(); Entity* getEntityByName(std::string name); Entity* getEntityById(uint32_t id); Model* getModelByName(std::string name);