[0d9e02]: src / hugin1 / hugin / OverviewCameraTool.cpp Maximize Restore History

Download this file

OverviewCameraTool.cpp    223 lines (194 with data), 7.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
// -*- c-basic-offset: 4 -*-
/** @file OverviewCameraTool.h
*
* @author Darko Makreshanski
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this software; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "OverviewCameraTool.h"
#include "GLViewer.h"
const double PanosphereOverviewCameraTool::limit_low = 1.2;
const double PanosphereOverviewCameraTool::limit_high = 5.0;
void PanosphereOverviewCameraTool::Activate()
{
helper->NotifyMe(ToolHelper::MOUSE_MOVE, this);
helper->NotifyMe(ToolHelper::MOUSE_PRESS, this);
helper->NotifyMe(ToolHelper::MOUSE_WHEEL, this);
helper->NotifyMe(ToolHelper::KEY_PRESS, this);
down = false;
}
void PanosphereOverviewCameraTool::MouseMoveEvent(double x, double y, wxMouseEvent & e)
{
if (down) {
hugin_utils::FDiff2D pos = helper->GetMouseScreenPosition();
PanosphereOverviewVisualizationState* state = (PanosphereOverviewVisualizationState*) helper->GetVisualizationStatePtr();
double b_angx = state->getAngX();
double b_angy = state->getAngY();
//FIXME: include a scale factor for the panosphere
double scale = (state->getR() - state->getSphereRadius()) / 40000.0;
state->setAngX((pos.x - start_x) * scale + start_angx);
double ey = (pos.y - start_y) * scale + start_angy;
if (ey >= M_PI / 2.0) {ey = M_PI / 2.0 - 0.0001;}
if (ey <= -M_PI / 2.0) {ey = -M_PI / 2.0 + 0.0001;}
state->setAngY(ey);
state->Redraw();
}
}
void PanosphereOverviewCameraTool::MouseButtonEvent(wxMouseEvent &e)
{
// DEBUG_DEBUG("mouse ov drag button");
if ((e.ButtonDown() && (!helper->IsMouseOverPano() || e.ControlDown() || e.AltDown())) || e.MiddleDown()) {
down = true;
hugin_utils::FDiff2D pos = helper->GetMouseScreenPosition();
start_x = pos.x;
start_y = pos.y;
PanosphereOverviewVisualizationState* state = (PanosphereOverviewVisualizationState*) helper->GetVisualizationStatePtr();
start_angx = state->getAngX();
start_angy = state->getAngY();
}
if (e.ButtonUp()) {
if (down) {
down = false;
}
}
}
void PanosphereOverviewCameraTool::ChangeZoomLevel(bool zoomIn, double scale) {
PanosphereOverviewVisualizationState* state = (PanosphereOverviewVisualizationState*) helper->GetVisualizationStatePtr();
double radius = state->getSphereRadius();
if (zoomIn) {
if (state->getR() > limit_low * radius) {
state->setR((state->getR() - radius) / scale + radius);
state->SetDirtyViewport();
state->ForceRequireRedraw();
state->Redraw();
}
} else {
if (state->getR() < limit_high * radius) {
state->setR((state->getR() - radius) * scale + radius);
state->SetDirtyViewport();
state->ForceRequireRedraw();
state->Redraw();
}
}
}
void PanosphereOverviewCameraTool::MouseWheelEvent(wxMouseEvent &e)
{
if (e.GetWheelRotation() != 0) {
ChangeZoomLevel(e.GetWheelRotation() > 0);
}
}
void PanosphereOverviewCameraTool::KeypressEvent(int keycode, int modifiers, bool pressed) {
// std::cout << "kc: " << keycode << " " << modifiers << std::endl;
// std::cout << "cmd: " << wxMOD_CMD << " " << wxMOD_CONTROL << " " << WXK_ADD << " " << WXK_SUBTRACT << std::endl;
// std::cout << "cmd: " << wxMOD_CMD << " " << wxMOD_CONTROL << " " << WXK_NUMPAD_ADD << " " << WXK_NUMPAD_SUBTRACT << std::endl;
if (pressed)
if (modifiers == wxMOD_CMD) {
if (keycode == WXK_ADD) {
ChangeZoomLevel(true);
} else if (keycode == WXK_SUBTRACT) {
ChangeZoomLevel(false);
}
}
}
void PlaneOverviewCameraTool::Activate()
{
helper->NotifyMe(ToolHelper::MOUSE_MOVE, this);
helper->NotifyMe(ToolHelper::MOUSE_PRESS, this);
helper->NotifyMe(ToolHelper::MOUSE_WHEEL, this);
down = false;
}
void PlaneOverviewCameraTool::MouseMoveEvent(double x, double y, wxMouseEvent & e)
{
if (down) {
PlaneOverviewToolHelper * thelper = (PlaneOverviewToolHelper*) helper;
PlaneOverviewVisualizationState* state = (PlaneOverviewVisualizationState*) helper->GetVisualizationStatePtr();
//
//same code as in tool helper to get position on the z-plane but with initial position
double d = state->getR();
int tcanv_w, tcanv_h;
state->GetViewer()->GetClientSize(&tcanv_w,&tcanv_h);
double canv_w, canv_h;
canv_w = tcanv_w;
canv_h = tcanv_h;
double fov = state->getFOV();
double fovy, fovx;
if (canv_w > canv_h) {
fovy = DEG_TO_RAD(fov);
fovx = 2 * atan( tan(fovy / 2.0) * canv_w / canv_h);
} else {
fovx = DEG_TO_RAD(fov);
fovy = 2 * atan( tan(fovx / 2.0) * canv_h / canv_w);
}
double vis_w, vis_h;
vis_w = 2.0 * tan ( fovx / 2.0 ) * d;
vis_h = 2.0 * tan ( fovy / 2.0 ) * d;
//position of the mouse on the z=0 plane
double prim_x, prim_y;
prim_x = (double) x / canv_w * vis_w - vis_w / 2.0 + start_pos_x;
prim_y = ((double) y / canv_h * vis_h - vis_h / 2.0 - start_pos_y);
// DEBUG_DEBUG("mouse ov tool 1 " << state->getX() << " " << state->getY());
state->setX((-prim_x + start_x) + start_pos_x);
state->setY((prim_y - start_y) + start_pos_y);
// DEBUG_DEBUG("mouse ov tool 2 " << state->getX() << " " << state->getY());
state->ForceRequireRedraw();
state->Redraw();
}
}
void PlaneOverviewCameraTool::MouseButtonEvent(wxMouseEvent &e)
{
PlaneOverviewToolHelper * thelper = (PlaneOverviewToolHelper*) helper;
PlaneOverviewVisualizationState* state = (PlaneOverviewVisualizationState*) helper->GetVisualizationStatePtr();
// DEBUG_DEBUG("mouse ov drag button");
if (((e.ControlDown() || e.AltDown()) && e.LeftDown()) || e.MiddleDown()) {
down = true;
start_x = thelper->getPlaneX();
start_y = thelper->getPlaneY();
start_pos_x = state->getX();
start_pos_y = state->getY();
}
if (e.LeftUp() || e.MiddleUp()) {
if (down) {
down = false;
}
}
}
void PlaneOverviewCameraTool::ChangeZoomLevel(bool zoomIn, double scale) {
PlaneOverviewVisualizationState* state = (PlaneOverviewVisualizationState*) helper->GetVisualizationStatePtr();
if (zoomIn) {
state->setR(state->getR() / scale);
} else {
state->setR(state->getR() * scale);
}
state->SetDirtyViewport();
state->ForceRequireRedraw();
state->Redraw();
}
void PlaneOverviewCameraTool::MouseWheelEvent(wxMouseEvent &e)
{
if (e.GetWheelRotation() != 0) {
ChangeZoomLevel(e.GetWheelRotation() > 0);
}
}
void PlaneOverviewCameraTool::KeypressEvent(int keycode, int modifiers, bool pressed) {
if (pressed)
if (modifiers == wxMOD_CMD) {
if (keycode == WXK_ADD) {
ChangeZoomLevel(true);
} else if (keycode == WXK_SUBTRACT) {
ChangeZoomLevel(false);
}
}
}