Blender V5.0
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_screen_types.h"
12#include "DNA_space_types.h"
13
14#include "MEM_guardedalloc.h"
15
16#include "BLI_math_matrix.h"
17#include "BLI_math_rotation.h"
18#include "BLI_math_vector.h"
19
20#include "BKE_library.hh"
21#include "BKE_report.hh"
22
23#include "transform.hh"
24#include "transform_convert.hh"
25
26namespace blender::ed::transform {
27
28/* -------------------------------------------------------------------- */
31
32static void createTransCursor_2D_impl(TransInfo *t, float cursor_location[2])
33{
34 TransData *td;
35 TransData2D *td2d;
36 {
39 tc->data_len = 1;
40 td = tc->data = MEM_callocN<TransData>("TransTexspace");
41 td2d = tc->data_2d = MEM_calloc_arrayN<TransData2D>(tc->data_len, "TransObData2D(Cursor)");
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 TransDataExtension *td_ext;
128
129 Scene *scene = t->scene;
130 if (!ID_IS_EDITABLE(scene)) {
131 BKE_report(t->reports, RPT_ERROR, "Cannot create transform on linked data");
132 return;
133 }
134
135 View3DCursor *cursor = &scene->cursor;
136 {
139 tc->data_len = 1;
140 td = tc->data = MEM_callocN<TransData>("TransTexspace");
141 td_ext = tc->data_ext = MEM_callocN<TransDataExtension>("TransTexspace");
142 }
143
144 td->flag = TD_SELECTED;
145 copy_v3_v3(td->center, cursor->location);
146
147 unit_m3(td->mtx);
148 copy_m3_m3(td->axismtx, cursor->matrix<float3x3>().ptr());
151
152 td->loc = cursor->location;
153 copy_v3_v3(td->iloc, cursor->location);
154
155 if (cursor->rotation_mode > 0) {
156 td_ext->rot = cursor->rotation_euler;
157 td_ext->rotAxis = nullptr;
158 td_ext->rotAngle = nullptr;
159 td_ext->quat = nullptr;
160
161 copy_v3_v3(td_ext->irot, cursor->rotation_euler);
162 }
163 else if (cursor->rotation_mode == ROT_MODE_AXISANGLE) {
164 td_ext->rot = nullptr;
165 td_ext->rotAxis = cursor->rotation_axis;
166 td_ext->rotAngle = &cursor->rotation_angle;
167 td_ext->quat = nullptr;
168
169 td_ext->irotAngle = cursor->rotation_angle;
170 copy_v3_v3(td_ext->irotAxis, cursor->rotation_axis);
171 }
172 else {
173 td_ext->rot = nullptr;
174 td_ext->rotAxis = nullptr;
175 td_ext->rotAngle = nullptr;
176 td_ext->quat = cursor->rotation_quaternion;
177
178 copy_qt_qt(td_ext->iquat, cursor->rotation_quaternion);
179 }
180 td_ext->rotOrder = cursor->rotation_mode;
181}
182
187
189
191 /*flags*/ T_2D_EDIT,
192 /*create_trans_data*/ createTransCursor_image,
193 /*recalc_data*/ recalcData_cursor_image,
194 /*special_aftertrans_update*/ nullptr,
195};
196
198 /*flags*/ T_2D_EDIT,
199 /*create_trans_data*/ createTransCursor_sequencer,
200 /*recalc_data*/ recalcData_cursor_sequencer,
201 /*special_aftertrans_update*/ nullptr,
202};
203
205 /*flags*/ 0,
206 /*create_trans_data*/ createTransCursor_view3d,
207 /*recalc_data*/ recalcData_cursor_view3d,
208 /*special_aftertrans_update*/ nullptr,
209};
210
211} // namespace blender::ed::transform
@ RPT_ERROR
Definition BKE_report.hh:39
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:153
#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:1118
#define ID_IS_EDITABLE(_id)
Definition DNA_ID.h:705
@ ROT_MODE_AXISANGLE
@ SEQ_DRAW_IMG_IMBUF
Read Guarded memory(de)allocation.
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:802
conversion and adaptation of different datablocks to a common struct.