- fixed editing vertices again!
authorTon Roosendaal <ton@blender.org>
Thu, 16 Oct 2003 09:39:19 +0000 (09:39 +0000)
committerTon Roosendaal <ton@blender.org>
Thu, 16 Oct 2003 09:39:19 +0000 (09:39 +0000)
I had to clean up very old calls to switch matrices for 3d windows.
To make it more clear, I've introduced defines for the infamous persp()
function:

persp(PERSP_WIN);  sets matrices at pixel level window
persp(PERSP_VIEW); restores matrices back to 3d drawing
persp(PERSP_STORE); only called once, to store correct matrices

I will now check on frontbuffer drawing of vertices... it's very doubtful
if it's used still correctly, was only meant for visual speed in the
early nineties you know. :)

source/blender/include/BSE_view.h
source/blender/makesdna/DNA_view3d_types.h
source/blender/src/drawobject.c
source/blender/src/drawview.c
source/blender/src/edit.c
source/blender/src/editcurve.c
source/blender/src/editmesh.c
source/blender/src/editview.c
source/blender/src/view.c

index f46de2ba3ff9d0ab7d23afac63959676018748b6..49a41e26ab185fa68fa38fd7e8ce75dc3487a60d 100644 (file)
@@ -39,9 +39,13 @@ struct BoundBox;
 struct View3D;
 struct ScrArea;
 
-void persp3d(struct View3D *v3d, int a);
+#define PERSP_WIN      0
+#define PERSP_VIEW     1
+#define PERSP_STORE    2
+
 void persp_general(int a);
 void persp(int a);
+
 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);
index cf19e79f3a33a3840dc7f512363ddea139abf465..fbba5d674dd0e845d64c0d5f9a2c94e52b3b7d7e 100644 (file)
@@ -71,6 +71,10 @@ typedef struct View3D {
        float viewinv[4][4];
        float persmat[4][4];
        float persinv[4][4];
+       
+       float winmat1[4][4];  // persp(1) storage, for swap matrices
+       float viewmat1[4][4];
+       
        float viewquat[4], dist;
 
        /**
index 03e63a6a4b1667623e255080f1dad7b09b88ea0b..4313ae5227493cf2f48cbe420e6a9ca177071ace 100644 (file)
@@ -258,7 +258,7 @@ void helpline(float *vec)
        getmouseco_areawin(mval);
        project_short_noclip(vecrot, mval1);
 
-       persp(0);
+       persp(PERSP_WIN);
        
        glDrawBuffer(GL_FRONT);
        
@@ -271,7 +271,7 @@ void helpline(float *vec)
        glEnd();
        setlinestyle(0);
        
-       persp(1);
+       persp(PERSP_VIEW);
        glFinish(); // flush display for frontbuffer
        glDrawBuffer(GL_BACK);
 }
@@ -944,6 +944,8 @@ void calc_meshverts_ext(void)
 {
 
        areawinset(curarea->win);
+       persp(PERSP_VIEW);
+       
        mymultmatrix(G.obedit->obmat);
        calc_meshverts();
        myloadmatrix(G.vd->viewmat);
index 8043a09b5af633fbe229064438204397e3ae652e..b5113ab7e02d69db6983c97c64d86fd48184a2f3 100644 (file)
@@ -446,7 +446,7 @@ static void drawgrid(void)
                }
        }
        
-       persp(0);
+       persp(PERSP_WIN);
 
        cpack(0x606060);
        
@@ -480,7 +480,7 @@ static void drawgrid(void)
 
        fdrawline(x,  0.0,  x,  (float)curarea->winy); 
 
-       persp(1);
+       persp(PERSP_VIEW);
        setlinestyle(0);
 }
 
@@ -1081,7 +1081,6 @@ void drawview3dspace(ScrArea *sa, void *spacedata)
        Object *ob;
        
        setwinmatrixview3d(0);  /* 0= no pick rect */
-
        setviewmatrixview3d();
 
        Mat4MulMat4(G.vd->persmat, G.vd->viewmat, curarea->winmat);
@@ -1107,6 +1106,7 @@ void drawview3dspace(ScrArea *sa, void *spacedata)
        }
        
        myloadmatrix(G.vd->viewmat);
