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

Generated on 3 Aug 2015 for Hugintrunk by  doxygen 1.4.7