~ubuntu-branches/ubuntu/trusty/blender/trusty-proposed

« back to all changes in this revision

Viewing changes to source/blender/editors/space_view3d/view3d_edit.c

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2013-08-14 10:43:49 UTC
  • mfrom: (14.2.19 sid)
  • Revision ID: package-import@ubuntu.com-20130814104349-t1d5mtwkphp12dyj
Tags: 2.68a-3
* Upload to unstable
* debian/: python3.3 Depends simplified
  - debian/control: python3.3 Depends dropped
    for blender-data package
  - 0001-blender_thumbnailer.patch refreshed
* debian/control: libavcodec b-dep versioning dropped

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
 
45
45
#include "BLI_blenlib.h"
46
46
#include "BLI_math.h"
47
 
#include "BLI_rand.h"
48
47
#include "BLI_utildefines.h"
49
48
 
50
49
#include "BKE_camera.h"
86
85
/* for ndof prints */
87
86
// #define DEBUG_NDOF_MOTION
88
87
 
 
88
static void view3d_offset_lock_report(ReportList *reports)
 
89
{
 
90
        BKE_report(reports, RPT_WARNING, "View offset is locked");
 
91
}
 
92
 
 
93
bool ED_view3d_offset_lock_check(struct View3D *v3d, struct RegionView3D *rv3d)
 
94
{
 
95
        return (rv3d->persp != RV3D_CAMOB) && (v3d->ob_centre_cursor || v3d->ob_centre);
 
96
}
 
97
 
 
98
#define VIEW3D_OP_OFS_LOCK_TEST(C, op) \
 
99
        { \
 
100
                View3D *v3d_tmp = CTX_wm_view3d(C); \
 
101
                RegionView3D *rv3d_tmp = CTX_wm_region_view3d(C); \
 
102
                if (ED_view3d_offset_lock_check(v3d_tmp, rv3d_tmp)) { \
 
103
                        view3d_offset_lock_report((op)->reports); \
 
104
                        return OPERATOR_CANCELLED; \
 
105
                } \
 
106
        } (void)0
 
107
 
 
108
 
89
109
/* ********************** view3d_edit: view manipulations ********************* */
90
110
 
91
 
int ED_view3d_camera_lock_check(View3D *v3d, RegionView3D *rv3d)
 
111
bool ED_view3d_camera_lock_check(View3D *v3d, RegionView3D *rv3d)
92
112
{
93
113
        return ((v3d->camera) &&
94
114
                (v3d->camera->id.lib == NULL) &&
105
125
        }
106
126
}
107
127
 
108
 
/* return TRUE if the camera is moved */
109
 
int ED_view3d_camera_lock_sync(View3D *v3d, RegionView3D *rv3d)
 
128
/* return true if the camera is moved */
 
129
bool ED_view3d_camera_lock_sync(View3D *v3d, RegionView3D *rv3d)
110
130
{
111
131
        if (ED_view3d_camera_lock_check(v3d, rv3d)) {
112
132
                ObjectTfmProtectedChannels obtfm;
114
134
 
115
135
                if ((U.uiflag & USER_CAM_LOCK_NO_PARENT) == 0 && (root_parent = v3d->camera->parent)) {
116
136
                        Object *ob_update;
 
137
                        float tmat[4][4];
 
138
                        float imat[4][4];
117
139
                        float view_mat[4][4];
118
140
                        float diff_mat[4][4];
119
141
                        float parent_mat[4][4];
124
146
 
125
147
                        ED_view3d_to_m4(view_mat, rv3d->ofs, rv3d->viewquat, rv3d->dist);
126
148
 
127
 
                        invert_m4_m4(v3d->camera->imat, v3d->camera->obmat);
128
 
                        mult_m4_m4m4(diff_mat, view_mat, v3d->camera->imat);
129
 
 
130
 
                        mult_m4_m4m4(parent_mat, diff_mat, root_parent->obmat);
 
149
                        normalize_m4_m4(tmat, v3d->camera->obmat);
 
150
 
 
151
                        invert_m4_m4(imat, tmat);
 
152
                        mul_m4_m4m4(diff_mat, view_mat, imat);
 
153
 
 
154
                        mul_m4_m4m4(parent_mat, diff_mat, root_parent->obmat);
131
155
 
132
156
                        BKE_object_tfm_protected_backup(root_parent, &obtfm);
133
 
                        BKE_object_apply_mat4(root_parent, parent_mat, TRUE, FALSE);
 
157
                        BKE_object_apply_mat4(root_parent, parent_mat, true, false);
134
158
                        BKE_object_tfm_protected_restore(root_parent, &obtfm, root_parent->protectflag);
135
159
 
136
160
                        ob_update = v3d->camera;
141
165
                        }
142
166
                }
143
167
                else {
 
168
                        /* always maintain the same scale */
 
169
                        const short protect_scale_all = (OB_LOCK_SCALEX | OB_LOCK_SCALEY | OB_LOCK_SCALEZ);
144
170
                        BKE_object_tfm_protected_backup(v3d->camera, &obtfm);
145
171
                        ED_view3d_to_object(v3d->camera, rv3d->ofs, rv3d->viewquat, rv3d->dist);
146
 
                        BKE_object_tfm_protected_restore(v3d->camera, &obtfm, v3d->camera->protectflag);
 
172
                        BKE_object_tfm_protected_restore(v3d->camera, &obtfm, v3d->camera->protectflag | protect_scale_all);
147
173
 
148
174
                        DAG_id_tag_update(&v3d->camera->id, OB_RECALC_OB);
149
175
                        WM_main_add_notifier(NC_OBJECT | ND_TRANSFORM, v3d->camera);
150
176
                }
151
177
 
152
 
                return TRUE;
 
178
                return true;
153
179
        }
154
180
        else {
155
 
                return FALSE;
 
181
                return false;
156
182
        }
157
183
}
158
184
 
309
335
}
310
336
 
311
337
/* 'clip' is used to know if our clip setting has changed */
312
 
void ED_view3d_quadview_update(ScrArea *sa, ARegion *ar, short do_clip)
 
