Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/space_view3d/view3d_fly.c')
-rw-r--r--source/blender/editors/space_view3d/view3d_fly.c163
1 files changed, 89 insertions, 74 deletions
diff --git a/source/blender/editors/space_view3d/view3d_fly.c b/source/blender/editors/space_view3d/view3d_fly.c
index 700027d62a2..2cedf7da725 100644
--- a/source/blender/editors/space_view3d/view3d_fly.c
+++ b/source/blender/editors/space_view3d/view3d_fly.c
@@ -78,9 +78,21 @@ enum {
FLY_MODAL_FREELOOK_ENABLE,
FLY_MODAL_FREELOOK_DISABLE,
FLY_MODAL_SPEED, /* mousepan typically */
-
};
+/* relative view axis locking - xlock, zlock */
+typedef enum eFlyPanState {
+ /* disabled */
+ FLY_AXISLOCK_STATE_OFF = 0,
+
+ /* enabled but not checking because mouse hasn't moved outside the margin since locking was checked an not needed
+ * when the mouse moves, locking is set to 2 so checks are done. */
+ FLY_AXISLOCK_STATE_IDLE = 1,
+
+ /* mouse moved and checking needed, if no view altering is done its changed back to #FLY_AXISLOCK_STATE_IDLE */
+ FLY_AXISLOCK_STATE_ACTIVE = 2
+} eFlyPanState;
+
/* called in transform_ops.c, on each regeneration of keymaps */
void fly_modal_keymap(wmKeyConfig *keyconf)
{
@@ -170,11 +182,11 @@ typedef struct FlyInfo {
wmTimer *timer; /* needed for redraws */
short state;
- short redraw;
- unsigned char use_precision;
+ bool redraw;
+ bool use_precision;
/* if the user presses shift they can look about
* without moving the direction there looking */
- unsigned char use_freelook;
+ bool use_freelook;
int mval[2]; /* latest 2D mouse values */
wmNDOFMotionData *ndof; /* latest 3D mouse values */
@@ -182,14 +194,9 @@ typedef struct FlyInfo {
/* fly state state */
float speed; /* the speed the view is moving per redraw */
short axis; /* Axis index to move along by default Z to move along the view */
- short pan_view; /* when true, pan the view instead of rotating */
-
- /* relative view axis locking - xlock, zlock
- * 0) disabled
- * 1) enabled but not checking because mouse hasn't moved outside the margin since locking was checked an not needed
- * when the mouse moves, locking is set to 2 so checks are done.
- * 2) mouse moved and checking needed, if no view altering is done its changed back to 1 */
- short xlock, zlock;
+ bool pan_view; /* when true, pan the view instead of rotating */
+
+ eFlyPanState xlock, zlock;
float xlock_momentum, zlock_momentum; /* nicer dynamics */
float grid; /* world scale 1.0 default */
@@ -208,7 +215,7 @@ typedef struct FlyInfo {
/* are we flying an ortho camera in perspective view,
* which was originall in ortho view?
* could probably figure it out but better be explicit */
- short is_ortho_cam;
+ bool is_ortho_cam;
void *obtfm; /* backup the objects transform */
/* compare between last state */
@@ -272,7 +279,7 @@ static void drawFlyPixel(const struct bContext *UNUSED(C), ARegion *UNUSED(ar),
#define FLY_CANCEL 1
#define FLY_CONFIRM 2
-static int initFlyInfo(bContext *C, FlyInfo *fly, wmOperator *op, const wmEvent *event)
+static bool initFlyInfo(bContext *C, FlyInfo *fly, wmOperator *op, const wmEvent *event)
{
wmWindow *win = CTX_wm_window(C);
float upvec[3]; /* tmp */
@@ -294,30 +301,30 @@ static int initFlyInfo(bContext *C, FlyInfo *fly, wmOperator *op, const wmEvent
if (fly->rv3d->persp == RV3D_CAMOB && fly->v3d->camera->id.lib) {
BKE_report(op->reports, RPT_ERROR, "Cannot fly a camera from an external library");
- return FALSE;
+ return false;
}
if (fly->v3d->ob_centre) {
BKE_report(op->reports, RPT_ERROR, "Cannot fly when the view is locked to an object");
- return FALSE;
+ return false;
}
if (fly->rv3d->persp == RV3D_CAMOB && fly->v3d->camera->constraints.first) {
BKE_report(op->reports, RPT_ERROR, "Cannot fly an object with constraints");
- return FALSE;
+ return false;
}
fly->state = FLY_RUNNING;
fly->speed = 0.0f;
fly->axis = 2;
- fly->pan_view = FALSE;
- fly->xlock = FALSE;
- fly->zlock = FALSE;
+ fly->pan_view = false;
+ fly->xlock = FLY_AXISLOCK_STATE_OFF;
+ fly->zlock = FLY_AXISLOCK_STATE_OFF;
fly->xlock_momentum = 0.0f;
fly->zlock_momentum = 0.0f;
fly->grid = 1.0f;
- fly->use_precision = FALSE;
- fly->use_freelook = FALSE;
+ fly->use_precision = false;
+ fly->use_freelook = false;
#ifdef NDOF_FLY_DRAW_TOOMUCH
fly->redraw = 1;
@@ -342,7 +349,7 @@ static int initFlyInfo(bContext *C, FlyInfo *fly, wmOperator *op, const wmEvent
copy_m3_m4(mat, fly->rv3d->viewinv);
mul_m3_v3(mat, upvec);
if (fabsf(upvec[2]) < 0.1f) {
- fly->zlock = 1;
+ fly->zlock = FLY_AXISLOCK_STATE_IDLE;
}
upvec[0] = 0;
upvec[1] = 0;
@@ -354,10 +361,10 @@ static int initFlyInfo(bContext *C, FlyInfo *fly, wmOperator *op, const wmEvent
/* check for flying ortho camera - which we cant support well
* we _could_ also check for an ortho camera but this is easier */
if ((fly->rv3d->persp == RV3D_CAMOB) &&
- (fly->rv3d->is_persp == FALSE))
+ (fly->rv3d->is_persp == false))
{
((Camera *)fly->v3d->camera->data)->type = CAM_PERSP;
- fly->is_ortho_cam = TRUE;
+ fly->is_ortho_cam = true;
}
if (fly->rv3d->persp == RV3D_CAMOB) {
@@ -601,11 +608,11 @@ static void flyEvent(FlyInfo *fly, const wmEvent *event)
break;
}
case FLY_MODAL_PAN_ENABLE:
- fly->pan_view = TRUE;
+ fly->pan_view = true;
break;
case FLY_MODAL_PAN_DISABLE:
//XXX2.5 WM_cursor_warp(CTX_wm_window(C), cent_orig[0], cent_orig[1]);
- fly->pan_view = FALSE;
+ fly->pan_view = false;
break;
/* implement WASD keys,
@@ -677,40 +684,41 @@ static void flyEvent(FlyInfo *fly, const wmEvent *event)
break;
case FLY_MODAL_AXIS_LOCK_X:
- if (fly->xlock)
- fly->xlock = 0;
+ if (fly->xlock != FLY_AXISLOCK_STATE_OFF)
+ fly->xlock = FLY_AXISLOCK_STATE_OFF;
else {
- fly->xlock = 2;
+ fly->xlock = FLY_AXISLOCK_STATE_ACTIVE;
fly->xlock_momentum = 0.0;
}
break;
case FLY_MODAL_AXIS_LOCK_Z:
- if (fly->zlock)
- fly->zlock = 0;
+ if (fly->zlock != FLY_AXISLOCK_STATE_OFF)
+ fly->zlock = FLY_AXISLOCK_STATE_OFF;
else {
- fly->zlock = 2;
+ fly->zlock = FLY_AXISLOCK_STATE_ACTIVE;
fly->zlock_momentum = 0.0;
}
break;
case FLY_MODAL_PRECISION_ENABLE:
- fly->use_precision = TRUE;
+ fly->use_precision = true;
break;
case FLY_MODAL_PRECISION_DISABLE:
- fly->use_precision = FALSE;
+ fly->use_precision = false;
break;
case FLY_MODAL_FREELOOK_ENABLE:
- fly->use_freelook = TRUE;
+ fly->use_freelook = true;
break;
case FLY_MODAL_FREELOOK_DISABLE:
- fly->use_freelook = FALSE;
+ fly->use_freelook = false;
break;
}
}
}
-static void move_camera(bContext *C, RegionView3D *rv3d, FlyInfo *fly, int orientationChanged, int positionChanged)
+static void flyMoveCamera(bContext *C, RegionView3D *rv3d, FlyInfo *fly,
+ const bool do_rotate, const bool do_translate)
{
/* we are in camera view so apply the view ofs and quat to the view matrix and set the camera to the view */
@@ -733,7 +741,7 @@ static void move_camera(bContext *C, RegionView3D *rv3d, FlyInfo *fly, int orien
ED_view3d_to_m4(view_mat, rv3d->ofs, rv3d->viewquat, rv3d->dist);
mult_m4_m4m4(diff_mat, view_mat, prev_view_imat);
mult_m4_m4m4(parent_mat, diff_mat, fly->root_parent->obmat);
- BKE_object_apply_mat4(fly->root_parent, parent_mat, TRUE, FALSE);
+ BKE_object_apply_mat4(fly->root_parent, parent_mat, true, false);
// BKE_object_where_is_calc(scene, fly->root_parent);
@@ -748,7 +756,7 @@ static void move_camera(bContext *C, RegionView3D *rv3d, FlyInfo *fly, int orien
else {
float view_mat[4][4];
ED_view3d_to_m4(view_mat, rv3d->ofs, rv3d->viewquat, rv3d->dist);
- BKE_object_apply_mat4(v3d->camera, view_mat, TRUE, FALSE);
+ BKE_object_apply_mat4(v3d->camera, view_mat, true, false);
id_key = &v3d->camera->id;
}
@@ -764,11 +772,11 @@ static void move_camera(bContext *C, RegionView3D *rv3d, FlyInfo *fly, int orien
* 2) on each subsequent frame
* TODO: need to check in future that frame changed before doing this
*/
- if (orientationChanged) {
+ if (do_rotate) {
KeyingSet *ks = ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_ROTATION_ID);
ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
}
- if (positionChanged) {
+ if (do_translate) {
KeyingSet *ks = ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_LOCATION_ID);
ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
}
@@ -851,7 +859,8 @@ static int flyApply(bContext *C, FlyInfo *fly)
/* Should we redraw? */
if ((fly->speed != 0.0f) ||
moffset[0] || moffset[1] ||
- fly->zlock || fly->xlock ||
+ (fly->zlock != FLY_AXISLOCK_STATE_OFF) ||
+ (fly->xlock != FLY_AXISLOCK_STATE_OFF) ||
dvec[0] || dvec[1] || dvec[2])
{
float dvec_tmp[3];
@@ -876,7 +885,7 @@ static int flyApply(bContext *C, FlyInfo *fly)
copy_m3_m4(mat, rv3d->viewinv);
- if (fly->pan_view == TRUE) {
+ if (fly->pan_view == true) {
/* pan only */
dvec_tmp[0] = -moffset[0];
dvec_tmp[1] = -moffset[1];
@@ -904,10 +913,10 @@ static int flyApply(bContext *C, FlyInfo *fly)
axis_angle_to_quat(tmp_quat, upvec, (float)moffset[1] * time_redraw * -FLY_ROTATE_FAC);
mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, tmp_quat);
- if (fly->xlock)
- fly->xlock = 2; /* check for rotation */
- if (fly->zlock)
- fly->zlock = 2;
+ if (fly->xlock != FLY_AXISLOCK_STATE_OFF)
+ fly->xlock = FLY_AXISLOCK_STATE_ACTIVE; /* check for rotation */
+ if (fly->zlock != FLY_AXISLOCK_STATE_OFF)
+ fly->zlock = FLY_AXISLOCK_STATE_ACTIVE;
fly->xlock_momentum = 0.0f;
}
@@ -940,13 +949,13 @@ static int flyApply(bContext *C, FlyInfo *fly)
axis_angle_to_quat(tmp_quat, upvec, (float)moffset[0] * time_redraw * FLY_ROTATE_FAC);
mul_qt_qtqt(rv3d->viewquat, rv3d->viewquat, tmp_quat);
- if (fly->xlock)
- fly->xlock = 2; /* check for rotation */
- if (fly->zlock)
- fly->zlock = 2;
+ if (fly->xlock != FLY_AXISLOCK_STATE_OFF)
+ fly->xlock = FLY_AXISLOCK_STATE_ACTIVE; /* check for rotation */
+ if (fly->zlock != FLY_AXISLOCK_STATE_OFF)
+ fly->zlock = FLY_AXISLOCK_STATE_ACTIVE;
}
- if (fly->zlock == 2) {
+ if (fly->zlock == FLY_AXISLOCK_STATE_ACTIVE) {
upvec[0] = 1.0f;
upvec[1] = 0.0f;
upvec[2] = 0.0f;
@@ -968,12 +977,13 @@ static int flyApply(bContext *C, FlyInfo *fly)
fly->zlock_momentum += FLY_ZUP_CORRECT_ACCEL;
}
else {
- fly->zlock = 1; /* don't check until the view rotates again */
+ fly->zlock = FLY_AXISLOCK_STATE_IDLE; /* don't check until the view rotates again */
fly->zlock_momentum = 0.0f;
}
}
- if (fly->xlock == 2 && moffset[1] == 0) { /* only apply xcorrect when mouse isn't applying x rot */
+ /* only apply xcorrect when mouse isn't applying x rot */
+ if (fly->xlock == FLY_AXISLOCK_STATE_ACTIVE && moffset[1] == 0) {
upvec[0] = 0;
upvec[1] = 0;
upvec[2] = 1;
@@ -995,7 +1005,7 @@ static int flyApply(bContext *C, FlyInfo *fly)
fly->xlock_momentum += 0.05f;
}
else {
- fly->xlock = 1; /* see above */
+ fly->xlock = FLY_AXISLOCK_STATE_IDLE; /* see above */
fly->xlock_momentum = 0.0f;
}
}
@@ -1035,8 +1045,13 @@ static int flyApply(bContext *C, FlyInfo *fly)
add_v3_v3(rv3d->ofs, dvec);
- if (rv3d->persp == RV3D_CAMOB)
- move_camera(C, rv3d, fly, (fly->xlock || fly->zlock || moffset[0] || moffset[1]), fly->speed);
+ if (rv3d->persp == RV3D_CAMOB) {
+ const bool do_rotate = ((fly->xlock != FLY_AXISLOCK_STATE_OFF) ||
+ (fly->zlock != FLY_AXISLOCK_STATE_OFF) ||
+ ((moffset[0] || moffset[1]) && !fly->pan_view));
+ const bool do_translate = (fly->speed != 0.0f || fly->pan_view);
+ flyMoveCamera(C, rv3d, fly, do_rotate, do_translate);
+ }
}
else {
@@ -1059,19 +1074,19 @@ static int flyApply_ndof(bContext *C, FlyInfo *fly)
const int flag = U.ndof_flag;
#if 0
- int shouldRotate = (flag & NDOF_SHOULD_ROTATE) && (fly->pan_view == FALSE);
- int shouldTranslate = (flag & (NDOF_SHOULD_PAN | NDOF_SHOULD_ZOOM));
+ bool do_rotate = (flag & NDOF_SHOULD_ROTATE) && (fly->pan_view == false);
+ bool do_translate = (flag & (NDOF_SHOULD_PAN | NDOF_SHOULD_ZOOM));
#endif
- int shouldRotate = (fly->pan_view == FALSE);
- int shouldTranslate = TRUE;
+ bool do_rotate = (fly->pan_view == false);
+ bool do_translate = true;
float view_inv[4];
invert_qt_qt(view_inv, rv3d->viewquat);
rv3d->rot_angle = 0.0f; /* disable onscreen rotation doo-dad */
- if (shouldTranslate) {
+ if (do_translate) {
const float forward_sensitivity = 1.0f;
const float vertical_sensitivity = 0.4f;
const float lateral_sensitivity = 0.6f;
@@ -1107,14 +1122,14 @@ static int flyApply_ndof(bContext *C, FlyInfo *fly)
if (!is_zero_v3(trans)) {
/* move center of view opposite of hand motion (this is camera mode, not object mode) */
sub_v3_v3(rv3d->ofs, trans);
- shouldTranslate = TRUE;
+ do_translate = true;
}
else {
- shouldTranslate = FALSE;
+ do_translate = false;
}
}
- if (shouldRotate) {
+ if (do_rotate) {
const float turn_sensitivity = 1.0f;
float rotation[4];
@@ -1122,7 +1137,7 @@ static int flyApply_ndof(bContext *C, FlyInfo *fly)
float angle = turn_sensitivity * ndof_to_axis_angle(ndof, axis);
if (fabsf(angle) > 0.0001f) {
- shouldRotate = TRUE;
+ do_rotate = true;
if (fly->use_precision)
angle *= 0.2f;
@@ -1164,15 +1179,15 @@ static int flyApply_ndof(bContext *C, FlyInfo *fly)
rv3d->view = RV3D_VIEW_USER;
}
else {
- shouldRotate = FALSE;
+ do_rotate = false;
}
}
- if (shouldTranslate || shouldRotate) {
- fly->redraw = TRUE;
+ if (do_translate || do_rotate) {
+ fly->redraw = true;
if (rv3d->persp == RV3D_CAMOB) {
- move_camera(C, rv3d, fly, shouldRotate, shouldTranslate);
+ flyMoveCamera(C, rv3d, fly, do_rotate, do_translate);
}
}
@@ -1191,7 +1206,7 @@ static int fly_invoke(bContext *C, wmOperator *op, const wmEvent *event)
op->customdata = fly;
- if (initFlyInfo(C, fly, op, event) == FALSE) {
+ if (initFlyInfo(C, fly, op, event) == false) {
MEM_freeN(op->customdata);
return OPERATOR_CANCELLED;
}
@@ -1217,7 +1232,7 @@ static int fly_cancel(bContext *C, wmOperator *op)
static int fly_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
int exit_code;
- short do_draw = FALSE;
+ bool do_draw = false;
FlyInfo *fly = op->customdata;
RegionView3D *rv3d = fly->rv3d;
Object *fly_object = fly->root_parent ? fly->root_parent : fly->v3d->camera;
@@ -1240,7 +1255,7 @@ static int fly_modal(bContext *C, wmOperator *op, const wmEvent *event)
exit_code = flyEnd(C, fly);
if (exit_code != OPERATOR_RUNNING_MODAL)
- do_draw = TRUE;
+ do_draw = true;
if (do_draw) {
if (rv3d->persp == RV3D_CAMOB) {