Skip to content

Commit

Permalink
simple mouse control
Browse files Browse the repository at this point in the history
  • Loading branch information
xfusek08 committed May 2, 2020
1 parent aed3a92 commit 04a9e32
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 16 deletions.
5 changes: 1 addition & 4 deletions src/GeoPlanetDemo/ApplicationEventReceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ bool ApplicationEventReceiver::processSDLEvent(SDL_Event const& event)
case SDLK_F4: RUN_SET_ELEMENT_VT("planet", vt::types::PlanetWireFrameVT);
case SDLK_F5: RUN_SET_ELEMENT_VT("planet", vt::types::PlanetCubeMapVT);


case SDLK_1: RUN_SET_ELEMENT_VT("planet_data", vt::types::UndefinedVT);
case SDLK_2: RUN_SET_ELEMENT_VT("planet_data", vt::types::PlanetVectorsVT);

case SDLK_p: RUN_FOR_PLANET({
planetEntity->setResolution(planetEntity->getResolution() + 1);
});
Expand Down Expand Up @@ -83,6 +79,7 @@ bool ApplicationEventReceiver::processSDLEvent(SDL_Event const& event)
planetEntity->doWarp = !planetEntity->doWarp;
});
}
break;
default: break;
}
return false;
Expand Down
26 changes: 18 additions & 8 deletions src/GeoPlanetDemo/core/OrbitCameraController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,34 @@ OrbitCameraController::OrbitCameraController(shared_ptr<Camera> camera) :
performRotation();
}

void OrbitCameraController::up()
void OrbitCameraController::up(float degree)
{
performRotation(
speed,
(degree ? degree : speed),
glm::normalize(glm::cross(camera->getCameraDirection(), glm::vec3{ 0.f,1.f,0.f }))
);
}

void OrbitCameraController::down()
void OrbitCameraController::down(float degree)
{
performRotation(
-speed,
-(degree ? degree : speed),
glm::normalize(glm::cross(camera->getCameraDirection(), glm::vec3{ 0.f,1.f,0.f }))
);
}

void OrbitCameraController::left()
void OrbitCameraController::left(float degree)
{
performRotation(
-speed,
-(degree ? degree : speed),
glm::vec3(0.f, 1.f, 0.f)
);
}

void OrbitCameraController::right()
void OrbitCameraController::right(float degree)
{
performRotation(
speed,
(degree ? degree : speed),
glm::vec3(0.f, 1.f, 0.f)
);
}
Expand All @@ -69,8 +69,18 @@ void OrbitCameraController::zoomOut()
performRotation();
}

void OrbitCameraController::zoom(float amount)
{
radius += amount / 10;
GPD_LOG_INFO("zoom radius: " << radius);
performRotation();
}

void OrbitCameraController::lookXY(glm::vec2 delta)
{
GPD_LOG_INFO("dragging: relx: " << delta.x <<" rely: " << delta.y);
down(radius * (delta.y / 2000));
right(radius * (delta.x / 2000));
}

void OrbitCameraController::performRotation(float angleIncrement, glm::vec3 axis)
Expand Down
9 changes: 5 additions & 4 deletions src/GeoPlanetDemo/core/OrbitCameraController.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ namespace gpd

inline std::shared_ptr<core::Camera> getCamera() { return camera; }

void up();
void down();
void left();
void right();
void up(float degree = 0);
void down(float degree = 0);
void left(float degree = 0);
void right(float degree = 0);

void zoomIn();
void zoomOut();
void zoom(float amount);

void lookXY(glm::vec2 delta);
protected:
Expand Down
13 changes: 13 additions & 0 deletions src/GeoPlanetDemo/sdl/SDLOrbitCameraController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ SDLOrbitCameraController::SDLOrbitCameraController(shared_ptr<Camera> camera) :

bool SDLOrbitCameraController::processSDLEvent(SDL_Event const& event)
{
switch (event.type) {
case SDL_MOUSEMOTION:
if (event.motion.state & SDL_BUTTON_LEFT) {
lookXY({event.motion.xrel, event.motion.yrel});
return true;
}
break;
case SDL_MOUSEWHEEL:
zoom(-event.wheel.y);
return true;
break;
default: break;
}
return false;
}

Expand Down

0 comments on commit 04a9e32

Please sign in to comment.