338
void ED_view3d_quadview_update(ScrArea *sa, ARegion *ar, bool do_clip)
313
339
{
314
340
        ARegion *ar_sync = NULL;
315
341
        RegionView3D *rv3d = ar->regiondata;
323
349
                viewlock = 0;
324
350
        else if ((viewlock & RV3D_BOXVIEW) == 0) {
325
351
                viewlock &= ~RV3D_BOXCLIP;
326
 
                do_clip = TRUE;
 
352
                do_clip = true;
327
353
        }
328
354
 
329
355
        for (; ar; ar = ar->prev) {
365
391
        float viewquat[4]; /* working copy of rv3d->viewquat */
366
392
        float trackvec[3];
367
393
        float mousevec[3]; /* dolly only */
368
 
        float reverse, dist0, camzoom0;
 
394
        float reverse;
 
395
        float dist_prev, camzoom_prev;
369
396
        float grid, far;
370
 
        short axis_snap; /* view rotate only */
 
397
        bool axis_snap;  /* view rotate only */
 
398
        float zfac;
371
399
 
372
400
        /* use for orbit selection and auto-dist */
373
401
        float ofs[3], dyn_ofs[3];
374
 
        short use_dyn_ofs;
 
402
        bool use_dyn_ofs;
375
403
 
376
404
        int origx, origy, oldx, oldy;
377
405
        int origkey; /* the key that triggered the operator */
407
435
}
408
436
 
409
437
 
410
 
static void viewops_data_create(bContext *C, wmOperator *op, wmEvent *event)
 
438
static void viewops_data_create(bContext *C, wmOperator *op, const wmEvent *event)
411
439
{
412
440
        static float lastofs[3] = {0, 0, 0};
413
441
        RegionView3D *rv3d;
424
452
         * we may want to make this optional but for now its needed always */
425
453
        ED_view3d_camera_lock_init(vod->v3d, vod->rv3d);
426
454
 
427
 
        vod->dist0 = rv3d->dist;
428
 
        vod->camzoom0 = rv3d->camzoom;
 
455
        vod->dist_prev = rv3d->dist;
 
456
        vod->camzoom_prev = rv3d->camzoom;
429
457
        copy_qt_qt(vod->viewquat, rv3d->viewquat);
430
458
        copy_qt_qt(vod->oldquat, rv3d->viewquat);
431
459
        vod->origx = vod->oldx = event->x;
432
460
        vod->origy = vod->oldy = event->y;
433
461
        vod->origkey = event->type; /* the key that triggered the operator.  */
434
 
        vod->use_dyn_ofs = (U.uiflag & USER_ORBIT_SELECTION) ? 1 : 0;
 
462
        vod->use_dyn_ofs = (U.uiflag & USER_ORBIT_SELECTION) != 0;
435
463
        copy_v3_v3(vod->ofs, rv3d->ofs);
436
464
 
437
465
        if (vod->use_dyn_ofs) {
438
466
                Scene *scene = CTX_data_scene(C);
439
467
                Object *ob = OBACT;
440
468
 
441
 
                if (ob && ob->mode & OB_MODE_ALL_PAINT) {
442
 
                        /* transformation is disabled for painting modes, which will make it
443
 
                         * so previous offset is used. This is annoying when you open file
444
 
                         * saved with active object in painting mode
 
469
                if (ob && (ob->mode & OB_MODE_ALL_PAINT) && (BKE_object_pose_armature_get(ob) == NULL)) {
 
470
                        /* in case of sculpting use last average stroke position as a rotation
 
471
                         * center, in other cases it's not clear what rotation center shall be
 
472
                         * so just rotate around object origin
445
473
                         */
446
 
                        copy_v3_v3(lastofs, ob->obmat[3]);
 
474
                        if (ob->mode & OB_MODE_SCULPT) {
 
475
                                float stroke[3];
 
476
                                ED_sculpt_get_average_stroke(ob, stroke);
 
477
                                copy_v3_v3(lastofs, stroke);
 
478
                        }
 
479
                        else {
 
480
                                copy_v3_v3(lastofs, ob->obmat[3]);
 
481
                        }
447
482
                }
448
483
                else {
449
484
                        /* If there's no selection, lastofs is unmodified and last value since static */
453
488
                negate_v3_v3(vod->dyn_ofs, lastofs);
454
489
        }
455
490
        else if (U.uiflag & USER_ZBUF_ORBIT) {
 
491
                Scene *scene = CTX_data_scene(C);
456
492
 
457
493
                view3d_operator_needs_opengl(C); /* needed for zbuf drawing */
458
494
 
459
 
                if ((vod->use_dyn_ofs = ED_view3d_autodist(CTX_data_scene(C), vod->ar, vod->v3d, event->mval, vod->dyn_ofs))) {
 
495
                if ((vod->use_dyn_ofs = ED_view3d_autodist(scene, vod->ar, vod->v3d, event->mval, vod->dyn_ofs, true))) {
460
496
                        if (rv3d->is_persp) {
461
497
                                float my_origin[3]; /* original G.vd->ofs */
462
498
                                float my_pivot[3]; /* view */
482
518
 
483
519
                                /* find a new ofs value that is along the view axis (rather than the mouse location) */
484
520
                                closest_to_line_v3(dvec, vod->dyn_ofs, my_pivot, my_origin);
485
 
                                vod->dist0 = rv3d->dist = len_v3v3(my_pivot, dvec);
 
521
                                vod->dist_prev = rv3d->dist = len_v3v3(my_pivot, dvec);
486
522
 
487
523
                                negate_v3_v3(rv3d->ofs, dvec);
488
524
                        }
504
540
 
505
541
        calctrackballvec(&vod->ar->winrct, event->x, event->y, vod->trackvec);
506
542
 
507
 
        initgrabz(rv3d, -rv3d->ofs[0], -rv3d->ofs[1], -rv3d->ofs[2]);
 
543
        {
 
544
                float tvec[3];
 
545
                negate_v3_v3(tvec, rv3d->ofs);
 
546
                vod->zfac = ED_view3d_calc_zfac(rv3d, tvec, NULL);
 
547
        }
508
548
 
509
549
        vod->reverse = 1.0f;
510
550
        if (rv3d->persmat[2][1] < 0.0f)
516
556
static void viewops_data_free(bContext *C, wmOperator *op)
517
557
{
518
558
        ARegion *ar;
519
 
        Paint *p = paint_get_active_from_context(C);
 
559
        Paint *p = BKE_paint_get_active_from_context(C);
520
560
 
521
561
        if (op->customdata) {
522
562
                ViewOpsData *vod = op->customdata;
648
688
{
649
689
        RegionView3D *rv3d = vod->rv3d;
650
690
 
651
 
        rv3d->view = RV3D_VIEW_USER; /* need to reset everytime because of view snapping */
 
691
        rv3d->view = RV3D_VIEW_USER; /* need to reset every time because of view snapping */
652
692
 
653
693
        if (U.flag & USER_TRACKBALL) {
654
694
                float phi, si, q1[4], dvec[3], newvec[3];
836
876
        ED_region_tag_redraw(vod->ar);
837
877
}
838
878
 
839
 
static int viewrotate_modal(bContext *C, wmOperator *op, wmEvent *event)
 
879
static int viewrotate_modal(bContext *C, wmOperator *op, const wmEvent *event)
840
880
{
841
881
        ViewOpsData *vod = op->customdata;
842
882
        short event_code = VIEW_PASS;
851
891
                                event_code = VIEW_CONFIRM;
852
892
                                break;
853
893
                        case VIEWROT_MODAL_AXIS_SNAP_ENABLE:
854
 
                                vod->axis_snap = TRUE;
 
894
                                vod->axis_snap = true;
855
895
                                event_code = VIEW_APPLY;
856
896
                                break;
857
897
                        case VIEWROT_MODAL_AXIS_SNAP_DISABLE:
858
 
                                vod->axis_snap = FALSE;
 
898
                                vod->axis_snap = false;
859
899
                                event_code = VIEW_APPLY;
860
900
                                break;
861
901
                        case VIEWROT_MODAL_SWITCH_ZOOM:
885
925
        return OPERATOR_RUNNING_MODAL;
886
926
}
887
927
 
888
 
static int viewrotate_invoke(bContext *C, wmOperator *op, wmEvent *event)
 
928
static int viewrotate_invoke(bContext *C, wmOperator *op, const wmEvent *event)
889
929
{
890
930
        ViewOpsData *vod;
891
931
        RegionView3D *rv3d;
996
1036
/* NDOF utility functions
997
1037
 * (should these functions live in this file?)
998
1038
 */
999
 
float ndof_to_axis_angle(struct wmNDOFMotionData *ndof, float axis[3])
 
1039
float ndof_to_axis_angle(const struct wmNDOFMotionData *ndof, float axis[3])
1000
1040
{
1001
1041
        return ndof->dt * normalize_v3_v3(axis, ndof->rvec);
1002
1042
}
1003
1043
 
1004
 
void ndof_to_quat(struct wmNDOFMotionData *ndof, float q[4])
 
1044
void ndof_to_quat(const struct wmNDOFMotionData *ndof, float q[4])
1005
1045
{
1006
1046
        float axis[3];
1007
1047
        float angle;
1010
1050
        axis_angle_to_quat(q, axis, angle);
1011
1051
}
1012
1052
 
 
1053
static void view3d_ndof_orbit(const struct wmNDOFMotionData *ndof, RegionView3D *rv3d, const float view_inv[4],
 
1054
                              const float rot_sensitivity, const float dt,
 
1055
                              /* optional, can be NULL*/
 
1056
                              ViewOpsData *vod)
 
1057
{
 
1058
        if (U.ndof_flag & NDOF_TURNTABLE) {
 
1059
 
 
1060
                /* turntable view code by John Aughey, adapted for 3D mouse by [mce] */
 
1061
                float angle, rot[4];
 
1062
                float xvec[3] = {1, 0, 0};
 
1063
 
 
1064
                /* Determine the direction of the x vector (for rotating up and down) */
 
1065
                mul_qt_v3(view_inv, xvec);
 
1066
 
 
1067
                /* Perform the up/down rotation */
 
1068
                angle = rot_sensitivity * dt * ndof->rx;
 
1069
                if (U.ndof_flag & NDOF_TILT_INVERT_AXIS)
 
1070
                        angle = -angle;
 
1071
                rot[0] = cosf(angle);
 
1072
                mul_v3_v3fl(rot + 1, xvec, sin(angle));
 
1073
                mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot);
 
1074
 
 
1075
                /* Perform the orbital rotation */
 
1076
                angle = rot_sensitivity * dt * ndof->ry;
 
1077
                if (U.ndof_flag & NDOF_ROTATE_INVERT_AXIS)
 
1078
                        angle = -angle;
 
1079
 
 
1080
                /* update the onscreen doo-dad */
 
1081
                rv3d->rot_angle = angle;
 
1082
                rv3d->rot_axis[0] = 0;
 
1083
                rv3d->rot_axis[1] = 0;
 
1084
                rv3d->rot_axis[2] = 1;
 
1085
 
 
1086
                rot[0] = cosf(angle);
 
1087
                rot[1] = rot[2] = 0.0;
 
1088
                rot[3] = sinf(angle);
 
1089
                mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot);
 
1090
 
 
1091
        }
 
1092
        else {
 
1093
                float rot[4];
 
1094
                float axis[3];
 
1095
                float angle = rot_sensitivity * ndof_to_axis_angle(ndof, axis);
 
1096
 
 
1097
                if (U.ndof_flag & NDOF_ROLL_INVERT_AXIS)   axis[2] = -axis[2];
 
1098
                if (U.ndof_flag & NDOF_TILT_INVERT_AXIS)   axis[0] = -axis[0];
 
1099
                if (U.ndof_flag & NDOF_ROTATE_INVERT_AXIS) axis[1] = -axis[1];
 
1100
 
 
1101
 
 
1102
                /* transform rotation axis from view to world coordinates */
 
1103
                mul_qt_v3(view_inv, axis);
 
1104
 
 
1105
                /* update the onscreen doo-dad */
 
1106
                rv3d->rot_angle = angle;
 
1107
                copy_v3_v3(rv3d->rot_axis, axis);
 
1108
 
 
1109
                axis_angle_to_quat(rot, axis, angle);
 
1110
 
 
1111
                /* apply rotation */
 
1112
                mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot);
 
1113
        }
 
1114
 
 
1115
        /* rotate around custom center */
 
1116
        if (vod && vod->use_dyn_ofs) {
 
1117
                float q1[4];
 
1118
 
 
1119
                /* compute the post multiplication quat, to rotate the offset correctly */
 
1120
                conjugate_qt_qt(q1, vod->oldquat);
 
1121
                mul_qt_qtqt(q1, q1, rv3d->viewquat);
 
1122
 
 
1123
                conjugate_qt(q1); /* conj == inv for unit quat */
 
1124
                copy_v3_v3(rv3d->ofs, vod->ofs);
 
1125
                sub_v3_v3(rv3d->ofs, vod->dyn_ofs);
 
1126
                mul_qt_v3(q1, rv3d->ofs);
 
1127
                add_v3_v3(rv3d->ofs, vod->dyn_ofs);
 
1128
        }
 
1129
}
 
1130
 
1013
1131
/* -- "orbit" navigation (trackball/turntable)
1014
1132
 * -- zooming
1015
1133
 * -- panning in rotationally-locked views
1016
1134
 */
1017
 
static int ndof_orbit_invoke(bContext *C, wmOperator *op, wmEvent *event)
 
1135
static int ndof_orbit_invoke(bContext *C, wmOperator *op, const wmEvent *event)
1018
1136
{
1019
1137
        
1020
1138
        if (event->type != NDOF_MOTION)
1065
1183
                        }
1066
1184
 
1067
1185
                        if (has_rotation) {
1068
 
 
1069
1186
                                rv3d->view = RV3D_VIEW_USER;
1070
 
 
1071
 
                                if (U.ndof_flag & NDOF_TURNTABLE) {
1072
 
 
1073
 
                                        /* turntable view code by John Aughey, adapted for 3D mouse by [mce] */
1074
 
                                        float angle, rot[4];
1075
 
                                        float xvec[3] = {1, 0, 0};
1076
 
 
1077
 
                                        /* Determine the direction of the x vector (for rotating up and down) */
1078
 
                                        mul_qt_v3(view_inv, xvec);
1079
 
 
1080
 
                                        /* Perform the up/down rotation */
1081
 
                                        angle = rot_sensitivity * dt * ndof->rx;
1082
 
                                        if (U.ndof_flag & NDOF_TILT_INVERT_AXIS)
1083
 
                                                angle = -angle;
1084
 
                                        rot[0] = cos(angle);
1085
 
                                        mul_v3_v3fl(rot + 1, xvec, sin(angle));
1086
 
                                        mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot);
1087
 
 
1088
 
                                        /* Perform the orbital rotation */
1089
 
                                        angle = rot_sensitivity * dt * ndof->ry;
1090
 
                                        if (U.ndof_flag & NDOF_ROTATE_INVERT_AXIS)
1091
 
                                                angle = -angle;
1092
 
 
1093
 
                                        /* update the onscreen doo-dad */
1094
 
                                        rv3d->rot_angle = angle;
1095
 
                                        rv3d->rot_axis[0] = 0;
1096
 
                                        rv3d->rot_axis[1] = 0;
1097
 
                                        rv3d->rot_axis[2] = 1;
1098
 
 
1099
 
                                        rot[0] = cos(angle);
1100
 
                                        rot[1] = rot[2] = 0.0;
1101
 
                                        rot[3] = sin(angle);
1102
 
                                        mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot);
1103
 
                                        
1104
 
                                }
1105
 
                                else {
1106
 
                                        float rot[4];
1107
 
                                        float axis[3];
1108
 
                                        float angle = rot_sensitivity * ndof_to_axis_angle(ndof, axis);
1109
 
 
1110
 
                                        if (U.ndof_flag & NDOF_ROLL_INVERT_AXIS)
1111
 
                                                axis[2] = -axis[2];
1112
 
 
1113
 
                                        if (U.ndof_flag & NDOF_TILT_INVERT_AXIS)
1114
 
                                                axis[0] = -axis[0];
1115
 
 
1116
 
                                        if (U.ndof_flag & NDOF_ROTATE_INVERT_AXIS)
1117
 
                                                axis[1] = -axis[1];
1118
 
                                        
1119
 
 
1120
 
                                        /* transform rotation axis from view to world coordinates */
1121
 
                                        mul_qt_v3(view_inv, axis);
1122
 
 
1123
 
                                        /* update the onscreen doo-dad */
1124
 
                                        rv3d->rot_angle = angle;
1125
 
                                        copy_v3_v3(rv3d->rot_axis, axis);
1126
 
 
1127
 
                                        axis_angle_to_quat(rot, axis, angle);
1128
 
 
1129
 
                                        /* apply rotation */
1130
 
                                        mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot);
1131
 
                                        
1132
 
                                }
1133
 
                                
1134
 
                                /* rotate around custom center */
1135
 
                                if (vod && vod->use_dyn_ofs) {
1136
 
                                        float q1[4];
1137
 
                                        
1138
 
                                        /* compute the post multiplication quat, to rotate the offset correctly */
1139
 
                                        conjugate_qt_qt(q1, vod->oldquat);
1140
 
                                        mul_qt_qtqt(q1, q1, rv3d->viewquat);
1141
 
                                        
1142
 
                                        conjugate_qt(q1); /* conj == inv for unit quat */
1143
 
                                        copy_v3_v3(rv3d->ofs, vod->ofs);
1144
 
                                        sub_v3_v3(rv3d->ofs, vod->dyn_ofs);
1145
 
                                        mul_qt_v3(q1, rv3d->ofs);
1146
 
                                        add_v3_v3(rv3d->ofs, vod->dyn_ofs);
1147
 
                                }
 
1187
                                view3d_ndof_orbit(ndof, rv3d, view_inv, rot_sensitivity, dt, vod);
1148
1188
                        }
1149
1189
                }
1150
1190
 
1174
1214
}
1175
1215
 
1176
1216
 
1177
 
static int ndof_orbit_zoom_invoke(bContext *C, wmOperator *op, wmEvent *event)
 
1217
static int ndof_orbit_zoom_invoke(bContext *C, wmOperator *op, const wmEvent *event)
1178
1218
{
1179
1219
        
1180
1220
        if (event->type != NDOF_MOTION)
1239
1279
                        }
1240
1280
 
1241
1281
                        if (has_rotation) {
1242
 
 
1243
1282
                                rv3d->view = RV3D_VIEW_USER;
1244
 
 
1245
 
                                if (U.ndof_flag & NDOF_TURNTABLE) {
1246
 
 
1247
 
                                        /* turntable view code by John Aughey, adapted for 3D mouse by [mce] */
1248
 
                                        float angle, rot[4];
1249
 
                                        float xvec[3] = {1, 0, 0};
1250
 
 
1251
 
                                        /* Determine the direction of the x vector (for rotating up and down) */
1252
 
                                        mul_qt_v3(view_inv, xvec);
1253
 
 
1254
 
                                        /* Perform the up/down rotation */
1255
 
                                        angle = rot_sensitivity * dt * ndof->rx;
1256
 
                                        if (U.ndof_flag & NDOF_TILT_INVERT_AXIS)
1257
 
                                                angle = -angle;
1258
 
                                        rot[0] = cos(angle);
1259
 
                                        mul_v3_v3fl(rot + 1, xvec, sin(angle));
1260
 
                                        mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot);
1261
 
 
1262
 
                                        /* Perform the orbital rotation */
1263
 
                                        angle = rot_sensitivity * dt * ndof->ry;
1264
 
                                        if (U.ndof_flag & NDOF_ROTATE_INVERT_AXIS)
1265
 
                                                angle = -angle;
1266
 
 
1267
 
                                        /* update the onscreen doo-dad */
1268
 
                                        rv3d->rot_angle = angle;
1269
 
                                        rv3d->rot_axis[0] = 0;
1270
 
                                        rv3d->rot_axis[1] = 0;
1271
 
                                        rv3d->rot_axis[2] = 1;
1272
 
 
1273
 
                                        rot[0] = cos(angle);
1274
 
                                        rot[1] = rot[2] = 0.0;
1275
 
                                        rot[3] = sin(angle);
1276
 
                                        mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot);
1277
 
                                        
1278
 
                                }
1279
 
                                else {
1280
 
                                        float rot[4];
1281
 
                                        float axis[3];
1282
 
                                        float angle = rot_sensitivity * ndof_to_axis_angle(ndof, axis);
1283
 
 
1284
 
                                        if (U.ndof_flag & NDOF_ROLL_INVERT_AXIS)
1285
 
                                                axis[2] = -axis[2];
1286
 
 
1287
 
                                        if (U.ndof_flag & NDOF_TILT_INVERT_AXIS)
1288
 
                                                axis[0] = -axis[0];
1289
 
 
1290
 
                                        if (U.ndof_flag & NDOF_ROTATE_INVERT_AXIS)
1291
 
                                                axis[1] = -axis[1];
1292
 
                                        
1293
 
 
1294
 
                                        /* transform rotation axis from view to world coordinates */
1295
 
                                        mul_qt_v3(view_inv, axis);
1296
 
 
1297
 
                                        /* update the onscreen doo-dad */
1298
 
                                        rv3d->rot_angle = angle;
1299
 
                                        copy_v3_v3(rv3d->rot_axis, axis);
1300
 
 
1301
 
                                        axis_angle_to_quat(rot, axis, angle);
1302
 
 
1303
 
                                        /* apply rotation */
1304
 
                                        mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot);
1305
 
                                        
1306
 
                                }
