[Bf-committers] Patch for constrain-to-plane
Bill Baxter
bf-committers@blender.org
Sun, 25 Jan 2004 22:52:39 -0500
This is a multi-part message in MIME format.
--------------050703020301080509090908
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Ooops. I left one debug printf in there... Here's the patch with it
removed.
I guess the other thing I should have said could be improved is:
- The kinda confusing overall. There's this ax variable and an axismode
variable, and ax was holding just single a axis, so thinking over it in
retrospect, I think the ax variable was meant to be just an indicator of
the current typein field. But with constrain-to-plane, 'ax' sometimes
needs two values now... well I probably didn't handle the code for that
so gracefully. Instead of changing it to hold axis flags or something
so it could have two values, I just kinda worked around it by using the
axismode flags sometimes. Probably would have been cleaner to make
'ax' always have the proper axes for typein instead. I just didn't
realize that was 'ax's job when I started.
--bb
--------------050703020301080509090908
Content-Type: text/plain;
name="patch.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="patch.txt"
Index: source/blender/src/editobject.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/src/editobject.c,v
retrieving revision 1.68
diff -r1.68 editobject.c
4303a4304,4306
> #define YZTRANS (YTRANS|ZTRANS)
> #define XZTRANS (XTRANS|ZTRANS)
> #define XYTRANS (XTRANS|YTRANS)
4305,4307c4308,4313
< #define XTRANSLOCAL (XTRANS|TRANSLOCAL)
< #define YTRANSLOCAL (YTRANS|TRANSLOCAL)
< #define ZTRANSLOCAL (ZTRANS|TRANSLOCAL)
---
> #define XTRANSLOCAL (XTRANS|TRANSLOCAL)
> #define YTRANSLOCAL (YTRANS|TRANSLOCAL)
> #define ZTRANSLOCAL (ZTRANS|TRANSLOCAL)
> #define YZTRANSLOCAL (YZTRANS|TRANSLOCAL)
> #define XZTRANSLOCAL (XZTRANS|TRANSLOCAL)
> #define XYTRANSLOCAL (XYTRANS|TRANSLOCAL)
4354a4361,4384
> case XYTRANSLOCAL:
> constline(cnst.centre, cnst.vx, 'x', NULL);
> constline(cnst.centre, cnst.vy, 'y', matone);
> break;
> case YZTRANSLOCAL:
> constline(cnst.centre, cnst.vy, 'y', NULL);
> constline(cnst.centre, cnst.vz, 'z', matone);
> break;
> case XZTRANSLOCAL:
> constline(cnst.centre, cnst.vx, 'x', NULL);
> constline(cnst.centre, cnst.vz, 'z', matone);
> break;
> case XYTRANS:
> constline(cnst.centre, cnst.imat, 'x', NULL);
> constline(cnst.centre, cnst.imat+3, 'y', NULL);
> break;
> case YZTRANS:
> constline(cnst.centre, cnst.imat+3, 'y', NULL);
> constline(cnst.centre, cnst.imat+6, 'z', NULL);
> break;
> case XZTRANS:
> constline(cnst.centre, cnst.imat, 'x', NULL);
> constline(cnst.centre, cnst.imat+6, 'z', NULL);
> break;
4361a4392,4403
> case XYTRANS:
> constline(cnst.centre, cnst.vx, 'x', NULL);
> constline(cnst.centre, cnst.vy, 'y', NULL);
> break;
> case YZTRANS:
> constline(cnst.centre, cnst.vy, 'y', NULL);
> constline(cnst.centre, cnst.vz, 'z', NULL);
> break;
> case XZTRANS:
> constline(cnst.centre, cnst.vx, 'x', NULL);
> constline(cnst.centre, cnst.vz, 'z', NULL);
> break;
4370a4413,4424
> case XYTRANSLOCAL:
> constline(tob->loc, tob->axismat[0], 'x', tob->axismat);
> constline(tob->loc, tob->axismat[1], 'y', tob->axismat);
> break;
> case YZTRANSLOCAL:
> constline(tob->loc, tob->axismat[1], 'y', tob->axismat);
> constline(tob->loc, tob->axismat[2], 'z', tob->axismat);
> break;
> case XZTRANSLOCAL:
> constline(tob->loc, tob->axismat[0], 'x', tob->axismat);
> constline(tob->loc, tob->axismat[2], 'z', tob->axismat);
> break;
4672c4726
< char gmode[10] = "";
---
> char gmode[11] = "";
4681a4736,4741
> if (axismode==XYTRANSLOCAL) strcpy(gmode, "Local XY: ");
> if (axismode==YZTRANSLOCAL) strcpy(gmode, "Local YZ: ");
> if (axismode==XZTRANSLOCAL) strcpy(gmode, "Local XZ: ");
> if (axismode==XYTRANS) strcpy(gmode, "XY Plane: ");
> if (axismode==YZTRANS) strcpy(gmode, "YZ Plane: ");
> if (axismode==XZTRANS) strcpy(gmode, "XZ Plane: ");
4693,4695c4753,4760
< if(axismode & XTRANS) dvec[1]=dvec[2]= 0.0;
< if(axismode & YTRANS) dvec[0]=dvec[2]= 0.0;
< if(axismode & ZTRANS) dvec[0]=dvec[1]= 0.0;
---
> switch (axismode&(XTRANS|YTRANS|ZTRANS)) {
> case XTRANS: dvec[1]=dvec[2]= 0.0; break;
> case YTRANS: dvec[0]=dvec[2]= 0.0; break;
> case ZTRANS: dvec[0]=dvec[1]= 0.0; break;
> case XYTRANS: dvec[2] = 0.0; break;
> case YZTRANS: dvec[0] = 0.0; break;
> case XZTRANS: dvec[1] = 0.0; break;
> }
4706a4772,4774
> if(axismode == XYTRANS) dvec[2]= 0.0;
> if(axismode == YZTRANS) dvec[0]= 0.0;
> if(axismode == XZTRANS) dvec[1]= 0.0;
4728a4797,4799
> if(axismode==XYTRANSLOCAL) dvecp[2]=0;
> if(axismode==YZTRANSLOCAL) dvecp[0]=0;
> if(axismode==XZTRANSLOCAL) dvecp[1]=0;
4735a4807,4809
> if(axismode==XYTRANSLOCAL) dvecp[2]=0;
> if(axismode==YZTRANSLOCAL) dvecp[0]=0;
> if(axismode==XZTRANSLOCAL) dvecp[1]=0;
4782,4791c4856,4862
< switch (ax){
< case 0:
< sprintf(str, "%sDx: >%.4f< Dy: %.4f Dz: %.4f", gmode, dvec[0], dvec[1], dvec[2]);
< break;
< case 1:
< sprintf(str, "%sDx: %.4f Dy: >%.4f< Dz: %.4f", gmode, dvec[0], dvec[1], dvec[2]);
< break;
< case 2:
< sprintf(str, "%sDx: %.4f Dy: %.4f Dz: >%.4f<", gmode, dvec[0], dvec[1], dvec[2]);
< }
---
> int l=0;
> if (ax==0||axismode&XTRANS) l+=sprintf(str+l,"%sDx: >%.4f< ",gmode, dvec[0]);
> else l+=sprintf(str+l,"%sDx: %.4f ", gmode, dvec[0]);
> if (ax==1||axismode&YTRANS) l+=sprintf(str+l,"Dy: >%.4f< ",dvec[1]);
> else l+=sprintf(str+l,"Dy: %.4f ", dvec[1]);
> if (ax==2||axismode&ZTRANS) l+=sprintf(str+l,"Dz: >%.4f< ",dvec[2]);
> else l+=sprintf(str+l,"Dz: %.4f ", dvec[2]);
4819a4891
> int rotaxismode=axismode&~(XTRANS|YTRANS|ZTRANS);
4824a4897,4904
> /* Treat planar constraint modes as rot around the plane normal */
> if ((axismode&XYTRANS) == XYTRANS) { rotaxismode |= ZTRANS; }
> else if ((axismode&YZTRANS) == YZTRANS) { rotaxismode |= XTRANS; }
> else if ((axismode&XZTRANS) == XZTRANS) { rotaxismode |= YTRANS; }
> else {
> rotaxismode = axismode;
> }
>
4855d4934
<
4865,4868c4944,4947
< if(axismode) {
< if(axismode==XTRANS) vec[0]= -1.0; else vec[0]= 0.0;
< if(axismode==YTRANS) vec[1]= 1.0; else vec[1]= 0.0;
< if(axismode==ZTRANS) vec[2]= -1.0; else vec[2]= 0.0;
---
> if(rotaxismode) {
> if(rotaxismode==XTRANS) vec[0]= -1.0; else vec[0]= 0.0;
> if(rotaxismode==YTRANS) vec[1]= 1.0; else vec[1]= 0.0;
> if(rotaxismode==ZTRANS) vec[2]= -1.0; else vec[2]= 0.0;
4870,4873c4949,4952
< if (axismode == XTRANSLOCAL) VECCOPY(vec, G.obedit->obmat[0]);
< if (axismode == YTRANSLOCAL) VECCOPY(vec, G.obedit->obmat[1]);
< if (axismode == ZTRANSLOCAL) VECCOPY(vec, G.obedit->obmat[2]);
< if (axismode & TRANSLOCAL) VecMulf(vec, -1.0);
---
> if (rotaxismode == XTRANSLOCAL) VECCOPY(vec, G.obedit->obmat[0]);
> if (rotaxismode == YTRANSLOCAL) VECCOPY(vec, G.obedit->obmat[1]);
> if (rotaxismode == ZTRANSLOCAL) VECCOPY(vec, G.obedit->obmat[2]);
> if (rotaxismode & TRANSLOCAL) VecMulf(vec, -1.0);
4879c4958
< if(axismode) {
---
> if(rotaxismode) {
4889c4968
< if(axismode) {
---
> if(rotaxismode) {
4913,4914c4992,4993
< if (tob && axismode && (turntable == 0)){
< if (axismode == XTRANSLOCAL){
---
> if (tob && rotaxismode && (turntable == 0)){
> if (rotaxismode == XTRANSLOCAL){
4917c4996
< if (axismode == YTRANSLOCAL){
---
> if (rotaxismode == YTRANSLOCAL){
4920c4999
< if (axismode == ZTRANSLOCAL){
---
> if (rotaxismode == ZTRANSLOCAL){
4924c5003
< if ((axismode & TRANSLOCAL) && ((G.vd->viewmat[0][2] * vec[0]+G.vd->viewmat[1][2] * vec[1]+G.vd->viewmat[2][2] * vec[2])>0)){
---
> if ((rotaxismode & TRANSLOCAL) && ((G.vd->viewmat[0][2] * vec[0]+G.vd->viewmat[1][2] * vec[1]+G.vd->viewmat[2][2] * vec[2])>0)){
5090c5169
< else if(axismode) {
---
> else if(rotaxismode) {
5092,5097c5171,5176
< if(axismode==XTRANS) sprintf(str, "Rot X: >%.2f<", addvec[0]);
< else if(axismode==YTRANS) sprintf(str, "Rot Y: >%.2f<", addvec[0]);
< else if(axismode==ZTRANS) sprintf(str, "Rot Z: >%.2f<", addvec[0]);
< else if(axismode==XTRANSLOCAL) sprintf(str, "Local Rot X: >%.2f<", addvec[0]);
< else if(axismode==YTRANSLOCAL) sprintf(str, "Local Rot Y: >%.2f<", addvec[0]);
< else if(axismode==ZTRANSLOCAL) sprintf(str, "Local Rot Z: >%.2f<", addvec[0]);
---
> if(rotaxismode==XTRANS) sprintf(str, "Rot X: >%.2f<", addvec[0]);
> else if(rotaxismode==YTRANS) sprintf(str, "Rot Y: >%.2f<", addvec[0]);
> else if(rotaxismode==ZTRANS) sprintf(str, "Rot Z: >%.2f<", addvec[0]);
> else if(rotaxismode==XTRANSLOCAL) sprintf(str, "Local Rot X: >%.2f<", addvec[0]);
> else if(rotaxismode==YTRANSLOCAL) sprintf(str, "Local Rot Y: >%.2f<", addvec[0]);
> else if(rotaxismode==ZTRANSLOCAL) sprintf(str, "Local Rot Z: >%.2f<", addvec[0]);
5100,5105c5179,5184
< if(axismode==XTRANS) sprintf(str, "Rot X: %.2f", 180.0*phi/M_PI);
< else if(axismode==YTRANS) sprintf(str, "Rot Y: %.2f", 180.0*phi/M_PI);
< else if(axismode==ZTRANS) sprintf(str, "Rot Z: %.2f", 180.0*phi/M_PI);
< else if(axismode==XTRANSLOCAL) sprintf(str, "Local Rot X: %.2f", 180.0*phi/M_PI);
< else if(axismode==YTRANSLOCAL) sprintf(str, "Local Rot Y: %.2f", 180.0*phi/M_PI);
< else if(axismode==ZTRANSLOCAL) sprintf(str, "Local Rot Z: %.2f", 180.0*phi/M_PI);
---
> if(rotaxismode==XTRANS) sprintf(str, "Rot X: %.2f", 180.0*phi/M_PI);
> else if(rotaxismode==YTRANS) sprintf(str, "Rot Y: %.2f", 180.0*phi/M_PI);
> else if(rotaxismode==ZTRANS) sprintf(str, "Rot Z: %.2f", 180.0*phi/M_PI);
> else if(rotaxismode==XTRANSLOCAL) sprintf(str, "Local Rot X: %.2f", 180.0*phi/M_PI);
> else if(rotaxismode==YTRANSLOCAL) sprintf(str, "Local Rot Y: %.2f", 180.0*phi/M_PI);
> else if(rotaxismode==ZTRANSLOCAL) sprintf(str, "Local Rot Z: %.2f", 180.0*phi/M_PI);
5121c5200
< set_constline_callback(mode, axismode, midtog, centre, imat, vx, vy, vz);
---
> set_constline_callback(mode, rotaxismode, midtog, centre, imat, vx, vy, vz);
5157a5237,5239
> if(axismode==XYTRANS) axismode = XYTRANSLOCAL;
> if(axismode==YZTRANS) axismode = YZTRANSLOCAL;
> if(axismode==XZTRANS) axismode = XZTRANSLOCAL;
5161a5244,5246
> if(axismode==XYTRANS) size[2]= 1.0;
> if(axismode==YZTRANS) size[0]= 1.0;
> if(axismode==XZTRANS) size[1]= 1.0;
5164a5250,5252
> if(axismode==XYTRANSLOCAL) size[2]= 1.0;
> if(axismode==YZTRANSLOCAL) size[0]= 1.0;
> if(axismode==XZTRANSLOCAL) size[1]= 1.0;
5321a5410,5424
> char gmode[11] = "";
>
> if (axismode==XTRANSLOCAL) strcpy(gmode, "Local X: ");
> if (axismode==YTRANSLOCAL) strcpy(gmode, "Local Y: ");
> if (axismode==ZTRANSLOCAL) strcpy(gmode, "Local Z: ");
> if (axismode==XTRANS) strcpy(gmode, "X Axis: ");
> if (axismode==YTRANS) strcpy(gmode, "Y Axis: ");
> if (axismode==ZTRANS) strcpy(gmode, "Z Axis: ");
> if (axismode==XYTRANSLOCAL) strcpy(gmode, "Local XY: ");
> if (axismode==YZTRANSLOCAL) strcpy(gmode, "Local YZ: ");
> if (axismode==XZTRANSLOCAL) strcpy(gmode, "Local XZ: ");
> if (axismode==XYTRANS) strcpy(gmode, "XY Plane: ");
> if (axismode==YZTRANS) strcpy(gmode, "YZ Plane: ");
> if (axismode==XZTRANS) strcpy(gmode, "XZ Plane: ");
>
5323,5335c5426,5432
< switch (ax){
< case 0:
< sprintf(str, "Sizex: >%.3f< Sizey: >%.3f< Sizez: >%.3f<", sizelo[0], sizelo[1], sizelo[2]);
< break;
< case 1:
< sprintf(str, "Sizex: >%.3f< Sizey: %.3f Sizez: %.3f", sizelo[0], sizelo[1], sizelo[2]);
< break;
< case 2:
< sprintf(str, "Sizex: %.3f Sizey: >%.3f< Sizez: %.3f", sizelo[0], sizelo[1], sizelo[2]);
< break;
< case 3:
< sprintf(str, "Sizex: %.3f Sizey: %.3f Sizez: >%.3f<", sizelo[0], sizelo[1], sizelo[2]);
< }
---
> int l=0;
> if (ax==0||ax==1||axismode&XTRANS) l+=sprintf(str+l,"%sSizex: >%.3f< ",gmode,sizelo[0]);
> else l+=sprintf(str+l,"%sSizex: %.3f ", gmode,sizelo[0]);
> if (ax==0||ax==2||axismode&YTRANS) l+=sprintf(str+l,"Sizey: >%.3f< ",sizelo[1]);
> else l+=sprintf(str+l,"Sizey: %.3f ", sizelo[1]);
> if (ax==0||ax==3||axismode&ZTRANS) l+=sprintf(str+l,"Sizez: >%.3f<", sizelo[2]);
> else l+=sprintf(str+l,"Sizez: %.3f", sizelo[2]);
5338c5435,5436
< sprintf(str, "Sizex: %.3f Sizey: %.3f Sizez: %.3f", sizelo[0], sizelo[1], sizelo[2]);
---
> sprintf(str, "%sSizex: %.3f Sizey: %.3f Sizez: %.3f", gmode, sizelo[0], sizelo[1], sizelo[2]);
>
5548,5553c5646,5662
< if (axismode==XTRANS)
< axismode=XTRANSLOCAL;
< else if (axismode==XTRANSLOCAL)
< axismode=0;
< else{
< axismode= XTRANS;
---
> if (G.qual & LR_CTRLKEY) {
> if (axismode==YZTRANS)
> axismode=YZTRANSLOCAL;
> else if (axismode==YZTRANSLOCAL)
> axismode=0;
> else {
> axismode= YZTRANS;
> }
> }
> else {
> if (axismode==XTRANS)
> axismode=XTRANSLOCAL;
> else if (axismode==XTRANSLOCAL)
> axismode=0;
> else{
> axismode= XTRANS;
> }
5556,5557c5665,5666
< if (axismode & XTRANS)
< ax = 0;
---
> if (axismode & XTRANS)
> ax = 0;
5559,5560c5668,5669
< if (axismode & XTRANS)
< ax = 1;
---
> if (axismode & XTRANS)
> ax = 1;
5566,5571c5675,5691
< if (axismode==YTRANS)
< axismode=YTRANSLOCAL;
< else if (axismode==YTRANSLOCAL)
< axismode=0;
< else{
< axismode= YTRANS;
---
> if (G.qual & LR_CTRLKEY) {
> if (axismode==XZTRANS)
> axismode=XZTRANSLOCAL;
> else if (axismode==XZTRANSLOCAL)
> axismode=0;
> else{
> axismode= XZTRANS;
> }
> }
> else {
> if (axismode==YTRANS)
> axismode=YTRANSLOCAL;
> else if (axismode==YTRANSLOCAL)
> axismode=0;
> else{
> axismode= YTRANS;
> }
5584,5589c5704,5720
< if (axismode==ZTRANS)
< axismode=ZTRANSLOCAL;
< else if (axismode==ZTRANSLOCAL)
< axismode=0;
< else{
< axismode= ZTRANS;
---
> if (G.qual & LR_CTRLKEY) {
> if (axismode==XYTRANS)
> axismode=XYTRANSLOCAL;
> else if (axismode==XYTRANSLOCAL)
> axismode=0;
> else{
> axismode= XYTRANS;
> }
> }
> else {
> if (axismode==ZTRANS)
> axismode=ZTRANSLOCAL;
> else if (axismode==ZTRANSLOCAL)
> axismode=0;
> else{
> axismode= ZTRANS;
> }
5662,5665c5793,5804
< addvec[ax-1]=0;
< pe[ax-1]=0;
< mi[ax-1]=1;
< numchange[ax-1]=0;
---
> if (axismode&XTRANS) {
> addvec[0]=pe[0]=numchange[0]=0;
> mi[0]=1;
> }
> if (axismode&YTRANS) {
> addvec[1]=pe[1]=numchange[1]=0;
> mi[1]=1;
> }
> if (axismode&ZTRANS) {
> addvec[2]=pe[2]=numchange[2]=0;
> mi[2]=1;
> }
5706,5711c5845,5851
< else if (mode == 's'){
< if (pe[ax-1] == 0){pe[ax-1] = 1;}
< }
< else{
< if (pe[ax] == 0){pe[ax] = 1;}
< }
---
> else if (mode=='g') {
> if ((axismode&XTRANS) && pe[0] == 0){pe[0] = 1;}
> if ((axismode&YTRANS) && pe[1] == 0){pe[1] = 1;}
> if ((axismode&ZTRANS) && pe[2] == 0){pe[2] = 1;}
> } else {
> if (pe[0] == 0) pe[ax] = 1;
> }
5725,5727c5865,5868
< else if (mode == 's'){
< addvec[ax-1]*=-1;
< mi[ax-1] *= -1;
---
> else if (mode == 's' || mode == 'g' ){
> if (axismode&XTRANS) { addvec[0]*=-1; mi[0]*=-1; }
> if (axismode&YTRANS) { addvec[1]*=-1; mi[1]*=-1; }
> if (axismode&ZTRANS) { addvec[2]*=-1; mi[2]*=-1; }
5737a5879
> int was_typemode = typemode;
5742,5745c5884,5887
< if ((mode != 'r') && (mode != 'R')){
< if (axismode != 0)
< break;
< ax += 1;
---
> if ((mode != 'r') && (mode != 'R') ) {
> if (axismode != 0)
> break;
> ax += was_typemode;
5753c5895
< ax += 1;
---
> ax += was_typemode;
5792,5798c5934,5965
< if (axismode & XTRANS)
< ax = 1;
< if (axismode & YTRANS)
< ax = 2;
< if (axismode & ZTRANS)
< ax = 3;
< if (ax == 0){
---
> if (typemode&& !axismode && ax!=0) {
> if (pe[ax-1]){
> int div = 1;
> int i;
> for (i = 0; i < pe[ax-1]; i++){div*=10;}
> addvec[ax-1] += mi[ax-1] * add_num / div;
> pe[ax-1]+=1;
> }
> else{
> addvec[ax-1] *= 10;
> addvec[ax-1] += mi[ax-1] * add_num;
> }
> numchange[ax-1]=1;
> }
> else if (axismode&(XTRANS|YTRANS|ZTRANS)) {
> for (ax=1;ax<=3;ax++){
> if (!(axismode & (XTRANS<<(ax-1)))) continue;
> if (pe[ax-1]){
> int div = 1;
> int i;
> for (i = 0; i < pe[ax-1]; i++){div*=10;}
> addvec[ax-1] += mi[ax-1] * add_num / div;
> pe[ax-1]+=1;
> }
> else{
> addvec[ax-1] *= 10;
> addvec[ax-1] += mi[ax-1] * add_num;
> }
> numchange[ax-1]=1;
> }
> }
> else {
5820,5833d5986
< else{
< if (pe[ax-1]){
< int div = 1;
< int i;
< for (i = 0; i < pe[ax-1]; i++){div*=10;}
< addvec[ax-1] += mi[ax-1] * add_num / div;
< pe[ax-1]+=1;
< }
< else{
< addvec[ax-1] *= 10;
< addvec[ax-1] += mi[ax-1] * add_num;
< }
< numchange[ax-1]=1;
< }
5859c6012
< if (pe[ax]){
---
> if (pe[ax] ){
5873,5878c6026,6031
< if (axismode & XTRANS)
< ax = 0;
< if (axismode & YTRANS)
< ax = 1;
< if (axismode & ZTRANS)
< ax = 2;
---
> if (axismode&(XTRANS|YTRANS|ZTRANS) == XTRANS)
> ax = 0;
> if (axismode&(XTRANS|YTRANS|ZTRANS) == YTRANS)
> ax = 1;
> if (axismode&(XTRANS|YTRANS|ZTRANS) == ZTRANS)
> ax = 2;
--------------050703020301080509090908--