[Bf-committers] Align view to edge (rotate about edge)
Campbell Barton
cbarton at metavr.com
Fri Jan 20 13:21:50 CET 2006
Hi, Hers a small addision to editmesh_mods.c that allows aligning teh
view to an edge. (2 verts) - see the last ~12 lines.
It seems trivial, but at the moment there is no easy way to rotate
around an edge- with this- "Align to view" & "Constrain transform to
view" - could be used to rotate about en edge.
Zr- do you own this module? - is it worth writing a patch?
- Cam
____________
void editmesh_align_view_to_selected(View3D *v3d, int axis)
{
EditMesh *em = G.editMesh;
int nselverts= EM_nvertices_selected();
if (nselverts<2) {
if (nselverts==0) {
error("No faces or vertices selected.");
} else {
error("At least one face or three vertices must be selected.");
}
} else if (EM_nfaces_selected()) {
float norm[3];
EditFace *efa;
norm[0]= norm[1]= norm[2]= 0.0;
for (efa= em->faces.first; efa; efa= efa->next) {
if (faceselectedAND(efa, SELECT)) {
float fno[3];
if (efa->v4) CalcNormFloat4(efa->v1->co, efa->v2->co,
efa->v3->co, efa->v4->co, fno);
else CalcNormFloat(efa->v1->co, efa->v2->co,
efa->v3->co, fno);
/* XXX, fixme, should be flipped intp a
* consistent direction. -zr
*/
norm[0]+= fno[0];
norm[1]+= fno[1];
norm[2]+= fno[2];
}
}
Mat4Mul3Vecfl(G.obedit->obmat, norm);
view3d_align_axis_to_vector(v3d, axis, norm);
} else if (nselverts>2) {
float cent[3], norm[3];
EditVert *eve, *leve= NULL;
norm[0]= norm[1]= norm[2]= 0.0;
editmesh_calc_selvert_center(cent);
for (eve= em->verts.first; eve; eve= eve->next) {
if (eve->f & SELECT) {
if (leve) {
float tno[3];
CalcNormFloat(cent, leve->co, eve->co, tno);
/* XXX, fixme, should be flipped intp a
* consistent direction. -zr
*/
norm[0]+= tno[0];
norm[1]+= tno[1];
norm[2]+= tno[2];
}
leve= eve;
}
}
Mat4Mul3Vecfl(G.obedit->obmat, norm);
view3d_align_axis_to_vector(v3d, axis, norm);
} else { /* Align view to edge (or 2 verts) */
float norm[3];
EditVert *eve, *leve= NULL;
norm[0]= norm[1]= norm[2]= 0.0;
for (eve= em->verts.first; eve; eve= eve->next) {
if (eve->f & SELECT) {
if (leve) {
norm[0]= leve->co[0] - eve->co[0];
norm[1]= leve->co[1] - eve->co[1];
norm[2]= leve->co[2] - eve->co[2];
}
leve= eve;
}
}
Mat4Mul3Vecfl(G.obedit->obmat, norm);
view3d_align_axis_to_vector(v3d, axis, norm);
}
}
--
Campbell J Barton
133 Hope Street
Geelong West, Victoria 3218 Australia
URL: http://www.metavr.com
e-mail: cbarton at metavr.com
phone: AU (03) 5229 0241
More information about the Bf-committers
mailing list