Skip to content

Commit

Permalink
Fix camera movement
Browse files Browse the repository at this point in the history
  • Loading branch information
zlondrej committed Oct 26, 2023
1 parent ffce8bf commit 79e3502
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions shaders/blend.frag
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ in vec2 textureCoords;
out vec3 color;

void main() {
vec4 front = texture2D(frontTexture, textureCoords);
vec4 back = texture2D(backTexture, textureCoords);
vec4 front = texture(frontTexture, textureCoords);
vec4 back = texture(backTexture, textureCoords);

vec4 frontD = texture2D(frontDepth, textureCoords);
vec4 backD = texture2D(backDepth, textureCoords);
vec4 frontD = texture(frontDepth, textureCoords);
vec4 backD = texture(backDepth, textureCoords);

if(backD.x <= frontD.x) {
color = back.rgb;
Expand Down
8 changes: 4 additions & 4 deletions src/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using namespace pgp;
using namespace glm;

Camera::Camera(SDL_Window *_window) : position(0.0, 35.0, 0.0), rotation(0, 0) {
Camera::Camera(SDL_Window *_window) : position(0.0, 35.0, 0.0), rotation(0, 0), movement(0, 0, 0) {
window = _window;
SDL_GetWindowSize(window, &(windowSize.x), &(windowSize.y));
}
Expand Down Expand Up @@ -40,7 +40,7 @@ IEventListener::EventResponse Camera::onEvent(SDL_Event* evt) {
SDL_KeyboardEvent *e = &evt->key;

positive = max(ivec3(0, 0, 0), movement);
negative = min(ivec3(0, 0, 0), movement);
negative = -min(ivec3(0, 0, 0), movement);

int active = (evt->type == SDL_KEYDOWN) ? 1 : 0;

Expand Down Expand Up @@ -76,8 +76,8 @@ IEventListener::EventResponse Camera::onEvent(SDL_Event* evt) {

if (SDL_BUTTON_LEFT & e->state) {
// TODO: Adjust mouse sensitivity coeficient
rotation.y += e->xrel * 0.002;
rotation.x -= e->yrel * 0.002;
rotation.y -= e->xrel * 0.002;
rotation.x += e->yrel * 0.002;

// To prevent horizontal turn
rotation.x = clamp(rotation.x, -PI_HALF_CLAMP, PI_HALF_CLAMP);
Expand Down

0 comments on commit 79e3502

Please sign in to comment.