[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [13448] trunk/blender/source/blender/ python/api2_2x:

Brecht Van Lommel brechtvanlommel at pandora.be
Tue Jan 29 10:44:29 CET 2008


Revision: 13448
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=13448
Author:   blendix
Date:     2008-01-29 10:44:26 +0100 (Tue, 29 Jan 2008)

Log Message:
-----------

Bugfix: quaternion angle calculation in python used the acos function.
This gives nan if the input is e.g. 1.00000001 due to rounding errors,
better is to use saacos (safe acos) that checks for the range first.

Modified Paths:
--------------
    trunk/blender/source/blender/python/api2_2x/Mathutils.c
    trunk/blender/source/blender/python/api2_2x/quat.c

Modified: trunk/blender/source/blender/python/api2_2x/Mathutils.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Mathutils.c	2008-01-29 08:57:41 UTC (rev 13447)
+++ trunk/blender/source/blender/python/api2_2x/Mathutils.c	2008-01-29 09:44:26 UTC (rev 13448)
@@ -1,5 +1,5 @@
 /* 
- * $Id: Mathutils.c 11502 2007-08-06 14:27:08Z khughes $
+ * $Id$
  *
  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
  *
@@ -500,10 +500,7 @@
 	}
 	dot /= (sqrt(test_v1) * sqrt(test_v2));
 
-	if (dot < -1.0f || dot > 1.0f) {
-		CLAMP(dot,-1.0f,1.0f);
-	}
-	angleRads = (double)acos(dot);
+	angleRads = (double)saacos(dot);
 
 	return PyFloat_FromDouble(angleRads * (180/ Py_PI));
 

Modified: trunk/blender/source/blender/python/api2_2x/quat.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/quat.c	2008-01-29 08:57:41 UTC (rev 13447)
+++ trunk/blender/source/blender/python/api2_2x/quat.c	2008-01-29 09:44:26 UTC (rev 13448)
@@ -1,5 +1,5 @@
 /*
- * $Id: quat.c 12314 2007-10-20 20:24:09Z campbellbarton $
+ * $Id$
  *
  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
  *
@@ -184,13 +184,13 @@
 	}
 	if(STREQ(name, "angle")) {
 		mag = self->quat[0];
-		mag = 2 * (acos(mag));
+		mag = 2 * (saacos(mag));
 		mag *= (180 / Py_PI);
 		return PyFloat_FromDouble(mag);
 	}
 	if(STREQ(name, "axis")) {
 		mag = self->quat[0] * (Py_PI / 180);
-		mag = 2 * (acos(mag));
+		mag = 2 * (saacos(mag));
 		mag = sin(mag / 2);
 		for(x = 0; x < 3; x++) {
 			vec[x] = (float)(self->quat[x + 1] / mag);





More information about the Bf-blender-cvs mailing list