1307
 
                                
1308
 
                                /* rotate around custom center */
1309
 
                                if (vod && vod->use_dyn_ofs) {
1310
 
                                        float q1[4];
1311
 
                                        
1312
 
                                        /* compute the post multiplication quat, to rotate the offset correctly */
1313
 
                                        conjugate_qt_qt(q1, vod->oldquat);
1314
 
                                        mul_qt_qtqt(q1, q1, rv3d->viewquat);
1315
 
                                        
1316
 
                                        conjugate_qt(q1); /* conj == inv for unit quat */
1317
 
                                        copy_v3_v3(rv3d->ofs, vod->ofs);
1318
 
                                        sub_v3_v3(rv3d->ofs, vod->dyn_ofs);
1319
 
                                        mul_qt_v3(q1, rv3d->ofs);
1320
 
                                        add_v3_v3(rv3d->ofs, vod->dyn_ofs);
1321
 
                                }
 
1283
                                view3d_ndof_orbit(ndof, rv3d, view_inv, rot_sensitivity, dt, vod);
1322
1284
                        }
1323
1285
                }
1324
1286
 
1350
1312
/* -- "pan" navigation
1351
1313
 * -- zoom or dolly?
1352
1314
 */
1353
 
static int ndof_pan_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event)
 
1315
static int ndof_pan_invoke(bContext *C, wmOperator *op, const wmEvent *event)
1354
1316
{
1355
1317
        if (event->type != NDOF_MOTION)
1356
1318
                return OPERATOR_CANCELLED;
1359
1321
                RegionView3D *rv3d = CTX_wm_region_view3d(C);
1360
1322
                wmNDOFMotionData *ndof = (wmNDOFMotionData *) event->customdata;
1361
1323
 
 
1324
                VIEW3D_OP_OFS_LOCK_TEST(C, op);
 
1325
 
1362
1326
                ED_view3d_camera_lock_init(v3d, rv3d);
1363
1327
 
1364
1328
                rv3d->rot_angle = 0.f; /* we're panning here! so erase any leftover rotation from other operators */
1444
1408
/*
1445
1409
 * this is basically just the pan only code + the rotate only code crammed into one function that does both
1446
1410
 */
1447
 
static int ndof_all_invoke(bContext *C, wmOperator *op, wmEvent *event)
 
1411
static int ndof_all_invoke(bContext *C, wmOperator *op, const wmEvent *event)
1448
1412
{
1449
1413
        if (event->type != NDOF_MOTION) {
1450
1414
                return OPERATOR_CANCELLED;
1502
1466
 
1503
1467
                        /* move center of view opposite of hand motion (this is camera mode, not object mode) */
1504
1468
                        sub_v3_v3(rv3d->ofs, pan_vec);
1505
 
                        
1506
 
                        if (U.ndof_flag & NDOF_TURNTABLE) {
1507
 
                                /* turntable view code by John Aughey, adapted for 3D mouse by [mce] */
1508
 
                                float angle, rot[4];
1509
 
                                float xvec[3] = {1, 0, 0};
1510
 
 
1511
 
                                /* Determine the direction of the x vector (for rotating up and down) */
1512
 
                                mul_qt_v3(view_inv, xvec);
1513
 
 
1514
 
                                /* Perform the up/down rotation */
1515
 
                                angle = rot_sensitivity * dt * ndof->rx;
1516
 
                                if (U.ndof_flag & NDOF_TILT_INVERT_AXIS)
1517
 
                                        angle = -angle;
1518
 
                                rot[0] = cos(angle);
1519
 
                                mul_v3_v3fl(rot + 1, xvec, sin(angle));
1520
 
                                mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot);
1521
 
 
1522
 
                                /* Perform the orbital rotation */
1523
 
                                angle = rot_sensitivity * dt * ndof->ry;
1524
 
                                if (U.ndof_flag & NDOF_ROTATE_INVERT_AXIS)
1525
 
                                        angle = -angle;
1526
 
 
1527
 
                                /* update the onscreen doo-dad */
1528
 
                                rv3d->rot_angle = angle;
1529
 
                                rv3d->rot_axis[0] = 0;
1530
 
                                rv3d->rot_axis[1] = 0;
1531
 
                                rv3d->rot_axis[2] = 1;
1532
 
 
1533
 
                                rot[0] = cos(angle);
1534
 
                                rot[1] = rot[2] = 0.0;
1535
 
                                rot[3] = sin(angle);
1536
 
                                mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot);
1537
 
 
1538
 
                        }
1539
 
                        else {
1540
 
 
1541
 
                                float rot[4];
1542
 
                                float axis[3];
1543
 
                                float angle = rot_sensitivity * ndof_to_axis_angle(ndof, axis);
1544
 
 
1545
 
                                if (U.ndof_flag & NDOF_ROLL_INVERT_AXIS)
1546
 
                                        axis[2] = -axis[2];
1547
 
 
1548
 
                                if (U.ndof_flag & NDOF_TILT_INVERT_AXIS)
1549
 
                                        axis[0] = -axis[0];
1550
 
 
1551
 
                                if (U.ndof_flag & NDOF_ROTATE_INVERT_AXIS)
1552
 
                                        axis[1] = -axis[1];
1553
 
 
1554
 
                                /* transform rotation axis from view to world coordinates */
1555
 
                                mul_qt_v3(view_inv, axis);
1556
 
 
1557
 
                                /* update the onscreen doo-dad */
1558
 
                                rv3d->rot_angle = angle;
1559
 
                                copy_v3_v3(rv3d->rot_axis, axis);
1560
 
 
1561
 
                                axis_angle_to_quat(rot, axis, angle);
1562
 
 
1563
 
                                /* apply rotation */
1564
 
                                mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, rot);
1565
 
                                
1566
 
                        }
