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 "transform_numinput.h"
37 #include "BIF_transform.h"
39 /* ************************** Types ***************************** */
44 typedef struct TransCon {
45 char text[50]; /* Description of the Constraint for header_print */
46 float mtx[3][3]; /* Matrix of the Constraint space */
47 float imtx[3][3]; /* Inverse Matrix of the Constraint space */
48 float pmtx[3][3]; /* Projection Constraint Matrix (same as imtx with some axis == 0) */
49 float center[3]; /* transformation centre to define where to draw the view widget
50 ALWAYS in global space. Unlike the transformation center */
51 short imval[2]; /* initial mouse value for visual calculation */
52 /* the one in TransInfo is not garanty to stay the same (Rotates change it) */
53 int mode; /* Mode flags of the Constraint */
54 void (*drawExtra)(struct TransInfo *);
55 /* For constraints that needs to draw differently from the other
56 uses this instead of the generic draw function */
57 void (*applyVec)(struct TransInfo *, struct TransData *, float *, float *, float *);
58 /* Apply function pointer for linear vectorial transformation */
59 /* The last three parameters are pointers to the in/out/printable vectors */
60 void (*applySize)(struct TransInfo *, struct TransData *, float [3][3]);
61 /* Apply function pointer for rotation transformation (prototype will change */
62 void (*applyRot)(struct TransInfo *, struct TransData *, float [3]);
63 /* Apply function pointer for rotation transformation (prototype will change */
66 typedef struct TransDataIpokey {
67 int flag; /* which keys */
68 float *locx, *locy, *locz; /* channel pointers */
69 float *rotx, *roty, *rotz;
70 float *quatx, *quaty, *quatz, *quatw;
71 float *sizex, *sizey, *sizez;
72 float oldloc[9]; /* storage old values */
78 typedef struct TransDataExtension {
79 float drot[3]; /* Initial object drot */
80 float dsize[3]; /* Initial object dsize */
81 float *rot; /* Rotation of the data to transform (Faculative) */
82 float irot[3]; /* Initial rotation */
83 float *quat; /* Rotation quaternion of the data to transform (Faculative) */
84 float iquat[4]; /* Initial rotation quaternion */
85 float *size; /* Size of the data to transform (Faculative) */
86 float isize[3]; /* Initial size */
87 float obmat[3][3]; /* Object matrix */
88 void *bone; /* ARGH! old transform demanded it, added for now (ton) */
91 typedef struct TransData {
92 float dist; /* Distance needed to affect element (for Proportionnal Editing) */
93 float rdist; /* Distance to the nearest element (for Proportionnal Editing) */
94 float factor; /* Factor of the transformation (for Proportionnal Editing) */
95 float *loc; /* Location of the data to transform */
96 float iloc[3]; /* Initial location */
97 float *val; /* Value pointer for special transforms */
98 float ival; /* Old value*/
99 float center[3]; /* Individual data center */
100 float mtx[3][3]; /* Transformation matrix from data space to global space */
101 float smtx[3][3]; /* Transformation matrix from global space to data space */
102 float axismtx[3][3];/* Axis orientation matrix of the data */
104 TransDataExtension *ext; /* for objects, poses. 1 single malloc per TransInfo! */
105 TransDataIpokey *tdi; /* for objects, ipo keys. per transdata a malloc */
106 int flag; /* Various flags */
109 typedef struct TransInfo {
110 int mode; /* current mode */
111 int context; /* current context */
112 int (*transform)(struct TransInfo *, short *);
113 /* transform function pointer */
114 char redraw; /* redraw flag */
115 int flag; /* generic flags for special behaviors */
116 int total; /* total number of transformed data */
117 float propsize; /* proportional circle radius */
118 char proptext[20]; /* proportional falloff text */
119 float center[3]; /* center of transformation */
120 short center2d[2]; /* center in screen coordinates */
121 short imval[2]; /* initial mouse position */
122 short shiftmval[2]; /* mouse position when shift was pressed */
124 float snap[3]; /* Snapping Gears */
125 TransData *data; /* transformed data (array) */
126 TransDataExtension *ext; /* transformed data extension (array) */
127 TransCon con; /* transformed constraint */
128 NumInput num; /* numerical input */
129 float val; /* init value for some transformations (and rotation angle) */
130 float fac; /* factor for distance based transform */
132 float viewmat[4][4]; /* copy from G.vd, prevents feedback */
136 float vec[3]; /* translation, to show for widget */
137 float mat[3][3]; /* rot/rescale, to show for widget */
141 /* ******************** Macros & Prototypes *********************** */
144 #define NUM_NULL_ONE 2
145 #define NUM_NO_NEGATIVE 4
146 #define NUM_NO_ZERO 8
147 #define NUM_NO_FRACTION 16
148 #define NUM_AFFECT_ALL 32
150 /* transinfo->flag */
156 // when shift pressed, higher resolution transform. cannot rely on G.qual, need event!
157 #define T_SHIFT_MOD 32
158 // for manipulator exceptions, like scaling using center point, drawing help lines
159 #define T_USES_MANIPULATOR 128
161 /* restrictions flags */
162 #define T_ALL_RESTRICTIONS (256|512|1024)
163 #define T_NO_CONSTRAINT 256
164 #define T_NULL_ONE 512
165 #define T_NO_ZERO 1024
168 /* transinfo->con->mode */
173 #define CON_SELECT 16
174 #define CON_NOFLIP 32 /* does not reorient vector to face viewport when on */
176 /* transdata->flag */
177 #define TD_SELECTED 1
178 #define TD_NOACTION 2
180 #define TD_NOTCONNECTED 8
182 void initWarp(TransInfo *t);
183 int Warp(TransInfo *t, short mval[2]);
185 void initShear(TransInfo *t);
186 int Shear(TransInfo *t, short mval[2]);
188 void initResize(TransInfo *t);
189 int Resize(TransInfo *t, short mval[2]);
191 void initTranslation(TransInfo *t);
192 int Translation(TransInfo *t, short mval[2]);
194 void initToSphere(TransInfo *t);
195 int ToSphere(TransInfo *t, short mval[2]);
197 void initRotation(TransInfo *t);
198 int Rotation(TransInfo *t, short mval[2]);
200 void initShrinkFatten(TransInfo *t);
201 int ShrinkFatten(TransInfo *t, short mval[2]);
203 void initTilt(TransInfo *t);
204 int Tilt(TransInfo *t, short mval[2]);
206 void initTrackball(TransInfo *t);
207 int Trackball(TransInfo *t, short mval[2]);
209 void initPushPull(TransInfo *t);
210 int PushPull(TransInfo *t, short mval[2]);
212 /* exported from transform.c */
214 void count_bone_select(struct ListBase *lb, int *counter);
216 /* exported from transform_manipulator.c */
218 void draw_manipulator_ext(struct ScrArea *sa, int type, char axis, int col, float vec[3], float mat[][3]);