4 * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version. The Blender
10 * Foundation also sells licenses for use in proprietary software under
11 * the Blender License. See http://www.blender.org/BL/ for information
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24 * All rights reserved.
26 * The Original Code is: all of this file.
28 * Contributor(s): none yet.
30 * ***** END GPL/BL DUAL LICENSE BLOCK *****
36 #include "BIF_transform.h"
38 /* ************************** Types ***************************** */
45 typedef struct NumInput {
48 short flag; /* Different flags to indicate different behaviors */
49 float val[3]; /* Direct value of the input */
50 short ctrl[3]; /* Control to indicate what to do with the numbers that are typed */
54 The ctrl value has different meaning:
55 0 : No value has been typed
57 otherwise, |value| - 1 is where the cursor is located after the period
58 Positive : number is positive
59 Negative : number is negative
62 typedef struct TransCon {
63 char text[50]; /* Description of the Constraint for header_print */
64 float mtx[3][3]; /* Matrix of the Constraint space */
65 float imtx[3][3]; /* Inverse Matrix of the Constraint space */
66 float pmtx[3][3]; /* Projection Constraint Matrix (same as imtx with some axis == 0) */
67 float center[3]; /* transformation centre to define where to draw the view widget
68 ALWAYS in global space. Unlike the transformation center */
69 short imval[2]; /* initial mouse value for visual calculation */
70 /* the one in TransInfo is not garanty to stay the same (Rotates change it) */
71 int mode; /* Mode flags of the Constraint */
72 void (*drawExtra)(struct TransInfo *);
73 /* For constraints that needs to draw differently from the other
74 uses this instead of the generic draw function */
75 void (*applyVec)(struct TransInfo *, struct TransData *, float *, float *, float *);
76 /* Apply function pointer for linear vectorial transformation */
77 /* The last three parameters are pointers to the in/out/printable vectors */
78 void (*applySize)(struct TransInfo *, struct TransData *, float [3][3]);
79 /* Apply function pointer for rotation transformation (prototype will change */
80 void (*applyRot)(struct TransInfo *, struct TransData *, float [3]);
81 /* Apply function pointer for rotation transformation (prototype will change */
84 typedef struct TransDataIpokey {
85 int flag; /* which keys */
86 float *locx, *locy, *locz; /* channel pointers */
87 float *rotx, *roty, *rotz;
88 float *quatx, *quaty, *quatz, *quatw;
89 float *sizex, *sizey, *sizez;
90 float oldloc[9]; /* storage old values */
96 typedef struct TransDataExtension {
97 float drot[3]; /* Initial object drot */
98 float dsize[3]; /* Initial object dsize */
99 float *rot; /* Rotation of the data to transform (Faculative) */
100 float irot[3]; /* Initial rotation */
101 float *quat; /* Rotation quaternion of the data to transform (Faculative) */
102 float iquat[4]; /* Initial rotation quaternion */
103 float *size; /* Size of the data to transform (Faculative) */
104 float isize[3]; /* Initial size */
105 float obmat[3][3]; /* Object matrix */
106 } TransDataExtension;
108 typedef struct TransData2D {
109 float loc[3]; /* Location of data used to transform (x,y,0) */
110 float *loc2d; /* Pointer to real 2d location of data */
113 typedef struct TransData {
114 float dist; /* Distance needed to affect element (for Proportionnal Editing) */
115 float rdist; /* Distance to the nearest element (for Proportionnal Editing) */
116 float factor; /* Factor of the transformation (for Proportionnal Editing) */
117 float *loc; /* Location of the data to transform */
118 float iloc[3]; /* Initial location */
119 float *val; /* Value pointer for special transforms */
120 float ival; /* Old value*/
121 float center[3]; /* Individual data center */
122 float mtx[3][3]; /* Transformation matrix from data space to global space */
123 float smtx[3][3]; /* Transformation matrix from global space to data space */
124 float axismtx[3][3];/* Axis orientation matrix of the data */
126 TransDataExtension *ext; /* for objects, poses. 1 single malloc per TransInfo! */
127 TransDataIpokey *tdi; /* for objects, ipo keys. per transdata a malloc */
128 int flag; /* Various flags */
131 typedef struct TransInfo {
132 int mode; /* current mode */
133 int flag; /* generic flags for special behaviors */
134 short state; /* current state (running, canceled,...)*/
135 int context; /* current context */
136 float val; /* init value for some transformations (and rotation angle) */
137 float fac; /* factor for distance based transform */
138 int (*transform)(struct TransInfo *, short *);
139 /* transform function pointer */
140 int total; /* total number of transformed data */
141 TransData *data; /* transformed data (array) */
142 TransDataExtension *ext; /* transformed data extension (array) */
143 TransData2D *data2d; /* transformed data for 2d (array) */
144 TransCon con; /* transformed constraint */
145 NumInput num; /* numerical input */
146 char redraw; /* redraw flag */
147 float propsize; /* proportional circle radius */
148 char proptext[20]; /* proportional falloff text */
149 float center[3]; /* center of transformation */
150 int center2d[2]; /* center in screen coordinates */
151 short imval[2]; /* initial mouse position */
152 short shiftmval[2]; /* mouse position when shift was pressed */
153 short idx_max; /* maximum index on the input vector */
154 float snap[3]; /* Snapping Gears */
156 float viewmat[4][4]; /* copy from G.vd, prevents feedback, */
157 float viewinv[4][4]; /* and to make sure we don't have to */
158 float persmat[4][4]; /* access G.vd from other space types */
162 char spacetype; /* spacetype where transforming is */
164 float vec[3]; /* translation, to show for widget */
165 float mat[3][3]; /* rot/rescale, to show for widget */
167 char *undostr; /* if set, uses this string for undo */
168 float spacemtx[3][3]; /* orientation matrix of the current space */
169 char spacename[32]; /* name of the current space */
171 struct Object *poseobj; /* if t->flag & T_POSE, this denotes pose object */
175 /* ******************** Macros & Prototypes *********************** */
178 #define NUM_NULL_ONE 2
179 #define NUM_NO_NEGATIVE 4
180 #define NUM_NO_ZERO 8
181 #define NUM_NO_FRACTION 16
182 #define NUM_AFFECT_ALL 32
184 /* transinfo->state */
185 #define TRANS_RUNNING 0
186 #define TRANS_CONFIRM 1
187 #define TRANS_CANCEL 2
189 /* transinfo->flag */
195 // when shift pressed, higher resolution transform. cannot rely on G.qual, need event!
196 #define T_SHIFT_MOD 32
197 // trans on points, having no rotation/scale
199 // for manipulator exceptions, like scaling using center point, drawing help lines
200 #define T_USES_MANIPULATOR 128
202 /* restrictions flags */
203 #define T_ALL_RESTRICTIONS (256|512|1024)
204 #define T_NO_CONSTRAINT 256
205 #define T_NULL_ONE 512
206 #define T_NO_ZERO 1024
208 #define T_PROP_EDIT 2048
209 #define T_PROP_CONNECTED 4096
211 /* if MMB is pressed or not */
212 #define T_MMB_PRESSED 8192
213 #define T_V3D_ALIGN 16384
214 #define T_2D_EDIT 32768 /* for 2d views like uv or ipo */
215 #define T_CLIP_UV 65536
217 /* transinfo->con->mode */
222 #define CON_SELECT 16
223 #define CON_NOFLIP 32 /* does not reorient vector to face viewport when on */
227 /* transdata->flag */
228 #define TD_SELECTED 1
229 #define TD_NOACTION 2
231 #define TD_NOTCONNECTED 8
232 #define TD_SINGLESIZE 16 /* used for scaling of MetaElem->rad */
234 void checkFirstTime(void);
236 void setTransformViewMatrices(TransInfo *t);
237 void convertViewVec(TransInfo *t, float *vec, short dx, short dy);
238 void projectIntView(TransInfo *t, float *vec, int *adr);
239 void projectFloatView(TransInfo *t, float *vec, float *adr);
241 void convertVecToDisplayNum(float *vec, float *num);
242 void convertDisplayNumToVec(float *num, float *vec);
244 void initWarp(TransInfo *t);
245 int Warp(TransInfo *t, short mval[2]);
247 void initShear(TransInfo *t);
248 int Shear(TransInfo *t, short mval[2]);
250 void initResize(TransInfo *t);
251 int Resize(TransInfo *t, short mval[2]);
253 void initTranslation(TransInfo *t);
254 int Translation(TransInfo *t, short mval[2]);
256 void initToSphere(TransInfo *t);
257 int ToSphere(TransInfo *t, short mval[2]);
259 void initRotation(TransInfo *t);
260 int Rotation(TransInfo *t, short mval[2]);
262 void initShrinkFatten(TransInfo *t);
263 int ShrinkFatten(TransInfo *t, short mval[2]);
265 void initTilt(TransInfo *t);
266 int Tilt(TransInfo *t, short mval[2]);
268 void initTrackball(TransInfo *t);
269 int Trackball(TransInfo *t, short mval[2]);
271 void initPushPull(TransInfo *t);
272 int PushPull(TransInfo *t, short mval[2]);
274 void initCrease(TransInfo *t);
275 int Crease(TransInfo *t, short mval[2]);
277 void initBoneSize(TransInfo *t);
278 int BoneSize(TransInfo *t, short mval[2]);
280 void initBoneEnvelope(TransInfo *t);
281 int BoneEnvelope(TransInfo *t, short mval[2]);
283 /*********************** transform_conversions.c ********** */
285 void count_bone_select(TransInfo *t, struct ListBase *lb, int do_it);
286 void flushTransUVs(TransInfo *t);
287 int clipUVTransform(TransInfo *t, float *vec, int resize);
289 /*********************** exported from transform_manipulator.c ********** */
291 void draw_manipulator_ext(struct ScrArea *sa, int type, char axis, int col, float vec[3], float mat[][3]);
292 int calc_manipulator_stats(struct ScrArea *sa);
294 /*********************** TransData Creation and General Handling *********** */
295 void createTransData(TransInfo *t);
296 void sort_trans_data_dist(TransInfo *t);
297 void add_tdi_poin(float *poin, float *old, float delta);
298 void special_aftertrans_update(TransInfo *t);
300 /*********************** Constraints *****************************/
302 void getConstraintMatrix(TransInfo *t);
303 void setConstraint(TransInfo *t, float space[3][3], int mode, const char text[]);
304 void setLocalConstraint(TransInfo *t, int mode, const char text[]);
305 void setUserConstraint(TransInfo *t, int mode, const char text[]);
307 void constraintNumInput(TransInfo *t, float vec[3]);
309 void getConstraintMatrix(TransInfo *t);
310 int isLockConstraint(TransInfo *t);
311 int getConstraintSpaceDimension(TransInfo *t);
312 char constraintModeToChar(TransInfo *t);
314 void startConstraint(TransInfo *t);
315 void stopConstraint(TransInfo *t);
317 void initSelectConstraint(TransInfo *t, float mtx[3][3]);
318 void selectConstraint(TransInfo *t);
319 void postSelectConstraint(TransInfo *t);
321 void setNearestAxis(TransInfo *t);
323 /*********************** Generics ********************************/
325 void initTrans(TransInfo *t);
326 void initTransModeFlags(TransInfo *t, int mode);
327 void postTrans (TransInfo *t);
329 void drawLine(float *center, float *dir, char axis, short options);
331 /* DRAWLINE options flags */
336 void applyTransObjects(TransInfo *t);
337 void restoreTransObjects(TransInfo *t);
338 void recalcData(TransInfo *t);
340 void calculateCenter(TransInfo *t);
341 void calculateCenterBound(TransInfo *t);
342 void calculateCenterMedian(TransInfo *t);
343 void calculateCenterCursor(TransInfo *t);
345 void calculatePropRatio(TransInfo *t);
347 void snapGrid(TransInfo *t, float *val);
349 void getViewVector(float coord[3], float vec[3]);
351 TransInfo * BIF_GetTransInfo(void);
353 /*********************** NumInput ********************************/
355 void outputNumInput(NumInput *n, char *str);
356 short hasNumInput(NumInput *n);
357 void applyNumInput(NumInput *n, float *vec);
358 char handleNumInput(NumInput *n, unsigned short event);