Float precision error could cause RKEY to start with 0.02 degree rotation.

This because the used integer+float division could result in a
9.999999e-01 value, which is for acos() to return 3.452670e-04.

Converted the division to use doubles instead.
This commit is contained in:
2005-06-05 12:24:35 +00:00
parent f38e0686d9
commit f99b6a3042

View File

@@ -1485,17 +1485,17 @@ int Rotation(TransInfo *t, short mval[2])
int dx2 = t->center2d[0] - mval[0];
int dy2 = t->center2d[1] - mval[1];
float B = (float)sqrt(dx2*dx2+dy2*dy2);
double B = sqrt(dx2*dx2+dy2*dy2);
int dx1 = t->center2d[0] - t->imval[0];
int dy1 = t->center2d[1] - t->imval[1];
float A = (float)sqrt(dx1*dx1+dy1*dy1);
double A = sqrt(dx1*dx1+dy1*dy1);
int dx3 = mval[0] - t->imval[0];
int dy3 = mval[1] - t->imval[1];
float deler= ((dx1*dx1+dy1*dy1)+(dx2*dx2+dy2*dy2)-(dx3*dx3+dy3*dy3))
/ (2 * (A*B?A*B:1.0f));
/* use doubles here, to make sure a "1.0" (no rotation) doesnt become 9.999999e-01, which gives 0.02 for acos */
double deler= ((double)((dx1*dx1+dy1*dy1)+(dx2*dx2+dy2*dy2)-(dx3*dx3+dy3*dy3) ))
/ (2.0 * (A*B?A*B:1.0));
/* (A*B?A*B:1.0f) this takes care of potential divide by zero errors */
float dphi;
@@ -1507,7 +1507,7 @@ int Rotation(TransInfo *t, short mval[2])
VecMulf(axis, -1.0f);
Normalise(axis);
dphi = saacos(deler);
dphi = saacos((float)deler);
if( (dx1*dy2-dx2*dy1)>0.0 ) dphi= -dphi;
if(G.qual & LR_SHIFTKEY) t->fac += dphi/30.0f;