[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16127] trunk/blender/source/gameengine/ Converter/BL_BlenderDataConversion.cpp: BGE bug fix: the fix in revision 16022 for bug #17450 was wrong: the formula used to extract scaling and rotation was giving incorrect results for some type of rotation , leading to wrong position and orientation for parented objects with no scale applied .

Benoit Bolsee benoit.bolsee at online.be
Sat Aug 16 00:17:50 CEST 2008


Revision: 16127
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16127
Author:   ben2610
Date:     2008-08-16 00:17:50 +0200 (Sat, 16 Aug 2008)

Log Message:
-----------
BGE bug fix: the fix in revision 16022 for bug #17450 was wrong: the formula used to extract scaling and rotation was giving incorrect results for some type of rotation, leading to wrong position and orientation for parented objects with no scale applied. The new formula follows Blender's internal math.

Revision Links:
--------------
    http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16022

Modified Paths:
--------------
    trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp

Modified: trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp
===================================================================
--- trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp	2008-08-15 20:55:38 UTC (rev 16126)
+++ trunk/blender/source/gameengine/Converter/BL_BlenderDataConversion.cpp	2008-08-15 22:17:50 UTC (rev 16127)
@@ -1946,10 +1946,22 @@
 				//parentinversenode->SetLocalOrientation(parinvtrans.getBasis());
 
 				// Extract the rotation and the scaling from the basis
-				MT_Matrix3x3 inverseOrientation(parinvtrans.getRotation());
-				parentinversenode->SetLocalOrientation(inverseOrientation);
-				MT_Matrix3x3 scale(inverseOrientation.transposed()*parinvtrans.getBasis());
-				parentinversenode->SetLocalScale(MT_Vector3(scale[0][0], scale[1][1], scale[2][2]));
+				MT_Matrix3x3 ori(parinvtrans.getBasis());
+				MT_Vector3 x(ori.getColumn(0));
+				MT_Vector3 y(ori.getColumn(1));
+				MT_Vector3 z(ori.getColumn(2));
+				MT_Vector3 scale(x.length(), y.length(), z.length());
+				if (!MT_fuzzyZero(scale[0]))
+					x /= scale[0];
+				if (!MT_fuzzyZero(scale[1]))
+					y /= scale[1];
+				if (!MT_fuzzyZero(scale[2]))
+					z /= scale[2];
+				ori.setColumn(0, x);								
+				ori.setColumn(1, y);								
+				ori.setColumn(2, z);								
+				parentinversenode->SetLocalOrientation(ori);
+				parentinversenode->SetLocalScale(scale);
 				
 				parentinversenode->AddChild(gameobj->GetSGNode());
 			}
@@ -2129,7 +2141,24 @@
 								float* fl = (float*) blenderobject->parentinv;
 								MT_Transform parinvtrans(fl);
 								parentinversenode->SetLocalPosition(parinvtrans.getOrigin());
-								parentinversenode->SetLocalOrientation(parinvtrans.getBasis());
+
+								// Extract the rotation and the scaling from the basis
+								MT_Matrix3x3 ori(parinvtrans.getBasis());
+								MT_Vector3 x(ori.getColumn(0));
+								MT_Vector3 y(ori.getColumn(1));
+								MT_Vector3 z(ori.getColumn(2));
+								MT_Vector3 scale(x.length(), y.length(), z.length());
+								if (!MT_fuzzyZero(scale[0]))
+									x /= scale[0];
+								if (!MT_fuzzyZero(scale[1]))
+									y /= scale[1];
+								if (!MT_fuzzyZero(scale[2]))
+									z /= scale[2];
+								ori.setColumn(0, x);								
+								ori.setColumn(1, y);								
+								ori.setColumn(2, z);								
+								parentinversenode->SetLocalOrientation(ori);
+								parentinversenode->SetLocalScale(scale);
 								
 								parentinversenode->AddChild(gameobj->GetSGNode());
 							}





More information about the Bf-blender-cvs mailing list