Skip to content
Snippets Groups Projects
Commit d38924b2 authored by Martin Štourač's avatar Martin Štourač
Browse files

light uses own frame, attempt to fix pitch

parent d6e28d79
No related branches found
No related tags found
No related merge requests found
...@@ -14,20 +14,12 @@ ...@@ -14,20 +14,12 @@
class CameraController : public Controller class CameraController : public Controller
{ {
float overall_pitch = 0.0f;
float overall_yaw = -90.0f;
glm::vec2 sens; glm::vec2 sens;
float sens_multiplier = 10.0f; float sens_multiplier = 10.0f;
public: public:
using Controller::Controller; using Controller::Controller;
float getPitch() { return overall_pitch; }
float getYaw() { return overall_yaw; }
void adjustPitch(float yoffset);
void setYaw(float xoffset);
void setFrontVec(float xoffset, float yoffset); void setFrontVec(float xoffset, float yoffset);
void turn(float xoffset, float yoffset); void turn(float xoffset, float yoffset);
......
...@@ -9,37 +9,26 @@ class Light ...@@ -9,37 +9,26 @@ class Light
{ {
protected: protected:
glm::vec3 color; glm::vec3 color;
Frame frame;
public: public:
Light(glm::vec3 _color) : color{_color} {} Light(glm::vec3 _color, glm::vec3 _pos) : color{_color}, frame{_pos} {}
glm::vec3 getColor() { return color; } glm::vec3 getColor() { return color; }
// WTF, FIX!!! virtual glm::vec3 getPosition() { return frame.getPosition(); }
virtual glm::vec3 getPosition() { return color; } virtual glm::vec3 getDirection() { return frame.getPosition(); }
virtual ~Light() = default; virtual ~Light() = default;
}; };
class DirLight : public Light class DirLight : public Light
{ {
glm::vec3 direction;
public: public:
using Light::Light; using Light::Light;
DirLight(glm::vec3 _color, glm::vec3 _direction) : Light{_color}, direction{_direction} {}
glm::vec3 getDirection() { return direction; }
}; };
class PointLight : public Light class PointLight : public Light
{ {
glm::vec3 position;
bool bound_to_frame = false;
std::shared_ptr<Frame> bound_frame;
public: public:
using Light::Light; using Light::Light;
PointLight(glm::vec3 _color, glm::vec3 _position) : Light{_color}, position{_position} {}
PointLight(glm::vec3 _color, std::shared_ptr<Frame> _bound_frame)
: Light{_color}, bound_frame{_bound_frame} { bound_to_frame = true; }
glm::vec3 getPosition() override { return bound_to_frame ? bound_frame->getPosition() : position; }
}; };
#endif #endif
\ No newline at end of file
#include <gfx/cam_control.hpp> #include <gfx/cam_control.hpp>
#include <iostream> #include <iostream>
void CameraController::adjustPitch(float yoffset)
{
overall_pitch += yoffset;
if(overall_pitch > glm::radians(89.0f))
{
overall_pitch = glm::radians(89.0f);
}
else if(overall_pitch < glm::radians(-89.0f))
{
overall_pitch = glm::radians(-89.0f);
}
}
void CameraController::setYaw(float xoffset) { overall_yaw += xoffset; }
void CameraController::setFrontVec(float xoffset, float yoffset) void CameraController::setFrontVec(float xoffset, float yoffset)
{ {
// TO DO: fix pitch // TO DO: fix pitch
auto pitch = glm::angleAxis(yoffset, glm::vec3(1, 0, 0)); auto pitch = glm::angleAxis(yoffset, glm::vec3(1, 0, 0));
auto yaw = glm::angleAxis(-xoffset, glm::vec3(0, 1, 0)); auto yaw = glm::angleAxis(-xoffset, glm::vec3(0, 1, 0));
bound_frame->rotateRotationQuat(pitch * yaw); auto temp_rot_quat = pitch * bound_frame->getRotation();
auto temp_y_axis = glm::column(glm::toMat3(temp_rot_quat), 1);
// auto pitch = glm::angleAxis(overall_pitch, glm::vec3(1, 0, 0)); std::cout << "dot product: " << glm::dot(temp_y_axis, glm::vec3(0, 1, 0)) << std::endl;
// auto yaw = glm::angleAxis(-overall_yaw, glm::vec3(0, 1, 0)); if (glm::dot(temp_y_axis, glm::vec3(0, 1, 0)) > 0.15f) // 0
// bound_frame->setRotationQuat(pitch * yaw); {
bound_frame->rotateRotationQuat(pitch * yaw);
}
} }
void CameraController::turn(float xoffset, float yoffset) void CameraController::turn(float xoffset, float yoffset)
{ {
if (xoffset == 0 && yoffset == 0) if (xoffset == 0 && yoffset == 0)
return; return;
setYaw(xoffset);
adjustPitch(yoffset);
setFrontVec(xoffset, yoffset); setFrontVec(xoffset, yoffset);
} }
......
...@@ -84,7 +84,6 @@ void draw_objects(std::map<std::string, shader_ptr> &myShaders, Light &light, ...@@ -84,7 +84,6 @@ void draw_objects(std::map<std::string, shader_ptr> &myShaders, Light &light,
{ {
// Hardcoded light index // Hardcoded light index
// TO DO: enum promennych z shaderu // TO DO: enum promennych z shaderu
// TO DO: Light struct, kde bude info o pos, color
myShaders[shader_used]->setVec3("lightColor", light.getColor()); myShaders[shader_used]->setVec3("lightColor", light.getColor());
myShaders[shader_used]->setVec3("lightPos", light.getPosition()); myShaders[shader_used]->setVec3("lightPos", light.getPosition());
myShaders[shader_used]->setVec3("viewPos", cam_frames[active_camera]->getPosition()); myShaders[shader_used]->setVec3("viewPos", cam_frames[active_camera]->getPosition());
......
...@@ -124,7 +124,7 @@ Simulator::Simulator() ...@@ -124,7 +124,7 @@ Simulator::Simulator()
, obj_frames{std::make_shared<Frame>(), , obj_frames{std::make_shared<Frame>(),
std::make_shared<Frame>(glm::vec3(1.2f, 2.0f, 2.0f ))} std::make_shared<Frame>(glm::vec3(1.2f, 2.0f, 2.0f ))}
, obj_controls{std::make_shared<ObjectController>()} , obj_controls{std::make_shared<ObjectController>()}
, light{PointLight(glm::vec3(1.0f, 1.0f, 1.0f), obj_frames[1])} , light{glm::vec3(1.0f, 1.0f, 1.0f), obj_frames[1]->getPosition()}
{ {
// SET LIGHT CUBE SHADER AND SIZE // SET LIGHT CUBE SHADER AND SIZE
objects[1]->setShaderType("basic"); objects[1]->setShaderType("basic");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment