3a66bef7fc243c8993021817472d089c8e0885c8
[blender.git] / source / blender / editors / space_view3d / view3d_fly.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * Contributor(s): Campbell Barton
19  *
20  * ***** END GPL LICENSE BLOCK *****
21  */
22
23 /** \file blender/editors/space_view3d/view3d_fly.c
24  *  \ingroup spview3d
25  */
26
27 /* defines VIEW3D_OT_fly modal operator */
28
29 #ifdef WITH_INPUT_NDOF
30 //#  define NDOF_FLY_DEBUG
31 //#  define NDOF_FLY_DRAW_TOOMUCH  /* is this needed for ndof? - commented so redraw doesn't thrash - campbell */
32 #endif /* WITH_INPUT_NDOF */
33
34 #include "DNA_object_types.h"
35
36 #include "MEM_guardedalloc.h"
37
38 #include "BLI_math.h"
39 #include "BLI_blenlib.h"
40
41 #include "BKE_context.h"
42 #include "BKE_report.h"
43
44 #include "BLT_translation.h"
45
46 #include "BIF_gl.h"
47
48 #include "WM_api.h"
49 #include "WM_types.h"
50
51 #include "ED_screen.h"
52 #include "ED_space_api.h"
53
54 #include "PIL_time.h" /* smoothview */
55
56 #include "UI_interface.h"
57 #include "UI_resources.h"
58
59 #include "view3d_intern.h"  /* own include */
60
61 /* NOTE: these defines are saved in keymap files, do not change values but just add new ones */
62 enum {
63         FLY_MODAL_CANCEL = 1,
64         FLY_MODAL_CONFIRM,
65         FLY_MODAL_ACCELERATE,
66         FLY_MODAL_DECELERATE,
67         FLY_MODAL_PAN_ENABLE,
68         FLY_MODAL_PAN_DISABLE,
69         FLY_MODAL_DIR_FORWARD,
70         FLY_MODAL_DIR_BACKWARD,
71         FLY_MODAL_DIR_LEFT,
72         FLY_MODAL_DIR_RIGHT,
73         FLY_MODAL_DIR_UP,
74         FLY_MODAL_DIR_DOWN,
75         FLY_MODAL_AXIS_LOCK_X,
76         FLY_MODAL_AXIS_LOCK_Z,
77         FLY_MODAL_PRECISION_ENABLE,
78         FLY_MODAL_PRECISION_DISABLE,
79         FLY_MODAL_FREELOOK_ENABLE,
80         FLY_MODAL_FREELOOK_DISABLE,
81         FLY_MODAL_SPEED,        /* mousepan typically */
82 };
83
84 /* relative view axis locking - xlock, zlock */
85 typedef enum eFlyPanState {
86         /* disabled */
87         FLY_AXISLOCK_STATE_OFF    = 0,
88
89         /* enabled but not checking because mouse hasn't moved outside the margin since locking was
90          * checked an not needed when the mouse moves, locking is set to 2 so checks are done. */
91         FLY_AXISLOCK_STATE_IDLE   = 1,
92
93         /* mouse moved and checking needed,
94          * if no view altering is done its changed back to #FLY_AXISLOCK_STATE_IDLE */
95         FLY_AXISLOCK_STATE_ACTIVE = 2
96 } eFlyPanState;
97
98 /* called in transform_ops.c, on each regeneration of keymaps  */
99 void fly_modal_keymap(wmKeyConfig *keyconf)
100 {
101         static const EnumPropertyItem modal_items[] = {
102                 {FLY_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""},
103                 {FLY_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""},
104
105                 {FLY_MODAL_DIR_FORWARD, "FORWARD", 0, "Forward", ""},
106                 {FLY_MODAL_DIR_BACKWARD, "BACKWARD", 0, "Backward", ""},
107                 {FLY_MODAL_DIR_LEFT, "LEFT", 0, "Left", ""},
108                 {FLY_MODAL_DIR_RIGHT, "RIGHT", 0, "Right", ""},
109                 {FLY_MODAL_DIR_UP, "UP", 0, "Up", ""},
110                 {FLY_MODAL_DIR_DOWN, "DOWN", 0, "Down", ""},
111
112                 {FLY_MODAL_PAN_ENABLE, "PAN_ENABLE", 0, "Pan", ""},
113                 {FLY_MODAL_PAN_DISABLE, "PAN_DISABLE", 0, "Pan (Off)", ""},
114
115                 {FLY_MODAL_ACCELERATE, "ACCELERATE", 0, "Accelerate", ""},
116                 {FLY_MODAL_DECELERATE, "DECELERATE", 0, "Decelerate", ""},
117
118                 {FLY_MODAL_AXIS_LOCK_X, "AXIS_LOCK_X", 0, "X Axis Correction", "X axis correction (toggle)"},
119                 {FLY_MODAL_AXIS_LOCK_Z, "AXIS_LOCK_Z", 0, "X Axis Correction", "Z axis correction (toggle)"},
120
121                 {FLY_MODAL_PRECISION_ENABLE, "PRECISION_ENABLE", 0, "Precision", ""},
122                 {FLY_MODAL_PRECISION_DISABLE, "PRECISION_DISABLE", 0, "Precision (Off)", ""},
123
124                 {FLY_MODAL_FREELOOK_ENABLE, "FREELOOK_ENABLE", 0, "Rotation", ""},
125                 {FLY_MODAL_FREELOOK_DISABLE, "FREELOOK_DISABLE", 0, "Rotation (Off)", ""},
126
127                 {0, NULL, 0, NULL, NULL}};
128
129         wmKeyMap *keymap = WM_modalkeymap_get(keyconf, "View3D Fly Modal");
130
131         /* this function is called for each spacetype, only needs to add map once */
132         if (keymap && keymap->modal_items)
133                 return;
134
135         keymap = WM_modalkeymap_add(keyconf, "View3D Fly Modal", modal_items);
136
137         /* items for modal map */
138         WM_modalkeymap_add_item(keymap, RIGHTMOUSE, KM_ANY, KM_ANY, 0, FLY_MODAL_CANCEL);
139         WM_modalkeymap_add_item(keymap, ESCKEY, KM_PRESS, KM_ANY, 0, FLY_MODAL_CANCEL);
140
141         WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_ANY, KM_ANY, 0, FLY_MODAL_CONFIRM);
142         WM_modalkeymap_add_item(keymap, RETKEY, KM_PRESS, KM_ANY, 0, FLY_MODAL_CONFIRM);
143         WM_modalkeymap_add_item(keymap, SPACEKEY, KM_PRESS, KM_ANY, 0, FLY_MODAL_CONFIRM);
144         WM_modalkeymap_add_item(keymap, PADENTER, KM_PRESS, KM_ANY, 0, FLY_MODAL_CONFIRM);
145
146         WM_modalkeymap_add_item(keymap, PADPLUSKEY, KM_PRESS, KM_ANY, 0, FLY_MODAL_ACCELERATE);
147         WM_modalkeymap_add_item(keymap, PADMINUS, KM_PRESS, KM_ANY, 0, FLY_MODAL_DECELERATE);
148         WM_modalkeymap_add_item(keymap, WHEELUPMOUSE, KM_PRESS, KM_ANY, 0, FLY_MODAL_ACCELERATE);
149         WM_modalkeymap_add_item(keymap, WHEELDOWNMOUSE, KM_PRESS, KM_ANY, 0, FLY_MODAL_DECELERATE);
150
151         WM_modalkeymap_add_item(keymap, MOUSEPAN, 0, 0, 0, FLY_MODAL_SPEED);
152
153         WM_modalkeymap_add_item(keymap, MIDDLEMOUSE, KM_PRESS, KM_ANY, 0, FLY_MODAL_PAN_ENABLE);
154         /* XXX - Bug in the event system, middle mouse release doesn't work */
155         WM_modalkeymap_add_item(keymap, MIDDLEMOUSE, KM_RELEASE, KM_ANY, 0, FLY_MODAL_PAN_DISABLE);
156
157         /* WASD */
158         WM_modalkeymap_add_item(keymap, WKEY, KM_PRESS, 0, 0, FLY_MODAL_DIR_FORWARD);
159         WM_modalkeymap_add_item(keymap, SKEY, KM_PRESS, 0, 0, FLY_MODAL_DIR_BACKWARD);
160         WM_modalkeymap_add_item(keymap, AKEY, KM_PRESS, 0, 0, FLY_MODAL_DIR_LEFT);
161         WM_modalkeymap_add_item(keymap, DKEY, KM_PRESS, 0, 0, FLY_MODAL_DIR_RIGHT);
162         WM_modalkeymap_add_item(keymap, EKEY, KM_PRESS, 0, 0, FLY_MODAL_DIR_UP);
163         WM_modalkeymap_add_item(keymap, QKEY, KM_PRESS, 0, 0, FLY_MODAL_DIR_DOWN);
164
165         /* for legacy reasons, leave R/F working */
166         WM_modalkeymap_add_item(keymap, RKEY, KM_PRESS, 0, 0, FLY_MODAL_DIR_UP);
167         WM_modalkeymap_add_item(keymap, FKEY, KM_PRESS, 0, 0, FLY_MODAL_DIR_DOWN);
168
169         WM_modalkeymap_add_item(keymap, UPARROWKEY, KM_PRESS, 0, 0, FLY_MODAL_DIR_FORWARD);
170         WM_modalkeymap_add_item(keymap, DOWNARROWKEY, KM_PRESS, 0, 0, FLY_MODAL_DIR_BACKWARD);
171         WM_modalkeymap_add_item(keymap, LEFTARROWKEY, KM_PRESS, 0, 0, FLY_MODAL_DIR_LEFT);
172         WM_modalkeymap_add_item(keymap, RIGHTARROWKEY, KM_PRESS, 0, 0, FLY_MODAL_DIR_RIGHT);
173
174         WM_modalkeymap_add_item(keymap, XKEY, KM_PRESS, 0, 0, FLY_MODAL_AXIS_LOCK_X);
175         WM_modalkeymap_add_item(keymap, ZKEY, KM_PRESS, 0, 0, FLY_MODAL_AXIS_LOCK_Z);
176
177         WM_modalkeymap_add_item(keymap, LEFTALTKEY, KM_PRESS, KM_ANY, 0, FLY_MODAL_PRECISION_ENABLE);
178         WM_modalkeymap_add_item(keymap, LEFTALTKEY, KM_RELEASE, KM_ANY, 0, FLY_MODAL_PRECISION_DISABLE);
179
180         /* for legacy reasons, leave shift working */
181         WM_modalkeymap_add_item(keymap, LEFTSHIFTKEY, KM_PRESS, KM_ANY, 0, FLY_MODAL_PRECISION_ENABLE);
182         WM_modalkeymap_add_item(keymap, LEFTSHIFTKEY, KM_RELEASE, KM_ANY, 0, FLY_MODAL_PRECISION_DISABLE);
183
184         WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_PRESS, KM_ANY, 0, FLY_MODAL_FREELOOK_ENABLE);
185         WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_RELEASE, KM_ANY, 0, FLY_MODAL_FREELOOK_DISABLE);
186
187         /* assign map to operators */
188         WM_modalkeymap_assign(keymap, "VIEW3D_OT_fly");
189 }
190
191 typedef struct FlyInfo {
192         /* context stuff */
193         RegionView3D *rv3d;
194         View3D *v3d;
195         ARegion *ar;
196         Scene *scene;
197
198         wmTimer *timer; /* needed for redraws */
199
200         short state;
201         bool redraw;
202         bool use_precision;
203         /* if the user presses shift they can look about
204          * without moving the direction there looking */
205         bool use_freelook;
206
207         int mval[2]; /* latest 2D mouse values */
208         int center_mval[2]; /* center mouse values */
209         float width, height; /* camera viewport dimensions */
210
211 #ifdef WITH_INPUT_NDOF
212         wmNDOFMotionData *ndof;  /* latest 3D mouse values */
213 #endif
214
215         /* fly state state */
216         float speed; /* the speed the view is moving per redraw */
217         short axis; /* Axis index to move along by default Z to move along the view */
218         bool pan_view; /* when true, pan the view instead of rotating */
219
220         eFlyPanState xlock, zlock;
221         float xlock_momentum, zlock_momentum; /* nicer dynamics */
222         float grid; /* world scale 1.0 default */
223
224         /* compare between last state */
225         double time_lastwheel; /* used to accelerate when using the mousewheel a lot */
226         double time_lastdraw; /* time between draws */
227
228         void *draw_handle_pixel;
229
230         /* use for some lag */
231         float dvec_prev[3]; /* old for some lag */
232
233         struct View3DCameraControl *v3d_camera_control;
234
235 } FlyInfo;
236
237 static void drawFlyPixel(const struct bContext *UNUSED(C), ARegion *UNUSED(ar), void *arg)
238 {
239         FlyInfo *fly = arg;
240         rctf viewborder;
241         int xoff, yoff;
242         float x1, x2, y1, y2;
243
244         if (ED_view3d_cameracontrol_object_get(fly->v3d_camera_control)) {
245                 ED_view3d_calc_camera_border(fly->scene, fly->ar, fly->v3d, fly->rv3d, &viewborder, false);
246                 xoff = viewborder.xmin;
247                 yoff = viewborder.ymin;
248         }
249         else {
250                 xoff = 0;
251                 yoff = 0;
252         }
253
254         /* draws 4 edge brackets that frame the safe area where the
255          * mouse can move during fly mode without spinning the view */
256
257         x1 = xoff + 0.45f * fly->width;
258         y1 = yoff + 0.45f * fly->height;
259         x2 = xoff + 0.55f * fly->width;
260         y2 = yoff + 0.55f * fly->height;
261
262         UI_ThemeColor(TH_VIEW_OVERLAY);
263         glBegin(GL_LINES);
264         /* bottom left */
265         glVertex2f(x1, y1);
266         glVertex2f(x1, y1 + 5);
267
268         glVertex2f(x1, y1);
269         glVertex2f(x1 + 5, y1);
270
271         /* top right */
272         glVertex2f(x2, y2);
273         glVertex2f(x2, y2 - 5);
274
275         glVertex2f(x2, y2);
276         glVertex2f(x2 - 5, y2);
277
278         /* top left */
279         glVertex2f(x1, y2);
280         glVertex2f(x1, y2 - 5);
281
282         glVertex2f(x1, y2);
283         glVertex2f(x1 + 5, y2);
284
285         /* bottom right */
286         glVertex2f(x2, y1);
287         glVertex2f(x2, y1 + 5);
288
289         glVertex2f(x2, y1);
290         glVertex2f(x2 - 5, y1);
291         glEnd();
292 }
293
294 static void fly_update_header(bContext *C, wmOperator *op, FlyInfo *fly)
295 {
296         char header[UI_MAX_DRAW_STR];
297         char buf[UI_MAX_DRAW_STR];
298
299         char *p = buf;
300         int available_len = sizeof(buf);
301
302 #define WM_MODALKEY(_id) \
303         WM_modalkeymap_operator_items_to_string_buf(op->type, (_id), true, UI_MAX_SHORTCUT_STR, &available_len, &p)
304
305         BLI_snprintf(header, sizeof(header), IFACE_("%s: confirm, %s: cancel, "
306                                                     "%s: pan enable, "
307                                                     "%s|%s|%s|%s|%s|%s: direction, "
308                                                     "%s: slow, %s: free look, "
309                                                     "%s: Upright x axis (%s), "
310                                                     "%s: Upright z axis (%s), "
311                                                     "%s: increase  speed, %s: decrease speed"),
312                      WM_MODALKEY(FLY_MODAL_CONFIRM), WM_MODALKEY(FLY_MODAL_CANCEL),
313                      WM_MODALKEY(FLY_MODAL_PAN_ENABLE),
314                      WM_MODALKEY(FLY_MODAL_DIR_FORWARD), WM_MODALKEY(FLY_MODAL_DIR_LEFT),
315                      WM_MODALKEY(FLY_MODAL_DIR_BACKWARD), WM_MODALKEY(FLY_MODAL_DIR_RIGHT),
316                      WM_MODALKEY(FLY_MODAL_DIR_UP), WM_MODALKEY(FLY_MODAL_DIR_DOWN),
317                      WM_MODALKEY(FLY_MODAL_PRECISION_ENABLE), WM_MODALKEY(FLY_MODAL_FREELOOK_ENABLE),
318                      WM_MODALKEY(FLY_MODAL_AXIS_LOCK_X), WM_bool_as_string(fly->xlock != FLY_AXISLOCK_STATE_OFF),
319                      WM_MODALKEY(FLY_MODAL_AXIS_LOCK_Z), WM_bool_as_string(fly->zlock != FLY_AXISLOCK_STATE_OFF),
320                      WM_MODALKEY(FLY_MODAL_ACCELERATE), WM_MODALKEY(FLY_MODAL_DECELERATE));
321
322 #undef WM_MODALKEY
323
324         ED_area_headerprint(CTX_wm_area(C), header);
325 }
326
327 /* FlyInfo->state */
328 enum {
329         FLY_RUNNING     = 0,
330         FLY_CANCEL      = 1,
331         FLY_CONFIRM     = 2,
332 };
333
334 static bool initFlyInfo(bContext *C, FlyInfo *fly, wmOperator *op, const wmEvent *event)
335 {
336         wmWindow *win = CTX_wm_window(C);
337         rctf viewborder;
338
339         float upvec[3]; /* tmp */
340         float mat[3][3];
341
342         fly->rv3d = CTX_wm_region_view3d(C);
343         fly->v3d = CTX_wm_view3d(C);
344         fly->ar = CTX_wm_region(C);
345         fly->scene = CTX_data_scene(C);
346
347 #ifdef NDOF_FLY_DEBUG
348         puts("\n-- fly begin --");
349 #endif
350
351         /* sanity check: for rare but possible case (if lib-linking the camera fails) */
352         if ((fly->rv3d->persp == RV3D_CAMOB) && (fly->v3d->camera == NULL)) {
353                 fly->rv3d->persp = RV3D_PERSP;
354         }
355
356         if (fly->rv3d->persp == RV3D_CAMOB && ID_IS_LINKED(fly->v3d->camera)) {
357                 BKE_report(op->reports, RPT_ERROR, "Cannot fly a camera from an external library");
358                 return false;
359         }
360
361         if (ED_view3d_offset_lock_check(fly->v3d, fly->rv3d)) {
362                 BKE_report(op->reports, RPT_ERROR, "Cannot fly when the view offset is locked");
363                 return false;
364         }
365
366         if (fly->rv3d->persp == RV3D_CAMOB && fly->v3d->camera->constraints.first) {
367                 BKE_report(op->reports, RPT_ERROR, "Cannot fly an object with constraints");
368                 return false;
369         }
370
371         fly->state = FLY_RUNNING;
372         fly->speed = 0.0f;
373         fly->axis = 2;
374         fly->pan_view = false;
375         fly->xlock = FLY_AXISLOCK_STATE_OFF;
376         fly->zlock = FLY_AXISLOCK_STATE_OFF;
377         fly->xlock_momentum = 0.0f;
378         fly->zlock_momentum = 0.0f;
379         fly->grid = 1.0f;
380         fly->use_precision = false;
381         fly->use_freelook = false;
382
383 #ifdef NDOF_FLY_DRAW_TOOMUCH
384         fly->redraw = 1;
385 #endif
386         zero_v3(fly->dvec_prev);
387
388         fly->timer = WM_event_add_timer(CTX_wm_manager(C), win, TIMER, 0.01f);
389
390         copy_v2_v2_int(fly->mval, event->mval);
391
392 #ifdef WITH_INPUT_NDOF
393         fly->ndof = NULL;
394 #endif
395
396         fly->time_lastdraw = fly->time_lastwheel = PIL_check_seconds_timer();
397
398         fly->draw_handle_pixel = ED_region_draw_cb_activate(fly->ar->type, drawFlyPixel, fly, REGION_DRAW_POST_PIXEL);
399
400         fly->rv3d->rflag |= RV3D_NAVIGATING;
401
402         /* detect whether to start with Z locking */
403         copy_v3_fl3(upvec, 1.0f, 0.0f, 0.0f);
404         copy_m3_m4(mat, fly->rv3d->viewinv);
405         mul_m3_v3(mat, upvec);
406         if (fabsf(upvec[2]) < 0.1f) {
407                 fly->zlock = FLY_AXISLOCK_STATE_IDLE;
408         }
409
410         fly->v3d_camera_control = ED_view3d_cameracontrol_acquire(
411                 fly->scene, fly->v3d, fly->rv3d,
412                 (U.uiflag & USER_CAM_LOCK_NO_PARENT) == 0);
413
414         /* calculate center */
415         if (ED_view3d_cameracontrol_object_get(fly->v3d_camera_control)) {
416                 ED_view3d_calc_camera_border(fly->scene, fly->ar, fly->v3d, fly->rv3d, &viewborder, false);
417
418                 fly->width = BLI_rctf_size_x(&viewborder);
419                 fly->height = BLI_rctf_size_y(&viewborder);
420
421                 fly->center_mval[0] = viewborder.xmin + fly->width / 2;
422                 fly->center_mval[1] = viewborder.ymin + fly->height / 2;
423         }
424         else {
425                 fly->width = fly->ar->winx;
426                 fly->height = fly->ar->winy;
427
428                 fly->center_mval[0] = fly->width / 2;
429                 fly->center_mval[1] = fly->height / 2;
430         }
431
432         /* center the mouse, probably the UI mafia are against this but without its quite annoying */
433         WM_cursor_warp(win, fly->ar->winrct.xmin + fly->center_mval[0], fly->ar->winrct.ymin + fly->center_mval[1]);
434
435         fly_update_header(C, op, fly);
436         return 1;
437 }
438
439 static int flyEnd(bContext *C, FlyInfo *fly)
440 {
441         wmWindow *win;
442         RegionView3D *rv3d;
443
444         if (fly->state == FLY_RUNNING)
445                 return OPERATOR_RUNNING_MODAL;
446
447 #ifdef NDOF_FLY_DEBUG
448         puts("\n-- fly end --");
449 #endif
450
451         win = CTX_wm_window(C);
452         rv3d = fly->rv3d;
453
454         WM_event_remove_timer(CTX_wm_manager(C), win, fly->timer);
455
456         ED_region_draw_cb_exit(fly->ar->type, fly->draw_handle_pixel);
457
458         ED_view3d_cameracontrol_release(fly->v3d_camera_control, fly->state == FLY_CANCEL);
459
460         rv3d->rflag &= ~RV3D_NAVIGATING;
461
462 #ifdef WITH_INPUT_NDOF
463         if (fly->ndof)
464                 MEM_freeN(fly->ndof);
465 #endif
466
467         if (fly->state == FLY_CONFIRM) {
468                 MEM_freeN(fly);
469                 return OPERATOR_FINISHED;
470         }
471
472         MEM_freeN(fly);
473         return OPERATOR_CANCELLED;
474 }
475
476 static void flyEvent(bContext *C, wmOperator *op, FlyInfo *fly, const wmEvent *event)
477 {
478         if (event->type == TIMER && event->customdata == fly->timer) {
479                 fly->redraw = 1;
480         }
481         else if (event->type == MOUSEMOVE) {
482                 copy_v2_v2_int(fly->mval, event->mval);
483         }
484 #ifdef WITH_INPUT_NDOF
485         else if (event->type == NDOF_MOTION) {
486                 /* do these automagically get delivered? yes. */
487                 // puts("ndof motion detected in fly mode!");
488                 // static const char *tag_name = "3D mouse position";
489
490                 const wmNDOFMotionData *incoming_ndof = event->customdata;
491                 switch (incoming_ndof->progress) {
492                         case P_STARTING:
493                                 /* start keeping track of 3D mouse position */
494 #  ifdef NDOF_FLY_DEBUG
495                                 puts("start keeping track of 3D mouse position");
496 #  endif
497                                 /* fall-through */
498                         case P_IN_PROGRESS:
499                                 /* update 3D mouse position */
500 #  ifdef NDOF_FLY_DEBUG
501                                 putchar('.'); fflush(stdout);
502 #  endif
503                                 if (fly->ndof == NULL) {
504                                         // fly->ndof = MEM_mallocN(sizeof(wmNDOFMotionData), tag_name);
505                                         fly->ndof = MEM_dupallocN(incoming_ndof);
506                                         // fly->ndof = malloc(sizeof(wmNDOFMotionData));
507                                 }
508                                 else {
509                                         memcpy(fly->ndof, incoming_ndof, sizeof(wmNDOFMotionData));
510                                 }
511                                 break;
512                         case P_FINISHING:
513                                 /* stop keeping track of 3D mouse position */
514 #  ifdef NDOF_FLY_DEBUG
515                                 puts("stop keeping track of 3D mouse position");
516 #  endif
517                                 if (fly->ndof) {
518                                         MEM_freeN(fly->ndof);
519                                         // free(fly->ndof);
520                                         fly->ndof = NULL;
521                                 }
522                                 /* update the time else the view will jump when 2D mouse/timer resume */
523                                 fly->time_lastdraw = PIL_check_seconds_timer();
524                                 break;
525                         default:
526                                 break; /* should always be one of the above 3 */
527                 }
528         }
529 #endif /* WITH_INPUT_NDOF */
530         /* handle modal keymap first */
531         else if (event->type == EVT_MODAL_MAP) {
532                 switch (event->val) {
533                         case FLY_MODAL_CANCEL:
534                                 fly->state = FLY_CANCEL;
535                                 break;
536                         case FLY_MODAL_CONFIRM:
537                                 fly->state = FLY_CONFIRM;
538                                 break;
539
540                         /* speed adjusting with mousepan (trackpad) */
541                         case FLY_MODAL_SPEED:
542                         {
543                                 float fac = 0.02f * (event->prevy - event->y);
544
545                                 /* allowing to brake immediate */
546                                 if (fac > 0.0f && fly->speed < 0.0f)
547                                         fly->speed = 0.0f;
548                                 else if (fac < 0.0f && fly->speed > 0.0f)
549                                         fly->speed = 0.0f;
550                                 else
551                                         fly->speed += fly->grid * fac;
552
553                                 break;
554                         }
555                         case FLY_MODAL_ACCELERATE:
556                         {
557                                 double time_currwheel;
558                                 float time_wheel;
559
560                                 /* not quite correct but avoids confusion WASD/arrow keys 'locking up' */
561                                 if (fly->axis == -1) {
562                                         fly->axis = 2;
563                                         fly->speed = fabsf(fly->speed);
564                                 }
565
566                                 time_currwheel = PIL_check_seconds_timer();
567                                 time_wheel = (float)(time_currwheel - fly->time_lastwheel);
568                                 fly->time_lastwheel = time_currwheel;
569                                 /* Mouse wheel delays range from (0.5 == slow) to (0.01 == fast) */
570                                 /* 0-0.5 -> 0-5.0 */
571                                 time_wheel = 1.0f + (10.0f - (20.0f * min_ff(time_wheel, 0.5f)));
572
573                                 if (fly->speed < 0.0f) {
574                                         fly->speed = 0.0f;
575                                 }
576                                 else {
577                                         fly->speed += fly->grid * time_wheel * (fly->use_precision ? 0.1f : 1.0f);
578                                 }
579                                 break;
580                         }
581                         case FLY_MODAL_DECELERATE:
582                         {
583                                 double time_currwheel;
584                                 float time_wheel;
585
586                                 /* not quite correct but avoids confusion WASD/arrow keys 'locking up' */
587                                 if (fly->axis == -1) {
588                                         fly->axis = 2;
589                                         fly->speed = -fabsf(fly->speed);
590                                 }
591
592                                 time_currwheel = PIL_check_seconds_timer();
593                                 time_wheel = (float)(time_currwheel - fly->time_lastwheel);
594                                 fly->time_lastwheel = time_currwheel;
595                                 /* 0-0.5 -> 0-5.0 */
596                                 time_wheel = 1.0f + (10.0f - (20.0f * min_ff(time_wheel, 0.5f)));
597
598                                 if (fly->speed > 0.0f) {
599                                         fly->speed = 0;
600                                 }
601                                 else {
602                                         fly->speed -= fly->grid * time_wheel * (fly->use_precision ? 0.1f : 1.0f);
603                                 }
604                                 break;
605                         }
606                         case FLY_MODAL_PAN_ENABLE:
607                                 fly->pan_view = true;
608                                 break;
609                         case FLY_MODAL_PAN_DISABLE:
610                                 fly->pan_view = false;
611                                 break;
612
613                         /* implement WASD keys,
614                          * comments only for 'forward '*/
615                         case FLY_MODAL_DIR_FORWARD:
616                                 if (fly->axis == 2 && fly->speed < 0.0f) {
617                                         /* reverse direction stops, tap again to continue */
618                                         fly->axis = -1;
619                                 }
620                                 else {
621                                         /* flip speed rather than stopping, game like motion,
622                                          * else increase like mousewheel if were already moving in that direction */
623                                         if (fly->speed < 0.0f)   fly->speed = -fly->speed;
624                                         else if (fly->axis == 2) fly->speed += fly->grid;
625                                         fly->axis = 2;
626                                 }
627                                 break;
628                         case FLY_MODAL_DIR_BACKWARD:
629                                 if (fly->axis == 2 && fly->speed > 0.0f) {
630                                         fly->axis = -1;
631                                 }
632                                 else {
633                                         if (fly->speed > 0.0f)   fly->speed = -fly->speed;
634                                         else if (fly->axis == 2) fly->speed -= fly->grid;
635
636                                         fly->axis = 2;
637                                 }
638                                 break;
639                         case FLY_MODAL_DIR_LEFT:
640                                 if (fly->axis == 0 && fly->speed < 0.0f) {
641                                         fly->axis = -1;
642                                 }
643                                 else {
644                                         if (fly->speed < 0.0f)   fly->speed = -fly->speed;
645                                         else if (fly->axis == 0) fly->speed += fly->grid;
646
647                                         fly->axis = 0;
648                                 }
649                                 break;
650                         case FLY_MODAL_DIR_RIGHT:
651                                 if (fly->axis == 0 && fly->speed > 0.0f) {
652                                         fly->axis = -1;
653                                 }
654                                 else {
655                                         if (fly->speed > 0.0f)   fly->speed = -fly->speed;
656                                         else if (fly->axis == 0) fly->speed -= fly->grid;
657
658                                         fly->axis = 0;
659                                 }
660                                 break;
661                         case FLY_MODAL_DIR_DOWN:
662                                 if (fly->axis == 1 && fly->speed < 0.0f) {
663                                         fly->axis = -1;
664                                 }
665                                 else {
666                                         if (fly->speed < 0.0f)   fly->speed = -fly->speed;
667                                         else if (fly->axis == 1) fly->speed += fly->grid;
668                                         fly->axis = 1;
669                                 }
670                                 break;
671                         case FLY_MODAL_DIR_UP:
672                                 if (fly->axis == 1 && fly->speed > 0.0f) {
673                                         fly->axis = -1;
674                                 }
675                                 else {
676                                         if (fly->speed > 0.0f)   fly->speed = -fly->speed;
677                                         else if (fly->axis == 1) fly->speed -= fly->grid;
678                                         fly->axis = 1;
679                                 }
680                                 break;
681
682                         case FLY_MODAL_AXIS_LOCK_X:
683                                 if (fly->xlock != FLY_AXISLOCK_STATE_OFF)
684                                         fly->xlock = FLY_AXISLOCK_STATE_OFF;
685                                 else {
686                                         fly->xlock = FLY_AXISLOCK_STATE_ACTIVE;
687                                         fly->xlock_momentum = 0.0;
688                                 }
689                                 fly_update_header(C, op, fly);
690                                 break;
691                         case FLY_MODAL_AXIS_LOCK_Z:
692                                 if (fly->zlock != FLY_AXISLOCK_STATE_OFF)
693                                         fly->zlock = FLY_AXISLOCK_STATE_OFF;
694                                 else {
695                                         fly->zlock = FLY_AXISLOCK_STATE_ACTIVE;
696                                         fly->zlock_momentum = 0.0;
697                                 }
698                                 fly_update_header(C, op, fly);
699                                 break;
700
701                         case FLY_MODAL_PRECISION_ENABLE:
702                                 fly->use_precision = true;
703                                 break;
704                         case FLY_MODAL_PRECISION_DISABLE:
705                                 fly->use_precision = false;
706                                 break;
707
708                         case FLY_MODAL_FREELOOK_ENABLE:
709                                 fly->use_freelook = true;
710                                 break;
711                         case FLY_MODAL_FREELOOK_DISABLE:
712                                 fly->use_freelook = false;
713                                 break;
714                 }
715         }
716 }
717
718 static void flyMoveCamera(bContext *C, FlyInfo *fly,
719                           const bool do_rotate, const bool do_translate)
720 {
721         ED_view3d_cameracontrol_update(fly->v3d_camera_control, true, C, do_rotate, do_translate);
722 }
723
724 static int flyApply(bContext *C, FlyInfo *fly)
725 {
726 #define FLY_ROTATE_FAC 10.0f /* more is faster */
727 #define FLY_ZUP_CORRECT_FAC 0.1f /* amount to correct per step */
728 #define FLY_ZUP_CORRECT_ACCEL 0.05f /* increase upright momentum each step */
729 #define FLY_SMOOTH_FAC 20.0f  /* higher value less lag */
730
731         /* fly mode - Shift+F
732          * a fly loop where the user can move move the view as if they are flying
733          */
734         RegionView3D *rv3d = fly->rv3d;
735
736         /* 3x3 copy of the view matrix so we can move along the view axis */
737         float mat[3][3];
738         /* this is the direction that's added to the view offset per redraw */
739         float dvec[3] = {0, 0, 0};
740
741         /* Camera Uprighting variables */
742         float moffset[2]; /* mouse offset from the views center */
743         float tmp_quat[4]; /* used for rotating the view */
744
745         /* x and y margin are define the safe area where the mouses movement wont rotate the view */
746         int xmargin, ymargin;
747
748 #ifdef NDOF_FLY_DEBUG
749         {
750                 static unsigned int iteration = 1;
751                 printf("fly timer %d\n", iteration++);
752         }
753 #endif
754
755         xmargin = fly->width / 20.0f;
756         ymargin = fly->height / 20.0f;
757
758         {
759
760                 /* mouse offset from the center */
761                 moffset[0] = fly->mval[0] - fly->center_mval[0];
762                 moffset[1] = fly->mval[1] - fly->center_mval[1];
763
764                 /* enforce a view margin */
765                 if      (moffset[0] >  xmargin) moffset[0] -= xmargin;
766                 else if (moffset[0] < -xmargin) moffset[0] += xmargin;
767                 else                            moffset[0] =  0;
768
769                 if      (moffset[1] >  ymargin) moffset[1] -= ymargin;
770                 else if (moffset[1] < -ymargin) moffset[1] += ymargin;
771                 else                            moffset[1] =  0;
772
773
774                 /* scale the mouse movement by this value - scales mouse movement to the view size
775                  * moffset[0] / (ar->winx-xmargin * 2) - window size minus margin (same for y)
776                  *
777                  * the mouse moves isn't linear */
778
779                 if (moffset[0]) {
780                         moffset[0] /= fly->width - (xmargin * 2);
781                         moffset[0] *= fabsf(moffset[0]);
782                 }
783
784                 if (moffset[1]) {
785                         moffset[1] /= fly->height - (ymargin * 2);
786                         moffset[1] *= fabsf(moffset[1]);
787                 }
788
789                 /* Should we redraw? */
790                 if ((fly->speed != 0.0f) ||
791                     moffset[0] || moffset[1] ||
792                     (fly->zlock != FLY_AXISLOCK_STATE_OFF) ||
793                     (fly->xlock != FLY_AXISLOCK_STATE_OFF) ||
794                     dvec[0] || dvec[1] || dvec[2])
795                 {
796                         float dvec_tmp[3];
797
798                         /* time how fast it takes for us to redraw,
799                          * this is so simple scenes don't fly too fast */
800                         double time_current;
801                         float time_redraw;
802                         float time_redraw_clamped;
803 #ifdef NDOF_FLY_DRAW_TOOMUCH
804                         fly->redraw = 1;
805 #endif
806                         time_current = PIL_check_seconds_timer();
807                         time_redraw = (float)(time_current - fly->time_lastdraw);
808
809                         /* clamp redraw time to avoid jitter in roll correction */
810                         time_redraw_clamped = min_ff(0.05f, time_redraw);
811
812                         fly->time_lastdraw = time_current;
813
814                         /* Scale the time to use shift to scale the speed down- just like
815                          * shift slows many other areas of blender down */
816                         if (fly->use_precision)
817                                 fly->speed = fly->speed * (1.0f - time_redraw_clamped);
818
819                         copy_m3_m4(mat, rv3d->viewinv);
820
821                         if (fly->pan_view == true) {
822                                 /* pan only */
823                                 copy_v3_fl3(dvec_tmp, -moffset[0], -moffset[1], 0.0f);
824
825                                 if (fly->use_precision) {
826                                         dvec_tmp[0] *= 0.1f;
827                                         dvec_tmp[1] *= 0.1f;
828                                 }
829
830                                 mul_m3_v3(mat, dvec_tmp);
831                                 mul_v3_fl(dvec_tmp, time_redraw * 200.0f * fly->grid);
832                         }
833                         else {
834                                 float roll; /* similar to the angle between the camera's up and the Z-up,
835                                              * but its very rough so just roll */
836
837                                 /* rotate about the X axis- look up/down */
838                                 if (moffset[1]) {
839                                         float upvec[3];
840                                         copy_v3_fl3(upvec, 1.0f, 0.0f, 0.0f);
841                                         mul_m3_v3(mat, upvec);
842                                         /* Rotate about the relative up vec */
843                                         axis_angle_to_quat(tmp_quat, upvec, moffset[1] * time_redraw * -FLY_ROTATE_FAC);
844                                         mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, tmp_quat);
845
846                                         if (fly->xlock != FLY_AXISLOCK_STATE_OFF)
847                                                 fly->xlock = FLY_AXISLOCK_STATE_ACTIVE;  /* check for rotation */
848                                         if (fly->zlock != FLY_AXISLOCK_STATE_OFF)
849                                                 fly->zlock = FLY_AXISLOCK_STATE_ACTIVE;
850                                         fly->xlock_momentum = 0.0f;
851                                 }
852
853                                 /* rotate about the Y axis- look left/right */
854                                 if (moffset[0]) {
855                                         float upvec[3];
856                                         /* if we're upside down invert the moffset */
857                                         copy_v3_fl3(upvec, 0.0f, 1.0f, 0.0f);
858                                         mul_m3_v3(mat, upvec);
859
860                                         if (upvec[2] < 0.0f)
861                                                 moffset[0] = -moffset[0];
862
863                                         /* make the lock vectors */
864                                         if (fly->zlock) {
865                                                 copy_v3_fl3(upvec, 0.0f, 0.0f, 1.0f);
866                                         }
867                                         else {
868                                                 copy_v3_fl3(upvec, 0.0f, 1.0f, 0.0f);
869                                                 mul_m3_v3(mat, upvec);
870                                         }
871
872                                         /* Rotate about the relative up vec */
873                                         axis_angle_to_quat(tmp_quat, upvec, moffset[0] * time_redraw * FLY_ROTATE_FAC);
874                                         mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, tmp_quat);
875
876                                         if (fly->xlock != FLY_AXISLOCK_STATE_OFF)
877                                                 fly->xlock = FLY_AXISLOCK_STATE_ACTIVE;  /* check for rotation */
878                                         if (fly->zlock != FLY_AXISLOCK_STATE_OFF)
879                                                 fly->zlock = FLY_AXISLOCK_STATE_ACTIVE;
880                                 }
881
882                                 if (fly->zlock == FLY_AXISLOCK_STATE_ACTIVE) {
883                                         float upvec[3];
884                                         copy_v3_fl3(upvec, 1.0f, 0.0f, 0.0f);
885                                         mul_m3_v3(mat, upvec);
886
887                                         /* make sure we have some z rolling */
888                                         if (fabsf(upvec[2]) > 0.00001f) {
889                                                 roll = upvec[2] * 5.0f;
890                                                 /* rotate the view about this axis */
891                                                 copy_v3_fl3(upvec, 0.0f, 0.0f, 1.0f);
892                                                 mul_m3_v3(mat, upvec);
893                                                 /* Rotate about the relative up vec */
894                                                 axis_angle_to_quat(tmp_quat, upvec,
895                                                                    roll * time_redraw_clamped * fly->zlock_momentum * FLY_ZUP_CORRECT_FAC);
896                                                 mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, tmp_quat);
897
898                                                 fly->zlock_momentum += FLY_ZUP_CORRECT_ACCEL;
899                                         }
900                                         else {
901                                                 /* don't check until the view rotates again */
902                                                 fly->zlock = FLY_AXISLOCK_STATE_IDLE;
903                                                 fly->zlock_momentum = 0.0f;
904                                         }
905                                 }
906
907                                 /* only apply xcorrect when mouse isn't applying x rot */
908                                 if (fly->xlock == FLY_AXISLOCK_STATE_ACTIVE && moffset[1] == 0) {
909                                         float upvec[3];
910                                         copy_v3_fl3(upvec, 0.0f, 0.0f, 1.0f);
911                                         mul_m3_v3(mat, upvec);
912                                         /* make sure we have some z rolling */
913                                         if (fabsf(upvec[2]) > 0.00001f) {
914                                                 roll = upvec[2] * -5.0f;
915                                                 /* rotate the view about this axis */
916                                                 copy_v3_fl3(upvec, 1.0f, 0.0f, 0.0f);
917                                                 mul_m3_v3(mat, upvec);
918
919                                                 /* Rotate about the relative up vec */
920                                                 axis_angle_to_quat(tmp_quat, upvec, roll * time_redraw_clamped * fly->xlock_momentum * 0.1f);
921                                                 mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, tmp_quat);
922
923                                                 fly->xlock_momentum += 0.05f;
924                                         }
925                                         else {
926                                                 fly->xlock = FLY_AXISLOCK_STATE_IDLE; /* see above */
927                                                 fly->xlock_momentum = 0.0f;
928                                         }
929                                 }
930
931                                 if (fly->axis == -1) {
932                                         /* pause */
933                                         zero_v3(dvec_tmp);
934                                 }
935                                 else if (!fly->use_freelook) {
936                                         /* Normal operation */
937                                         /* define dvec, view direction vector */
938                                         zero_v3(dvec_tmp);
939                                         /* move along the current axis */
940                                         dvec_tmp[fly->axis] = 1.0f;
941
942                                         mul_m3_v3(mat, dvec_tmp);
943                                 }
944                                 else {
945                                         normalize_v3_v3(dvec_tmp, fly->dvec_prev);
946                                         if (fly->speed < 0.0f) {
947                                                 negate_v3(dvec_tmp);
948                                         }
949                                 }
950
951                                 mul_v3_fl(dvec_tmp, fly->speed * time_redraw * 0.25f);
952                         }
953
954                         /* impose a directional lag */
955                         interp_v3_v3v3(dvec, dvec_tmp, fly->dvec_prev, (1.0f / (1.0f + (time_redraw * FLY_SMOOTH_FAC))));
956
957                         if (rv3d->persp == RV3D_CAMOB) {
958                                 Object *lock_ob = ED_view3d_cameracontrol_object_get(fly->v3d_camera_control);
959                                 if (lock_ob->protectflag & OB_LOCK_LOCX) dvec[0] = 0.0;
960                                 if (lock_ob->protectflag & OB_LOCK_LOCY) dvec[1] = 0.0;
961                                 if (lock_ob->protectflag & OB_LOCK_LOCZ) dvec[2] = 0.0;
962                         }
963
964                         add_v3_v3(rv3d->ofs, dvec);
965
966                         if (rv3d->persp == RV3D_CAMOB) {
967                                 const bool do_rotate = ((fly->xlock != FLY_AXISLOCK_STATE_OFF) ||
968                                                         (fly->zlock != FLY_AXISLOCK_STATE_OFF) ||
969                                                         ((moffset[0] || moffset[1]) && !fly->pan_view));
970                                 const bool do_translate = (fly->speed != 0.0f || fly->pan_view);
971                                 flyMoveCamera(C, fly, do_rotate, do_translate);
972                         }
973
974                 }
975                 else {
976                         /* we're not redrawing but we need to update the time else the view will jump */
977                         fly->time_lastdraw = PIL_check_seconds_timer();
978                 }
979                 /* end drawing */
980                 copy_v3_v3(fly->dvec_prev, dvec);
981         }
982
983         return OPERATOR_FINISHED;
984 }
985
986 #ifdef WITH_INPUT_NDOF
987 static void flyApply_ndof(bContext *C, FlyInfo *fly)
988 {
989         Object *lock_ob = ED_view3d_cameracontrol_object_get(fly->v3d_camera_control);
990         bool has_translate, has_rotate;
991
992         view3d_ndof_fly(fly->ndof,
993                         fly->v3d, fly->rv3d,
994                         fly->use_precision, lock_ob ? lock_ob->protectflag : 0,
995                         &has_translate, &has_rotate);
996
997         if (has_translate || has_rotate) {
998                 fly->redraw = true;
999
1000                 if (fly->rv3d->persp == RV3D_CAMOB) {
1001                         flyMoveCamera(C, fly, has_rotate, has_translate);
1002                 }
1003         }
1004 }
1005 #endif /* WITH_INPUT_NDOF */
1006
1007 static int fly_invoke(bContext *C, wmOperator *op, const wmEvent *event)
1008 {
1009         RegionView3D *rv3d = CTX_wm_region_view3d(C);
1010         FlyInfo *fly;
1011
1012         if (rv3d->viewlock & RV3D_LOCKED)
1013                 return OPERATOR_CANCELLED;
1014
1015         fly = MEM_callocN(sizeof(FlyInfo), "FlyOperation");
1016
1017         op->customdata = fly;
1018
1019         if (initFlyInfo(C, fly, op, event) == false) {
1020                 MEM_freeN(op->customdata);
1021                 return OPERATOR_CANCELLED;
1022         }
1023
1024         flyEvent(C, op, fly, event);
1025
1026         WM_event_add_modal_handler(C, op);
1027
1028         return OPERATOR_RUNNING_MODAL;
1029 }
1030
1031 static void fly_cancel(bContext *C, wmOperator *op)
1032 {
1033         FlyInfo *fly = op->customdata;
1034
1035         fly->state = FLY_CANCEL;
1036         flyEnd(C, fly);
1037         op->customdata = NULL;
1038 }
1039
1040 static int fly_modal(bContext *C, wmOperator *op, const wmEvent *event)
1041 {
1042         int exit_code;
1043         bool do_draw = false;
1044         FlyInfo *fly = op->customdata;
1045         RegionView3D *rv3d = fly->rv3d;
1046         Object *fly_object = ED_view3d_cameracontrol_object_get(fly->v3d_camera_control);
1047
1048         fly->redraw = 0;
1049
1050         flyEvent(C, op, fly, event);
1051
1052 #ifdef WITH_INPUT_NDOF
1053         if (fly->ndof) { /* 3D mouse overrules [2D mouse + timer] */
1054                 if (event->type == NDOF_MOTION) {
1055                         flyApply_ndof(C, fly);
1056                 }
1057         }
1058         else
1059 #endif /* WITH_INPUT_NDOF */
1060         if (event->type == TIMER && event->customdata == fly->timer) {
1061                 flyApply(C, fly);
1062         }
1063
1064         do_draw |= fly->redraw;
1065
1066         exit_code = flyEnd(C, fly);
1067
1068         if (exit_code != OPERATOR_RUNNING_MODAL)
1069                 do_draw = true;
1070
1071         if (do_draw) {
1072                 if (rv3d->persp == RV3D_CAMOB) {
1073                         WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, fly_object);
1074                 }
1075
1076                 // puts("redraw!"); // too frequent, commented with NDOF_FLY_DRAW_TOOMUCH for now
1077                 ED_region_tag_redraw(CTX_wm_region(C));
1078         }
1079
1080         if (ELEM(exit_code, OPERATOR_FINISHED, OPERATOR_CANCELLED))
1081                 ED_area_headerprint(CTX_wm_area(C), NULL);
1082
1083         return exit_code;
1084 }
1085
1086 void VIEW3D_OT_fly(wmOperatorType *ot)
1087 {
1088         /* identifiers */
1089         ot->name = "Fly Navigation";
1090         ot->description = "Interactively fly around the scene";
1091         ot->idname = "VIEW3D_OT_fly";
1092
1093         /* api callbacks */
1094         ot->invoke = fly_invoke;
1095         ot->cancel = fly_cancel;
1096         ot->modal = fly_modal;
1097         ot->poll = ED_operator_region_view3d_active;
1098
1099         /* flags */
1100         ot->flag = OPTYPE_BLOCKING;
1101 }