+       persp(PERSP_STORE);  // store correct view for persp(PERSP_VIEW) calls
 
        if(G.vd->view==0 || G.vd->persp!=0) {
                drawfloor();
@@ -1260,7 +1260,7 @@ void drawview3dspace(ScrArea *sa, void *spacedata)
                glDisable(GL_DEPTH_TEST);
        }
 
-       persp(0);
+       persp(PERSP_WIN);  // set ortho
        
        if(G.vd->persp>1) drawviewborder();
        drawcursor();
@@ -1276,6 +1276,7 @@ void drawview3dspace(ScrArea *sa, void *spacedata)
        bwin_scalematrix(sa->win, G.vd->blockscale, G.vd->blockscale, G.vd->blockscale);
        view3d_blockhandlers(sa);
 
+
        curarea->win_swap= WIN_BACK_OK;
        
        if(G.f & (G_VERTEXPAINT|G_FACESELECT|G_TEXTUREPAINT|G_WEIGHTPAINT)) {
index ac3ea078c3208dddd688f4df3bd38fcacc28f990..81dedcf0aeb10c5e325173f8f2872554a7b321f4 100644 (file)
@@ -138,7 +138,7 @@ int get_border(rcti *rect, short col)
        mywinset(curarea->win);
        
        glDrawBuffer(GL_FRONT);
-       persp(0);
+       persp(PERSP_WIN);
        initgrabz(0.0, 0.0, 0.0);
        
        getmouseco_areawin(mvalo);
@@ -150,9 +150,9 @@ int get_border(rcti *rect, short col)
        while(TRUE) {
        
                /* for when a renderwindow is open, and a mouse cursor activates it */
-               persp(1);
+               persp(PERSP_VIEW);
                mywinset(curarea->win);
-               persp(0);
+               persp(PERSP_WIN);
                
                /* selection loop while mouse pressed */
                getmouseco_areawin(mval);
@@ -218,9 +218,9 @@ int get_border(rcti *rect, short col)
                        event= extern_qread(&val);
                        
                        /* still because of the renderwindow... */
-                       persp(1);
+                       persp(PERSP_VIEW);
                        mywinset(curarea->win);
-                       persp(0);
+                       persp(PERSP_WIN);
                                
                        if(val==0) {
                                if(event==ESCKEY) {
@@ -307,7 +307,7 @@ int get_border(rcti *rect, short col)
        glReadBuffer(GL_BACK);
        glDrawBuffer(GL_BACK);
 
-       persp(1);
+       persp(PERSP_VIEW);
        
        /* pressed B again ? -> brush select */
        if(event==BKEY) {
@@ -335,7 +335,7 @@ void draw_sel_circle(short *mval, short *mvalo, float rad, float rado, int selec
                return;
        }
 
-       persp(0);
+       persp(PERSP_WIN);
        glDrawBuffer(GL_FRONT);
 
        /* draw circle */
@@ -349,7 +349,7 @@ void draw_sel_circle(short *mval, short *mvalo, float rad, float rado, int selec
        }
 
        glFlush();
-       persp(1);
+       persp(PERSP_VIEW);
        glDrawBuffer(GL_BACK);
        
        no_mvalo= 0;
index 476901586c621460e3a6b6feb3d0452d4d47c5d6..467f550e198d13a786f4d23a21bbd0d4d030f860 100644 (file)
@@ -191,7 +191,7 @@ static void printweightsNurb(void)
 
        if(G.obedit==0) return;
 
-       persp(0);
+       persp(PERSP_WIN);
 
        glDrawBuffer(GL_FRONT); 
 
@@ -224,7 +224,7 @@ static void printweightsNurb(void)
        }
 
        glDrawBuffer(GL_BACK); 
-       persp(1);
+       persp(PERSP_VIEW);
 }
 #endif
 
index 9ea3fe6fa1d41ff7a0d52f57d7b5454804501c38..c1c937875ae00ab87f5b9c40129ab245aed19626 100644 (file)
@@ -6623,7 +6623,9 @@ CutCurve *get_mouse_trail(int *len){
        }
        mywinset(curarea->win);
        glDrawBuffer(GL_FRONT);
-       persp(0);
+
+       persp(PERSP_WIN);
+
        event=extern_qread(&val);
        while((event != RETKEY ) && (event != RIGHTMOUSE) ){  
                event=extern_qread(&val);       /* Enter or RMB indicates finish */
@@ -6708,8 +6710,12 @@ CutCurve *get_mouse_trail(int *len){
        for(j=1;j<i;j++) {
                sdrawXORline(curve[j-1].x, curve[j-1].y, curve[j].x, curve[j].y );
        }
+
        glFlush();
+       persp(PERSP_VIEW);
+
        *len=i;
+
        return(curve);
 }
 
index 8f21df450bda195cad51459687f8d6317e97ffa5..81813f7f8374ba7db234275a51eb8115b55fc198 100644 (file)
@@ -674,7 +674,7 @@ void borderselect(void)
                                
                                calc_meshverts_ext();   /* drawobject.c */
                                eve= G.edve.first;
-                               while(eve) {
+                               while(eve) {            
                                        if(eve->h==0 && eve->xs>rect.xmin && eve->xs<rect.xmax) {
                                                if(eve->ys>rect.ymin && eve->ys<rect.ymax) {
                                                        if(val==LEFTMOUSE) eve->f|= 1;
@@ -683,8 +683,7 @@ void borderselect(void)
                                        }
                                        eve= eve->next;
                                }
-                               if(val!=LEFTMOUSE) tekenvertices_ext(0);
-                               tekenvertices_ext(1);
+                               allqueue(REDRAWVIEW3D, 0);
                                
                        }
                        else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) {
index 8025d7663e335e5abb277d80807524906128ed89..0d4550d8d8488ac3c08dce01253832c47c793a93 100644 (file)
 
 #define TRACKBALLSIZE  (1.1)
 
-void persp3d(View3D *v3d, int a)
-{
-       ScrArea *area= v3d->area;
-       
-               /* only 3D windows */
-       if(a== 0) {
-               bwin_get_winmatrix(area->win, area->winmat);
-               glMatrixMode(GL_MODELVIEW);
-               bwin_ortho2(area->win, -0.5, (float)(area->winx)-.05, -0.5, (float)(area->winy)-0.5);
-               glLoadIdentity();
-       }
-       else if(a== 1) {
-               glMatrixMode(GL_PROJECTION);
-               bwin_load_winmatrix(area->win, area->winmat);
-               glMatrixMode(GL_MODELVIEW);
-               bwin_load_viewmatrix(area->win, v3d->viewmat);
-       }
-}
-
 void persp_general(int a)
 {
        /* for all window types, not 3D */
@@ -129,18 +110,23 @@ void persp(int a)
        /* only 3D windows */
 
        if(curarea->spacetype!=SPACE_VIEW3D) persp_general(a);
-       else if(a== 0) {
+       else if(a == PERSP_STORE) {             // only store
                glMatrixMode(GL_PROJECTION);
-               mygetmatrix(curarea->winmat);
+               mygetmatrix(G.vd->winmat1);     
                glMatrixMode(GL_MODELVIEW);
+               mygetmatrix(G.vd->viewmat1); 
+       }
+       else if(a== PERSP_WIN) {                // only set
                myortho2(-0.5, (float)(curarea->winx)-.05, -0.5, (float)(curarea->winy)-0.5);
                glLoadIdentity();
        }
-       else if(a== 1) {
+       else if(a== PERSP_VIEW) {
                glMatrixMode(GL_PROJECTION);
-               myloadmatrix(curarea->winmat);
-               glMatrixMode(GL_MODELVIEW);
-               myloadmatrix(G.vd->viewmat);
+               myloadmatrix(G.vd->winmat1); // put back
+               Mat4CpyMat4(curarea->winmat, G.vd->winmat1); // to be sure? 
+               glMatrixMode(GL_MODELVIEW); 
+               myloadmatrix(G.vd->viewmat); // put back
+               
        }
 }