Code Cleanup: use math functions and reduce View3d axis drawing into a loop

This commit is contained in:
Campbell Barton
2013-11-24 21:25:05 +11:00
parent 0c7d2de382
commit 1decd824f3
5 changed files with 43 additions and 87 deletions

View File

@@ -301,8 +301,9 @@ void bmo_create_uvsphere_exec(BMesh *bm, BMOperator *op)
BMVert *eve, *preveve;
BMEdge *e;
BMIter iter;
float vec[3], mat[4][4], cmat[3][3], phi, q[4];
float phid;
const float axis[3] = {0, 0, 1};
float vec[3], mat[4][4], cmat[3][3];
float phi, phid;
int a;
BMO_slot_mat4_get(op->slots_in, "matrix", mat);
@@ -331,11 +332,7 @@ void bmo_create_uvsphere_exec(BMesh *bm, BMOperator *op)
}
/* extrude and rotate; negative phi to make normals face outward */
phi = -M_PI / seg;
q[0] = cosf(phi);
q[3] = sinf(phi);
q[1] = q[2] = 0.0f;
quat_to_mat3(cmat, q);
axis_angle_to_mat3(cmat, axis, -(M_PI * 2) / seg);
for (a = 0; a < seg; a++) {
if (a) {

View File

@@ -4364,7 +4364,7 @@ bool ed_editnurb_spin(float viewmat[4][4], Object *obedit, const float axis[3],
Curve *cu = (Curve *)obedit->data;
ListBase *editnurb = object_editcurve_get(obedit);
Nurb *nu;
float si, phi, n[3], q[4], cmat[3][3], tmat[3][3], imat[3][3];
float cmat[3][3], tmat[3][3], imat[3][3];
float bmat[3][3], rotmat[3][3], scalemat1[3][3], scalemat2[3][3];
float persmat[3][3], persinv[3][3];
bool ok, changed = false;
@@ -4377,15 +4377,7 @@ bool ed_editnurb_spin(float viewmat[4][4], Object *obedit, const float axis[3],
copy_m3_m4(bmat, obedit->obmat);
invert_m3_m3(imat, bmat);
normalize_v3_v3(n, axis);
/* TODO - use math func */
phi = M_PI / 8.0;
q[0] = cos(phi);
si = sin(phi);
q[1] = n[0] * si;
q[2] = n[1] * si;
q[3] = n[2] * si;
quat_to_mat3(cmat, q);
axis_angle_to_mat3(cmat, axis, M_PI / 4.0);
mul_m3_m3m3(tmat, cmat, bmat);
mul_m3_m3m3(rotmat, imat, tmat);

View File

@@ -1210,18 +1210,16 @@ static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
/* skip drawing extra info */
}
else if ((la->type == LA_SPOT) || (la->type == LA_YF_PHOTON)) {
lvec[0] = lvec[1] = 0.0;
lvec[2] = 1.0;
x = rv3d->persmat[0][2];
y = rv3d->persmat[1][2];
z = rv3d->persmat[2][2];
vvec[0] = x * ob->obmat[0][0] + y * ob->obmat[0][1] + z * ob->obmat[0][2];
vvec[1] = x * ob->obmat[1][0] + y * ob->obmat[1][1] + z * ob->obmat[1][2];
vvec[2] = x * ob->obmat[2][0] + y * ob->obmat[2][1] + z * ob->obmat[2][2];
y = cosf(la->spotsize * (float)(M_PI / 360.0));
spotvolume(lvec, vvec, y);
copy_v3_fl3(lvec, 0.0f, 0.0f, 1.0f);
copy_v3_fl3(vvec, rv3d->persmat[0][2], rv3d->persmat[1][2], rv3d->persmat[2][2]);
mul_mat3_m4_v3(ob->obmat, vvec);
x = -la->dist;
y = cosf(la->spotsize * (float)(M_PI / 360.0));
z = x * sqrtf(1.0f - y * y);
spotvolume(lvec, vvec, y);
mul_v3_fl(lvec, x);
mul_v3_fl(vvec, x);
@@ -1232,7 +1230,6 @@ static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
glVertex3fv(lvec);
glEnd();
z = x * sqrtf(1.0f - y * y);
x *= y;
/* draw the circle/square at the end of the cone */

View File

@@ -583,7 +583,9 @@ static void draw_view_axis(RegionView3D *rv3d, rcti *rect)
float ydisp = 0.0; /* vertical displacement to allow obj info text */
int bright = - 20 * (10 - U.rvibright); /* axis alpha offset (rvibright has range 0-10) */
float vec[3];
char axis_text[2] = "x";
float dx, dy;
int i;
startx += rect->xmin;
starty += rect->ymin;
@@ -594,60 +596,27 @@ static void draw_view_axis(RegionView3D *rv3d, rcti *rect)
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
/* X */
vec[0] = 1;
vec[1] = vec[2] = 0;
mul_qt_v3(rv3d->viewquat, vec);
dx = vec[0] * k;
dy = vec[1] * k;
UI_ThemeColorShadeAlpha(TH_AXIS_X, 0, bright);
glBegin(GL_LINES);
glVertex2f(startx, starty + ydisp);
glVertex2f(startx + dx, starty + dy + ydisp);
glEnd();
for (i = 0; i < 3; i++) {
zero_v3(vec);
vec[i] = 1.0f;
mul_qt_v3(rv3d->viewquat, vec);
dx = vec[0] * k;
dy = vec[1] * k;
if (fabsf(dx) > toll || fabsf(dy) > toll) {
BLF_draw_default_ascii(startx + dx + 2, starty + dy + ydisp + 2, 0.0f, "x", 1);
}
/* BLF_draw_default disables blending */
glEnable(GL_BLEND);
UI_ThemeColorShadeAlpha(TH_AXIS_X + i, 0, bright);
glBegin(GL_LINES);
glVertex2f(startx, starty + ydisp);
glVertex2f(startx + dx, starty + dy + ydisp);
glEnd();
/* Y */
vec[1] = 1;
vec[0] = vec[2] = 0;
mul_qt_v3(rv3d->viewquat, vec);
dx = vec[0] * k;
dy = vec[1] * k;
UI_ThemeColorShadeAlpha(TH_AXIS_Y, 0, bright);
glBegin(GL_LINES);
glVertex2f(startx, starty + ydisp);
glVertex2f(startx + dx, starty + dy + ydisp);
glEnd();
if (fabsf(dx) > toll || fabsf(dy) > toll) {
BLF_draw_default_ascii(startx + dx + 2, starty + dy + ydisp + 2, 0.0f, axis_text, 1);
}
if (fabsf(dx) > toll || fabsf(dy) > toll) {
BLF_draw_default_ascii(startx + dx + 2, starty + dy + ydisp + 2, 0.0f, "y", 1);
}
axis_text[0]++;
glEnable(GL_BLEND);
/* Z */
vec[2] = 1;
vec[1] = vec[0] = 0;
mul_qt_v3(rv3d->viewquat, vec);
dx = vec[0] * k;
dy = vec[1] * k;
UI_ThemeColorShadeAlpha(TH_AXIS_Z, 0, bright);
glBegin(GL_LINES);
glVertex2f(startx, starty + ydisp);
glVertex2f(startx + dx, starty + dy + ydisp);
glEnd();
if (fabsf(dx) > toll || fabsf(dy) > toll) {
BLF_draw_default_ascii(startx + dx + 2, starty + dy + ydisp + 2, 0.0f, "z", 1);
/* BLF_draw_default disables blending */
glEnable(GL_BLEND);
}
/* restore line-width */

View File

@@ -4144,16 +4144,17 @@ void ED_view3d_cursor3d_position(bContext *C, float fp[3], const int mval[2])
}
}
else {
const float dx = ((float)(mval[0] - (ar->winx / 2))) * zfac / (ar->winx / 2);
const float dy = ((float)(mval[1] - (ar->winy / 2))) * zfac / (ar->winy / 2);
const float fz = (rv3d->persmat[0][3] * fp[0] +
rv3d->persmat[1][3] * fp[1] +
rv3d->persmat[2][3] * fp[2] +
rv3d->persmat[3][3]) / zfac;
float tvec[3];
fp[0] = (rv3d->persinv[0][0] * dx + rv3d->persinv[1][0] * dy + rv3d->persinv[2][0] * fz) - rv3d->ofs[0];
fp[1] = (rv3d->persinv[0][1] * dx + rv3d->persinv[1][1] * dy + rv3d->persinv[2][1] * fz) - rv3d->ofs[1];
fp[2] = (rv3d->persinv[0][2] * dx + rv3d->persinv[1][2] * dy + rv3d->persinv[2][2] * fz) - rv3d->ofs[2];
tvec[0] = ((float)(mval[0] - (ar->winx / 2))) * zfac / (ar->winx / 2);
tvec[1] = ((float)(mval[1] - (ar->winy / 2))) * zfac / (ar->winy / 2);
tvec[2] = (rv3d->persmat[0][3] * fp[0] +
rv3d->persmat[1][3] * fp[1] +
rv3d->persmat[2][3] * fp[2] +
rv3d->persmat[3][3]) / zfac;
mul_mat3_m4_v3(rv3d->persinv, tvec);
sub_v3_v3v3(fp, tvec, rv3d->ofs);
}
}