Skip to content
Snippets Groups Projects
Commit bee3b3ea authored by Joseph Walton-Rivers's avatar Joseph Walton-Rivers
Browse files

add edge scrolling back in

parent 8b0537d6
No related branches found
No related tags found
No related merge requests found
Pipeline #3041 failed
......@@ -161,6 +161,54 @@ void process_freecam(fggl::ecs::ECS& ecs, InputManager input, fggl::ecs::entity_
camComp->target = pivot;
}
void process_edgescroll(fggl::ecs::ECS& ecs, InputManager input, fggl::ecs::entity_t cam) {
glm::vec3 translation(0.0f);
auto& mouse = input->mouse;
// calulate movement (user input)
if ( mouse.axis( MouseAxis::Y ) < 0.9f ) {
translation -= fggl::math::RIGHT;
}
if ( mouse.axis( MouseAxis::Y) > -0.9f ) {
translation += fggl::math::RIGHT;
}
if ( mouse.axis( MouseAxis::X) > -0.9f ) {
translation += fggl::math::FORWARD;
}
if ( mouse.axis( MouseAxis::X ) < 0.9f ) {
translation -= fggl::math::FORWARD;
}
// apply rotation/movement
auto camTransform = ecs.getComponent<fggl::math::Transform>(cam);
auto camComp = ecs.getComponent<fggl::gfx::Camera>(cam);
glm::vec4 position( camTransform->origin(), 1.0f );
glm::vec4 pivot( camComp->target, 1.0f );
// apply movement
if ( translation != glm::vec3(0.0f) ) {
const auto rotation = (position - pivot);
const float angle = atan2( rotation.x, rotation.z );
const auto rotationMat = glm::rotate( MAT_IDENTITY, angle, fggl::math::UP );
auto deltaMove = (rotationMat * glm::vec4( translation, 1.0f )) * PAN_SPEED;
deltaMove.w = 0.0f;
position += deltaMove;
pivot += deltaMove;
}
// move camera
camTransform->origin( position );
camComp->target = pivot;
}
void process_camera(fggl::gfx::Window& window, fggl::ecs::ECS& ecs, InputManager input, fggl::ecs::entity_t cam) {
auto camTransform = ecs.getComponent<fggl::math::Transform>(cam);
auto camComp = ecs.getComponent<fggl::gfx::Camera>(cam);
......@@ -181,6 +229,7 @@ void process_camera(fggl::gfx::Window& window, fggl::ecs::ECS& ecs, InputManager
} else if ( cam_mode == cam_free ) {
process_freecam(ecs, input, cam);
}
process_edgescroll( ecs, input, cam );
}
int main(int argc, char* argv[]) {
......
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