- added VecLerpf to blenlib
authorDaniel Dunbar <daniel@zuster.org>
Mon, 8 Aug 2005 18:50:47 +0000 (18:50 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Mon, 8 Aug 2005 18:50:47 +0000 (18:50 +0000)
 - switch to using DerivedMesh.drawMappedFaceCentersEM to draw
   face dots, still need to do some work so this works in all
   selection modes (atm it does not work in no-zbuf mode)

source/blender/blenkernel/intern/subsurf_ccg.c
source/blender/blenlib/BLI_arithb.h
source/blender/blenlib/intern/arithb.c
source/blender/src/drawobject.c
source/blender/src/editmesh_mods.c

index 3dfb9abf597c02bfa79d037b2af95bb7b709bf0e..d75b6c31d9142b9cec4f7e7662ee8751f8de9e4e 100644 (file)
@@ -1369,6 +1369,26 @@ static void ccgDM_drawMappedFaceNormalsEM(DerivedMesh *dm, float length, int (*s
 
        ccgFaceIterator_free(fi);
 }
+static void ccgDM_drawMappedFaceCentersEM(DerivedMesh *dm, int (*setDrawOptions)(void *userData, struct EditFace *efa), void *userData) {
+       CCGDerivedMesh *ccgdm = (CCGDerivedMesh*) dm;
+       CCGSubSurf *ss = ccgdm->ss;
+       CCGFaceIterator *fi = ccgSubSurf_getFaceIterator(ss);
+       int gridSize = ccgSubSurf_getGridSize(ss);
+
+       bglBegin(GL_POINTS);
+       for (; !ccgFaceIterator_isStopped(fi); ccgFaceIterator_next(fi)) {
+               CCGFace *f = ccgFaceIterator_getCurrent(fi);
+               EditFace *efa = ccgDM_getFaceHandle(ccgdm, f);
+               if (efa && (!setDrawOptions || setDrawOptions(userData, efa))) {
+                       VertData *vd = ccgSubSurf_getFaceCenterData(ss, f);
+
+                       bglVertex3fv(vd->co);
+               }
+       }
+       bglEnd();
+
+       ccgFaceIterator_free(fi);
+}
 
 static void ccgDM_release(DerivedMesh *dm) {
        CCGDerivedMesh *ccgdm = (CCGDerivedMesh*) dm;
@@ -1408,6 +1428,7 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss, int fromEditmesh, Mesh
        ccgdm->dm.drawMappedEdgesEM = ccgDM_drawMappedEdgesEM;
        ccgdm->dm.drawMappedFacesEM = ccgDM_drawMappedFacesEM;
        ccgdm->dm.drawMappedFaceNormalsEM = ccgDM_drawMappedFaceNormalsEM;
+       ccgdm->dm.drawMappedFaceCentersEM = ccgDM_drawMappedFaceCentersEM;
 
        ccgdm->dm.release = ccgDM_release;
        
index 9583f259ab0105660f33bc0192d2294a5bcbe691..901c0c9776a3345393ee88b79b96e7a818427a25 100644 (file)
@@ -545,6 +545,13 @@ VecAddf(
        float *v, 
        float *v1, 
        float *v2
+);
+       void
+VecLerpf(
+       float *target, 
+       float *a, 
+       float *b,
+       float t
 );
        void 
 VecUpMat3(
index 41f52e2455cd822ecb31c6551a4ef7b51121f92b..e8317383e3fba2e1b666a18b84a4c2f9b796b85d 100644 (file)
@@ -1790,6 +1790,15 @@ void VecSubf(float *v, float *v1, float *v2)
        v[2]= v1[2]- v2[2];
 }
 
+void VecLerpf(float *target, float *a, float *b, float t)
+{
+       float s = 1.0f-t;
+
+       target[0]= s*a[0] + t*b[0];
+       target[1]= s*a[1] + t*b[1];
+       target[2]= s*a[2] + t*b[2];
+}
+
 void VecMidf(float *v, float *v1, float *v2)
 {
        v[0]= 0.5f*(v1[0]+ v2[0]);
index 9254dcf9cae91d1b96e2eed63579afb53868515e..280165fb6d5fe4d7b6cb47b66a40aaeb7518baac 100644 (file)
@@ -1221,16 +1221,8 @@ static int ev_nonhidden__setDrawOptions(void *userData, EditVert *eve)
 static void draw_dm_face_normals(DerivedMesh *dm) {
        dm->drawMappedFaceNormalsEM(dm, G.scene->editbutsize, ef_nonhiddenAndFgon__setDrawOptions, 0);
 }
-static void draw_em_face_centers(EditMesh *em, int sel) {
-       EditFace *efa;
-
-       bglBegin(GL_POINTS);
-       for(efa= em->faces.first; efa; efa= efa->next) {
-               if(efa->h==0 && efa->fgonf!=EM_FGON && (efa->f&SELECT)==sel) {
-                       bglVertex3fv(efa->cent);
-               }
-       }
-       bglEnd();
+static void draw_dm_face_centers(DerivedMesh *dm, int sel) {
+       dm->drawMappedFaceCentersEM(dm, ef_nonhiddenAndFgon__setDrawOptions, (void*) (sel+1));
 }
 
 static void draw_dm_vert_normals(DerivedMesh *dm) {
@@ -1402,7 +1394,7 @@ static void draw_em_fancy_verts(EditMesh *em, DerivedMesh *cageDM)
                        if(G.scene->selectmode & SCE_SELECT_FACE) {
                                glPointSize(fsize);
                                glColor4ubv(fcol);
-                               draw_em_face_centers(em, sel);
+                               draw_dm_face_centers(cageDM, sel);
                        }
                        
                        if (pass==0) {
@@ -1576,18 +1568,14 @@ static void draw_em_measure_stats(Object *ob, EditMesh *em)
                        if( (e4->f & e1->f & SELECT) || (G.moving && (efa->v1->f & SELECT)) ) {
                                /* Vec 1 */
                                sprintf(val,"%.3f", VecAngle3(v4, v1, v2));
-                               fvec[0]= 0.2*efa->cent[0] + 0.8*efa->v1->co[0];
-                               fvec[1]= 0.2*efa->cent[1] + 0.8*efa->v1->co[1];
-                               fvec[2]= 0.2*efa->cent[2] + 0.8*efa->v1->co[2];
+                               VecLerpf(fvec, efa->cent, efa->v1->co, 0.8);
                                glRasterPos3fv(fvec);
                                BMF_DrawString( G.fonts, val);
                        }
                        if( (e1->f & e2->f & SELECT) || (G.moving && (efa->v2->f & SELECT)) ) {
                                /* Vec 2 */
                                sprintf(val,"%.3f", VecAngle3(v1, v2, v3));
-                               fvec[0]= 0.2*efa->cent[0] + 0.8*efa->v2->co[0];
-                               fvec[1]= 0.2*efa->cent[1] + 0.8*efa->v2->co[1];
-                               fvec[2]= 0.2*efa->cent[2] + 0.8*efa->v3->co[2];
+                               VecLerpf(fvec, efa->cent, efa->v2->co, 0.8);
                                glRasterPos3fv(fvec);
                                BMF_DrawString( G.fonts, val);
                        }
@@ -1597,9 +1585,7 @@ static void draw_em_measure_stats(Object *ob, EditMesh *em)
                                        sprintf(val,"%.3f", VecAngle3(v2, v3, v4));
                                else
                                        sprintf(val,"%.3f", VecAngle3(v2, v3, v1));
-                               fvec[0]= 0.2*efa->cent[0] + 0.8*efa->v3->co[0];
-                               fvec[1]= 0.2*efa->cent[1] + 0.8*efa->v3->co[1];
-                               fvec[2]= 0.2*efa->cent[2] + 0.8*efa->v3->co[2];
+                               VecLerpf(fvec, efa->cent, efa->v3->co, 0.8);
                                glRasterPos3fv(fvec);
                                BMF_DrawString( G.fonts, val);
                        }
@@ -1607,10 +1593,7 @@ static void draw_em_measure_stats(Object *ob, EditMesh *em)
                        if(efa->v4) {
                                if( (e3->f & e4->f & SELECT) || (G.moving && (efa->v4->f & SELECT)) ) {
                                        sprintf(val,"%.3f", VecAngle3(v3, v4, v1));
-
-                                       fvec[0]= 0.2*efa->cent[0] + 0.8*efa->v4->co[0];
-                                       fvec[1]= 0.2*efa->cent[1] + 0.8*efa->v4->co[1];
-                                       fvec[2]= 0.2*efa->cent[2] + 0.8*efa->v4->co[2];
+                                       VecLerpf(fvec, efa->cent, efa->v4->co, 0.8);
                                        glRasterPos3fv(fvec);
                                        BMF_DrawString( G.fonts, val);
                                }
@@ -3897,7 +3880,7 @@ static int bbs_mesh_wire(DerivedMesh *dm, int offset)
        return offset;
 }              
 
-static int bbs_mesh_solid__setDrawOptions(void *userData, EditFace *efa)
+static int bbs_mesh_solid__setSolidDrawOptions(void *userData, EditFace *efa)
 {
        if (efa->h==0) {
                if (userData) {
@@ -3908,6 +3891,17 @@ static int bbs_mesh_solid__setDrawOptions(void *userData, EditFace *efa)
                return 0;
        }
 }
+
+int bbs_mesh_solid__setCenterDrawOptions(void *userData, EditFace *efa)
+{
+       if (efa->h==0 && efa->fgonf!=EM_FGON) {
+               set_framebuffer_index_color((int) efa->prev);
+               return 1; 
+       } else {
+               return 0;
+       }
+}
+
 /* two options, facecolors or black */
 static int bbs_mesh_solid_EM(DerivedMesh *dm, int facecol)
 {
@@ -3922,26 +3916,19 @@ static int bbs_mesh_solid_EM(DerivedMesh *dm, int facecol)
                        efa->prev= (EditFace *)(b);
                a = b;
 
-               dm->drawMappedFacesEM(dm, bbs_mesh_solid__setDrawOptions, (void*) 1);
+               dm->drawMappedFacesEM(dm, bbs_mesh_solid__setSolidDrawOptions, (void*) 1);
 
                if(G.scene->selectmode & SCE_SELECT_FACE) {
                        glPointSize(BIF_GetThemeValuef(TH_FACEDOT_SIZE));
-                       
-                       bglBegin(GL_POINTS);
-                       for(efa= G.editMesh->faces.first; efa; efa= efa->next) {
-                               if(efa->h==0 && efa->fgonf!=EM_FGON) {
-                                       set_framebuffer_index_color((int)efa->prev);
-                                       bglVertex3fv(efa->cent);
-                               }
-                       }
-                       bglEnd();
+               
+                       dm->drawMappedFaceCentersEM(dm, bbs_mesh_solid__setCenterDrawOptions, NULL);
                }
 
                for (prevefa= NULL, efa= G.editMesh->faces.first; efa; prevefa= efa, efa= efa->next)
                        efa->prev= prevefa;
                return a;
        } else {
-               dm->drawMappedFacesEM(dm, bbs_mesh_solid__setDrawOptions, (void*) 0);
+               dm->drawMappedFacesEM(dm, bbs_mesh_solid__setSolidDrawOptions, (void*) 0);
                return 1;
        }
 }
index ee3d6a476dfa7d17b04319ad2455e61ad8d5dff4..08fd3981f1f5532b1d84a531d4661a6aee002c5a 100644 (file)
@@ -684,6 +684,15 @@ static void draw_dm_mapped_edge(DerivedMesh *dm, EditEdge *eed)
        dm->drawMappedEdgesEM(dm, draw_dm_mapped_edge__setDrawOptions, eed);
 }
 
+static int draw_dm_mapped_face_center__setDrawOptions(void *theFace, EditFace *efa)
+{
+       return theFace==efa;
+}
+static void draw_dm_mapped_face_center(DerivedMesh *dm, EditFace *efa)
+{
+       dm->drawMappedFaceCentersEM(dm, draw_dm_mapped_face_center__setDrawOptions, efa);
+}
+
 static void unified_select_draw(EditVert *eve, EditEdge *eed, EditFace *efa)
 {
        int dmNeedsFree;
@@ -729,9 +738,7 @@ static void unified_select_draw(EditVert *eve, EditEdge *eed, EditFace *efa)
                                glPointSize(BIF_GetThemeValuef(TH_FACEDOT_SIZE));
                                BIF_ThemeColor((efa->f & SELECT)?TH_FACE_DOT:TH_WIRE);
 
-                               bglBegin(GL_POINTS);
-                               bglVertex3fv(efa->cent);
-                               bglEnd();
+                               draw_dm_mapped_face_center(dm, efa);
                        }
                }
        }