diff --git a/source/blender/include/BDR_drawobject.h b/source/blender/include/BDR_drawobject.h index f12474eb299..54c0b11d18c 100644 --- a/source/blender/include/BDR_drawobject.h +++ b/source/blender/include/BDR_drawobject.h @@ -47,6 +47,7 @@ struct Base; void init_draw_rects(void); void helpline(float *vec); +void constline(float *center, float *dir, int col); void drawaxes(float size); void drawcamera(struct Object *ob); void calc_lattverts_ext(void); diff --git a/source/blender/include/BSE_view.h b/source/blender/include/BSE_view.h index 49a41e26ab1..4da0c331318 100644 --- a/source/blender/include/BSE_view.h +++ b/source/blender/include/BSE_view.h @@ -50,6 +50,7 @@ void initgrabz(float x, float y, float z); void window_to_3d(float *vec, short mx, short my); void project_short(float *vec, short *adr); void project_short_noclip(float *vec, short *adr); +void project_short_infiniteline(float *vec, float *dir, short *adr1, short *adr2); /* clips infinite line to screen border */ void project_float(float *vec, float *adr); int boundbox_clip(float obmat[][4], struct BoundBox *bb); void fdrawline(float x1, float y1, float x2, float y2); diff --git a/source/blender/src/drawobject.c b/source/blender/src/drawobject.c index 7cf51d08acb..d7b5fad8a5e 100644 --- a/source/blender/src/drawobject.c +++ b/source/blender/src/drawobject.c @@ -271,6 +271,40 @@ void helpline(float *vec) glDrawBuffer(GL_BACK); } +void constline(float *center, float *dir, int col) +{ + float v1[3], v2[3]; + short val1[2], val2[2]; + + + VecCopyf(v1, center); + VecCopyf(v2, dir); + if(G.obedit){ + Mat4Mul3Vecfl(G.obedit->obmat, v1); + VecAddf(v1, v1, G.obedit->obmat[3]); + } + if(G.obedit) Mat4Mul3Vecfl(G.obedit->obmat, v2); + + project_short_infiniteline(v1, v2, val1, val2); + + persp(0); + + glDrawBuffer(GL_FRONT); + + cpack(col); + + setlinestyle(0); + glBegin(GL_LINE_STRIP); + glVertex2sv(val1); + glVertex2sv(val2); + glEnd(); + + persp(PERSP_VIEW); + + glFinish(); // flush display for frontbuffer + glDrawBuffer(GL_BACK); +} + void drawaxes(float size) { int axis; diff --git a/source/blender/src/editobject.c b/source/blender/src/editobject.c index 8d107a15b1c..62ccbc823ec 100644 --- a/source/blender/src/editobject.c +++ b/source/blender/src/editobject.c @@ -3851,6 +3851,9 @@ void transform(int mode) short mval[2], afbreek=0, doit, xn, yn, xc, yc, xo, yo = 0, val; char str[100]; int keyflags = 0; + + short drawhelpline = 0; // for new help lines code. + float vx[3] = {1,0,0}, vy[3] = {0,1,0}, vz[3] = {0,0,1}; if (mode % 'x' == 0) axismode = XTRANSLOCAL; @@ -4698,6 +4701,72 @@ void transform(int mode) screen_swapbuffers(); } } + /* Help line drawing starts here */ + /* Drawing stuff I choose to put it in here so it can draw one line per object or per vertex */ + if (((drawhelpline)||(axismode)) && (mode != 'C') && (mode != 'w') && (mode!='N') && (! (((mode=='R')||(mode=='r')) && (midtog)) ) ){ + if (G.obedit && ((mode=='R')||(mode=='r')||(G.totvertsel > 5))){ + if(axismode==XTRANSLOCAL) constline(centre, vx, 0xFF); + if(axismode==YTRANSLOCAL) constline(centre, vy, 0xFF00); + if(axismode==ZTRANSLOCAL) constline(centre, vz, 0xFF0000); + if(axismode==XTRANS) constline(centre, imat[0], 0xFF); + if(axismode==YTRANS) constline(centre, imat[1], 0xFF00); + if(axismode==ZTRANS) constline(centre, imat[2], 0xFF0000); + if((axismode==0)&&(drawhelpline==2)){ + constline(centre, vx, 0xFF); + constline(centre, vy, 0xFF00); + constline(centre, vz, 0xFF0000); + } + if((axismode==0)&&(drawhelpline==1)){ + constline(centre, imat[0], 0xFF); + constline(centre, imat[1], 0xFF00); + constline(centre, imat[2], 0xFF0000); + } + } + else { + tob= transmain; + tv= transvmain; + for(a=0; aloc, tob->axismat[0], 0xFF); + if(axismode==YTRANSLOCAL) constline(tob->loc, tob->axismat[1], 0xFF00); + if(axismode==ZTRANSLOCAL) constline(tob->loc, tob->axismat[2], 0xFF0000); + if(axismode==XTRANS) constline(tob->loc, vx, 0xFF); + if(axismode==YTRANS) constline(tob->loc, vy, 0xFF00); + if(axismode==ZTRANS) constline(tob->loc, vz, 0xFF0000); + if((axismode==0)&&(drawhelpline==1)){ + constline(tob->oldloc, vx, 0xFF); + constline(tob->oldloc, vy, 0xFF00); + constline(tob->oldloc, vz, 0xFF0000); + } + if((axismode==0)&&(drawhelpline==2)){ + constline(tob->oldloc, tob->axismat[0], 0xFF); + constline(tob->oldloc, tob->axismat[1], 0xFF00); + constline(tob->oldloc, tob->axismat[2], 0xFF0000); + } + } + else { + if(axismode==XTRANSLOCAL) constline(tv->loc, vx, 0xFF); + if(axismode==YTRANSLOCAL) constline(tv->loc, vy, 0xFF00); + if(axismode==ZTRANSLOCAL) constline(tv->loc, vz, 0xFF0000); + if(axismode==XTRANS) constline(tv->loc, imat[0], 0xFF); + if(axismode==YTRANS) constline(tv->loc, imat[1], 0xFF00); + if(axismode==ZTRANS) constline(tv->loc, imat[2], 0xFF0000); + if((axismode==0)&&(drawhelpline==2)){ + constline(G.obedit->obmat[4], vx, 0xFF); + constline(G.obedit->obmat[4], vy, 0xFF00); + constline(G.obedit->obmat[4], vz, 0xFF0000); + } + if((axismode==0)&&(drawhelpline==1)){ + constline(G.obedit->obmat[4], imat[0], 0xFF); + constline(G.obedit->obmat[4], imat[1], 0xFF00); + constline(G.obedit->obmat[4], imat[2], 0xFF0000); + } + } + } + } + } + + } while( qtest() ) { @@ -4760,40 +4829,94 @@ void transform(int mode) break; case XKEY: - if (axismode==XTRANS) - axismode=XTRANSLOCAL; - else if (axismode==XTRANSLOCAL) - axismode=0; + if (drawhelpline==0){ + if (axismode==XTRANS) + axismode=XTRANSLOCAL; + else if (axismode==XTRANSLOCAL) + axismode=0; + else{ + //xref= -xref; + axismode= XTRANS; + } + } + else if (drawhelpline==1){ + if (axismode==XTRANS) + axismode=0; + else{ + axismode= XTRANS; + } + } else{ - xref= -xref; - axismode= XTRANS; + if (axismode==XTRANSLOCAL) + axismode=0; + else{ + axismode=XTRANSLOCAL; + } } firsttime=1; break; case YKEY: - if (axismode==YTRANS) - axismode=YTRANSLOCAL; - else if (axismode==YTRANSLOCAL) - axismode=0; + if (drawhelpline==0){ + if (axismode==YTRANS) + axismode=YTRANSLOCAL; + else if (axismode==YTRANSLOCAL) + axismode=0; + else{ + //yref= -yref; + axismode= YTRANS; + } + } + else if (drawhelpline==1){ + if (axismode==YTRANS) + axismode=0; + else{ + axismode= YTRANS; + } + } else{ - yref= -yref; - axismode= YTRANS; + if (axismode==YTRANSLOCAL) + axismode=0; + else{ + axismode=YTRANSLOCAL; + } } firsttime=1; break; case ZKEY: - if (axismode==ZTRANS) - axismode=ZTRANSLOCAL; - else if (axismode==ZTRANSLOCAL) - axismode=0; + if (drawhelpline==0){ + if (axismode==ZTRANS) + axismode=ZTRANSLOCAL; + else if (axismode==ZTRANSLOCAL) + axismode=0; + else{ + //zref= -zref; + axismode= ZTRANS; + } + } + else if (drawhelpline==1){ + if (axismode==ZTRANS) + axismode=0; + else{ + axismode= ZTRANS; + } + } else{ - zref= -zref; - axismode= ZTRANS; + if (axismode==ZTRANSLOCAL) + axismode=0; + else{ + axismode=ZTRANSLOCAL; + } } firsttime=1; break; + case LKEY: + // toggle between drawhelpline = 0,1,2 (None, Global, Local) + drawhelpline += 1; + if (drawhelpline==3) drawhelpline = 0; + firsttime = 1; + break; case WHEELDOWNMOUSE: case PADPLUSKEY: diff --git a/source/blender/src/view.c b/source/blender/src/view.c index 6bfd945537e..8b8f11bd2ff 100644 --- a/source/blender/src/view.c +++ b/source/blender/src/view.c @@ -227,6 +227,61 @@ void project_float(float *vec, float *adr) } } +void project_short_infiniteline(float *vec, float *dir, short *adr1, short *adr2) /* clips infinite line to screen border */ +{ + float vp[2], vd[2], temp[2]; + short min, max; + float tvec[3], tmp; + + project_float(vec, vp); + VecMulf(dir, 10); + VecAddf(tvec, vec, dir); + project_float(tvec, temp); + + vd[0] = temp[0] - vp[0]; + vd[1] = temp[1] - vp[1]; + + if ((vd[0] == 0) && (vd[1] == 0)){ + adr1[0] = adr2[0] = vp[0]; + adr1[1] = adr2[1] = vp[1]; + } + else if (vd[0] == 0){ + adr1[0] = adr2[0] = vp[0]; + adr1[1] = 0; + adr2[1] = curarea->winy; + } + else if (vd[1] == 0){ + adr1[0] = 0; + adr2[0] = curarea->winx; + adr1[1] = adr2[1] = vp[1]; + } + else{ + tmp = vd[0]; + max = (curarea->winx - vp[0]) / tmp * vd[1] + vp[1]; + if (max > curarea->winy){ + tmp = vd[1]; + adr2[0] = ((curarea->winy) - vp[1]) / tmp * vd[0] + vp[0]; + adr2[1] = curarea->winy; + } + else{ + adr2[0] = curarea->winx; + adr2[1] = max; + } + + tmp = vd[0]; + min = (-vp[0]) / tmp * vd[1] + vp[1]; + if (min < 0){ + tmp = vd[1]; + adr1[0] = (-vp[1]) / tmp * vd[0] + vp[0]; + adr1[1] = 0; + } + else{ + adr1[0] = 0; + adr1[1] = min; + } + } +} + int boundbox_clip(float obmat[][4], BoundBox *bb) { /* return 1: draw */