Skip to content

Commit

Permalink
Rotate on command
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaweees committed Oct 18, 2024
1 parent 16a7b2c commit 1c0645d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
2 changes: 2 additions & 0 deletions include/display.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class Display {
Vector3D camera;
Vector3D rotation;

SDL_Keycode keyPressed;

int prevTime;

public:
Expand Down
25 changes: 23 additions & 2 deletions src/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Display::Display() {
// Initialize the camera
camera = Vector3D(0, 0, -5);
rotation = Vector3D(0, 0, 0);
keyPressed = SDLK_UP;

prevTime = SDL_GetTicks();

Expand Down Expand Up @@ -144,7 +145,21 @@ void Display::update() {
}
#endif
// Update rotation
rotation.translate(0.01, 0, 0);
switch (keyPressed) {
case SDLK_UP:
rotation.x += 0.01;
break;
case SDLK_DOWN:
rotation.x -= 0.01;
break;
case SDLK_LEFT:
rotation.y += 0.01;
break;
case SDLK_RIGHT:
rotation.y -= 0.01;
break;
}
// rotation.translate(0.01, 0, 0);
deltaTime = 0;
}
}
Expand Down Expand Up @@ -175,10 +190,16 @@ void Display::render() {

void Display::processInput() {
SDL_Event event;
switch (event.type) {
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_KEYDOWN:
keyPressed = event.key.keysym.sym;
printf("Key pressed: %c\n", keyPressed);
break;
default:
break;
}
}
}

void Display::clear() {
Expand Down

0 comments on commit 1c0645d

Please sign in to comment.