1567
 
                        
1568
 
                        /* rotate around custom center */
1569
 
                        if (vod->use_dyn_ofs) {
1570
 
                                float q1[4];
1571
 
                                
1572
 
                                /* compute the post multiplication quat, to rotate the offset correctly */
1573
 
                                conjugate_qt_qt(q1, vod->oldquat);
1574
 
                                mul_qt_qtqt(q1, q1, rv3d->viewquat);
1575
 
                                
1576
 
                                conjugate_qt(q1); /* conj == inv for unit quat */
1577
 
                                copy_v3_v3(rv3d->ofs, vod->ofs);
1578
 
                                sub_v3_v3(rv3d->ofs, vod->dyn_ofs);
1579
 
                                mul_qt_v3(q1, rv3d->ofs);
1580
 
                                add_v3_v3(rv3d->ofs, vod->dyn_ofs);
1581
 
                        }
1582
 
 
 
1469
 
 
1470
                        view3d_ndof_orbit(ndof, rv3d, view_inv, rot_sensitivity, dt, vod);
1583
1471
                }
1584
1472
                
1585
1473
                viewops_data_free(C, op);
1662
1550
 
1663
1551
                mval_f[0] = x - vod->oldx;
1664
1552
                mval_f[1] = y - vod->oldy;
1665
 
                ED_view3d_win_to_delta(vod->ar, mval_f, dvec);
 
1553
                ED_view3d_win_to_delta(vod->ar, mval_f, dvec, vod->zfac);
1666
1554
 
1667
1555
                add_v3_v3(vod->rv3d->ofs, dvec);
1668
1556
 
1679
1567
}
1680
1568
 
1681
1569
 
1682
 
static int viewmove_modal(bContext *C, wmOperator *op, wmEvent *event)
 
1570
static int viewmove_modal(bContext *C, wmOperator *op, const wmEvent *event)
1683
1571
{
1684
1572
 
1685
1573
        ViewOpsData *vod = op->customdata;
1722
1610
        return OPERATOR_RUNNING_MODAL;
1723
1611
}
1724
1612
 
1725
 
static int viewmove_invoke(bContext *C, wmOperator *op, wmEvent *event)
 
