Some cleanups

This commit is contained in:
2021-01-13 19:03:47 +01:00
parent 89ae811beb
commit 0370a2e871
24 changed files with 321 additions and 237 deletions

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -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;
};

View File

@@ -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),

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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;
};

View File

@@ -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();
}

View File

@@ -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;

View File

@@ -2,6 +2,34 @@
#include <string>
// 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();
}

View File

@@ -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;
};

View File

@@ -40,3 +40,8 @@ void Mesh::drawWithoutTextures()
glDrawElements(GL_TRIANGLES, numElements, GL_UNSIGNED_INT, 0);
vertexArray.unbind();
}
VertexArray* Mesh::getVertexArray()
{
return &vertexArray;
}

View File

@@ -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<Texture *> textures;
VertexArray vertexArray;
void setupMesh();
};

View File

@@ -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;
}

View File

@@ -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<Mesh *> meshes;
std::vector<Texture *> loadedTextures;
std::string directory;

View File

@@ -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;
}

View File

@@ -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;
};

View File

@@ -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;
}

View File

@@ -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<std::string> texturePaths;
GLuint textureId;

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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<Entity*> getEntities()
{
return entities;
}
PointLight *getPointLights()
{
return pointLights.data();
}
Skybox *getSkybox()
{
return skybox;
}
std::vector<Entity*> getEntities();
PointLight *getPointLights();
Skybox *getSkybox();
Entity* getEntityByName(std::string name);
Entity* getEntityById(uint32_t id);
Model* getModelByName(std::string name);