Blender V4.5
transform_convert_cursor.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
10
11#include "DNA_space_types.h"
12
13#include "MEM_guardedalloc.h"
14
15#include "BLI_math_matrix.h"
16#include "BLI_math_rotation.h"
17#include "BLI_math_vector.h"
18
19#include "BKE_library.hh"
20#include "BKE_report.hh"
21
22#include "transform.hh"
23#include "transform_convert.hh"
24
25namespace blender::ed::transform {
26
27/* -------------------------------------------------------------------- */
30
31static void createTransCursor_2D_impl(TransInfo *t, float cursor_location[2])
32{
33 TransData *td;
34 TransData2D *td2d;
35 {
38 tc->data_len = 1;
39 td = tc->data = MEM_callocN<TransData>("TransTexspace");
40 td2d = tc->data_2d = MEM_calloc_arrayN<TransData2D>(tc->data_len, "TransObData2D(Cursor)");
41 td->ext = tc->data_ext = MEM_callocN<TransDataExtension>("TransCursorExt");
42 }
43
44 td->flag = TD_SELECTED;
45
46 td2d->loc2d = cursor_location;
47
48 /* UV coords are scaled by aspects (see #UVsToTransData). This also applies for the Cursor in the
49 * UV Editor which also means that for display and when the cursor coords are flushed
50 * (recalcData_cursor_image), these are converted each time. */
51 td2d->loc[0] = cursor_location[0] * t->aspect[0];
52 td2d->loc[1] = cursor_location[1] * t->aspect[1];
53 td2d->loc[2] = 0.0f;
54
55 copy_v3_v3(td->center, td2d->loc);
56
57 unit_m3(td->mtx);
58 unit_m3(td->axismtx);
60
61 td->loc = td2d->loc;
62 copy_v3_v3(td->iloc, td2d->loc);
63}
64
66{
68 TransData *td = tc->data;
69 TransData2D *td2d = tc->data_2d;
70 float aspect_inv[2];
71
72 aspect_inv[0] = 1.0f / t->aspect[0];
73 aspect_inv[1] = 1.0f / t->aspect[1];
74
75 td2d->loc2d[0] = td->loc[0] * aspect_inv[0];
76 td2d->loc2d[1] = td->loc[1] * aspect_inv[1];
77
79}
80
82
83/* -------------------------------------------------------------------- */
86
88{
89 SpaceImage *sima = static_cast<SpaceImage *>(t->area->spacedata.first);
91}
92
97
99
100/* -------------------------------------------------------------------- */
103
105{
106 SpaceSeq *sseq = static_cast<SpaceSeq *>(t->area->spacedata.first);
107 if (sseq->mainb != SEQ_DRAW_IMG_IMBUF) {
108 return;
109 }
111}
112
117
119
120/* -------------------------------------------------------------------- */
123
125{
126 TransData *td;
127
128 Scene *scene = t->scene;
129 if (!ID_IS_EDITABLE(scene)) {
130 BKE_report(t->reports, RPT_ERROR, "Linked data can't text-space transform");
131 return;
132 }
133
134 View3DCursor *cursor = &scene->cursor;
135 {
138 tc->data_len = 1;
139 td = tc->data = MEM_callocN<TransData>("TransTexspace");
140 td->ext = tc->data_ext = MEM_callocN<TransDataExtension>("TransTexspace");
141 }
142
143 td->flag = TD_SELECTED;
144 copy_v3_v3(td->center, cursor->location);
145
146 unit_m3(td->mtx);
147 copy_m3_m3(td->axismtx, cursor->matrix<float3x3>().ptr());
150
151 td->loc = cursor->location;
152 copy_v3_v3(td->iloc, cursor->location);
153
154 if (cursor->rotation_mode > 0) {
155 td->ext->rot = cursor->rotation_euler;
156 td->ext->rotAxis = nullptr;
157 td->ext->rotAngle = nullptr;
158 td->ext->quat = nullptr;
159
160 copy_v3_v3(td->ext->irot, cursor->rotation_euler);
161 }
162 else if (cursor->rotation_mode == ROT_MODE_AXISANGLE) {
163 td->ext->rot = nullptr;
164 td->ext->rotAxis = cursor->rotation_axis;
165 td->ext->rotAngle = &cursor->rotation_angle;
166 td->ext->quat = nullptr;
167
168 td->ext->irotAngle = cursor->rotation_angle;
169 copy_v3_v3(td->ext->irotAxis, cursor->rotation_axis);
170 }
171 else {
172 td->ext->rot = nullptr;
173 td->ext->rotAxis = nullptr;
174 td->ext->rotAngle = nullptr;
175 td->ext->quat = cursor->rotation_quaternion;
176
178 }
179 td->ext->rotOrder = cursor->rotation_mode;
180}
181
186
188
190 /*flags*/ T_2D_EDIT,
191 /*create_trans_data*/ createTransCursor_image,
192 /*recalc_data*/ recalcData_cursor_image,
193 /*special_aftertrans_update*/ nullptr,
194};
195
197 /*flags*/ T_2D_EDIT,
198 /*create_trans_data*/ createTransCursor_sequencer,
199 /*recalc_data*/ recalcData_cursor_sequencer,
200 /*special_aftertrans_update*/ nullptr,
201};
202
204 /*flags*/ 0,
205 /*create_trans_data*/ createTransCursor_view3d,
206 /*recalc_data*/ recalcData_cursor_view3d,
207 /*special_aftertrans_update*/ nullptr,
208};
209
210} // namespace blender::ed::transform
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:126
#define BLI_assert(a)
Definition BLI_assert.h:46
void pseudoinverse_m3_m3(float inverse[3][3], const float mat[3][3], float epsilon)
void copy_m3_m3(float m1[3][3], const float m2[3][3])
void unit_m3(float m[3][3])
#define PSEUDOINVERSE_EPSILON
void normalize_m3(float R[3][3]) ATTR_NONNULL()
void copy_qt_qt(float q[4], const float a[4])
MINLINE void copy_v3_v3(float r[3], const float a[3])
void DEG_id_tag_update(ID *id, unsigned int flags)
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1026
@ ROT_MODE_AXISANGLE
@ SEQ_DRAW_IMG_IMBUF
Read Guarded memory(de)allocation.
#define ID_IS_EDITABLE(_id)
void * MEM_calloc_arrayN(size_t len, size_t size, const char *str)
Definition mallocn.cc:123
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
static void createTransCursor_image(bContext *, TransInfo *t)
static void createTransCursor_sequencer(bContext *, TransInfo *t)
static void recalcData_cursor_view3d(TransInfo *t)
TransConvertTypeInfo TransConvertType_CursorImage
static void recalcData_cursor_2D_impl(TransInfo *t)
static void recalcData_cursor_image(TransInfo *t)
static void createTransCursor_view3d(bContext *, TransInfo *t)
static void recalcData_cursor_sequencer(TransInfo *t)
TransConvertTypeInfo TransConvertType_CursorSequencer
static void createTransCursor_2D_impl(TransInfo *t, float cursor_location[2])
TransConvertTypeInfo TransConvertType_Cursor3D
MatBase< float, 3, 3 > float3x3
void * first
View3DCursor cursor
ListBase spacedata
float cursor[2]
float cursor[2]
float rotation_axis[3]
float rotation_quaternion[4]
float rotation_euler[3]
TransDataContainer * data_container
Definition transform.hh:797
conversion and adaptation of different datablocks to a common struct.