1613
static int viewmove_invoke(bContext *C, wmOperator *op, const wmEvent *event)
1726
1614
{
1727
1615
        ViewOpsData *vod;
1728
1616
 
 
1617
        VIEW3D_OP_OFS_LOCK_TEST(C, op);
 
1618
 
1729
1619
        /* makes op->customdata */
1730
1620
        viewops_data_create(C, op, event);
1731
1621
        vod = op->customdata;
1819
1709
                float tpos[3];
1820
1710
                float mval_f[2];
1821
1711
                float new_dist;
 
1712
                float zfac;
1822
1713
 
1823
1714
                negate_v3_v3(tpos, rv3d->ofs);
1824
1715
 
1825
 
                /* Project cursor position into 3D space */
1826
 
                initgrabz(rv3d, tpos[0], tpos[1], tpos[2]);
1827
 
 
1828
1716
                mval_f[0] = (float)(((mx - ar->winrct.xmin) * 2) - ar->winx) / 2.0f;
1829
1717
                mval_f[1] = (float)(((my - ar->winrct.ymin) * 2) - ar->winy) / 2.0f;
1830
 
                ED_view3d_win_to_delta(ar, mval_f, dvec);
 
1718
 
 
1719
                /* Project cursor position into 3D space */
 
1720
                zfac = ED_view3d_calc_zfac(rv3d, tpos, NULL);
 
1721
                ED_view3d_win_to_delta(ar, mval_f, dvec, zfac);
1831
1722
 
1832
1723
                /* Calculate view target position for dolly */
1833
1724
                add_v3_v3v3(tvec, tpos, dvec);
1851
1742
static void viewzoom_apply(ViewOpsData *vod, const int x, const int y, const short viewzoom, const short zoom_invert)
1852
1743
{
1853
1744
        float zfac = 1.0;
1854
 
        short use_cam_zoom;
 
1745
        bool use_cam_zoom;
1855
1746
 
1856
1747
        use_cam_zoom = (vod->rv3d->persp == RV3D_CAMOB) && !(vod->rv3d->is_persp && ED_view3d_camera_lock_check(vod->v3d, vod->rv3d));
1857
1748
 
1858
1749
        if (use_cam_zoom) {
1859
1750
                float delta;
1860
1751
                delta = (x - vod->origx + y - vod->origy) / 10.0f;
1861
 
                vod->rv3d->camzoom = vod->camzoom0 + (zoom_invert ? -delta : delta);
 
1752
                vod->rv3d->camzoom = vod->camzoom_prev + (zoom_invert ? -delta : delta);
1862
1753
 
1863
1754
                CLAMP(vod->rv3d->camzoom, RV3D_CAMZOOM_MIN, RV3D_CAMZOOM_MAX);
1864
1755
        }
1893
1784
                len1 = (int)sqrt((ctr[0] - x) * (ctr[0] - x) + (ctr[1] - y) * (ctr[1] - y)) + 5;
1894
1785
                len2 = (int)sqrt((ctr[0] - vod->origx) * (ctr[0] - vod->origx) + (ctr[1] - vod->origy) * (ctr[1] - vod->origy)) + 5;
1895
1786
 
1896
 
                zfac = vod->dist0 * ((float)len2 / len1) / vod->rv3d->dist;
 
1787
                zfac = vod->dist_prev * ((float)len2 / len1) / vod->rv3d->dist;
1897
1788
        }
1898
1789
        else {  /* USER_ZOOM_DOLLY */
1899
1790
                float len1, len2;
1913
1804
                if (use_cam_zoom) {
1914
1805
                        /* zfac is ignored in this case, see below */
1915
1806
#if 0
1916
 
                        zfac = vod->camzoom0 * (2.0f * ((len1 / len2) - 1.0f) + 1.0f) / vod->rv3d->camzoom;
 
1807
                        zfac = vod->camzoom_prev * (2.0f * ((len1 / len2) - 1.0f) + 1.0f) / vod->rv3d->camzoom;
1917
1808
#endif
1918
1809
                }
1919
1810
                else {
1920
 
                        zfac = vod->dist0 * (2.0f * ((len1 / len2) - 1.0f) + 1.0f) / vod->rv3d->dist;
 
1811
                        zfac = vod->dist_prev * (2.0f * ((len1 / len2) - 1.0f) + 1.0f) / vod->rv3d->dist;
1921
1812
                }
1922
1813
        }
1923
1814
 
1942
1833
}
1943
1834
 
1944
1835
 
1945
 
static int viewzoom_modal(bContext *C, wmOperator *op, wmEvent *event)
 
