Blender  V3.3
transform_convert_cursor.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 
10 #include "DNA_space_types.h"
11 
12 #include "MEM_guardedalloc.h"
13 
14 #include "BLI_math.h"
15 
16 #include "BKE_context.h"
17 #include "BKE_report.h"
18 #include "BKE_scene.h"
19 
20 #include "transform.h"
21 #include "transform_convert.h"
22 
23 /* -------------------------------------------------------------------- */
27 static void createTransCursor_2D_impl(TransInfo *t, float cursor_location[2])
28 {
29  TransData *td;
30  TransData2D *td2d;
31  {
32  BLI_assert(t->data_container_len == 1);
33  TransDataContainer *tc = t->data_container;
34  tc->data_len = 1;
35  td = tc->data = MEM_callocN(sizeof(TransData), "TransTexspace");
36  td2d = tc->data_2d = MEM_callocN(tc->data_len * sizeof(TransData2D), "TransObData2D(Cursor)");
37  td->ext = tc->data_ext = MEM_callocN(sizeof(TransDataExtension), "TransCursorExt");
38  }
39 
40  td->flag = TD_SELECTED;
41 
42  td2d->loc2d = cursor_location;
43 
44  /* UV coords are scaled by aspects (see #UVsToTransData). This also applies for the Cursor in the
45  * UV Editor which also means that for display and when the cursor coords are flushed
46  * (recalcData_cursor_image), these are converted each time. */
47  td2d->loc[0] = cursor_location[0] * t->aspect[0];
48  td2d->loc[1] = cursor_location[1] * t->aspect[1];
49  td2d->loc[2] = 0.0f;
50 
51  copy_v3_v3(td->center, td2d->loc);
52 
53  td->ob = NULL;
54 
55  unit_m3(td->mtx);
56  unit_m3(td->axismtx);
58 
59  td->loc = td2d->loc;
60  copy_v3_v3(td->iloc, td2d->loc);
61 }
62 
64 {
65  TransDataContainer *tc = t->data_container;
66  TransData *td = tc->data;
67  TransData2D *td2d = tc->data_2d;
68  float aspect_inv[2];
69 
70  aspect_inv[0] = 1.0f / t->aspect[0];
71  aspect_inv[1] = 1.0f / t->aspect[1];
72 
73  td2d->loc2d[0] = td->loc[0] * aspect_inv[0];
74  td2d->loc2d[1] = td->loc[1] * aspect_inv[1];
75 
77 }
78 
81 /* -------------------------------------------------------------------- */
86 {
87  SpaceImage *sima = t->area->spacedata.first;
89 }
90 
92 {
94 }
95 
98 /* -------------------------------------------------------------------- */
103 {
104  SpaceSeq *sseq = t->area->spacedata.first;
105  if (sseq->mainb != SEQ_DRAW_IMG_IMBUF) {
106  return;
107  }
109 }
110 
112 {
114 }
115 
118 /* -------------------------------------------------------------------- */
123 {
124  TransData *td;
125 
126  Scene *scene = t->scene;
127  if (ID_IS_LINKED(scene)) {
128  BKE_report(t->reports, RPT_ERROR, "Linked data can't text-space transform");
129  return;
130  }
131 
132  View3DCursor *cursor = &scene->cursor;
133  {
134  BLI_assert(t->data_container_len == 1);
135  TransDataContainer *tc = t->data_container;
136  tc->data_len = 1;
137  td = tc->data = MEM_callocN(sizeof(TransData), "TransTexspace");
138  td->ext = tc->data_ext = MEM_callocN(sizeof(TransDataExtension), "TransTexspace");
139  }
140 
141  td->flag = TD_SELECTED;
142  copy_v3_v3(td->center, cursor->location);
143  td->ob = NULL;
144 
145  unit_m3(td->mtx);
147  normalize_m3(td->axismtx);
149 
150  td->loc = cursor->location;
151  copy_v3_v3(td->iloc, cursor->location);
152 
153  if (cursor->rotation_mode > 0) {
154  td->ext->rot = cursor->rotation_euler;
155  td->ext->rotAxis = NULL;
156  td->ext->rotAngle = NULL;
157  td->ext->quat = NULL;
158 
159  copy_v3_v3(td->ext->irot, cursor->rotation_euler);
160  }
161  else if (cursor->rotation_mode == ROT_MODE_AXISANGLE) {
162  td->ext->rot = NULL;
163  td->ext->rotAxis = cursor->rotation_axis;
164  td->ext->rotAngle = &cursor->rotation_angle;
165  td->ext->quat = NULL;
166 
167  td->ext->irotAngle = cursor->rotation_angle;
168  copy_v3_v3(td->ext->irotAxis, cursor->rotation_axis);
169  }
170  else {
171  td->ext->rot = NULL;
172  td->ext->rotAxis = NULL;
173  td->ext->rotAngle = NULL;
174  td->ext->quat = cursor->rotation_quaternion;
175 
176  copy_qt_qt(td->ext->iquat, cursor->rotation_quaternion);
177  }
178  td->ext->rotOrder = cursor->rotation_mode;
179 }
180 
182 {
184 }
185 
189  /* flags */ T_2D_EDIT,
190  /* createTransData */ createTransCursor_image,
191  /* recalcData */ recalcData_cursor_image,
192  /* special_aftertrans_update */ NULL,
193 };
194 
196  /* flags */ T_2D_EDIT,
197  /* createTransData */ createTransCursor_sequencer,
198  /* recalcData */ recalcData_cursor_sequencer,
199  /* special_aftertrans_update */ NULL,
200 };
201 
203  /* flags */ 0,
204  /* createTransData */ createTransCursor_view3d,
205  /* recalcData */ recalcData_cursor_view3d,
206  /* special_aftertrans_update */ NULL,
207 };
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition: report.c:83
void BKE_scene_cursor_rot_to_mat3(const struct View3DCursor *cursor, float mat[3][3])
#define BLI_assert(a)
Definition: BLI_assert.h:46
void unit_m3(float m[3][3])
Definition: math_matrix.c:40
#define PSEUDOINVERSE_EPSILON
void normalize_m3(float R[3][3]) ATTR_NONNULL()
Definition: math_matrix.c:1912
void pseudoinverse_m3_m3(float Ainv[3][3], const float A[3][3], float epsilon)
Definition: math_matrix.c:3107
void copy_qt_qt(float q[4], const float a[4])
Definition: math_rotation.c:33
MINLINE void copy_v3_v3(float r[3], const float a[3])
#define UNUSED(x)
void DEG_id_tag_update(struct ID *id, int flag)
@ ID_RECALC_COPY_ON_WRITE
Definition: DNA_ID.h:834
#define ID_IS_LINKED(_id)
Definition: DNA_ID.h:566
@ ROT_MODE_AXISANGLE
@ SEQ_DRAW_IMG_IMBUF
_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.
#define C
Definition: RandGen.cpp:25
Scene scene
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:31
View3DCursor cursor
float cursor[2]
float cursor[2]
float * loc2d
float loc[3]
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.
TransConvertTypeInfo TransConvertType_CursorImage
static void recalcData_cursor_sequencer(TransInfo *t)
static void createTransCursor_2D_impl(TransInfo *t, float cursor_location[2])
static void createTransCursor_image(bContext *UNUSED(C), TransInfo *t)
static void createTransCursor_view3d(bContext *UNUSED(C), TransInfo *t)
TransConvertTypeInfo TransConvertType_Cursor3D
static void createTransCursor_sequencer(bContext *UNUSED(C), TransInfo *t)
static void recalcData_cursor_2D_impl(TransInfo *t)
TransConvertTypeInfo TransConvertType_CursorSequencer
static void recalcData_cursor_view3d(TransInfo *t)
static void recalcData_cursor_image(TransInfo *t)
@ TD_SELECTED