OverviewCameraTool.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00024 #include "OverviewCameraTool.h"
00025 #include "GLViewer.h"
00026 
00027 const double PanosphereOverviewCameraTool::limit_low = 1.2;
00028 const double PanosphereOverviewCameraTool::limit_high = 5.0;
00029 
00030 void PanosphereOverviewCameraTool::Activate()
00031 {
00032     helper->NotifyMe(ToolHelper::MOUSE_MOVE, this);
00033     helper->NotifyMe(ToolHelper::MOUSE_PRESS, this);
00034     helper->NotifyMe(ToolHelper::MOUSE_WHEEL, this);
00035     helper->NotifyMe(ToolHelper::KEY_PRESS, this);
00036     down = false;
00037 }
00038 
00039 
00040 
00041 void PanosphereOverviewCameraTool::MouseMoveEvent(double x, double y, wxMouseEvent & e)
00042 {
00043     if (down) {
00044         hugin_utils::FDiff2D pos = helper->GetMouseScreenPosition();
00045         PanosphereOverviewVisualizationState*  state = (PanosphereOverviewVisualizationState*) helper->GetVisualizationStatePtr();
00046         double b_angx = state->getAngX();
00047         double b_angy = state->getAngY();
00048         //FIXME: include a scale factor for the panosphere
00049         double scale = (state->getR() - state->getSphereRadius()) / 40000.0;
00050         state->setAngX((pos.x - start_x) * scale + start_angx);
00051         double ey = (pos.y - start_y) * scale + start_angy;
00052         if (ey >= M_PI / 2.0) {ey = M_PI / 2.0 - 0.0001;}
00053         if (ey <= -M_PI / 2.0) {ey = -M_PI / 2.0 + 0.0001;}
00054         state->setAngY(ey);
00055         state->Redraw();
00056     }
00057 }
00058 
00059 void PanosphereOverviewCameraTool::MouseButtonEvent(wxMouseEvent &e)
00060 {
00061 //    DEBUG_DEBUG("mouse ov drag button");
00062     if ((e.ButtonDown() && (!helper->IsMouseOverPano() || e.CmdDown() || e.AltDown())) || e.MiddleDown()) {
00063         down = true;
00064         hugin_utils::FDiff2D pos = helper->GetMouseScreenPosition();
00065         start_x = pos.x;
00066         start_y = pos.y;
00067         PanosphereOverviewVisualizationState*  state = (PanosphereOverviewVisualizationState*) helper->GetVisualizationStatePtr();
00068         start_angx = state->getAngX();
00069         start_angy = state->getAngY();
00070     }
00071     if (e.ButtonUp()) {
00072         if (down) {
00073             down = false;
00074         }
00075     }
00076 }
00077 
00078 
00079 void PanosphereOverviewCameraTool::ChangeZoomLevel(bool zoomIn, double scale) {
00080     PanosphereOverviewVisualizationState*  state = (PanosphereOverviewVisualizationState*) helper->GetVisualizationStatePtr();
00081     double radius = state->getSphereRadius();
00082     if (zoomIn) {
00083         if (state->getR() > limit_low * radius) {
00084             state->setR((state->getR() - radius) / scale + radius);
00085             state->SetDirtyViewport();
00086             state->ForceRequireRedraw();
00087             state->Redraw();
00088         }
00089     } else {
00090         if (state->getR() < limit_high * radius) {
00091             state->setR((state->getR() - radius) * scale + radius);
00092             state->SetDirtyViewport();
00093             state->ForceRequireRedraw();
00094             state->Redraw();
00095         }
00096     }
00097 }
00098 
00099 void PanosphereOverviewCameraTool::MouseWheelEvent(wxMouseEvent &e)
00100 {
00101     if (e.GetWheelRotation() != 0) {
00102         ChangeZoomLevel(e.GetWheelRotation() > 0);
00103     }
00104 }
00105 
00106 void PanosphereOverviewCameraTool::KeypressEvent(int keycode, int modifiers, bool pressed) {
00107 //    std::cout << "kc: " << keycode << " " << modifiers << std::endl;
00108 //    std::cout << "cmd: " << wxMOD_CMD << " " << wxMOD_CONTROL << " " << WXK_ADD << " " << WXK_SUBTRACT << std::endl;
00109 //    std::cout << "cmd: " << wxMOD_CMD << " " << wxMOD_CONTROL << " " << WXK_NUMPAD_ADD << " " << WXK_NUMPAD_SUBTRACT << std::endl;
00110     if (pressed)
00111     if (modifiers == wxMOD_CMD) {
00112         if (keycode == WXK_ADD) {
00113             ChangeZoomLevel(true);
00114         } else if (keycode == WXK_SUBTRACT) {
00115             ChangeZoomLevel(false);
00116         }
00117     }
00118 }
00119 
00120 void PlaneOverviewCameraTool::Activate()
00121 {
00122     helper->NotifyMe(ToolHelper::MOUSE_MOVE, this);
00123     helper->NotifyMe(ToolHelper::MOUSE_PRESS, this);
00124     helper->NotifyMe(ToolHelper::MOUSE_WHEEL, this);
00125     down = false;
00126 }
00127 
00128 void PlaneOverviewCameraTool::MouseMoveEvent(double x, double y, wxMouseEvent & e)
00129 {
00130     if (down) {
00131         PlaneOverviewToolHelper * thelper = (PlaneOverviewToolHelper*) helper;
00132         PlaneOverviewVisualizationState*  state = (PlaneOverviewVisualizationState*) helper->GetVisualizationStatePtr();
00133 //
00134         //same code as in tool helper to get position on the z-plane but with initial position
00135         double d = state->getR();
00136 
00137         int tcanv_w, tcanv_h;
00138         state->GetViewer()->GetClientSize(&tcanv_w,&tcanv_h);
00139 
00140         double canv_w, canv_h;
00141         canv_w = tcanv_w;
00142         canv_h = tcanv_h;
00143         
00144         double fov = state->getFOV();
00145 
00146         double fovy, fovx;
00147         if (canv_w > canv_h) {
00148             fovy = DEG_TO_RAD(fov);
00149             fovx = 2 * atan( tan(fovy / 2.0) * canv_w / canv_h);
00150         } else {
00151             fovx = DEG_TO_RAD(fov);
00152             fovy = 2 * atan( tan(fovx / 2.0) * canv_h / canv_w);
00153         }
00154 
00155         double vis_w, vis_h;
00156         vis_w = 2.0 * tan ( fovx / 2.0 ) * d;
00157         vis_h = 2.0 * tan ( fovy / 2.0 ) * d;
00158 
00159         //position of the mouse on the z=0 plane
00160         double prim_x, prim_y;
00161         prim_x = (double) x / canv_w * vis_w - vis_w / 2.0 + start_pos_x;
00162         prim_y = ((double) y / canv_h * vis_h - vis_h / 2.0 - start_pos_y);
00163 
00164 //        DEBUG_DEBUG("mouse ov tool 1 " << state->getX() << " " << state->getY());
00165         state->setX((-prim_x + start_x) + start_pos_x);
00166         state->setY((prim_y - start_y) + start_pos_y);
00167 //        DEBUG_DEBUG("mouse ov tool 2 " << state->getX() << " " << state->getY());
00168         state->ForceRequireRedraw();
00169         state->Redraw();
00170     }
00171 }
00172 
00173 void PlaneOverviewCameraTool::MouseButtonEvent(wxMouseEvent &e)
00174 {
00175     PlaneOverviewToolHelper * thelper = (PlaneOverviewToolHelper*) helper;
00176     PlaneOverviewVisualizationState*  state = (PlaneOverviewVisualizationState*) helper->GetVisualizationStatePtr();
00177 //    DEBUG_DEBUG("mouse ov drag button");
00178     if (((e.CmdDown() || e.AltDown()) && e.LeftDown()) || e.MiddleDown()) {
00179         down = true;
00180         start_x = thelper->getPlaneX();
00181         start_y = thelper->getPlaneY();
00182         start_pos_x = state->getX();
00183         start_pos_y = state->getY();
00184     }
00185     if (e.LeftUp() || e.MiddleUp()) {
00186         if (down) {
00187             down = false;
00188         }
00189     }
00190 }
00191 
00192 void PlaneOverviewCameraTool::ChangeZoomLevel(bool zoomIn, double scale) {
00193     PlaneOverviewVisualizationState*  state = (PlaneOverviewVisualizationState*) helper->GetVisualizationStatePtr();
00194     if (zoomIn) {
00195         state->setR(state->getR() / scale);
00196     } else {
00197         state->setR(state->getR() * scale);
00198     }
00199     state->SetDirtyViewport();
00200     state->ForceRequireRedraw();
00201     state->Redraw();
00202 }
00203 
00204 void PlaneOverviewCameraTool::MouseWheelEvent(wxMouseEvent &e)
00205 {
00206     if (e.GetWheelRotation() != 0) {
00207         ChangeZoomLevel(e.GetWheelRotation() > 0);
00208     }
00209 }
00210 
00211 void PlaneOverviewCameraTool::KeypressEvent(int keycode, int modifiers, bool pressed) {
00212     if (pressed)
00213     if (modifiers == wxMOD_CMD) {
00214         if (keycode == WXK_ADD) {
00215             ChangeZoomLevel(true);
00216         } else if (keycode == WXK_SUBTRACT) {
00217             ChangeZoomLevel(false);
00218         }
00219     }
00220 }
00221 
00222 

Generated on 28 Nov 2014 for Hugintrunk by  doxygen 1.4.7