Beispiel #1
0
/**
 * Release view control.
 *
 * \param restore  Sets the view state to the values that were set
 *                 before #ED_view3d_control_aquire was called.
 */
void ED_view3d_cameracontrol_release(
    View3DCameraControl *vctrl,
    const bool restore)
{
    View3D *v3d        = vctrl->ctx_v3d;
    RegionView3D *rv3d = vctrl->ctx_rv3d;

    rv3d->dist = vctrl->dist_backup;
    if (restore) {
        /* Revert to original view? */
        if (vctrl->persp_backup == RV3D_CAMOB) { /* a camera view */
            Object *ob_back = view3d_cameracontrol_object(vctrl);

            /* store the original camera loc and rot */
            BKE_object_tfm_restore(ob_back, vctrl->obtfm);

            DAG_id_tag_update(&ob_back->id, OB_RECALC_OB);
        }
        else {
            /* Non Camera we need to reset the view back to the original location bacause the user canceled*/
            copy_qt_qt(rv3d->viewquat, vctrl->rot_backup);
            rv3d->persp = vctrl->persp_backup;
        }
        /* always, is set to zero otherwise */
        copy_v3_v3(rv3d->ofs, vctrl->ofs_backup);
    }
    else if (vctrl->persp_backup == RV3D_CAMOB) { /* camera */
        DAG_id_tag_update((ID *)view3d_cameracontrol_object(vctrl), OB_RECALC_OB);

        /* always, is set to zero otherwise */
        copy_v3_v3(rv3d->ofs, vctrl->ofs_backup);
    }
    else { /* not camera */
        float tvec[3];

        /* Apply the fly mode view */
        /* restore the dist */
        copy_v3_fl3(tvec, 0.0f, 0.0f, vctrl->dist_backup);
        mul_mat3_m4_v3(rv3d->viewinv, tvec);
        add_v3_v3(rv3d->ofs, tvec);
        /* Done with correcting for the dist */
    }

    if (vctrl->is_ortho_cam) {
        ((Camera *)v3d->camera->data)->type = CAM_ORTHO;
    }

    if (vctrl->obtfm) {
        MEM_freeN(vctrl->obtfm);
    }

    MEM_freeN(vctrl);
}
Beispiel #2
0
static int flyEnd(bContext *C, FlyInfo *fly)
{
	RegionView3D *rv3d = fly->rv3d;
	View3D *v3d = fly->v3d;

	float upvec[3];

	if (fly->state == FLY_RUNNING)
		return OPERATOR_RUNNING_MODAL;

#ifdef NDOF_FLY_DEBUG
	puts("\n-- fly end --");
#endif

	WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), fly->timer);

	ED_region_draw_cb_exit(fly->ar->type, fly->draw_handle_pixel);

	rv3d->dist = fly->dist_backup;
	if (fly->state == FLY_CANCEL) {
		/* Revert to original view? */
		if (fly->persp_backup == RV3D_CAMOB) { /* a camera view */
			Object *ob_back;
			ob_back = (fly->root_parent) ? fly->root_parent : fly->v3d->camera;

			/* store the original camera loc and rot */
			BKE_object_tfm_restore(ob_back, fly->obtfm);

			DAG_id_tag_update(&ob_back->id, OB_RECALC_OB);
		}
		else {
			/* Non Camera we need to reset the view back to the original location bacause the user canceled*/
			copy_qt_qt(rv3d->viewquat, fly->rot_backup);
			rv3d->persp = fly->persp_backup;
		}
		/* always, is set to zero otherwise */
		copy_v3_v3(rv3d->ofs, fly->ofs_backup);
	}
	else if (fly->persp_backup == RV3D_CAMOB) { /* camera */
		DAG_id_tag_update(fly->root_parent ? &fly->root_parent->id : &v3d->camera->id, OB_RECALC_OB);
		
		/* always, is set to zero otherwise */
		copy_v3_v3(rv3d->ofs, fly->ofs_backup);
	}
	else { /* not camera */

		/* Apply the fly mode view */
		/* restore the dist */
		float mat[3][3];
		upvec[0] = upvec[1] = 0;
		upvec[2] = fly->dist_backup; /* x and y are 0 */
		copy_m3_m4(mat, rv3d->viewinv);
		mul_m3_v3(mat, upvec);
		add_v3_v3(rv3d->ofs, upvec);
		/* Done with correcting for the dist */
	}

	if (fly->is_ortho_cam) {
		((Camera *)fly->v3d->camera->data)->type = CAM_ORTHO;
	}

	rv3d->rflag &= ~RV3D_NAVIGATING;
//XXX2.5	BIF_view3d_previewrender_signal(fly->sa, PR_DBASE|PR_DISPRECT); /* not working at the moment not sure why */

	if (fly->obtfm)
		MEM_freeN(fly->obtfm);
	if (fly->ndof)
		MEM_freeN(fly->ndof);

	if (fly->state == FLY_CONFIRM) {
		MEM_freeN(fly);
		return OPERATOR_FINISHED;
	}

	MEM_freeN(fly);
	return OPERATOR_CANCELLED;
}