From f99b6a304249b9645bbaa3c20abc282e899a512d Mon Sep 17 00:00:00 2001 From: Ton Roosendaal Date: Sun, 5 Jun 2005 12:24:35 +0000 Subject: 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. --- source/blender/src/transform.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/blender/src/transform.c b/source/blender/src/transform.c index bc26252007a..9abc5250e49 100755 --- a/source/blender/src/transform.c +++ b/source/blender/src/transform.c @@ -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; -- cgit v1.2.3