1836
static int viewzoom_modal(bContext *C, wmOperator *op, const wmEvent *event)
1946
1837
{
1947
1838
        ViewOpsData *vod = op->customdata;
1948
1839
        short event_code = VIEW_PASS;
1993
1884
        RegionView3D *rv3d;
1994
1885
        ScrArea *sa;
1995
1886
        ARegion *ar;
1996
 
        short use_cam_zoom;
 
1887
        bool use_cam_zoom;
1997
1888
 
1998
 
        int delta = RNA_int_get(op->ptr, "delta");
 
1889
        const int delta = RNA_int_get(op->ptr, "delta");
1999
1890
        int mx, my;
2000
1891
 
2001
1892
        if (op->customdata) {
2087
1978
}
2088
1979
 
2089
1980
/* viewdolly_invoke() copied this function, changes here may apply there */
2090
 
static int viewzoom_invoke(bContext *C, wmOperator *op, wmEvent *event)
 
1981
static int viewzoom_invoke(bContext *C, wmOperator *op, const wmEvent *event)
2091
1982
{
2092
1983
        ViewOpsData *vod;
2093
1984
 
2207
2098
}
2208
2099
 
2209
2100
 
2210
 
static int viewdolly_modal(bContext *C, wmOperator *op, wmEvent *event)
 
2101
static int viewdolly_modal(bContext *C, wmOperator *op, const wmEvent *event)
2211
2102
{
2212
2103
        ViewOpsData *vod = op->customdata;
2213
2104
        short event_code = VIEW_PASS;
2256
2147
        ARegion *ar;
2257
2148
        float mousevec[3];
2258
2149
 
2259
 
        int delta = RNA_int_get(op->ptr, "delta");
 
2150
        const int delta = RNA_int_get(op->ptr, "delta");
2260
2151
 
2261
2152
        if (op->customdata) {
2262
2153
                ViewOpsData *vod = op->customdata;
2299
2190
}
2300
2191
 
2301
2192
/* copied from viewzoom_invoke(), changes here may apply there */
2302
 
static int viewdolly_invoke(bContext *C, wmOperator *op, wmEvent *event)
 
2193
static int viewdolly_invoke(bContext *C, wmOperator *op, const wmEvent *event)
2303
2194
{
2304
2195
        ViewOpsData *vod;
2305
2196
 
 
2197
        VIEW3D_OP_OFS_LOCK_TEST(C, op);
 
2198
 
2306
2199
        /* makes op->customdata */
2307
2200
        viewops_data_create(C, op, event);
2308
2201
        vod = op->customdata;
2324
2217
                }
2325
2218
 
2326
2219
                if (event->type == MOUSEZOOM) {
2327
 
                        /* Bypass Zoom invert flag for track pads (pass FALSE always) */
 
2220
                        /* Bypass Zoom invert flag for track pads (pass false always) */
2328
2221
 
2329
2222
                        if (U.uiflag & USER_ZOOM_HORIZ) {
2330
2223
                                vod->origx = vod->oldx = event->x;
2401
2294
 
2402
2295
static void view3d_from_minmax(bContext *C, View3D *v3d, ARegion *ar,
2403
2296
                                          const float min[3], const float max[3],
2404
 
                                          int ok_dist)
 
2297
                                          bool ok_dist)
2405
2298
{
2406
2299
        RegionView3D *rv3d = ar->regiondata;
2407
2300
        float afm[3];
2440
2333
                else { /* ortho */
2441
2334
                        if (size < 0.0001f) {
2442
2335
                                /* bounding box was a single point so do not zoom */
2443
 
                                ok_dist = 0;
 
2336
                                ok_dist = false;
2444
2337
                        }
2445
2338
                        else {
2446
2339
                                /* adjust zoom so it looks nicer */
2475
2368
/* same as view3d_from_minmax but for all regions (except cameras) */
2476
2369
static void view3d_from_minmax_multi(bContext *C, View3D *v3d,
2477
2370
                                     const float min[3], const float max[3],
2478
 
                                     const int ok_dist)
 
2371
                                     const bool ok_dist)
2479
2372
{
2480
2373
        ScrArea *sa = CTX_wm_area(C);
2481
2374
        ARegion *ar;
2498
2391
        Scene *scene = CTX_data_scene(C);
2499
2392
        Base *base;
2500
2393
        float *curs;
2501
 
        const short use_all_regions = RNA_boolean_get(op->ptr, "use_all_regions");
2502
 
        const short skip_camera = (ED_view3d_camera_lock_check(v3d, ar->regiondata) ||
2503
 
                                   /* any one of the regions may be locked */
2504
 
                                   (use_all_regions && v3d->flag2 & V3D_LOCK_CAMERA));
2505
 
        int center = RNA_boolean_get(op->ptr, "center");
 
2394
        const bool use_all_regions = RNA_boolean_get(op->ptr, "use_all_regions");
 
2395
        const bool skip_camera = (ED_view3d_camera_lock_check(v3d, ar->regiondata) ||
 
2396
                                  /* any one of the regions may be locked */
 
2397
                                  (use_all_regions && v3d->flag2 & V3D_LOCK_CAMERA));
 
2398
        const bool center = RNA_boolean_get(op->ptr, "center");
2506
2399
 
2507
2400
        float min[3], max[3];
2508
 
        int ok = 1, onedone = FALSE;
 
2401
        bool change = false;
2509
2402
 
2510
2403
        if (center) {
2511
2404
                /* in 2.4x this also move the cursor to (0, 0, 0) (with shift+c). */
2520
2413
 
2521
2414
        for (base = scene->base.first; base; base = base->next) {
2522
2415
                if (BASE_VISIBLE(v3d, base)) {
2523
 
                        onedone = TRUE;
 
2416
                        change = true;
2524
2417
 
2525
2418
                        if (skip_camera && base->object == v3d->camera) {
2526
2419
                                continue;
2527
2420
                        }
2528
2421
 
2529
 
                        BKE_object_minmax(base->object, min, max, FALSE);
 
2422
                        BKE_object_minmax(base->object, min, max, false);
2530
2423
                }
2531
2424
        }
2532
 
        if (!onedone) {
 
2425
        if (!change) {
2533
2426
                ED_region_tag_redraw(ar);
2534
2427
                /* TODO - should this be cancel?
2535
2428
                 * I think no, because we always move the cursor, with or without
2541
2434
                return OPERATOR_FINISHED;
2542
2435
        }
2543
2436
 
2544
 
        if (ok == 0) {
2545
 
                return OPERATOR_FINISHED;
2546
 
        }
2547
 
 
2548
2437
        if (use_all_regions) {
2549
 
                view3d_from_minmax_multi(C, v3d, min, max, TRUE);
 
2438
                view3d_from_minmax_multi(C, v3d, min, max, true);
2550
2439
        }
2551
2440
        else {
2552
 
                view3d_from_minmax(C, v3d, ar, min, max, TRUE);
 
2441
                view3d_from_minmax(C, v3d, ar, min, max, true);
2553
2442
        }
2554
2443
 
2555
2444
        return OPERATOR_FINISHED;
2586
2475
        Object *ob = OBACT;
2587
2476
        Object *obedit = CTX_data_edit_object(C);
2588
2477
        float min[3], max[3];
2589
 
        int ok = 0, ok_dist = 1;
2590
 
        const short use_all_regions = RNA_boolean_get(op->ptr, "use_all_regions");
2591
 
        const short skip_camera = (ED_view3d_camera_lock_check(v3d, ar->regiondata) ||
2592
 
                                   /* any one of the regions may be locked */
2593
 
                                   (use_all_regions && v3d->flag2 & V3D_LOCK_CAMERA));
 
2478
        bool ok = false, ok_dist = true;
 
2479
        const bool use_all_regions = RNA_boolean_get(op->ptr, "use_all_regions");
 
2480
        const bool skip_camera = (ED_view3d_camera_lock_check(v3d, ar->regiondata) ||
 
2481
                                  /* any one of the regions may be locked */
 
2482
                                  (use_all_regions && v3d->flag2 & V3D_LOCK_CAMERA));
2594
2483
 
2595
2484
        INIT_MINMAX(min, max);
2596
2485
 
2653
2542
                                }
2654
2543
 
2655
2544
                                /* account for duplis */
2656
 
                                if (BKE_object_minmax_dupli(scene, base->object, min, max, FALSE) == 0)
2657
 
                                        BKE_object_minmax(base->object, min, max, FALSE);  /* use if duplis not found */
 
2545
                                if (BKE_object_minmax_dupli(scene, base->object, min, max, false) == 0)
 
2546
                                        BKE_object_minmax(base->object, min, max, false);  /* use if duplis not found */
2658
2547
 
2659
2548
                                ok = 1;
2660
2549
                        }
2816
2705
        ot->flag = 0;
2817
2706
}
2818
2707
 
 
2708
static int viewcenter_pick_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
 
2709
{
 
2710
        View3D *v3d = CTX_wm_view3d(C);
 
2711
        RegionView3D *rv3d = CTX_wm_region_view3d(C);
 
2712
        Scene *scene = CTX_data_scene(C);
 
2713
        ARegion *ar = CTX_wm_region(C);
 
2714
 
 
2715
        if (rv3d) {
 
2716
                float new_ofs[3];
 
2717
 
 
2718
                view3d_operator_needs_opengl(C);
 
2719
 
 
2720
                if (ED_view3d_autodist(scene, ar, v3d, event->mval, new_ofs, false)) {
 
2721
                        /* pass */
 
2722
                }
 
2723
                else {
 
2724
                        /* fallback to simple pan */
 
2725
                        negate_v3_v3(new_ofs, rv3d->ofs);
 
2726
                        ED_view3d_win_to_3d_int(ar, new_ofs, event->mval, new_ofs);
 
2727
                }
 
2728
                negate_v3(new_ofs);
 
2729
                view3d_smooth_view(C, v3d, ar, NULL, NULL, new_ofs, NULL, NULL, NULL);
 
2730
        }
 
2731
 
 
2732
        return OPERATOR_FINISHED;
 
2733
}
 
2734
 
 
2735
void VIEW3D_OT_view_center_pick(wmOperatorType *ot)
 
2736
{
 
2737
        /* identifiers */
 
2738
        ot->name = "Center View to Mouse";
 
2739
        ot->description = "Center the view to the Z-depth position under the mouse cursor";
 
2740
        ot->idname = "VIEW3D_OT_view_center_pick";
 
2741
 
 
2742
        /* api callbacks */
 
2743
        ot->invoke = viewcenter_pick_invoke;
 
2744
        ot->poll = ED_operator_view3d_active;
 
2745
 
 
2746
        /* flags */
 
2747
        ot->flag = 0;
 
2748
}
 
2749
 
2819
2750
static int view3d_center_camera_exec(bContext *C, wmOperator *UNUSED(op)) /* was view3d_home() in 2.4x */
2820
2751
{
2821
2752
        Scene *scene = CTX_data_scene(C);
2874
2805
        rcti rect;
2875
2806
        rctf vb, border;
2876
2807
 
2877
 
        int camera_only = RNA_boolean_get(op->ptr, "camera_only");
 
2808
        const bool camera_only = RNA_boolean_get(op->ptr, "camera_only");
2878
2809
 
2879
2810
        if (camera_only && rv3d->persp != RV3D_CAMOB)
2880
2811
                return OPERATOR_PASS_THROUGH;
2885
2816
        /* calculate range */
2886
2817
 
2887
2818
        if (rv3d->persp == RV3D_CAMOB) {
2888
 
                ED_view3d_calc_camera_border(scene, ar, v3d, rv3d, &vb, FALSE);
 
2819
                ED_view3d_calc_camera_border(scene, ar, v3d, rv3d, &vb, false);
2889
2820
        }
2890
2821
        else {
2891
2822
                vb.xmin = 0;
3044
2975
 
3045
2976
        /* Get Z Depths, needed for perspective, nice for ortho */
3046
2977
        bgl_get_mats(&mats);
3047
 
        draw_depth(scene, ar, v3d, NULL);
 
2978
        draw_depth(scene, ar, v3d, NULL, true);
3048
2979
        
3049
2980
        {
3050
2981
                /* avoid allocating the whole depth buffer */
3111
3042
                }
3112
3043
                else {
3113
3044
                        float mval_f[2];
 
3045
                        float zfac;
 
3046
 
3114
3047
                        /* We cant use the depth, fallback to the old way that dosnt set the center depth */
3115
3048
                        copy_v3_v3(new_ofs, rv3d->ofs);
3116
3049
 
3117
 
                        initgrabz(rv3d, -new_ofs[0], -new_ofs[1], -new_ofs[2]);
 
3050
                        {
 
3051
                                float tvec[3];
 
3052
                                negate_v3_v3(tvec, new_ofs);
 
3053
                                zfac = ED_view3d_calc_zfac(rv3d, tvec, NULL);
 
3054
                        }
3118
3055
 
3119
3056
                        mval_f[0] = (rect.xmin + rect.xmax - vb[0]) / 2.0f;
3120
3057
                        mval_f[1] = (rect.ymin + rect.ymax - vb[1]) / 2.0f;
3121
 
                        ED_view3d_win_to_delta(ar, mval_f, dvec);
 
3058
                        ED_view3d_win_to_delta(ar, mval_f, dvec, zfac);
3122
3059
                        /* center the view to the center of the rectangle */
3123
3060
                        sub_v3_v3(new_ofs, dvec);
3124
3061
                }
3151
3088
        return OPERATOR_FINISHED;
3152
3089
}
3153
3090
 
3154
 
static int view3d_zoom_border_invoke(bContext *C, wmOperator *op, wmEvent *event)
 
3091
static int view3d_zoom_border_invoke(bContext *C, wmOperator *op, const wmEvent *event)
3155
3092
{
3156
3093
        View3D *v3d = CTX_wm_view3d(C);
3157
3094
        RegionView3D *rv3d = CTX_wm_region_view3d(C);
3182
3119
        ot->flag = 0;
3183
3120
 
3184
3121
        /* rna */
3185
 
        WM_operator_properties_gesture_border(ot, FALSE);
 
3122
        WM_operator_properties_gesture_border(ot, false);
3186
3123
}
3187
3124
 
3188
3125
/* sets the view to 1:1 camera/render-pixel */
3248
3185
 
3249
3186
static void axis_set_view(bContext *C, View3D *v3d, ARegion *ar,
3250
3187
                          float q1, float q2, float q3, float q4,
3251
 
                          short view, int perspo, int align_active)
 
3188
                          short view, int perspo, bool align_active)
3252
3189
{
3253
3190
        RegionView3D *rv3d = ar->regiondata; /* no NULL check is needed, poll checks */
3254
3191
        float new_quat[4];
3262
3199
                Object *obact = CTX_data_active_object(C);
3263
3200
                if (obact == NULL) {
3264
3201
                        /* no active object, ignore this option */
3265
 
                        align_active = FALSE;
 
3202
                        align_active = false;
3266
3203
                }
3267
3204
                else {
 
3205
                        const float z_flip_quat[4] = {0.0f, 0.0f, 0.0f, 1.0f};
3268
3206
                        float obact_quat[4];
3269
3207
                        float twmat[3][3];
3270
3208
 
 
3209
                        /* flip the input, the end result being that an object
 
3210
                         * with no rotation behaves as if 'align_active' is off */
 
3211
                        mul_qt_qtqt(new_quat, new_quat, z_flip_quat);
 
3212
 
3271
3213
                        /* same as transform manipulator when normal is set */
3272
 
                        ED_getTransformOrientationMatrix(C, twmat, FALSE);
 
3214
                        ED_getTransformOrientationMatrix(C, twmat, false);
3273
3215
 
3274
3216
                        mat3_to_quat(obact_quat, twmat);
3275
3217
                        invert_qt(obact_quat);
3279
3221
                }
3280
3222
        }
3281
3223
 
3282
 
        if (align_active == FALSE) {
 
3224
        if (align_active == false) {
3283
3225
                /* normal operation */
3284
3226
                if (rv3d->viewlock) {
3285
3227
                        /* only pass on if */
3328
3270
        RegionView3D *rv3d;
3329
3271
        Scene *scene = CTX_data_scene(C);
3330
3272
        static int perspo = RV3D_PERSP;
3331
 
        int viewnum, align_active, nextperspo;
 
3273
        int viewnum, nextperspo;
 
3274
        bool align_active;
3332
3275
 
3333
3276
        /* no NULL check is needed, poll checks */
3334
3277
        ED_view3d_context_user_region(C, &v3d, &ar);
3339
3282
 
3340
3283
        /* set this to zero, gets handled in axis_set_view */
3341
3284
        if (rv3d->viewlock)
3342
 
                align_active = 0;
 
3285
                align_active = false;
3343
3286
 
3344
3287
        /* Use this to test if we started out with a camera */
3345
3288
 
3566
3509
 
3567
3510
static int viewpan_exec(bContext *C, wmOperator *op)
3568
3511
{
 
3512
        ScrArea *sa = CTX_wm_area(C);
3569
3513
        ARegion *ar = CTX_wm_region(C);
 
3514
        View3D *v3d = CTX_wm_view3d(C);
3570
3515
        RegionView3D *rv3d = CTX_wm_region_view3d(C);
3571
3516
        float vec[3];
 
3517
        const float co_zero[3] = {0.0f};
3572
3518
        float mval_f[2] = {0.0f, 0.0f};
 
3519
        float zfac;
3573
3520
        int pandir;
3574
3521
 
 
3522
        VIEW3D_OP_OFS_LOCK_TEST(C, op);
 
3523
 
3575
3524
        pandir = RNA_enum_get(op->ptr, "type");
3576
3525
 
3577
 
        initgrabz(rv3d, 0.0, 0.0, 0.0);
3578
 
        if      (pandir == V3D_VIEW_PANRIGHT)  { mval_f[0] = -32.0f; ED_view3d_win_to_delta(ar, mval_f, vec); }
3579
 
        else if (pandir == V3D_VIEW_PANLEFT)   { mval_f[0] =  32.0f; ED_view3d_win_to_delta(ar, mval_f, vec); }
3580
 
        else if (pandir == V3D_VIEW_PANUP)     { mval_f[1] = -25.0f; ED_view3d_win_to_delta(ar, mval_f, vec); }
3581
 
        else if (pandir == V3D_VIEW_PANDOWN)   { mval_f[1] =  25.0f; ED_view3d_win_to_delta(ar, mval_f, vec); }
 
3526
        ED_view3d_camera_lock_init(v3d, rv3d);
 
3527
 
 
3528
        zfac = ED_view3d_calc_zfac(rv3d, co_zero, NULL);
 
3529
        if      (pandir == V3D_VIEW_PANRIGHT)  { mval_f[0] = -32.0f; }
 
3530
        else if (pandir == V3D_VIEW_PANLEFT)   { mval_f[0] =  32.0f; }
 
3531
        else if (pandir == V3D_VIEW_PANUP)     { mval_f[1] = -25.0f; }
 
3532
        else if (pandir == V3D_VIEW_PANDOWN)   { mval_f[1] =  25.0f; }
 
3533
        ED_view3d_win_to_delta(ar, mval_f, vec, zfac);
3582
3534
        add_v3_v3(rv3d->ofs, vec);
3583
3535
 
3584
3536
        if (rv3d->viewlock & RV3D_BOXVIEW)
3585
 
                view3d_boxview_sync(CTX_wm_area(C), ar);
 
3537
                view3d_boxview_sync(sa, ar);
 
3538
 
 
3539
        ED_view3d_depth_tag_update(rv3d);
 
3540
 
 
3541
        ED_view3d_camera_lock_sync(v3d, rv3d);
3586
3542
 
3587
3543
        ED_region_tag_redraw(ar);
3588
3544
 
3660
3616
        return OPERATOR_FINISHED;
3661
3617
}
3662
3618
 
3663
 
static int background_image_add_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
 
3619
static int background_image_add_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
3664
3620
{
3665
3621
        View3D *v3d = CTX_wm_view3d(C);
3666
3622
        Image *ima = NULL;
3699
3655
void VIEW3D_OT_background_image_add(wmOperatorType *ot)
3700
3656
{
3701
3657
        /* identifiers */
3702
 
        ot->name   = "Add Background Image";
 
3658
        /* note: having key shortcut here is bad practice,
 
3659
         * but for now keep because this displays when dragging an image over the 3D viewport */
 
3660
        ot->name   = "Add Background Image (Ctrl for Empty Object)";
3703
3661
        ot->description = "Add a new background image";
3704
3662
        ot->idname = "VIEW3D_OT_background_image_add";
3705
3663
 
3721
3679
static int background_image_remove_exec(bContext *C, wmOperator *op)
3722
3680
{
3723
3681
        View3D *v3d = CTX_wm_view3d(C);
3724
 
        int index = RNA_int_get(op->ptr, "index");
 
3682
        const int index = RNA_int_get(op->ptr, "index");
3725
3683
        BGpic *bgpic_rem = BLI_findlink(&v3d->bgpicbase, index);
3726
3684
 
3727
3685
        if (bgpic_rem) {
3755
3713
 
3756
3714
/* ********************* set clipping operator ****************** */
3757
3715
 
3758
 
static void calc_clipping_plane(float clip[6][4], BoundBox *clipbb)
 
3716
static void calc_clipping_plane(float clip[6][4], const BoundBox *clipbb)
3759
3717
{
3760
3718
        int val;
3761
3719
 
3762
3720
        for (val = 0; val < 4; val++) {
3763
 
 
3764
3721
                normal_tri_v3(clip[val], clipbb->vec[val], clipbb->vec[val == 3 ? 0 : val + 1], clipbb->vec[val + 4]);
3765
 
 
3766
 
                /* TODO - this is just '-dot_v3v3(clip[val], clipbb->vec[val])' isnt it? - sould replace */
3767
 
                clip[val][3] = -clip[val][0] * clipbb->vec[val][0] -
3768
 
                                clip[val][1] * clipbb->vec[val][1] -
3769
 
                                clip[val][2] * clipbb->vec[val][2];
 
3722
                clip[val][3] = -dot_v3v3(clip[val], clipbb->vec[val]);
3770
3723
        }
3771
3724
}
3772
3725
 
3813
3766
        return OPERATOR_FINISHED;
3814
3767
}
3815
3768
 
3816
 
static int view3d_clipping_invoke(bContext *C, wmOperator *op, wmEvent *event)
 
3769
static int view3d_clipping_invoke(bContext *C, wmOperator *op, const wmEvent *event)
3817
3770
{
3818
3771
        RegionView3D *rv3d = CTX_wm_region_view3d(C);
3819
3772
        ARegion *ar = CTX_wm_region(C);
3858
3811
 
3859
3812
/* cursor position in vec, result in vec, mval in region coords */
3860
3813
/* note: cannot use event->mval here (called by object_add() */
3861
 
void ED_view3d_cursor3d_position(bContext *C, float *fp, int mx, int my)
 
3814
void ED_view3d_cursor3d_position(bContext *C, float fp[3], const int mval[2])
3862
3815
{
3863
3816
        Scene *scene = CTX_data_scene(C);
3864
3817
        ARegion *ar = CTX_wm_region(C);
3865
3818
        View3D *v3d = CTX_wm_view3d(C);
3866
3819
        RegionView3D *rv3d = CTX_wm_region_view3d(C);
3867
3820
        float mval_fl[2];
3868
 
        int mval[2];
3869
 
        int flip;
3870
 
 
3871
 
        mval[0] = mx - ar->winrct.xmin;
3872
 
        mval[1] = my - ar->winrct.ymin;
 
3821
        float zfac;
 
3822
        bool flip;
3873
3823
        
3874
 
        flip = initgrabz(rv3d, fp[0], fp[1], fp[2]);
 
3824
        zfac = ED_view3d_calc_zfac(rv3d, fp, &flip);
3875
3825
        
3876
3826
        /* reset the depth based on the view offset (we _know_ the offset is infront of us) */
3877
3827
        if (flip) {
3878
3828
                negate_v3_v3(fp, rv3d->ofs);
3879
3829
                /* re initialize, no need to check flip again */
3880
 
                /* flip = */ initgrabz(rv3d, fp[0], fp[1], fp[2]);
 
3830
                zfac = ED_view3d_calc_zfac(rv3d, fp, NULL /* &flip */ );
3881
3831
        }
3882
3832
 
3883
3833
        if (ED_view3d_project_float_global(ar, fp, mval_fl, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) {
3884
 
                short depth_used = FALSE;
 
3834
                bool depth_used = false;
3885
3835
 
3886
3836
                if (U.uiflag & USER_ZBUF_CURSOR) {  /* maybe this should be accessed some other way */
3887
3837
                        view3d_operator_needs_opengl(C);
3888
 
                        if (ED_view3d_autodist(scene, ar, v3d, mval, fp))
3889
 
                                depth_used = TRUE;
 
3838
                        if (ED_view3d_autodist(scene, ar, v3d, mval, fp, true))
 
3839
                                depth_used = true;
3890
3840
                }
3891
3841
 
3892
 
                if (depth_used == FALSE) {
 
3842
                if (depth_used == false) {
3893
3843
                        float dvec[3];
3894
3844
                        VECSUB2D(mval_fl, mval_fl, mval);
3895
 
                        ED_view3d_win_to_delta(ar, mval_fl, dvec);
 
3845
                        ED_view3d_win_to_delta(ar, mval_fl, dvec, zfac);
3896
3846
                        sub_v3_v3(fp, dvec);
3897
3847
                }
3898
3848
        }
3899
3849
        else {
3900
 
                const float dx = ((float)(mval[0] - (ar->winx / 2))) * rv3d->zfac / (ar->winx / 2);
3901
 
                const float dy = ((float)(mval[1] - (ar->winy / 2))) * rv3d->zfac / (ar->winy / 2);
 
3850
                const float dx = ((float)(mval[0] - (ar->winx / 2))) * zfac / (ar->winx / 2);
 
3851
                const float dy = ((float)(mval[1] - (ar->winy / 2))) * zfac / (ar->winy / 2);
3902
3852
                const float fz = (rv3d->persmat[0][3] * fp[0] +
3903
3853
                                  rv3d->persmat[1][3] * fp[1] +
3904
3854
                                  rv3d->persmat[2][3] * fp[2] +
3905
 
                                  rv3d->persmat[3][3]) / rv3d->zfac;
 
3855
                                  rv3d->persmat[3][3]) / zfac;
3906
3856
 
3907
3857
                fp[0] = (rv3d->persinv[0][0] * dx + rv3d->persinv[1][0] * dy + rv3d->persinv[2][0] * fz) - rv3d->ofs[0];
3908
3858
                fp[1] = (rv3d->persinv[0][1] * dx + rv3d->persinv[1][1] * dy + rv3d->persinv[2][1] * fz) - rv3d->ofs[1];
3911
3861
 
3912
3862
}
3913
3863
 
3914
 
static int view3d_cursor3d_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event)
 
3864
static int view3d_cursor3d_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
3915
3865
{
3916
3866
        Scene *scene = CTX_data_scene(C);
3917
3867
        View3D *v3d = CTX_wm_view3d(C);
3918
3868
        float *fp = give_cursor(scene, v3d);
3919
3869
 
3920
 
        ED_view3d_cursor3d_position(C, fp, event->x, event->y);
 
3870
        ED_view3d_cursor3d_position(C, fp, event->mval);
3921
3871
        
3922
3872
        if (v3d && v3d->localvd)
3923
3873
                WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d);
3950
3900
/* ***************** manipulator op ******************* */
3951
3901
 
3952
3902
 
3953
 
static int manipulator_invoke(bContext *C, wmOperator *op, wmEvent *event)
 
3903
static int manipulator_invoke(bContext *C, wmOperator *op, const wmEvent *event)
3954
3904
{
3955
3905
        View3D *v3d = CTX_wm_view3d(C);
3956
3906
 
3986
3936
        Transform_Properties(ot, P_CONSTRAINT);
3987
3937
}
3988
3938
 
3989
 
static int enable_manipulator_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
 
3939
static int enable_manipulator_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
3990
3940
{
3991
3941
        View3D *v3d = CTX_wm_view3d(C);
3992
3942
 
4057
4007
}
4058
4008
 
4059
4009
/* XXX todo Zooms in on a border drawn by the user */
4060
 
int ED_view3d_autodist(Scene *scene, ARegion *ar, View3D *v3d, const int mval[2], float mouse_worldloc[3])
 
4010
bool ED_view3d_autodist(Scene *scene, ARegion *ar, View3D *v3d, const int mval[2], float mouse_worldloc[3], bool alphaoverride)
4061
4011
{
4062
4012
        bglMats mats; /* ZBuffer depth vars */
4063
 
        float depth_close = FLT_MAX;
 
4013
        float depth_close;
4064
4014
        double cent[2],  p[3];
4065
4015
 
4066
4016
        /* Get Z Depths, needed for perspective, nice for ortho */
4067
4017
        bgl_get_mats(&mats);
4068
 
        draw_depth(scene, ar, v3d, NULL);
 
4018
        draw_depth(scene, ar, v3d, NULL, alphaoverride);
4069
4019
 
4070
4020
        depth_close = view_autodist_depth_margin(ar, mval, 4);
4071
4021
 
4072
4022
        if (depth_close == FLT_MAX)
4073
 
                return 0;
 
4023
                return false;
4074
4024
 
4075
4025
        cent[0] = (double)mval[0];
4076
4026
        cent[1] = (double)mval[1];
4078
4028
        if (!gluUnProject(cent[0], cent[1], depth_close,
4079
4029
                          mats.modelview, mats.projection, (GLint *)mats.viewport, &p[0], &p[1], &p[2]))
4080
4030
        {
4081
 
                return 0;
 
4031
                return false;
4082
4032
        }
4083
4033
 
4084
4034
        mouse_worldloc[0] = (float)p[0];
4085
4035
        mouse_worldloc[1] = (float)p[1];
4086
4036
        mouse_worldloc[2] = (float)p[2];
4087
 
        return 1;
 
4037
        return true;
4088
4038
}
4089
4039
 
4090
 
int ED_view3d_autodist_init(Scene *scene, ARegion *ar, View3D *v3d, int mode)
 
4040
void ED_view3d_autodist_init(Scene *scene, ARegion *ar, View3D *v3d, int mode)
4091
4041
{
4092
4042
        /* Get Z Depths, needed for perspective, nice for ortho */
4093
4043
        switch (mode) {
4094
4044
                case 0:
4095
 
                        draw_depth(scene, ar, v3d, NULL);
 
4045
                        draw_depth(scene, ar, v3d, NULL, true);
4096
4046
                        break;
4097
4047
                case 1:
4098
4048
                        draw_depth_gpencil(scene, ar, v3d);
4099
4049
                        break;
4100
4050
        }
4101
 
 
4102
 
        return 1;
4103
4051
}
4104
4052
 
4105
 
/* no 4x4 sampling, run view_autodist_init first */
4106
 
int ED_view3d_autodist_simple(ARegion *ar, const int mval[2], float mouse_worldloc[3],
4107
 
                              int margin, float *force_depth)
 
4053
/* no 4x4 sampling, run #ED_view3d_autodist_init first */
 
4054
bool ED_view3d_autodist_simple(ARegion *ar, const int mval[2], float mouse_worldloc[3],
 
4055
                               int margin, float *force_depth)
4108
4056
{
4109
4057
        bglMats mats; /* ZBuffer depth vars, could cache? */
4110
4058
        float depth;
4117
4065
                depth = view_autodist_depth_margin(ar, mval, margin);
4118
4066
 
4119
4067
        if (depth == FLT_MAX)
4120
 
                return 0;
 
4068
                return false;
4121
4069
 
4122
4070
        cent[0] = (double)mval[0];
4123
4071
        cent[1] = (double)mval[1];
4127
4075
        if (!gluUnProject(cent[0], cent[1], depth,
4128
4076
                          mats.modelview, mats.projection, (GLint *)mats.viewport, &p[0], &p[1], &p[2]))
4129
4077
        {
4130
 
                return 0;
 
4078
                return false;
4131
4079
        }
4132
4080
 
4133
4081
        mouse_worldloc[0] = (float)p[0];
4134
4082
        mouse_worldloc[1] = (float)p[1];
4135
4083
        mouse_worldloc[2] = (float)p[2];
4136
 
        return 1;
 
4084
        return true;
4137
4085
}
4138
4086
 
4139
 
int ED_view3d_autodist_depth(ARegion *ar, const int mval[2], int margin, float *depth)
 
4087
bool ED_view3d_autodist_depth(ARegion *ar, const int mval[2], int margin, float *depth)
4140
4088
{
4141
4089
        *depth = view_autodist_depth_margin(ar, mval, margin);
4142
4090
 
4143
 
        return (*depth == FLT_MAX) ? 0 : 1;
 
4091
        return (*depth != FLT_MAX);
4144
4092
}
4145
4093
 
4146
 
static int depth_segment_cb(int x, int y, void *userData)
 
4094
static bool depth_segment_cb(int x, int y, void *userData)
4147
4095
{
4148
4096
        struct { ARegion *ar; int margin; float depth; } *data = userData;
4149
4097
        int mval[2];
4163
4111
        }
4164
4112
}
4165
4113
 
4166
 
int ED_view3d_autodist_depth_seg(ARegion *ar, const int mval_sta[2], const int mval_end[2],
4167
 
                                 int margin, float *depth)
 
4114
bool ED_view3d_autodist_depth_seg(ARegion *ar, const int mval_sta[2], const int mval_end[2],
 
4115
                                  int margin, float *depth)
4168
4116
{
4169
4117
        struct { ARegion *ar; int margin; float depth; } data = {NULL};
4170
4118
        int p1[2];
4181
4129
 
4182
4130
        *depth = data.depth;
4183
4131
 
4184
 
        return (*depth == FLT_MAX) ? 0 : 1;
 
4132
        return (*depth != FLT_MAX);
4185
4133
}
4186
4134
 
4187
4135
/* problem - ofs[3] can be on same location as camera itself.
4225
4173
        /* Quat */
4226
4174
        if (quat) {
4227
4175
                float imat[4][4];
4228
 
                invert_m4_m4(imat, mat);
 
4176
                normalize_m4_m4(imat, mat);
 
4177
                invert_m4(imat);
4229
4178
                mat4_to_quat(quat, imat);
4230
4179
        }
4231
4180
 
4295
4244
{
4296
4245
        float mat[4][4];
4297
4246
        ED_view3d_to_m4(mat, ofs, quat, dist);
4298
 
        BKE_object_apply_mat4(ob, mat, TRUE, TRUE);
 
4247
        BKE_object_apply_mat4(ob, mat, true, true);
4299
4248
}
4300
4249
 
4301
4250
BGpic *ED_view3D_background_image_new(View3D *v3d)
4338
4287
{
4339
4288
        v3d->ob_centre = NULL;
4340
4289
        v3d->ob_centre_bone[0] = '\0';
4341
 
        v3d->ob_centre_cursor = FALSE;
 
4290
        v3d->ob_centre_cursor = false;
4342
4291
        v3d->flag2 &= ~V3D_LOCK_CAMERA;
4343
4292
}