Blender V5.3
view3d_navigate_view_orbit.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_math_base_c.hh"
11
12#include "DNA_userdef_types.h"
13
14#include "WM_api.hh"
15
16#include "RNA_access.hh"
17#include "RNA_define.hh"
18
19#include "view3d_intern.hh"
20
21#include "view3d_navigate.hh" /* own include */
22
23namespace blender {
24
25/* -------------------------------------------------------------------- */
30
31enum {
36};
37
39 {V3D_VIEW_STEPLEFT, "ORBITLEFT", 0, "Orbit Left", "Orbit the view around to the left"},
40 {V3D_VIEW_STEPRIGHT, "ORBITRIGHT", 0, "Orbit Right", "Orbit the view around to the right"},
41 {V3D_VIEW_STEPUP, "ORBITUP", 0, "Orbit Up", "Orbit the view up"},
42 {V3D_VIEW_STEPDOWN, "ORBITDOWN", 0, "Orbit Down", "Orbit the view down"},
43 {0, nullptr, 0, nullptr, nullptr},
44};
45
47{
48 float angle;
49 {
50 PropertyRNA *prop_angle = RNA_struct_find_property(op->ptr, "angle");
51 angle = RNA_property_is_set(op->ptr, prop_angle) ?
52 RNA_property_float_get(op->ptr, prop_angle) :
53 DEG2RADF(U.pad_rot_angle);
54 }
55
56 ViewOpsData vod = {};
57 vod.init_context(C);
58
60
61 /* support for switching to the opposite view (even when in locked views) */
62 eRegionView3D_View view_opposite = (fabsf(angle) == float(M_PI)) ?
65
66 if ((RV3D_LOCK_FLAGS(vod.rv3d) & RV3D_LOCK_ROTATION) && (view_opposite == RV3D_VIEW_USER)) {
67 /* no nullptr check is needed, poll checks */
69 vod.rv3d = static_cast<RegionView3D *>(vod.region->regiondata);
70
72 }
73
74 if ((RV3D_LOCK_FLAGS(vod.rv3d) & RV3D_LOCK_ROTATION) && (view_opposite == RV3D_VIEW_USER)) {
75 return OPERATOR_CANCELLED;
76 }
77
78 const bool is_camera_lock = ED_view3d_camera_lock_check(vod.v3d, vod.rv3d);
79 if (vod.rv3d->persp == RV3D_CAMOB && !is_camera_lock) {
80 return OPERATOR_CANCELLED;
81 }
82
83 vod.init_navigation(C, nullptr, &ViewOpsType_orbit, nullptr, false);
84
85 int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
86 float quat_mul[4];
87 float quat_new[4];
88
89 int orbitdir = RNA_enum_get(op->ptr, "type");
91 if (orbitdir == V3D_VIEW_STEPRIGHT) {
92 angle = -angle;
93 }
94
95 /* z-axis */
96 axis_angle_to_quat_single(quat_mul, 'Z', angle);
97 }
98 else {
99 if (orbitdir == V3D_VIEW_STEPDOWN) {
100 angle = -angle;
101 }
102
103 /* horizontal axis */
104 axis_angle_to_quat(quat_mul, vod.rv3d->viewinv[0], angle);
105 }
106
107 mul_qt_qtqt(quat_new, vod.curr.viewquat, quat_mul);
108
109 /* avoid precision loss over time */
110 normalize_qt(quat_new);
111
112 if (view_opposite != RV3D_VIEW_USER) {
113 vod.rv3d->view = view_opposite;
114 /* avoid float in-precision, just get a new orientation */
115 ED_view3d_quat_from_axis_view(view_opposite, vod.rv3d->view_axis_roll, quat_new);
116 }
117 else {
118 vod.rv3d->view = RV3D_VIEW_USER;
119 }
120
121 V3D_SmoothParams sview = {nullptr};
122 sview.quat = quat_new;
123 sview.lens = &vod.v3d->lens;
124 /* Group as successive orbit may run by holding a key. */
125 sview.undo_str = op->type->name;
126 sview.undo_grouped = true;
127
128 if (vod.use_dyn_ofs) {
129 sview.dyn_ofs = vod.dyn_ofs;
130 }
131
132 ED_view3d_smooth_view(C, vod.v3d, vod.region, smooth_viewtx, &sview);
133
134 vod.end_navigation(C);
135
136 return OPERATOR_FINISHED;
137}
138
140{
141 PropertyRNA *prop;
142
143 /* identifiers */
144 ot->name = "View Orbit";
145 ot->description = "Orbit the view";
147
148 /* API callbacks. */
149 ot->exec = vieworbit_exec;
151
152 /* flags */
153 ot->flag = 0;
154
155 /* properties */
156 prop = RNA_def_float(ot->srna, "angle", 0, -FLT_MAX, FLT_MAX, "Roll", "", -FLT_MAX, FLT_MAX);
158
159 ot->prop = RNA_def_enum(
160 ot->srna, "type", prop_view_orbit_items, 0, "Orbit", "Direction of View Orbit");
161}
162
164
167 /*idname*/ "VIEW3D_OT_view_orbit",
168 /*poll_fn*/ nullptr,
169 /*init_fn*/ nullptr,
170 /*apply_fn*/ nullptr,
171};
172
173} // namespace blender
#define DEG2RADF(_deg)
#define M_PI
#define RV3D_LOCK_FLAGS(rv3d)
#define C
Definition RandGen.cpp:29
#define ELEM(...)
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition btVector3.h:356
#define FLT_MAX
BMesh Iterators.
bool ED_view3d_context_user_region(bContext *C, View3D **r_v3d, ARegion **r_region)
UserDef U
Definition blender.cc:58
void VIEW3D_OT_view_orbit(wmOperatorType *ot)
bool ED_view3d_camera_lock_check(const View3D *v3d, const RegionView3D *rv3d)
int RNA_enum_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
bool ED_operator_rv3d_user_region_poll(bContext *C)
float normalize_qt(float q[4])
int WM_operator_smooth_viewtx_get(const wmOperator *op)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
void axis_angle_to_quat(float r[4], const float axis[3], float angle)
const ViewOpsType ViewOpsType_orbit
void mul_qt_qtqt(float q[4], const float a[4], const float b[4])
eRegionView3D_View ED_view3d_axis_view_opposite(eRegionView3D_View view)
void axis_angle_to_quat_single(float q[4], char axis, float angle)
@ VIEWOPS_FLAG_ORBIT_SELECT
float RNA_property_float_get(PointerRNA *ptr, PropertyRNA *prop)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
static const EnumPropertyItem prop_view_orbit_items[]
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
void ED_view3d_smooth_view_force_finish(bContext *C, View3D *v3d, ARegion *region)
bool ED_view3d_quat_from_axis_view(eRegionView3D_View view, eRegionView3D_ViewAxisRoll view_axis_roll, float r_quat[4])
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
void ED_view3d_smooth_view(bContext *C, View3D *v3d, ARegion *region, int smooth_viewtx, const V3D_SmoothParams *sview)
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
static wmOperatorStatus vieworbit_exec(bContext *C, wmOperator *op)
#define fabsf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
eRegionView3D_ViewAxisRoll view_axis_roll
eRegionView3D_Persp persp
eRegionView3D_View view
void end_navigation(bContext *C)
void init_navigation(bContext *C, const wmEvent *event, const ViewOpsType *nav_type, const float dyn_ofs_override[3]=nullptr, const bool use_cursor_init=false)
void init_context(bContext *C)
struct blender::ViewOpsData::@337054214024237015354033064215073157327063021373 curr
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
struct wmOperatorType * type