Blender V5.0
transform_mode_trackball.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstdlib>
10
11#include "BLI_math_matrix.h"
12#include "BLI_math_rotation.h"
13#include "BLI_math_vector.h"
14#include "BLI_string_utf8.h"
15#include "BLI_task.hh"
16
17#include "BKE_unit.hh"
18
19#include "ED_screen.hh"
20
21#include "UI_interface.hh"
22
23#include "BLT_translation.hh"
24
25#include "transform.hh"
26#include "transform_convert.hh"
27#include "transform_snap.hh"
28
29#include "transform_mode.hh"
30
31namespace blender::ed::transform {
32
33/* -------------------------------------------------------------------- */
36
38 const TransDataContainer *tc,
39 TransData *td,
40 TransDataExtension *td_ext,
41 const float axis[3],
42 const float angle,
43 const float mat_final[3][3])
44{
45 float mat_buf[3][3];
46 const float (*mat)[3] = mat_final;
47 if (t->flag & T_PROP_EDIT) {
48 axis_angle_normalized_to_mat3(mat_buf, axis, td->factor * angle);
49 mat = mat_buf;
50 }
51 ElementRotation(t, tc, td, td_ext, mat, t->around);
52}
53
55 const float phi[2],
56 float r_axis[3],
57 float *r_angle)
58{
59 float axis1[3], axis2[3];
60 normalize_v3_v3(axis1, t->persinv[0]);
61 normalize_v3_v3(axis2, t->persinv[1]);
62
63 mul_v3_v3fl(r_axis, axis1, phi[0]);
64 madd_v3_v3fl(r_axis, axis2, phi[1]);
65 *r_angle = normalize_v3(r_axis);
66}
67
68static void applyTrackballValue(TransInfo *t, const float axis[3], const float angle)
69{
70 float mat_final[3][3];
71
72 axis_angle_normalized_to_mat3(mat_final, axis, angle);
73
75 threading::parallel_for(IndexRange(tc->data_len), 1024, [&](const IndexRange range) {
76 for (const int i : range) {
77 TransData *td = &tc->data[i];
78 TransDataExtension *td_ext = tc->data_ext ? &tc->data_ext[i] : nullptr;
79 if (td->flag & TD_SKIP) {
80 continue;
81 }
82 transdata_elem_trackball(t, tc, td, td_ext, axis, angle, mat_final);
83 }
84 });
85 }
86}
87
89{
90 char str[UI_MAX_DRAW_STR];
91 size_t ofs = 0;
92 float phi[2];
93
94 copy_v2_v2(phi, t->values);
95
97
98 applyNumInput(&t->num, phi);
99
100 copy_v2_v2(t->values_final, phi);
101
102 if (hasNumInput(&t->num)) {
103 char c[NUM_STR_REP_LEN * 2];
104
105 outputNumInput(&(t->num), c, t->scene->unit);
106
107 ofs += BLI_snprintf_utf8_rlen(str + ofs,
108 sizeof(str) - ofs,
109 IFACE_("Trackball: %s %s %s"),
110 &c[0],
111 &c[NUM_STR_REP_LEN],
112 t->proptext);
113 }
114 else {
115 ofs += BLI_snprintf_utf8_rlen(str + ofs,
116 sizeof(str) - ofs,
117 IFACE_("Trackball: %.2f %.2f %s"),
118 RAD2DEGF(phi[0]),
119 RAD2DEGF(phi[1]),
120 t->proptext);
121 }
122
123 if (t->flag & T_PROP_EDIT_ALL) {
125 str + ofs, sizeof(str) - ofs, IFACE_(" Proportional size: %.2f"), t->prop_size);
126 }
127
128 float axis_final[3], angle_final;
129 applyTrackballValue_calc_axis_angle(t, phi, axis_final, &angle_final);
130 applyTrackballValue(t, axis_final, angle_final);
131
132 recalc_data(t);
133
135}
136
137static void applyTrackballMatrix(TransInfo *t, float mat_xform[4][4])
138{
139 const float phi[2] = {UNPACK2(t->values_final)};
140
141 float axis_final[3], angle_final;
142 applyTrackballValue_calc_axis_angle(t, phi, axis_final, &angle_final);
143
144 float mat3[3][3], mat4[4][4];
145 axis_angle_normalized_to_mat3(mat3, axis_final, angle_final);
146
147 copy_m4_m3(mat4, mat3);
149 mul_m4_m4m4(mat_xform, mat4, mat_xform);
150}
151
152static void initTrackball(TransInfo *t, wmOperator * /*op*/)
153{
154 t->mode = TFM_TRACKBALL;
155
158 status.item(TIP_("Transform is set to only affect location"), ICON_ERROR);
160 }
161 else {
163 }
164
165 t->idx_max = 1;
166 t->num.idx_max = 1;
167 t->increment = float3(DEG2RAD(5.0));
168 t->increment_precision = 0.2f;
169
171 t->num.unit_sys = t->scene->unit.system;
175}
176
178
180 /*flags*/ T_NO_CONSTRAINT,
181 /*init_fn*/ initTrackball,
182 /*transform_fn*/ applyTrackball,
183 /*transform_matrix_fn*/ applyTrackballMatrix,
184 /*handle_event_fn*/ nullptr,
185 /*snap_distance_fn*/ nullptr,
186 /*snap_apply_fn*/ nullptr,
187 /*draw_fn*/ nullptr,
188};
189
190} // namespace blender::ed::transform
@ B_UNIT_ROTATION
Definition BKE_unit.hh:141
#define DEG2RAD(_deg)
#define RAD2DEGF(_rad)
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
void copy_m4_m3(float m1[4][4], const float m2[3][3])
void transform_pivot_set_m4(float mat[4][4], const float pivot[3])
void axis_angle_normalized_to_mat3(float R[3][3], const float axis[3], float angle)
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
MINLINE void copy_v2_v2(float r[2], const float a[2])
MINLINE float normalize_v3_v3(float r[3], const float a[3])
MINLINE void copy_v3_fl(float r[3], float f)
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
MINLINE float normalize_v3(float n[3])
size_t BLI_snprintf_utf8_rlen(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
#define UNPACK2(a)
#define TIP_(msgid)
#define IFACE_(msgid)
@ USER_UNIT_ROT_RADIANS
#define NUM_STR_REP_LEN
bool applyNumInput(NumInput *n, float *vec)
Definition numinput.cc:190
void outputNumInput(NumInput *n, char *str, const UnitSettings &unit_settings)
Definition numinput.cc:88
bool hasNumInput(const NumInput *n)
Definition numinput.cc:171
void ED_area_status_text(ScrArea *area, const char *str)
Definition area.cc:851
static double angle(const Eigen::Vector3d &v1, const Eigen::Vector3d &v2)
Definition IK_Math.h:117
#define UI_MAX_DRAW_STR
nullptr float
#define str(s)
VecBase< float, 3 > float3
static void transdata_elem_trackball(const TransInfo *t, const TransDataContainer *tc, TransData *td, TransDataExtension *td_ext, const float axis[3], const float angle, const float mat_final[3][3])
void initMouseInputMode(TransInfo *t, MouseInput *mi, MouseInputMode mode)
void recalc_data(TransInfo *t)
static void applyTrackballValue(TransInfo *t, const float axis[3], const float angle)
bool transform_snap_increment(const TransInfo *t, float *r_val)
static void applyTrackballValue_calc_axis_angle(const TransInfo *t, const float phi[2], float r_axis[3], float *r_angle)
static void initTrackball(TransInfo *t, wmOperator *)
static void applyTrackball(TransInfo *t)
bool transform_mode_affect_only_locations(const TransInfo *t)
void ElementRotation(const TransInfo *t, const TransDataContainer *tc, TransData *td, TransDataExtension *td_ext, const float mat[3][3], const short around)
static void applyTrackballMatrix(TransInfo *t, float mat_xform[4][4])
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
Definition BLI_task.hh:93
const int status
short idx_max
float val_inc[NUM_MAX_ELEMENTS]
int unit_type[NUM_MAX_ELEMENTS]
bool unit_use_radians
struct UnitSettings unit
#define T_PROP_EDIT_ALL
Definition transform.hh:28
#define FOREACH_TRANS_DATA_CONTAINER(t, th)
Definition transform.hh:42
conversion and adaptation of different datablocks to a common struct.
transform modes used by different operators.