Blender V4.3
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
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_report.hh"
20#include "BKE_scene.hh"
21
22#include "transform.hh"
23#include "transform_convert.hh"
24
25/* -------------------------------------------------------------------- */
29static void createTransCursor_2D_impl(TransInfo *t, float cursor_location[2])
30{
31 TransData *td;
32 TransData2D *td2d;
33 {
36 tc->data_len = 1;
37 td = tc->data = static_cast<TransData *>(MEM_callocN(sizeof(TransData), "TransTexspace"));
38 td2d = tc->data_2d = static_cast<TransData2D *>(
39 MEM_callocN(tc->data_len * sizeof(TransData2D), "TransObData2D(Cursor)"));
40 td->ext = tc->data_ext = static_cast<TransDataExtension *>(
41 MEM_callocN(sizeof(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 td->ob = nullptr;
58
59 unit_m3(td->mtx);
60 unit_m3(td->axismtx);
62
63 td->loc = td2d->loc;
64 copy_v3_v3(td->iloc, td2d->loc);
65}
66
68{
70 TransData *td = tc->data;
71 TransData2D *td2d = tc->data_2d;
72 float aspect_inv[2];
73
74 aspect_inv[0] = 1.0f / t->aspect[0];
75 aspect_inv[1] = 1.0f / t->aspect[1];
76
77 td2d->loc2d[0] = td->loc[0] * aspect_inv[0];
78 td2d->loc2d[1] = td->loc[1] * aspect_inv[1];
79
81}
82
85/* -------------------------------------------------------------------- */
90{
91 SpaceImage *sima = static_cast<SpaceImage *>(t->area->spacedata.first);
93}
94
99
102/* -------------------------------------------------------------------- */
107{
108 SpaceSeq *sseq = static_cast<SpaceSeq *>(t->area->spacedata.first);
109 if (sseq->mainb != SEQ_DRAW_IMG_IMBUF) {
110 return;
111 }
113}
114
119
122/* -------------------------------------------------------------------- */
127{
128 TransData *td;
129
130 Scene *scene = t->scene;
131 if (!ID_IS_EDITABLE(scene)) {
132 BKE_report(t->reports, RPT_ERROR, "Linked data can't text-space transform");
133 return;
134 }
135
136 View3DCursor *cursor = &scene->cursor;
137 {
140 tc->data_len = 1;
141 td = tc->data = static_cast<TransData *>(MEM_callocN(sizeof(TransData), "TransTexspace"));
142 td->ext = tc->data_ext = static_cast<TransDataExtension *>(
143 MEM_callocN(sizeof(TransDataExtension), "TransTexspace"));
144 }
145
146 td->flag = TD_SELECTED;
147 copy_v3_v3(td->center, cursor->location);
148 td->ob = nullptr;
149
150 unit_m3(td->mtx);
151 copy_m3_m3(td->axismtx, cursor->matrix<blender::float3x3>().ptr());
154
155 td->loc = cursor->location;
156 copy_v3_v3(td->iloc, cursor->location);
157
158 if (cursor->rotation_mode > 0) {
159 td->ext->rot = cursor->rotation_euler;
160 td->ext->rotAxis = nullptr;
161 td->ext->rotAngle = nullptr;
162 td->ext->quat = nullptr;
163
164 copy_v3_v3(td->ext->irot, cursor->rotation_euler);
165 }
166 else if (cursor->rotation_mode == ROT_MODE_AXISANGLE) {
167 td->ext->rot = nullptr;
168 td->ext->rotAxis = cursor->rotation_axis;
169 td->ext->rotAngle = &cursor->rotation_angle;
170 td->ext->quat = nullptr;
171
172 td->ext->irotAngle = cursor->rotation_angle;
173 copy_v3_v3(td->ext->irotAxis, cursor->rotation_axis);
174 }
175 else {
176 td->ext->rot = nullptr;
177 td->ext->rotAxis = nullptr;
178 td->ext->rotAngle = nullptr;
179 td->ext->quat = cursor->rotation_quaternion;
180
181 copy_qt_qt(td->ext->iquat, cursor->rotation_quaternion);
182 }
183 td->ext->rotOrder = cursor->rotation_mode;
184}
185
190
194 /*flags*/ T_2D_EDIT,
195 /*create_trans_data*/ createTransCursor_image,
196 /*recalc_data*/ recalcData_cursor_image,
197 /*special_aftertrans_update*/ nullptr,
198};
199
201 /*flags*/ T_2D_EDIT,
202 /*create_trans_data*/ createTransCursor_sequencer,
203 /*recalc_data*/ recalcData_cursor_sequencer,
204 /*special_aftertrans_update*/ nullptr,
205};
206
208 /*flags*/ 0,
209 /*create_trans_data*/ createTransCursor_view3d,
210 /*recalc_data*/ recalcData_cursor_view3d,
211 /*special_aftertrans_update*/ nullptr,
212};
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:125
#define BLI_assert(a)
Definition BLI_assert.h:50
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:1085
#define ID_IS_EDITABLE(_id)
Definition DNA_ID.h:658
@ ROT_MODE_AXISANGLE
@ SEQ_DRAW_IMG_IMBUF
Read Guarded memory(de)allocation.
void *(* MEM_callocN)(size_t len, const char *str)
Definition mallocn.cc:42
void * first
ListBase spacedata
float cursor[2]
TransData * data
Definition transform.hh:445
TransDataExtension * data_ext
Definition transform.hh:447
TransData2D * data_2d
Definition transform.hh:449
float smtx[3][3]
float axismtx[3][3]
float mtx[3][3]
TransDataExtension * ext
ReportList * reports
Definition transform.hh:661
float aspect[3]
Definition transform.hh:553
Scene * scene
Definition transform.hh:654
int data_container_len
Definition transform.hh:506
TransDataContainer * data_container
Definition transform.hh:505
ScrArea * area
Definition transform.hh:651
const c_style_mat & ptr() const
@ T_2D_EDIT
Definition transform.hh:104
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])
TransConvertTypeInfo TransConvertType_Cursor3D
static void createTransCursor_view3d(bContext *, TransInfo *t)
static void recalcData_cursor_2D_impl(TransInfo *t)
static void createTransCursor_sequencer(bContext *, TransInfo *t)
TransConvertTypeInfo TransConvertType_CursorSequencer
static void recalcData_cursor_view3d(TransInfo *t)
static void recalcData_cursor_image(TransInfo *t)
static void createTransCursor_image(bContext *, TransInfo *t)
@ TD_SELECTED