Blender  V3.3
transform_mode_trackball.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2001-2002 NaN Holding BV. All rights reserved. */
3 
8 #include <stdlib.h>
9 
10 #include "BLI_math.h"
11 #include "BLI_string.h"
12 #include "BLI_task.h"
13 
14 #include "BKE_context.h"
15 #include "BKE_unit.h"
16 
17 #include "ED_screen.h"
18 
19 #include "UI_interface.h"
20 
21 #include "BLT_translation.h"
22 
23 #include "transform.h"
24 #include "transform_convert.h"
25 #include "transform_snap.h"
26 
27 #include "transform_mode.h"
28 
29 /* -------------------------------------------------------------------- */
37  const TransInfo *t;
39  const float axis[3];
40  const float angle;
41  float mat_final[3][3];
42 };
43 
45  const TransDataContainer *tc,
46  TransData *td,
47  const float axis[3],
48  const float angle,
49  const float mat_final[3][3])
50 {
51  float mat_buf[3][3];
52  const float(*mat)[3] = mat_final;
53  if (t->flag & T_PROP_EDIT) {
54  axis_angle_normalized_to_mat3(mat_buf, axis, td->factor * angle);
55  mat = mat_buf;
56  }
57  ElementRotation(t, tc, td, mat, t->around);
58 }
59 
60 static void transdata_elem_trackball_fn(void *__restrict iter_data_v,
61  const int iter,
62  const TaskParallelTLS *__restrict UNUSED(tls))
63 {
64  struct TransDataArgs_Trackball *data = iter_data_v;
65  TransData *td = &data->tc->data[iter];
66  if (td->flag & TD_SKIP) {
67  return;
68  }
69  transdata_elem_trackball(data->t, data->tc, td, data->axis, data->angle, data->mat_final);
70 }
71 
74 /* -------------------------------------------------------------------- */
79  const float phi[2],
80  float r_axis[3],
81  float *r_angle)
82 {
83  float axis1[3], axis2[3];
84  normalize_v3_v3(axis1, t->persinv[0]);
85  normalize_v3_v3(axis2, t->persinv[1]);
86 
87  mul_v3_v3fl(r_axis, axis1, phi[0]);
88  madd_v3_v3fl(r_axis, axis2, phi[1]);
89  *r_angle = normalize_v3(r_axis);
90 }
91 
92 static void applyTrackballValue(TransInfo *t, const float axis[3], const float angle)
93 {
94  float mat_final[3][3];
95  int i;
96 
98 
101  TransData *td = tc->data;
102  for (i = 0; i < tc->data_len; i++, td++) {
103  if (td->flag & TD_SKIP) {
104  continue;
105  }
107  }
108  }
109  else {
110  struct TransDataArgs_Trackball data = {
111  .t = t,
112  .tc = tc,
113  .axis = {UNPACK3(axis)},
114  .angle = angle,
115  };
116  copy_m3_m3(data.mat_final, mat_final);
117 
118  TaskParallelSettings settings;
121  }
122  }
123 }
124 
125 static void applyTrackball(TransInfo *t, const int UNUSED(mval[2]))
126 {
127  char str[UI_MAX_DRAW_STR];
128  size_t ofs = 0;
129  float phi[2];
130 
131  copy_v2_v2(phi, t->values);
132 
134 
135  applyNumInput(&t->num, phi);
136 
137  copy_v2_v2(t->values_final, phi);
138 
139  if (hasNumInput(&t->num)) {
140  char c[NUM_STR_REP_LEN * 2];
141 
142  outputNumInput(&(t->num), c, &t->scene->unit);
143 
144  ofs += BLI_snprintf_rlen(str + ofs,
145  sizeof(str) - ofs,
146  TIP_("Trackball: %s %s %s"),
147  &c[0],
148  &c[NUM_STR_REP_LEN],
149  t->proptext);
150  }
151  else {
152  ofs += BLI_snprintf_rlen(str + ofs,
153  sizeof(str) - ofs,
154  TIP_("Trackball: %.2f %.2f %s"),
155  RAD2DEGF(phi[0]),
156  RAD2DEGF(phi[1]),
157  t->proptext);
158  }
159 
160  if (t->flag & T_PROP_EDIT_ALL) {
161  ofs += BLI_snprintf_rlen(
162  str + ofs, sizeof(str) - ofs, TIP_(" Proportional size: %.2f"), t->prop_size);
163  }
164 
165  float axis_final[3], angle_final;
166  applyTrackballValue_calc_axis_angle(t, phi, axis_final, &angle_final);
167  applyTrackballValue(t, axis_final, angle_final);
168 
169  recalcData(t);
170 
171  ED_area_status_text(t->area, str);
172 }
173 
174 static void applyTrackballMatrix(TransInfo *t, float mat_xform[4][4])
175 {
176  const float phi[2] = {UNPACK2(t->values_final)};
177 
178  float axis_final[3], angle_final;
179  applyTrackballValue_calc_axis_angle(t, phi, axis_final, &angle_final);
180 
181  float mat3[3][3], mat4[4][4];
182  axis_angle_normalized_to_mat3(mat3, axis_final, angle_final);
183 
184  copy_m4_m3(mat4, mat3);
185  transform_pivot_set_m4(mat4, t->center_global);
186  mul_m4_m4m4(mat_xform, mat4, mat_xform);
187 }
188 
190 {
191  t->mode = TFM_TRACKBALL;
192  t->transform = applyTrackball;
193  t->transform_matrix = applyTrackballMatrix;
194 
196 
197  t->idx_max = 1;
198  t->num.idx_max = 1;
199  t->snap[0] = DEG2RAD(5.0);
200  t->snap[1] = DEG2RAD(1.0);
201 
202  copy_v3_fl(t->num.val_inc, t->snap[1]);
203  t->num.unit_sys = t->scene->unit.system;
204  t->num.unit_use_radians = (t->scene->unit.system_rotation == USER_UNIT_ROT_RADIANS);
205  t->num.unit_type[0] = B_UNIT_ROTATION;
206  t->num.unit_type[1] = B_UNIT_ROTATION;
207 
208  t->flag |= T_NO_CONSTRAINT;
209 }
210 
typedef float(TangentPoint)[2]
@ B_UNIT_ROTATION
Definition: BKE_unit.h:105
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
Definition: math_matrix.c:259
void copy_m3_m3(float m1[3][3], const float m2[3][3])
Definition: math_matrix.c:71
void copy_m4_m3(float m1[4][4], const float m2[3][3])
Definition: math_matrix.c:102
void transform_pivot_set_m4(float mat[4][4], const float pivot[3])
Definition: math_matrix.c:2369
#define DEG2RAD(_deg)
void axis_angle_normalized_to_mat3(float R[3][3], const float axis[3], float angle)
#define RAD2DEGF(_rad)
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f)
MINLINE float normalize_v3(float r[3])
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)
size_t BLI_snprintf_rlen(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
void BLI_task_parallel_range(int start, int stop, void *userdata, TaskParallelRangeFunc func, const TaskParallelSettings *settings)
Definition: task_range.cc:94
BLI_INLINE void BLI_parallel_range_settings_defaults(TaskParallelSettings *settings)
Definition: BLI_task.h:293
#define UNPACK2(a)
#define UNUSED(x)
#define UNPACK3(a)
#define TIP_(msgid)
#define USER_UNIT_ROT_RADIANS
void outputNumInput(NumInput *n, char *str, struct UnitSettings *unit_settings)
Definition: numinput.c:87
#define NUM_STR_REP_LEN
Definition: ED_numinput.h:13
bool applyNumInput(NumInput *n, float *vec)
Definition: numinput.c:189
bool hasNumInput(const NumInput *n)
Definition: numinput.c:170
void ED_area_status_text(ScrArea *area, const char *str)
Definition: area.c:792
@ TFM_TRACKBALL
Definition: ED_transform.h:39
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
#define UI_MAX_DRAW_STR
Definition: UI_interface.h:91
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition: btVector3.h:356
#define str(s)
static unsigned c
Definition: RandGen.cpp:83
void initMouseInputMode(TransInfo *t, MouseInput *mi, MouseInputMode mode)
#define FOREACH_TRANS_DATA_CONTAINER(t, th)
const TransDataContainer * tc
void recalcData(TransInfo *t)
conversion and adaptation of different datablocks to a common struct.
@ TD_SKIP
#define TRANSDATA_THREAD_LIMIT
void ElementRotation(const TransInfo *t, const TransDataContainer *tc, TransData *td, const float mat[3][3], const short around)
transform modes used by different operators.
static void applyTrackballValue(TransInfo *t, const float axis[3], const float angle)
static void applyTrackballMatrix(TransInfo *t, float mat_xform[4][4])
static void transdata_elem_trackball(const TransInfo *t, const TransDataContainer *tc, TransData *td, const float axis[3], const float angle, const float mat_final[3][3])
static void applyTrackballValue_calc_axis_angle(const TransInfo *t, const float phi[2], float r_axis[3], float *r_angle)
static void applyTrackball(TransInfo *t, const int UNUSED(mval[2]))
void initTrackball(TransInfo *t)
static void transdata_elem_trackball_fn(void *__restrict iter_data_v, const int iter, const TaskParallelTLS *__restrict UNUSED(tls))
bool transform_snap_increment(const TransInfo *t, float *r_val)