Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_view3d/view3d_manipulator_camera.c
| Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "RNA_access.h" | #include "RNA_access.h" | ||||
| #include "WM_api.h" | #include "WM_api.h" | ||||
| #include "WM_types.h" | #include "WM_types.h" | ||||
| #include "WM_message.h" | #include "WM_message.h" | ||||
| #include "DEG_depsgraph_query.h" | |||||
| #include "view3d_intern.h" /* own include */ | #include "view3d_intern.h" /* own include */ | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Camera Manipulators | /** \name Camera Manipulators | ||||
| * \{ */ | * \{ */ | ||||
| Show All 13 Lines | if (camera->id.lib == NULL) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| static void WIDGETGROUP_camera_setup(const bContext *C, wmManipulatorGroup *mgroup) | static void WIDGETGROUP_camera_setup(const bContext *C, wmManipulatorGroup *mgroup) | ||||
| { | { | ||||
| const Depsgraph *depsgraph = CTX_data_depsgraph(C); | |||||
| Object *ob = CTX_data_active_object(C); | Object *ob = CTX_data_active_object(C); | ||||
| const Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); | |||||
| float dir[3]; | float dir[3]; | ||||
| const wmManipulatorType *wt_arrow = WM_manipulatortype_find("MANIPULATOR_WT_arrow_3d", true); | const wmManipulatorType *wt_arrow = WM_manipulatortype_find("MANIPULATOR_WT_arrow_3d", true); | ||||
| struct CameraWidgetGroup *camgroup = MEM_callocN(sizeof(struct CameraWidgetGroup), __func__); | struct CameraWidgetGroup *camgroup = MEM_callocN(sizeof(struct CameraWidgetGroup), __func__); | ||||
| mgroup->customdata = camgroup; | mgroup->customdata = camgroup; | ||||
| negate_v3_v3(dir, ob->obmat[2]); | negate_v3_v3(dir, ob_eval->obmat[2]); | ||||
| /* dof distance */ | /* dof distance */ | ||||
| { | { | ||||
| wmManipulator *mpr; | wmManipulator *mpr; | ||||
| mpr = camgroup->dop_dist = WM_manipulator_new_ptr(wt_arrow, mgroup, NULL); | mpr = camgroup->dop_dist = WM_manipulator_new_ptr(wt_arrow, mgroup, NULL); | ||||
| RNA_enum_set(mpr->ptr, "draw_style", ED_MANIPULATOR_ARROW_STYLE_CROSS); | RNA_enum_set(mpr->ptr, "draw_style", ED_MANIPULATOR_ARROW_STYLE_CROSS); | ||||
| WM_manipulator_set_flag(mpr, WM_MANIPULATOR_DRAW_HOVER, true); | WM_manipulator_set_flag(mpr, WM_MANIPULATOR_DRAW_HOVER, true); | ||||
| Show All 23 Lines | static void WIDGETGROUP_camera_setup(const bContext *C, wmManipulatorGroup *mgroup) | ||||
| } | } | ||||
| } | } | ||||
| static void WIDGETGROUP_camera_refresh(const bContext *C, wmManipulatorGroup *mgroup) | static void WIDGETGROUP_camera_refresh(const bContext *C, wmManipulatorGroup *mgroup) | ||||
| { | { | ||||
| if (!mgroup->customdata) | if (!mgroup->customdata) | ||||
| return; | return; | ||||
| const Depsgraph *depsgraph = CTX_data_depsgraph(C); | |||||
| struct CameraWidgetGroup *camgroup = mgroup->customdata; | struct CameraWidgetGroup *camgroup = mgroup->customdata; | ||||
| Object *ob = CTX_data_active_object(C); | Object *ob = CTX_data_active_object(C); | ||||
| const Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob); | |||||
| Camera *ca = ob->data; | Camera *ca = ob->data; | ||||
| PointerRNA camera_ptr; | PointerRNA camera_ptr; | ||||
| float dir[3]; | float dir[3]; | ||||
| const float ob_scale_inv[3] = { | const float ob_scale_inv[3] = { | ||||
| 1.0f / len_v3(ob->obmat[0]), | 1.0f / len_v3(ob_eval->obmat[0]), | ||||
| 1.0f / len_v3(ob->obmat[1]), | 1.0f / len_v3(ob_eval->obmat[1]), | ||||
| 1.0f / len_v3(ob->obmat[2]), | 1.0f / len_v3(ob_eval->obmat[2]), | ||||
| }; | }; | ||||
| const float ob_scale_uniform_inv = (ob_scale_inv[0] + ob_scale_inv[1] + ob_scale_inv[2]) / 3.0f; | const float ob_scale_uniform_inv = (ob_scale_inv[0] + ob_scale_inv[1] + ob_scale_inv[2]) / 3.0f; | ||||
| RNA_pointer_create(&ca->id, &RNA_Camera, ca, &camera_ptr); | RNA_pointer_create(&ca->id, &RNA_Camera, ca, &camera_ptr); | ||||
| negate_v3_v3(dir, ob->obmat[2]); | negate_v3_v3(dir, ob_eval->obmat[2]); | ||||
| if (ca->flag & CAM_SHOWLIMITS) { | if (ca->flag & CAM_SHOWLIMITS) { | ||||
| WM_manipulator_set_matrix_location(camgroup->dop_dist, ob->obmat[3]); | WM_manipulator_set_matrix_location(camgroup->dop_dist, ob_eval->obmat[3]); | ||||
| WM_manipulator_set_matrix_rotation_from_yz_axis(camgroup->dop_dist, ob->obmat[1], dir); | WM_manipulator_set_matrix_rotation_from_yz_axis(camgroup->dop_dist, ob_eval->obmat[1], dir); | ||||
| WM_manipulator_set_scale(camgroup->dop_dist, ca->drawsize); | WM_manipulator_set_scale(camgroup->dop_dist, ca->drawsize); | ||||
| WM_manipulator_set_flag(camgroup->dop_dist, WM_MANIPULATOR_HIDDEN, false); | WM_manipulator_set_flag(camgroup->dop_dist, WM_MANIPULATOR_HIDDEN, false); | ||||
| /* need to set property here for undo. TODO would prefer to do this in _init */ | /* need to set property here for undo. TODO would prefer to do this in _init */ | ||||
| WM_manipulator_target_property_def_rna(camgroup->dop_dist, "offset", &camera_ptr, "dof_distance", -1); | WM_manipulator_target_property_def_rna(camgroup->dop_dist, "offset", &camera_ptr, "dof_distance", -1); | ||||
| } | } | ||||
| else { | else { | ||||
| WM_manipulator_set_flag(camgroup->dop_dist, WM_MANIPULATOR_HIDDEN, true); | WM_manipulator_set_flag(camgroup->dop_dist, WM_MANIPULATOR_HIDDEN, true); | ||||
| Show All 20 Lines | if (true) { | ||||
| offset[1] = 2.0f * ca->shifty; | offset[1] = 2.0f * ca->shifty; | ||||
| offset[2] = 0.0f; | offset[2] = 0.0f; | ||||
| /* get aspect */ | /* get aspect */ | ||||
| aspect[0] = (sensor_fit == CAMERA_SENSOR_FIT_HOR) ? 1.0f : aspx / aspy; | aspect[0] = (sensor_fit == CAMERA_SENSOR_FIT_HOR) ? 1.0f : aspx / aspy; | ||||
| aspect[1] = (sensor_fit == CAMERA_SENSOR_FIT_HOR) ? aspy / aspx : 1.0f; | aspect[1] = (sensor_fit == CAMERA_SENSOR_FIT_HOR) ? aspy / aspx : 1.0f; | ||||
| unit_m4(widget->matrix_basis); | unit_m4(widget->matrix_basis); | ||||
| WM_manipulator_set_matrix_location(widget, ob->obmat[3]); | WM_manipulator_set_matrix_location(widget, ob_eval->obmat[3]); | ||||
| WM_manipulator_set_matrix_rotation_from_yz_axis(widget, ob->obmat[1], dir); | WM_manipulator_set_matrix_rotation_from_yz_axis(widget, ob_eval->obmat[1], dir); | ||||
| if (is_ortho) { | if (is_ortho) { | ||||
| scale_matrix = ca->ortho_scale * 0.5f; | scale_matrix = ca->ortho_scale * 0.5f; | ||||
| } | } | ||||
| else { | else { | ||||
| scale_matrix = ca->drawsize / ob_scale_uniform_inv; | scale_matrix = ca->drawsize / ob_scale_uniform_inv; | ||||
| } | } | ||||
| mul_v3_fl(widget->matrix_basis[0], scale_matrix); | mul_v3_fl(widget->matrix_basis[0], scale_matrix); | ||||
| ▲ Show 20 Lines • Show All 266 Lines • Show Last 20 Lines | |||||