diff options
-rw-r--r-- | main.c | 2 | ||||
-rw-r--r-- | qb.c | 15 |
2 files changed, 9 insertions, 8 deletions
@@ -191,7 +191,7 @@ redraw(void) n = normvec3(crossvec( subvec3(trans.p1, trans.p0), subvec3(trans.p2, trans.p0))); - if(dotvec3(n, subvec3(trans.p0, Vec3(0, 0, 0))) < 0){ + if(dotvec3(n, trans.p0) < 0){ trans.p0 = mulvecm(trans.p0, proj); trans.p1 = mulvecm(trans.p1, proj); trans.p2 = mulvecm(trans.p2, proj); @@ -48,29 +48,30 @@ mouseq(Point2 p, Quaternion *axis){ if(rsq > 1){ rsq = sqrt(rsq); - q.k = 0; + q.r = 0; q.i = p.x/rsq; q.j = p.y/rsq; - q.r = 0; - } - else{ + q.k = 0; + }else{ q.r = 0; q.i = p.x; q.j = p.y; q.k = sqrt(1 - rsq); } + if(axis != nil){ - l = q.i*axis->i + q.j*axis->j + q.k*axis->k; + l = dotq(q, *axis); q.i -= l*axis->i; q.j -= l*axis->j; q.k -= l*axis->k; - l = sqrt(q.i*q.i + q.j*q.j + q.k*q.k); - if(l != 0.){ + l = qlen(q); + if(l != 0){ q.i /= l; q.j /= l; q.k /= l; } } + return q; } |