From 90f2dfaf3b1911555b14da3cb8f804d09a3cfa02 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 5 Sep 2023 13:26:31 +0300 Subject: [PATCH] Refactor viewer to use Geometry::Angle --- tools/viewer.cpp | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/tools/viewer.cpp b/tools/viewer.cpp index 36a5dc9b..97685163 100644 --- a/tools/viewer.cpp +++ b/tools/viewer.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -75,11 +76,11 @@ private: GL::DirectionalLight light; GL::Lighting lighting; GL::Camera camera; - float yaw; - float pitch; + Geometry::Angle yaw; + Geometry::Angle pitch; float distance; - float light_yaw; - float light_pitch; + Geometry::Angle light_yaw; + Geometry::Angle light_pitch; unsigned dragging; Time::TimeStamp last_tick; @@ -138,11 +139,7 @@ Viewer::Viewer(int argc, char **argv): renderable(0), anim_object(0), anim_player(0), - yaw(0), - pitch(0), distance(10), - light_yaw(0), - light_pitch(0), dragging(0) { for(list::const_iterator i=opts.resource_locations.begin(); i!=opts.resource_locations.end(); ++i) @@ -327,17 +324,11 @@ void Viewer::axis_motion(unsigned axis, float, float delta) float dx = (axis==0 ? delta : 0); float dy = (axis==1 ? delta : 0); - yaw -= dx*M_PI*2; - while(yaw>M_PI) - yaw -= M_PI*2; - while(yaw<-M_PI) - yaw += M_PI*2; + yaw -= Geometry::Angle::from_turns(dx); + yaw.wrap_balanced(); - pitch += dy*M_PI; - if(pitch>M_PI*0.49) - pitch = M_PI*0.49; - if(pitch<-M_PI*0.49) - pitch = -M_PI*0.49; + pitch += Geometry::Angle::from_turns(dy*0.5f); + pitch = min(max(pitch, Geometry::Angle::from_turns(-0.24f)), Geometry::Angle::from_turns(0.24f)); update_camera(); } @@ -346,8 +337,8 @@ void Viewer::axis_motion(unsigned axis, float, float delta) float x = mouse.get_axis_value(0); float y = mouse.get_axis_value(1); - light_yaw = yaw+x*M_PI; - light_pitch = pitch-y*M_PI; + light_yaw = yaw+Geometry::Angle::from_turns(x*0.5f); + light_pitch = pitch-Geometry::Angle::from_turns(y*0.5f); update_light(); } -- 2.45.2