Blender  V2.93
transform_mode_trackball.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19 
24 #include <stdlib.h>
25 
26 #include "BLI_math.h"
27 #include "BLI_string.h"
28 
29 #include "BKE_context.h"
30 #include "BKE_unit.h"
31 
32 #include "ED_screen.h"
33 
34 #include "UI_interface.h"
35 
36 #include "BLT_translation.h"
37 
38 #include "transform.h"
39 #include "transform_mode.h"
40 #include "transform_snap.h"
41 
42 /* -------------------------------------------------------------------- */
47  const float axis1[3],
48  const float axis2[3],
49  const float angles[2])
50 {
51  float mat[3][3];
52  float axis[3];
53  float angle;
54  int i;
55 
56  mul_v3_v3fl(axis, axis1, angles[0]);
57  madd_v3_v3fl(axis, axis2, angles[1]);
58  angle = normalize_v3(axis);
60 
62  TransData *td = tc->data;
63  for (i = 0; i < tc->data_len; i++, td++) {
64  if (td->flag & TD_SKIP) {
65  continue;
66  }
67 
68  if (t->flag & T_PROP_EDIT) {
69  axis_angle_normalized_to_mat3(mat, axis, td->factor * angle);
70  }
71 
72  ElementRotation(t, tc, td, mat, t->around);
73  }
74  }
75 }
76 
77 static void applyTrackball(TransInfo *t, const int UNUSED(mval[2]))
78 {
79  char str[UI_MAX_DRAW_STR];
80  size_t ofs = 0;
81  float axis1[3], axis2[3];
82 #if 0 /* UNUSED */
83  float mat[3][3], totmat[3][3], smat[3][3];
84 #endif
85  float phi[2];
86 
87  copy_v3_v3(axis1, t->persinv[0]);
88  copy_v3_v3(axis2, t->persinv[1]);
89  normalize_v3(axis1);
90  normalize_v3(axis2);
91 
92  copy_v2_v2(phi, t->values);
93 
95 
96  applyNumInput(&t->num, phi);
97 
98  copy_v2_v2(t->values_final, phi);
99 
100  if (hasNumInput(&t->num)) {
101  char c[NUM_STR_REP_LEN * 2];
102 
103  outputNumInput(&(t->num), c, &t->scene->unit);
104 
105  ofs += BLI_snprintf(str + ofs,
106  sizeof(str) - ofs,
107  TIP_("Trackball: %s %s %s"),
108  &c[0],
109  &c[NUM_STR_REP_LEN],
110  t->proptext);
111  }
112  else {
113  ofs += BLI_snprintf(str + ofs,
114  sizeof(str) - ofs,
115  TIP_("Trackball: %.2f %.2f %s"),
116  RAD2DEGF(phi[0]),
117  RAD2DEGF(phi[1]),
118  t->proptext);
119  }
120 
121  if (t->flag & T_PROP_EDIT_ALL) {
122  ofs += BLI_snprintf(
123  str + ofs, sizeof(str) - ofs, TIP_(" Proportional size: %.2f"), t->prop_size);
124  }
125 
126 #if 0 /* UNUSED */
127  axis_angle_normalized_to_mat3(smat, axis1, phi[0]);
128  axis_angle_normalized_to_mat3(totmat, axis2, phi[1]);
129 
130  mul_m3_m3m3(mat, smat, totmat);
131 
132  /* TRANSFORM_FIX_ME */
133  // copy_m3_m3(t->mat, mat); /* used in gizmo. */
134 #endif
135 
136  applyTrackballValue(t, axis1, axis2, phi);
137 
138  recalcData(t);
139 
140  ED_area_status_text(t->area, str);
141 }
142 
144 {
145  t->mode = TFM_TRACKBALL;
146  t->transform = applyTrackball;
147 
149 
150  t->idx_max = 1;
151  t->num.idx_max = 1;
152  t->snap[0] = DEG2RAD(5.0);
153  t->snap[1] = DEG2RAD(1.0);
154 
155  copy_v3_fl(t->num.val_inc, t->snap[1]);
156  t->num.unit_sys = t->scene->unit.system;
157  t->num.unit_use_radians = (t->scene->unit.system_rotation == USER_UNIT_ROT_RADIANS);
158  t->num.unit_type[0] = B_UNIT_ROTATION;
159  t->num.unit_type[1] = B_UNIT_ROTATION;
160 
161  t->flag |= T_NO_CONSTRAINT;
162 }
@ B_UNIT_ROTATION
Definition: BKE_unit.h:83
void mul_m3_m3m3(float R[3][3], const float A[3][3], const float B[3][3])
Definition: math_matrix.c:391
#define DEG2RAD(_deg)
void axis_angle_normalized_to_mat3(float R[3][3], const float axis[3], const 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 void copy_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(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
#define UNUSED(x)
#define TIP_(msgid)
#define USER_UNIT_ROT_RADIANS
void outputNumInput(NumInput *n, char *str, struct UnitSettings *unit_settings)
Definition: numinput.c:102
#define NUM_STR_REP_LEN
Definition: ED_numinput.h:27
bool applyNumInput(NumInput *n, float *vec)
Definition: numinput.c:207
bool hasNumInput(const NumInput *n)
Definition: numinput.c:185
void ED_area_status_text(ScrArea *area, const char *str)
Definition: area.c:815
@ TFM_TRACKBALL
Definition: ED_transform.h:55
_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:90
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:97
@ INPUT_TRACKBALL
Definition: transform.h:734
void recalcData(TransInfo *t)
@ T_PROP_EDIT_ALL
Definition: transform.h:114
@ T_PROP_EDIT
Definition: transform.h:111
@ T_NO_CONSTRAINT
Definition: transform.h:106
void initMouseInputMode(TransInfo *t, MouseInput *mi, MouseInputMode mode)
#define FOREACH_TRANS_DATA_CONTAINER(t, th)
Definition: transform.h:813
@ TD_SKIP
void ElementRotation(TransInfo *t, TransDataContainer *tc, TransData *td, float mat[3][3], const short around)
transform modes used by different operators.
static void applyTrackball(TransInfo *t, const int UNUSED(mval[2]))
void initTrackball(TransInfo *t)
static void applyTrackballValue(TransInfo *t, const float axis1[3], const float axis2[3], const float angles[2])
bool transform_snap_increment(TransInfo *t, float *r_val)