diff options
author | Campbell Barton <ideasman42@gmail.com> | 2007-09-25 11:42:55 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2007-09-25 11:42:55 +0400 |
commit | ea32119d0b81260c5c58e66240d0c107c336f0b9 (patch) | |
tree | c499a39b2a0cca75ad2e1af8983627dd5a452cc0 /source/blender/src/transform_snap.c | |
parent | 7658066fe95677dfe5ff8aaff9f4f9458a5d01a9 (diff) |
snap transform for UV editing, missing the draw circle at the moment.
Diffstat (limited to 'source/blender/src/transform_snap.c')
-rw-r--r-- | source/blender/src/transform_snap.c | 117 |
1 files changed, 94 insertions, 23 deletions
diff --git a/source/blender/src/transform_snap.c b/source/blender/src/transform_snap.c index ce3212c63fa..3b632e8c467 100644 --- a/source/blender/src/transform_snap.c +++ b/source/blender/src/transform_snap.c @@ -56,6 +56,8 @@ #include "BIF_mywindow.h" #include "BIF_resources.h" #include "BIF_screen.h" +#include "BIF_editsima.h" +#include "BIF_drawimage.h" #include "BKE_global.h" #include "BKE_utildefines.h" @@ -96,32 +98,69 @@ void drawSnapping(TransInfo *t) { if ((t->tsnap.status & (SNAP_ON|POINT_INIT|TARGET_INIT)) == (SNAP_ON|POINT_INIT|TARGET_INIT) && (G.qual & LR_CTRLKEY)) { - float unitmat[4][4]; - float size; - char col[4]; - - glDisable(GL_DEPTH_TEST); - - size = get_drawsize(G.vd); - - size *= 0.5f * BIF_GetThemeValuef(TH_VERTEX_SIZE); + char col[4]; BIF_GetThemeColor3ubv(TH_TRANSFORM, col); glColor4ub(col[0], col[1], col[2], 128); - glPushMatrix(); - - glTranslatef(t->tsnap.snapPoint[0], t->tsnap.snapPoint[1], t->tsnap.snapPoint[2]); - - /* sets view screen aligned */ - glRotatef( -360.0f*saacos(G.vd->viewquat[0])/(float)M_PI, G.vd->viewquat[1], G.vd->viewquat[2], G.vd->viewquat[3]); - - Mat4One(unitmat); - drawcircball(GL_LINE_LOOP, unitmat[3], size, unitmat); - - glPopMatrix(); - - if(G.vd->zbuf) glEnable(GL_DEPTH_TEST); + if (t->spacetype==SPACE_VIEW3D) { + float unitmat[4][4]; + float size; + + glDisable(GL_DEPTH_TEST); + + size = get_drawsize(G.vd); + + size *= 0.5f * BIF_GetThemeValuef(TH_VERTEX_SIZE); + + glPushMatrix(); + + glTranslatef(t->tsnap.snapPoint[0], t->tsnap.snapPoint[1], t->tsnap.snapPoint[2]); + + /* sets view screen aligned */ + glRotatef( -360.0f*saacos(G.vd->viewquat[0])/(float)M_PI, G.vd->viewquat[1], G.vd->viewquat[2], G.vd->viewquat[3]); + + Mat4One(unitmat); + drawcircball(GL_LINE_LOOP, unitmat[3], size, unitmat); + + glPopMatrix(); + + if(G.vd->zbuf) glEnable(GL_DEPTH_TEST); + } else if (t->spacetype==SPACE_IMAGE) { + /*This will not draw, and Im nor sure why - campbell */ + + /* + float xuser_asp, yuser_asp; + int wi, hi; + float w, h; + + calc_image_view(G.sima, 'f'); // float + myortho2(G.v2d->cur.xmin, G.v2d->cur.xmax, G.v2d->cur.ymin, G.v2d->cur.ymax); + glLoadIdentity(); + + aspect_sima(G.sima, &xuser_asp, &yuser_asp); + + transform_width_height_tface_uv(&wi, &hi); + w = (((float)wi)/256.0f)*G.sima->zoom * xuser_asp; + h = (((float)hi)/256.0f)*G.sima->zoom * yuser_asp; + + cpack(0xFFFFFF); + glTranslatef(t->tsnap.snapPoint[0], t->tsnap.snapPoint[1], 0.0f); + + //glRectf(0,0,1,1); + + setlinestyle(0); + cpack(0x0); + fdrawline(-0.020/w, 0, -0.1/w, 0); + fdrawline(0.1/w, 0, .020/w, 0); + fdrawline(0, -0.020/h, 0, -0.1/h); + fdrawline(0, 0.1/h, 0, 0.020/h); + + glTranslatef(-t->tsnap.snapPoint[0], -t->tsnap.snapPoint[1], 0.0f); + setlinestyle(0); + */ + + } } } @@ -169,7 +208,7 @@ void initSnapping(TransInfo *t) { resetSnapping(t); - if (t->spacetype == SPACE_VIEW3D) { // Only 3D view (not UV) + if (t->spacetype == SPACE_VIEW3D || t->spacetype == SPACE_IMAGE) { // Only 3D view or UV setSnappingCallback(t); if (t->tsnap.applySnap != NULL && // A snapping function actually exist @@ -328,6 +367,8 @@ void CalcSnapGeometry(TransInfo *t, float *vec) if (G.obedit != NULL && G.obedit->type==OB_MESH) { /*if (G.scene->selectmode & B_SEL_VERT)*/ + + if (t->spacetype == SPACE_VIEW3D) { EditVert *nearest=NULL; float vec[3]; @@ -358,6 +399,36 @@ void CalcSnapGeometry(TransInfo *t, float *vec) t->tsnap.status &= ~POINT_INIT; } } + else if (t->spacetype == SPACE_IMAGE) + { + + MTFace *nearesttf=NULL; + unsigned int face_corner; + + float vec[3]; + int found = 0; + int dist = 40; // Use a user defined value here + + // use findnearestverts in vert mode, others in other modes + //nearest = findnearestvert(&dist, SELECT, 1); + find_nearest_uv(&nearesttf, NULL, NULL, &face_corner); + + if (nearesttf != NULL) + { + VECCOPY2D(t->tsnap.snapPoint, nearesttf->uv[face_corner]); + //Mat4MulVecfl(G.obedit->obmat, t->tsnap.snapPoint); + + t->tsnap.status |= POINT_INIT; + } + else + { + t->tsnap.status &= ~POINT_INIT; + } + + + } + + /* if (G.scene->selectmode & B_SEL_EDGE) { |