diff options
author | Daniel Dunbar <daniel@zuster.org> | 2005-08-15 08:10:02 +0400 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2005-08-15 08:10:02 +0400 |
commit | 0c7f65d15230a530afae116c93c7d83a9a6a6e0c (patch) | |
tree | 0b4ff3989fe0429aab2b5a98b69508ab606b8150 /source/blender | |
parent | 74623f33aa2e12da31b53423fc226ebf9e937df4 (diff) |
- added view3d_get_object_project_mat function, returns mat to project
object cos into screenspace without mucking with gl matrices.
- added view3d_project_ functions, take arguments instead of using
globals
- removed View3D.{mx,my,mxo,myo}
- switch drawobject foreachScreenVert functions to use new projection
functions
- switch edge slide to use new projection functions, fixes erratic
behavior (project was using wrong mat I believe)
- bug fix in edgeslide, nearest edge to start was one-off
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/include/BSE_view.h | 5 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_view3d_types.h | 4 | ||||
-rw-r--r-- | source/blender/src/drawobject.c | 93 | ||||
-rw-r--r-- | source/blender/src/drawview.c | 43 | ||||
-rw-r--r-- | source/blender/src/editmesh_loop.c | 2 | ||||
-rw-r--r-- | source/blender/src/editmesh_tools.c | 50 | ||||
-rw-r--r-- | source/blender/src/editview.c | 53 | ||||
-rw-r--r-- | source/blender/src/view.c | 81 |
8 files changed, 180 insertions, 151 deletions
diff --git a/source/blender/include/BSE_view.h b/source/blender/include/BSE_view.h index 5a70ebb5718..94f5266c4e3 100644 --- a/source/blender/include/BSE_view.h +++ b/source/blender/include/BSE_view.h @@ -46,6 +46,11 @@ struct ScrArea; void persp_general(int a); void persp(int a); +void view3d_get_object_project_mat(struct ScrArea *area, struct Object *ob, float mat[4][4]); +void view3d_project_float(struct ScrArea *area, float *vec, float *adr, float mat[4][4]); +void view3d_project_short(struct ScrArea *area, float *vec, short *adr, float mat[4][4]); +void view3d_project_short_noclip(struct ScrArea *area, float *vec, short *adr, float mat[4][4]); + 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); diff --git a/source/blender/makesdna/DNA_view3d_types.h b/source/blender/makesdna/DNA_view3d_types.h index 27447315385..6bd0a91fbdf 100644 --- a/source/blender/makesdna/DNA_view3d_types.h +++ b/source/blender/makesdna/DNA_view3d_types.h @@ -114,9 +114,6 @@ typedef struct View3D { float lens, grid, gridview, pad, near, far; float ofs[3], cursor[3]; - - short mx, my; /* have to remain together, because used as single pointer */ - short mxo, myo; short gridlines, viewbut; short gridflag; @@ -130,7 +127,6 @@ typedef struct View3D { struct ListBase afterdraw; /* drawflags, denoting state */ short zbuf, transp, xray, pad2; - } View3D; /* View3D->flag */ diff --git a/source/blender/src/drawobject.c b/source/blender/src/drawobject.c index 268eaaf9323..41881e0a296 100644 --- a/source/blender/src/drawobject.c +++ b/source/blender/src/drawobject.c @@ -791,7 +791,7 @@ static void tekenvertslatt(short sel) Lattice *lt; BPoint *bp; float size; - int a, uxt, u, vxt, v, wxt, w; + int a, u, v, w; size= BIF_GetThemeValuef(TH_VERTEX_SIZE); glPointSize(size); @@ -807,12 +807,11 @@ static void tekenvertslatt(short sel) if(lt->flag & LT_OUTSIDE) { for(w=0; w<lt->pntsw; w++) { - if(w==0 || w==lt->pntsw-1) wxt= 1; else wxt= 0; + int wxt = (w==0 || w==lt->pntsw-1); for(v=0; v<lt->pntsv; v++) { - if(v==0 || v==lt->pntsv-1) vxt= 1; else vxt= 0; - + int vxt = (v==0 || v==lt->pntsv-1); for(u=0; u<lt->pntsu; u++, bp++) { - if(u==0 || u==lt->pntsu-1) uxt= 1; else uxt= 0; + int uxt = (u==0 || u==lt->pntsu-1); if(uxt || vxt || wxt) { if(bp->hide==0) { if((bp->f1 & 1)==sel) bglVertex3fv(bp->vec); @@ -843,23 +842,16 @@ void lattice_foreachScreenVert(void (*func)(void *userData, BPoint *bp, int x, i float mat[4][4]; short s[2]; - areawinset(curarea->win); - persp(PERSP_VIEW); - mymultmatrix(G.obedit->obmat); - MTC_Mat4SwapMat4(G.vd->persmat, mat); - mygetsingmatrix(G.vd->persmat); + view3d_get_object_project_mat(curarea, G.obedit, mat); for (i=0; i<N; i++) { BPoint *bp = &editLatt->def[i]; if (bp->hide==0) { - project_short(bp->vec, s); + view3d_project_short(curarea, bp->vec, s, mat); func(userData, bp, s[0], s[1]); } } - - MTC_Mat4SwapMat4(G.vd->persmat, mat); - myloadmatrix(G.vd->viewmat); } @@ -969,14 +961,14 @@ static void drawlattice(Object *ob) static void mesh_foreachScreenVert__mapFunc(void *userData, EditVert *eve, float *co, float *no_f, short *no_s) { - struct { void (*func)(void *userData, EditVert *eve, int x, int y, int index); void *userData; int clipVerts; } *data = userData; + struct { void (*func)(void *userData, EditVert *eve, int x, int y, int index); void *userData; int clipVerts; float mat[4][4]; } *data = userData; short s[2]; if (eve->h==0) { if (data->clipVerts) { - project_short(co, s); + view3d_project_short(curarea, co, s, data->mat); } else { - project_short_noclip(co, s); + view3d_project_short_noclip(curarea, co, s, data->mat); } data->func(data->userData, eve, s[0], s[1], (int) eve->prev); @@ -984,10 +976,9 @@ static void mesh_foreachScreenVert__mapFunc(void *userData, EditVert *eve, float } void mesh_foreachScreenVert(void (*func)(void *userData, EditVert *eve, int x, int y, int index), void *userData, int clipVerts) { - struct { void (*func)(void *userData, EditVert *eve, int x, int y, int index); void *userData; int clipVerts; } data; + struct { void (*func)(void *userData, EditVert *eve, int x, int y, int index); void *userData; int clipVerts; float mat[4][4]; } data; int dmNeedsFree; DerivedMesh *dm = editmesh_get_derived_cage(&dmNeedsFree); - float mat[4][4]; EditVert *eve, *preveve; int index; @@ -995,11 +986,7 @@ void mesh_foreachScreenVert(void (*func)(void *userData, EditVert *eve, int x, i data.userData = userData; data.clipVerts = clipVerts; - areawinset(curarea->win); - persp(PERSP_VIEW); - mymultmatrix(G.obedit->obmat); - MTC_Mat4SwapMat4(G.vd->persmat, mat); - mygetsingmatrix(G.vd->persmat); + view3d_get_object_project_mat(curarea, G.obedit, data.mat); for (index=0,eve=G.editMesh->verts.first; eve; index++,eve= eve->next) eve->prev = (EditVert*) index; @@ -1009,9 +996,6 @@ void mesh_foreachScreenVert(void (*func)(void *userData, EditVert *eve, int x, i for (preveve=NULL, eve=G.editMesh->verts.first; eve; preveve=eve, eve= eve->next) eve->prev = preveve; - MTC_Mat4SwapMat4(G.vd->persmat, mat); - myloadmatrix(G.vd->viewmat); - if (dmNeedsFree) { dm->release(dm); } @@ -1019,16 +1003,16 @@ void mesh_foreachScreenVert(void (*func)(void *userData, EditVert *eve, int x, i static void mesh_foreachScreenEdge__mapFunc(void *userData, EditEdge *eed, float *v0co, float *v1co) { - struct { void (*func)(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index); void *userData; int clipVerts; } *data = userData; + struct { void (*func)(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index); void *userData; int clipVerts; float mat[4][4]; } *data = userData; short s[2][2]; if (eed->h==0) { if (data->clipVerts==1) { - project_short(v0co, s[0]); - project_short(v1co, s[1]); + view3d_project_short(curarea, v0co, s[0], data->mat); + view3d_project_short(curarea, v1co, s[1], data->mat); } else { - project_short_noclip(v0co, s[0]); - project_short_noclip(v1co, s[1]); + view3d_project_short_noclip(curarea, v0co, s[0], data->mat); + view3d_project_short_noclip(curarea, v1co, s[1], data->mat); if (data->clipVerts==2) { if (!(s[0][0]>=0 && s[0][1]>= 0 && s[0][0]<curarea->winx && s[0][1]<curarea->winy)) @@ -1042,10 +1026,9 @@ static void mesh_foreachScreenEdge__mapFunc(void *userData, EditEdge *eed, float } void mesh_foreachScreenEdge(void (*func)(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index), void *userData, int clipVerts) { - struct { void (*func)(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index); void *userData; int clipVerts; } data; + struct { void (*func)(void *userData, EditEdge *eed, int x0, int y0, int x1, int y1, int index); void *userData; int clipVerts; float mat[4][4]; } data; int dmNeedsFree; DerivedMesh *dm = editmesh_get_derived_cage(&dmNeedsFree); - float mat[4][4]; EditEdge *eed, *preveed; int index; @@ -1053,11 +1036,7 @@ void mesh_foreachScreenEdge(void (*func)(void *userData, EditEdge *eed, int x0, data.userData = userData; data.clipVerts = clipVerts; - areawinset(curarea->win); - persp(PERSP_VIEW); - mymultmatrix(G.obedit->obmat); - MTC_Mat4SwapMat4(G.vd->persmat, mat); - mygetsingmatrix(G.vd->persmat); + view3d_get_object_project_mat(curarea, G.obedit, data.mat); for (index=0,eed=G.editMesh->edges.first; eed; index++,eed= eed->next) eed->prev = (EditEdge*) index; @@ -1067,9 +1046,6 @@ void mesh_foreachScreenEdge(void (*func)(void *userData, EditEdge *eed, int x0, for (preveed=NULL, eed=G.editMesh->edges.first; eed; preveed=eed, eed= eed->next) eed->prev = preveed; - MTC_Mat4SwapMat4(G.vd->persmat, mat); - myloadmatrix(G.vd->viewmat); - if (dmNeedsFree) { dm->release(dm); } @@ -1077,32 +1053,27 @@ void mesh_foreachScreenEdge(void (*func)(void *userData, EditEdge *eed, int x0, static void mesh_foreachScreenFace__mapFunc(void *userData, EditFace *efa, float *cent, float *no) { - struct { void (*func)(void *userData, EditFace *efa, int x, int y, int index); void *userData; } *data = userData; + struct { void (*func)(void *userData, EditFace *efa, int x, int y, int index); void *userData; float mat[4][4]; } *data = userData; short s[2]; if (efa && efa->fgonf!=EM_FGON) { - project_short(cent, s); + view3d_project_short(curarea, cent, s, data->mat); data->func(data->userData, efa, s[0], s[1], (int) efa->prev); } } void mesh_foreachScreenFace(void (*func)(void *userData, EditFace *efa, int x, int y, int index), void *userData) { - struct { void (*func)(void *userData, EditFace *efa, int x, int y, int index); void *userData; } data; + struct { void (*func)(void *userData, EditFace *efa, int x, int y, int index); void *userData; float mat[4][4]; } data; int dmNeedsFree; DerivedMesh *dm = editmesh_get_derived_cage(&dmNeedsFree); - float mat[4][4]; EditFace *efa, *prevefa; int index = 0; data.func = func; data.userData = userData; - areawinset(curarea->win); - persp(PERSP_VIEW); - mymultmatrix(G.obedit->obmat); - MTC_Mat4SwapMat4(G.vd->persmat, mat); - mygetsingmatrix(G.vd->persmat); + view3d_get_object_project_mat(curarea, G.obedit, data.mat); for (index=0,efa=G.editMesh->faces.first; efa; index++,efa= efa->next) efa->prev = (EditFace*) index; @@ -1112,9 +1083,6 @@ void mesh_foreachScreenFace(void (*func)(void *userData, EditFace *efa, int x, i for (prevefa=NULL, efa=G.editMesh->faces.first; efa; prevefa=efa, efa= efa->next) efa->prev = prevefa; - MTC_Mat4SwapMat4(G.vd->persmat, mat); - myloadmatrix(G.vd->viewmat); - if (dmNeedsFree) { dm->release(dm); } @@ -1127,11 +1095,7 @@ void nurbs_foreachScreenVert(void (*func)(void *userData, Nurb *nu, BPoint *bp, Nurb *nu; int i; - areawinset(curarea->win); - persp(PERSP_VIEW); - mymultmatrix(G.obedit->obmat); - MTC_Mat4SwapMat4(G.vd->persmat, mat); - mygetsingmatrix(G.vd->persmat); + view3d_get_object_project_mat(curarea, G.obedit, mat); for (nu= editNurb.first; nu; nu=nu->next) { if((nu->type & 7)==CU_BEZIER) { @@ -1139,11 +1103,11 @@ void nurbs_foreachScreenVert(void (*func)(void *userData, Nurb *nu, BPoint *bp, BezTriple *bezt = &nu->bezt[i]; if(bezt->hide==0) { - project_short(bezt->vec[0], s); + view3d_project_short(curarea, bezt->vec[0], s, mat); func(userData, nu, NULL, bezt, 0, s[0], s[1]); - project_short(bezt->vec[1], s); + view3d_project_short(curarea, bezt->vec[1], s, mat); func(userData, nu, NULL, bezt, 1, s[0], s[1]); - project_short(bezt->vec[2], s); + view3d_project_short(curarea, bezt->vec[2], s, mat); func(userData, nu, NULL, bezt, 2, s[0], s[1]); } } @@ -1153,15 +1117,12 @@ void nurbs_foreachScreenVert(void (*func)(void *userData, Nurb *nu, BPoint *bp, BPoint *bp = &nu->bp[i]; if(bp->hide==0) { - project_short(bp->vec, s); + view3d_project_short(curarea, bp->vec, s, mat); func(userData, nu, bp, NULL, -1, s[0], s[1]); } } } } - - MTC_Mat4SwapMat4(G.vd->persmat, mat); - myloadmatrix(G.vd->viewmat); } //// diff --git a/source/blender/src/drawview.c b/source/blender/src/drawview.c index 0cbd5047821..0a447e24505 100644 --- a/source/blender/src/drawview.c +++ b/source/blender/src/drawview.c @@ -389,6 +389,8 @@ static void draw_bgpic(void) y2= vb.ymax; } else { + float sco[2]; + /* calc window coord */ initgrabz(0.0, 0.0, 0.0); window_to_3d(vec, 1, 0); @@ -397,16 +399,10 @@ static void draw_bgpic(void) asp= ( (float)ima->ibuf->y)/(float)ima->ibuf->x; - /* This code below was lifted from project_short_noclip - * because that code fails if the point is to close to - * the near clipping plane but we don't really care about - * that here. - */ - vec[0]= vec[1]= vec[2]= 0.0; vec[3]= 1.0; - Mat4MulVec4fl(G.vd->persmat, vec); - - cx= (curarea->winx/2.0)*(1 + vec[0]/vec[3]); - cy= (curarea->winy/2.0)*(1 + vec[1]/vec[3]); + vec[0] = vec[1] = vec[2] = 0.0; + view3d_project_float(curarea, vec, sco, G.vd->persmat); + cx = sco[0]; + cy = sco[1]; x1= cx+ fac*(bgpic->xof-bgpic->size); y1= cy+ asp*fac*(bgpic->yof-bgpic->size); @@ -762,29 +758,26 @@ static void drawfloor(void) static void drawcursor(void) { - - if(G.f & G_PLAYANIM) return; + short mx,my,co[2]; - project_short( give_cursor(), &G.vd->mx); + project_short( give_cursor(), co); + mx = co[0]; + my = co[1]; - G.vd->mxo= G.vd->mx; - G.vd->myo= G.vd->my; - - if( G.vd->mx!=3200) { - + if(mx!=3200) { setlinestyle(0); cpack(0xFF); - circ((float)G.vd->mx, (float)G.vd->my, 10.0); + circ((float)mx, (float)my, 10.0); setlinestyle(4); cpack(0xFFFFFF); - circ((float)G.vd->mx, (float)G.vd->my, 10.0); + circ((float)mx, (float)my, 10.0); setlinestyle(0); cpack(0x0); - sdrawline(G.vd->mx-20, G.vd->my, G.vd->mx-5, G.vd->my); - sdrawline(G.vd->mx+5, G.vd->my, G.vd->mx+20, G.vd->my); - sdrawline(G.vd->mx, G.vd->my-20, G.vd->mx, G.vd->my-5); - sdrawline(G.vd->mx, G.vd->my+5, G.vd->mx, G.vd->my+20); + sdrawline(mx-20, my, mx-5, my); + sdrawline(mx+5, my, mx+20, my); + sdrawline(mx, my-20, mx, my-5); + sdrawline(mx, my+5, mx, my+20); } } @@ -2090,7 +2083,7 @@ void drawview3dspace(ScrArea *sa, void *spacedata) persp(PERSP_WIN); // set ortho if(v3d->persp>1) drawviewborder(); - drawcursor(); + if(!(G.f & G_PLAYANIM)) drawcursor(); draw_view_icon(); ob= OBACT; diff --git a/source/blender/src/editmesh_loop.c b/source/blender/src/editmesh_loop.c index 813498b1043..2191cc94afd 100644 --- a/source/blender/src/editmesh_loop.c +++ b/source/blender/src/editmesh_loop.c @@ -684,7 +684,7 @@ void KnifeSubdivide(char mode) /* seg_intersect() Determines if and where a mouse trail intersects an EditEdge */ -short seg_intersect(EditEdge *e, CutCurve *c, int len) +static short seg_intersect(EditEdge *e, CutCurve *c, int len) { #define MAXSLOPE 100000 float x11, y11, x12=0, y12=0, x2max, x2min, y2max; diff --git a/source/blender/src/editmesh_tools.c b/source/blender/src/editmesh_tools.c index 32e0f5c4723..f32bdef74c0 100644 --- a/source/blender/src/editmesh_tools.c +++ b/source/blender/src/editmesh_tools.c @@ -4290,13 +4290,13 @@ int EdgeSlide(short immediate, float imperc) LinkNode *edgelist = NULL, *vertlist=NULL, *look; GHash *vertgh; SlideVert *tempsv; - float perc = 0, percp = 0,vertdist; + float perc = 0, percp = 0,vertdist, projectMat[4][4]; int i = 0,j, numsel, numadded=0, timesthrough = 0, vertsel=0, prop=1, cancel = 0; short event, draw=1; short mval[2], mvalo[2]; char str[128]; - + view3d_get_object_project_mat(curarea, G.obedit, projectMat); mvalo[0] = -1; mvalo[1] = -1; numsel =0; @@ -4550,17 +4550,18 @@ int EdgeSlide(short immediate, float imperc) BLI_linklist_free(edgelist,NULL); return 0; } - if(!sharesFace(tempsv->up,sv->up)){ - EditEdge *swap; - swap = sv->up; - sv->up = sv->down; - sv->down = swap; - } if(sv) { float tempdist, co[2]; - project_float(sv->origvert.co, co); + if(!sharesFace(tempsv->up,sv->up)){ + EditEdge *swap; + swap = sv->up; + sv->up = sv->down; + sv->down = swap; + } + + view3d_project_float(curarea, tempsv->origvert.co, co, projectMat); tempdist = sqrt(pow(co[0] - mval[0],2)+pow(co[1] - mval[1],2)); @@ -4583,7 +4584,7 @@ int EdgeSlide(short immediate, float imperc) /* For the % calculation */ short mval[2]; float labda, rc[2], len; - float v1[2], v2[2], v3[2]; + float v2[2], v3[2]; EditVert *centerVert, *upVert, *downVert; getmouseco_areawin(mval); @@ -4617,17 +4618,9 @@ int EdgeSlide(short immediate, float imperc) tempsv = BLI_ghash_lookup(vertgh,nearest); - getmouseco_areawin(mval); - v1[0]=(float)mval[0]; - v1[1]=(float)mval[1]; - centerVert = editedge_getSharedVert(tempsv->up, tempsv->down); upVert = editedge_getOtherVert(tempsv->up, centerVert); downVert = editedge_getOtherVert(tempsv->down, centerVert); - - project_float(upVert->co, v2); - project_float(downVert->co, v3); - // Highlight the Control Edges scrarea_do_windraw(curarea); @@ -4641,19 +4634,22 @@ int EdgeSlide(short immediate, float imperc) glVertex3fv(downVert->co); glEnd(); glPopMatrix(); - + + view3d_project_float(curarea, upVert->co, v2, projectMat); + view3d_project_float(curarea, downVert->co, v3, projectMat); + /* Determine the % on which the loop should be cut */ - rc[0]= v3[0]-v2[0]; - rc[1]= v3[1]-v2[1]; - len= rc[0]*rc[0]+ rc[1]*rc[1]; - if (len==0) {len = 0.0001;} - labda= ( rc[0]*(v1[0]-v2[0]) + rc[1]*(v1[1]-v2[1]) )/len; + rc[0]= v3[0]-v2[0]; + rc[1]= v3[1]-v2[1]; + len= rc[0]*rc[0]+ rc[1]*rc[1]; + if (len==0) {len = 0.0001;} + labda= ( rc[0]*(mval[0]-v2[0]) + rc[1]*(mval[1]-v2[1]) )/len; - if(labda<=0.0) labda=0.0; - else if(labda>=1.0)labda=1.0; + if(labda<=0.0) labda=0.0; + else if(labda>=1.0)labda=1.0; - perc=((1-labda)*2)-1; + perc=((1-labda)*2)-1; if(G.qual == 0){ perc *= 100; diff --git a/source/blender/src/editview.c b/source/blender/src/editview.c index 041aa894dcd..0710a1e8703 100644 --- a/source/blender/src/editview.c +++ b/source/blender/src/editview.c @@ -807,43 +807,40 @@ void mouse_cursor(void) if(gesture()) return; getmouseco_areawin(mval); + + mx= mval[0]; + my= mval[1]; + + fp= give_cursor(); - if(mval[0]!=G.vd->mx || mval[1]!=G.vd->my) { + if(G.obedit && ((G.qual & LR_CTRLKEY) || get_mbut()&R_MOUSE )) lr_click= 1; + VECCOPY(oldcurs, fp); + + project_short_noclip(fp, mval); - mx= mval[0]; - my= mval[1]; - - fp= give_cursor(); + initgrabz(fp[0], fp[1], fp[2]); + + if(mval[0]!=3200) { - if(G.obedit && ((G.qual & LR_CTRLKEY) || get_mbut()&R_MOUSE )) lr_click= 1; - VECCOPY(oldcurs, fp); + window_to_3d(dvec, mval[0]-mx, mval[1]-my); + VecSubf(fp, fp, dvec); - project_short_noclip(fp, mval); + } + else { - initgrabz(fp[0], fp[1], fp[2]); + dx= ((float)(mx-(curarea->winx/2)))*zfac/(curarea->winx/2); + dy= ((float)(my-(curarea->winy/2)))*zfac/(curarea->winy/2); - if(mval[0]!=3200) { - - window_to_3d(dvec, mval[0]-mx, mval[1]-my); - VecSubf(fp, fp, dvec); - - } - else { - - dx= ((float)(mx-(curarea->winx/2)))*zfac/(curarea->winx/2); - dy= ((float)(my-(curarea->winy/2)))*zfac/(curarea->winy/2); - - fz= G.vd->persmat[0][3]*fp[0]+ G.vd->persmat[1][3]*fp[1]+ G.vd->persmat[2][3]*fp[2]+ G.vd->persmat[3][3]; - fz= fz/zfac; - - fp[0]= (G.vd->persinv[0][0]*dx + G.vd->persinv[1][0]*dy+ G.vd->persinv[2][0]*fz)-G.vd->ofs[0]; - fp[1]= (G.vd->persinv[0][1]*dx + G.vd->persinv[1][1]*dy+ G.vd->persinv[2][1]*fz)-G.vd->ofs[1]; - fp[2]= (G.vd->persinv[0][2]*dx + G.vd->persinv[1][2]*dy+ G.vd->persinv[2][2]*fz)-G.vd->ofs[2]; - } + fz= G.vd->persmat[0][3]*fp[0]+ G.vd->persmat[1][3]*fp[1]+ G.vd->persmat[2][3]*fp[2]+ G.vd->persmat[3][3]; + fz= fz/zfac; - allqueue(REDRAWVIEW3D, 1); + fp[0]= (G.vd->persinv[0][0]*dx + G.vd->persinv[1][0]*dy+ G.vd->persinv[2][0]*fz)-G.vd->ofs[0]; + fp[1]= (G.vd->persinv[0][1]*dx + G.vd->persinv[1][1]*dy+ G.vd->persinv[2][1]*fz)-G.vd->ofs[1]; + fp[2]= (G.vd->persinv[0][2]*dx + G.vd->persinv[1][2]*dy+ G.vd->persinv[2][2]*fz)-G.vd->ofs[2]; } + allqueue(REDRAWVIEW3D, 1); + if(lr_click) { if(G.obedit->type==OB_MESH) addvert_mesh(); else if ELEM(G.obedit->type, OB_CURVE, OB_SURF) addvert_Nurb(0); diff --git a/source/blender/src/view.c b/source/blender/src/view.c index bd0e9f21e46..ba70a06489a 100644 --- a/source/blender/src/view.c +++ b/source/blender/src/view.c @@ -259,6 +259,87 @@ void project_float(float *vec, float *adr) } } +void view3d_get_object_project_mat(ScrArea *area, Object *ob, float mat[4][4]) +{ + if (area->spacetype!=SPACE_VIEW3D || !area->spacedata.first) { + Mat4One(mat); + } else { + View3D *vd = area->spacedata.first; + float tmp[4][4]; + + Mat4MulMat4(tmp, ob->obmat, vd->viewmat); + Mat4MulMat4(mat, tmp, vd->winmat1); + } +} + +void view3d_project_short(ScrArea *area, float *vec, short *adr, float mat[4][4]) +{ + float fx, fy, vec4[4]; + + adr[0]= 3200; + VECCOPY(vec4, vec); + vec4[3]= 1.0; + + Mat4MulVec4fl(mat, vec4); + + if( vec4[3]>BL_NEAR_CLIP ) { /* 0.001 is the NEAR clipping cutoff for picking */ + fx= (area->winx/2)*(1 + vec4[0]/vec4[3]); + + if( fx>0 && fx<area->winx) { + + fy= (area->winy/2)*(1 + vec4[1]/vec4[3]); + + if(fy>0.0 && fy< (float)area->winy) { + adr[0]= floor(fx); + adr[1]= floor(fy); + } + } + } +} + +void view3d_project_short_noclip(ScrArea *area, float *vec, short *adr, float mat[4][4]) +{ + float fx, fy, vec4[4]; + + adr[0]= 3200; + VECCOPY(vec4, vec); + vec4[3]= 1.0; + + Mat4MulVec4fl(mat, vec4); + + if( vec4[3]>BL_NEAR_CLIP ) { /* 0.001 is the NEAR clipping cutoff for picking */ + fx= (area->winx/2)*(1 + vec4[0]/vec4[3]); + + if( fx>-32700 && fx<32700) { + + fy= (area->winy/2)*(1 + vec4[1]/vec4[3]); + + if(fy>-32700.0 && fy<32700.0) { + adr[0]= floor(fx); + adr[1]= floor(fy); + } + } + } +} + +void view3d_project_float(ScrArea *area, float *vec, float *adr, float mat[4][4]) +{ + float vec4[4]; + + adr[0]= 3200.0; + VECCOPY(vec4, vec); + vec4[3]= 1.0; + + Mat4MulVec4fl(mat, vec4); + + if( vec4[3]>FLT_EPSILON ) { + adr[0] = (area->winx/2.0)+(area->winx/2.0)*vec4[0]/vec4[3]; + adr[1] = (area->winy/2.0)+(area->winy/2.0)*vec4[1]/vec4[3]; + } else { + adr[0] = adr[1] = 0.0; + } +} + int boundbox_clip(float obmat[][4], BoundBox *bb) { /* return 1: draw */ |