diff options
author | Ton Roosendaal <ton@blender.org> | 2005-06-05 16:24:35 +0400 |
---|---|---|
committer | Ton Roosendaal <ton@blender.org> | 2005-06-05 16:24:35 +0400 |
commit | f99b6a304249b9645bbaa3c20abc282e899a512d (patch) | |
tree | b8572acd392301aba6cd874d989236dc70c28493 /source/blender/src/transform.c | |
parent | f38e0686d909aa0d2882c197aeff59eeefa17081 (diff) |
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.
Diffstat (limited to 'source/blender/src/transform.c')
-rwxr-xr-x | source/blender/src/transform.c | 12 |
1 files 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; |