diff --git a/src/gfx/include/gfx/cam_control.hpp b/src/gfx/include/gfx/cam_control.hpp index 84dba3c85b2e8bf73de05dde1ffd532dc237dd87..9243e0819a86889fff3ac9d3298d092aa316f0e3 100644 --- a/src/gfx/include/gfx/cam_control.hpp +++ b/src/gfx/include/gfx/cam_control.hpp @@ -24,7 +24,7 @@ public: void turn(float xoffset, float yoffset); - glm::vec2 getSens() { return sens; } + glm::vec2 getSens() const { return sens; } void setSens(float x_size, float y_size); void setSensMultiplier(float multiplier) { sens_multiplier = multiplier; } diff --git a/src/gfx/include/gfx/camera.hpp b/src/gfx/include/gfx/camera.hpp index 27e1213a7ec0473d94e960153517bdbfb5100f77..e7e38343302f6014a12e7f86aa98cc109b5f5417 100644 --- a/src/gfx/include/gfx/camera.hpp +++ b/src/gfx/include/gfx/camera.hpp @@ -15,10 +15,10 @@ class Camera public: Camera(float fov); - float getFOV(); + float getFOV() const; void setFOV(float fov); - glm::vec2 getWindowSize(); + glm::vec2 getWindowSize() const; void setWindowSize(glm::u32vec2 size); }; diff --git a/src/gfx/include/gfx/control.hpp b/src/gfx/include/gfx/control.hpp index 3257b79ed9f8e5e6f6bcbb6063b1b2982f3e64c9..7581a889283a8fe963de2c925ee94951f158f841 100644 --- a/src/gfx/include/gfx/control.hpp +++ b/src/gfx/include/gfx/control.hpp @@ -31,8 +31,8 @@ public: void setFrame(std::shared_ptr<Frame> frame) { bound_frame = frame; } // void setFrame(Frame* frame) { bound_frame = frame; } - virtual glm::vec3 getFrontVec() { return -bound_frame->getRotationAxisZ(); } - virtual glm::vec3 getUpVec() { return glm::vec3(0.0f, 1.0f, 0.0f); } + virtual glm::vec3 getFrontVec() const { return -bound_frame->getRotationAxisZ(); } + virtual glm::vec3 getUpVec() const { return glm::vec3(0.0f, 1.0f, 0.0f); } // virtual void setUpVec(); void setStep(float dt); diff --git a/src/gfx/include/gfx/frame.hpp b/src/gfx/include/gfx/frame.hpp index a094b69d3a73b892d2ba9944b87e3db4cc04744f..58cd06e4624e8abc32c206b9621ca5735854493f 100644 --- a/src/gfx/include/gfx/frame.hpp +++ b/src/gfx/include/gfx/frame.hpp @@ -25,20 +25,20 @@ public: setRotationQuat(rotation); } - glm::vec3 getPosition() { return positionVec; } - glm::quat getRotation() { return rotationQuat; } - glm::vec3 getScale() { return scaleVec; } + glm::vec3 getPosition() const { return positionVec; } + glm::quat getRotation() const { return rotationQuat; } + glm::vec3 getScale() const { return scaleVec; } - glm::vec3 getRotationAxisX() { return glm::column(glm::toMat3(rotationQuat), 0); } - glm::vec3 getRotationAxisY() { return glm::column(glm::toMat3(rotationQuat), 1); } - glm::vec3 getRotationAxisZ() { return glm::column(glm::toMat3(rotationQuat), 2); } + glm::vec3 getRotationAxisX() const { return glm::column(glm::toMat3(rotationQuat), 0); } + glm::vec3 getRotationAxisY() const { return glm::column(glm::toMat3(rotationQuat), 1); } + glm::vec3 getRotationAxisZ() const { return glm::column(glm::toMat3(rotationQuat), 2); } - glm::mat4 getTranslationMat() { return glm::translate(glm::mat4(1.0f), positionVec); } - glm::mat4 getRotationMat() { return glm::toMat4(rotationQuat); } - glm::mat4 getScaleMat() { return glm::scale(glm::mat4(1.0f), scaleVec); } + glm::mat4 getTranslationMat() const { return glm::translate(glm::mat4(1.0f), positionVec); } + glm::mat4 getRotationMat() const { return glm::toMat4(rotationQuat); } + glm::mat4 getScaleMat() const { return glm::scale(glm::mat4(1.0f), scaleVec); } - glm::mat4 getModelMat() { return getTranslationMat() * getRotationMat() * getScaleMat(); } - glm::mat4 getViewMat() { return glm::inverse(getModelMat()); } + glm::mat4 getModelMat() const { return getTranslationMat() * getRotationMat() * getScaleMat(); } + glm::mat4 getViewMat() const { return glm::inverse(getModelMat()); } void setPosVec(glm::vec3 new_position) { positionVec = new_position; } void translatePosVec(glm::vec3 direction) { positionVec += direction; } diff --git a/src/gfx/include/gfx/light.hpp b/src/gfx/include/gfx/light.hpp index 8fb65bc7890d6f943e127cac4f4379683e4e899f..0205e6c7bc20767dc497a19e1eb73d119c9d55f3 100644 --- a/src/gfx/include/gfx/light.hpp +++ b/src/gfx/include/gfx/light.hpp @@ -14,8 +14,8 @@ public: Light(glm::vec3 _color, glm::vec3 _pos) : color{_color}, frame{_pos} {} glm::vec3 getColor() { return color; } - virtual glm::vec3 getPosition() { return frame.getPosition(); } - virtual glm::vec3 getDirection() { return frame.getPosition(); } + virtual glm::vec3 getPosition() const { return frame.getPosition(); } + virtual glm::vec3 getDirection() const { return frame.getPosition(); } virtual ~Light() = default; }; diff --git a/src/gfx/include/gfx/render.hpp b/src/gfx/include/gfx/render.hpp index a18ca6f31c3c04289643deb8c2745cadc868abc4..07e1df9b640db97e1811357a6bc51bb4411e3dc1 100644 --- a/src/gfx/include/gfx/render.hpp +++ b/src/gfx/include/gfx/render.hpp @@ -16,11 +16,12 @@ using object_ptr = std::shared_ptr<Object>; using camera_ptr = std::shared_ptr<Camera>; using frame_ptr = std::shared_ptr<Frame>; using shader_ptr = std::shared_ptr<Shader>; +using light_ptr = std::shared_ptr<Light>; std::vector<float> generate_grid_vertices(int span); std::vector<unsigned int> generate_grid_indices(int span); void send_matrices_to_shader(Shader &myShader, glm::mat4 &model, glm::mat4 &view, glm::mat4 &projection); -void gfx_draw(std::map<std::string, shader_ptr> &myShaders, Light &light, +void gfx_draw(std::map<std::string, shader_ptr> &myShaders, light_ptr light, std::vector<camera_ptr> &cameras, std::vector<frame_ptr> &cam_frames, int active_camera, std::vector<object_ptr> &objects, std::vector<frame_ptr> &obj_frames, Object &grid, Frame &grid_frame); diff --git a/src/gfx/src/camera.cpp b/src/gfx/src/camera.cpp index 7976218d2539b375f41475c9250ee7dd77fe27a6..8716ab7909cced0626b00b4f750804186f9a5c95 100644 --- a/src/gfx/src/camera.cpp +++ b/src/gfx/src/camera.cpp @@ -3,10 +3,10 @@ Camera::Camera(float fov) : FOV{fov} {} -float Camera::getFOV() { return FOV; } +float Camera::getFOV() const { return FOV; } void Camera::setFOV(float fov) { FOV = fov <= 120 ? fov : 120; } -glm::vec2 Camera::getWindowSize() +glm::vec2 Camera::getWindowSize() const { return window_size; } diff --git a/src/gfx/src/render.cpp b/src/gfx/src/render.cpp index dcf1c9b24a985a03684f40aeadfafe50fe519402..ff95e1894c402e3750bbf4ad85f6d745f48255bf 100644 --- a/src/gfx/src/render.cpp +++ b/src/gfx/src/render.cpp @@ -69,7 +69,7 @@ void send_matrices_to_shader(Shader &myShader, glm::mat4 &model, glm::mat4 &view ASSUMPTION(glGetError() == GL_NO_ERROR); } -void draw_objects(std::map<std::string, shader_ptr> &myShaders, Light &light, +void draw_objects(std::map<std::string, shader_ptr> &myShaders, light_ptr light, std::vector<frame_ptr> &cam_frames, int active_camera, std::vector<object_ptr> &objects,std::vector<frame_ptr> &obj_frames, glm::mat4 &view, glm::mat4 &projection) @@ -84,8 +84,8 @@ void draw_objects(std::map<std::string, shader_ptr> &myShaders, Light &light, { // Hardcoded light index // TO DO: enum promennych z shaderu - myShaders[shader_used]->setVec3("lightColor", light.getColor()); - myShaders[shader_used]->setVec3("lightPos", light.getPosition()); + myShaders[shader_used]->setVec3("lightColor", light->getColor()); + myShaders[shader_used]->setVec3("lightPos", light->getPosition()); myShaders[shader_used]->setVec3("viewPos", cam_frames[active_camera]->getPosition()); } @@ -120,7 +120,7 @@ void draw_grid(std::map<std::string, shader_ptr> &myShaders, Object &grid, Frame ASSUMPTION(glGetError() == GL_NO_ERROR); } -void gfx_draw(std::map<std::string, shader_ptr> &myShaders, Light &light, +void gfx_draw(std::map<std::string, shader_ptr> &myShaders, light_ptr light, std::vector<camera_ptr> &cameras, std::vector<frame_ptr> &cam_frames, int active_camera, std::vector<object_ptr> &objects, std::vector<frame_ptr> &obj_frames, Object &grid, Frame &grid_frame) diff --git a/src/studio/include/studio/simulator.hpp b/src/studio/include/studio/simulator.hpp index 74b4a10ee8ff07e90645a08dff0d091c08e38f20..2bca5dcfe2de9cf01aee0cb701edf77a3fa83c55 100644 --- a/src/studio/include/studio/simulator.hpp +++ b/src/studio/include/studio/simulator.hpp @@ -32,6 +32,7 @@ using camera_ptr = std::shared_ptr<Camera>; using frame_ptr = std::shared_ptr<Frame>; using obj_control_ptr = std::shared_ptr<ObjectController>; using cam_control_ptr = std::shared_ptr<CameraController>; +using light_ptr = std::shared_ptr<Light>; using shader_ptr = std::shared_ptr<Shader>; struct Simulator : public osi::Simulator @@ -63,7 +64,7 @@ struct Simulator : public osi::Simulator Object grid = Object(generate_grid_vertices(100), generate_grid_indices(100), {0, -1, 0}); Frame grid_frame = Frame({0, 0, 0}); - PointLight light; + light_ptr light; std::map<std::string, shader_ptr> myShaders; }; diff --git a/src/studio/src/simulator.cpp b/src/studio/src/simulator.cpp index c1a303547cff24f118bd85a6e328c5b41996fad2..49e65f53d762fe3377473761fe6c2c597f92066f 100644 --- a/src/studio/src/simulator.cpp +++ b/src/studio/src/simulator.cpp @@ -124,7 +124,7 @@ Simulator::Simulator() , obj_frames{std::make_shared<Frame>(), std::make_shared<Frame>(glm::vec3(1.2f, 2.0f, 2.0f ))} , obj_controls{std::make_shared<ObjectController>()} - , light{glm::vec3(1.0f, 1.0f, 1.0f), obj_frames[1]->getPosition()} + , light{std::make_shared<Light>(glm::vec3(1.0f, 1.0f, 1.0f), obj_frames[1]->getPosition())} { // SET LIGHT CUBE SHADER AND SIZE objects[1]->setShaderType("basic");