Blender  V2.93
transform_convert_cursor.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 "DNA_space_types.h"
25 
26 #include "MEM_guardedalloc.h"
27 
28 #include "BLI_math.h"
29 
30 #include "BKE_context.h"
31 #include "BKE_report.h"
32 #include "BKE_scene.h"
33 
34 #include "transform.h"
35 #include "transform_convert.h"
36 
37 /* -------------------------------------------------------------------- */
45 {
46  TransData *td;
47  SpaceImage *sima = t->area->spacedata.first;
48  float *cursor_location = sima->cursor;
49 
50  {
51  BLI_assert(t->data_container_len == 1);
52  TransDataContainer *tc = t->data_container;
53  tc->data_len = 1;
54  td = tc->data = MEM_callocN(sizeof(TransData), "TransTexspace");
55  td->ext = tc->data_ext = MEM_callocN(sizeof(TransDataExtension), "TransTexspace");
56  }
57 
58  td->flag = TD_SELECTED;
59 
60  /* UV coords are scaled by aspects (see UVsToTransData). This also applies for the Cursor in the
61  * UV Editor which also means that for display and when the cursor coords are flushed
62  * (recalcData_cursor_image), these are converted each time. */
63  cursor_location[0] = cursor_location[0] * t->aspect[0];
64  cursor_location[1] = cursor_location[1] * t->aspect[1];
65 
66  copy_v3_v3(td->center, cursor_location);
67  td->ob = NULL;
68 
69  unit_m3(td->mtx);
70  unit_m3(td->axismtx);
72 
73  td->loc = cursor_location;
74  copy_v3_v3(td->iloc, cursor_location);
75 }
76 
78 {
79  TransData *td;
80 
81  Scene *scene = t->scene;
82  if (ID_IS_LINKED(scene)) {
83  BKE_report(t->reports, RPT_ERROR, "Linked data can't text-space transform");
84  return;
85  }
86 
87  View3DCursor *cursor = &scene->cursor;
88  {
89  BLI_assert(t->data_container_len == 1);
90  TransDataContainer *tc = t->data_container;
91  tc->data_len = 1;
92  td = tc->data = MEM_callocN(sizeof(TransData), "TransTexspace");
93  td->ext = tc->data_ext = MEM_callocN(sizeof(TransDataExtension), "TransTexspace");
94  }
95 
96  td->flag = TD_SELECTED;
97  copy_v3_v3(td->center, cursor->location);
98  td->ob = NULL;
99 
100  unit_m3(td->mtx);
102  normalize_m3(td->axismtx);
104 
105  td->loc = cursor->location;
106  copy_v3_v3(td->iloc, cursor->location);
107 
108  if (cursor->rotation_mode > 0) {
109  td->ext->rot = cursor->rotation_euler;
110  td->ext->rotAxis = NULL;
111  td->ext->rotAngle = NULL;
112  td->ext->quat = NULL;
113 
114  copy_v3_v3(td->ext->irot, cursor->rotation_euler);
115  }
116  else if (cursor->rotation_mode == ROT_MODE_AXISANGLE) {
117  td->ext->rot = NULL;
118  td->ext->rotAxis = cursor->rotation_axis;
119  td->ext->rotAngle = &cursor->rotation_angle;
120  td->ext->quat = NULL;
121 
122  td->ext->irotAngle = cursor->rotation_angle;
123  copy_v3_v3(td->ext->irotAxis, cursor->rotation_axis);
124  }
125  else {
126  td->ext->rot = NULL;
127  td->ext->rotAxis = NULL;
128  td->ext->rotAngle = NULL;
129  td->ext->quat = cursor->rotation_quaternion;
130 
131  copy_qt_qt(td->ext->iquat, cursor->rotation_quaternion);
132  }
133  td->ext->rotOrder = cursor->rotation_mode;
134 }
135 
void BKE_report(ReportList *reports, ReportType type, const char *message)
Definition: report.c:104
void BKE_scene_cursor_rot_to_mat3(const struct View3DCursor *cursor, float mat[3][3])
#define BLI_assert(a)
Definition: BLI_assert.h:58
void unit_m3(float m[3][3])
Definition: math_matrix.c:58
#define PSEUDOINVERSE_EPSILON
void normalize_m3(float R[3][3]) ATTR_NONNULL()
Definition: math_matrix.c:1919
void pseudoinverse_m3_m3(float Ainv[3][3], const float A[3][3], float epsilon)
Definition: math_matrix.c:3228
void copy_qt_qt(float q[4], const float a[4])
Definition: math_rotation.c:52
MINLINE void copy_v3_v3(float r[3], const float a[3])
#define ID_IS_LINKED(_id)
Definition: DNA_ID.h:426
@ ROT_MODE_AXISANGLE
_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
Read Guarded memory(de)allocation.
Scene scene
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
View3DCursor cursor
float cursor[2]
TransData * data
Definition: transform.h:448
TransDataExtension * data_ext
Definition: transform.h:450
float smtx[3][3]
float axismtx[3][3]
float mtx[3][3]
TransDataExtension * ext
struct Object * ob
float rotation_axis[3]
float rotation_quaternion[4]
float rotation_euler[3]
conversion and adaptation of different datablocks to a common struct.
void createTransCursor_image(TransInfo *t)
void createTransCursor_view3d(TransInfo *t)
@ TD_SELECTED