[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15394] trunk/blender/source/gameengine/ Ketsji/KX_TrackToActuator.cpp: track to would crash (with a C++ assert) if the source and target are in the same location, which I have had happen a few times while testing.

Campbell Barton ideasman42 at gmail.com
Tue Jul 1 07:17:09 CEST 2008


Revision: 15394
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15394
Author:   campbellbarton
Date:     2008-07-01 07:16:08 +0200 (Tue, 01 Jul 2008)

Log Message:
-----------
track to would crash (with a C++ assert) if the source and target are in the same location, which I have had happen a few times while testing.

Modified Paths:
--------------
    trunk/blender/source/gameengine/Ketsji/KX_TrackToActuator.cpp

Modified: trunk/blender/source/gameengine/Ketsji/KX_TrackToActuator.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_TrackToActuator.cpp	2008-06-30 22:57:52 UTC (rev 15393)
+++ trunk/blender/source/gameengine/Ketsji/KX_TrackToActuator.cpp	2008-07-01 05:16:08 UTC (rev 15394)
@@ -224,7 +224,8 @@
 	{
 		KX_GameObject* curobj = (KX_GameObject*) GetParent();
 		MT_Vector3 dir = ((KX_GameObject*)m_object)->NodeGetWorldPosition() - curobj->NodeGetWorldPosition();
-		dir.normalize();
+		if (dir.length2())
+			dir.normalize();
 		MT_Vector3 up(0,0,1);
 		
 		
@@ -250,12 +251,12 @@
 #endif 
 		if (m_allow3D)
 		{
-			up = (up - up.dot(dir) * dir).normalized();
+			up = (up - up.dot(dir) * dir).safe_normalized();
 			
 		}
 		else
 		{
-			dir = (dir - up.dot(dir)*up).normalized();
+			dir = (dir - up.dot(dir)*up).safe_normalized();
 		}
 		
 		MT_Vector3 left;
@@ -266,8 +267,8 @@
 		case 0: // TRACK X
 			{
 				// (1.0 , 0.0 , 0.0 ) x direction is forward, z (0.0 , 0.0 , 1.0 ) up
-				left  = dir.normalized();
-				dir = (left.cross(up)).normalized();
+				left  = dir.safe_normalized();
+				dir = (left.cross(up)).safe_normalized();
 				mat.setValue (
 					left[0], dir[0],up[0], 
 					left[1], dir[1],up[1],
@@ -279,7 +280,7 @@
 		case 1:	// TRACK Y
 			{
 				// (0.0 , 1.0 , 0.0 ) y direction is forward, z (0.0 , 0.0 , 1.0 ) up
-				left  = (dir.cross(up)).normalized();
+				left  = (dir.cross(up)).safe_normalized();
 				mat.setValue (
 					left[0], dir[0],up[0], 
 					left[1], dir[1],up[1],
@@ -291,10 +292,10 @@
 			
 		case 2: // track Z
 			{
-				left = up.normalized();
-				up = dir.normalized();
+				left = up.safe_normalized();
+				up = dir.safe_normalized();
 				dir = left;
-				left  = (dir.cross(up)).normalized();
+				left  = (dir.cross(up)).safe_normalized();
 				mat.setValue (
 					left[0], dir[0],up[0], 
 					left[1], dir[1],up[1],
@@ -306,8 +307,8 @@
 		case 3: // TRACK -X
 			{
 				// (1.0 , 0.0 , 0.0 ) x direction is forward, z (0.0 , 0.0 , 1.0 ) up
-				left  = -dir.normalized();
-				dir = -(left.cross(up)).normalized();
+				left  = -dir.safe_normalized();
+				dir = -(left.cross(up)).safe_normalized();
 				mat.setValue (
 					left[0], dir[0],up[0], 
 					left[1], dir[1],up[1],
@@ -319,7 +320,7 @@
 		case 4: // TRACK -Y
 			{
 				// (0.0 , -1.0 , 0.0 ) -y direction is forward, z (0.0 , 0.0 , 1.0 ) up
-				left  = (-dir.cross(up)).normalized();
+				left  = (-dir.cross(up)).safe_normalized();
 				mat.setValue (
 					left[0], -dir[0],up[0], 
 					left[1], -dir[1],up[1],
@@ -329,10 +330,10 @@
 			}
 		case 5: // track -Z
 			{
-				left = up.normalized();
-				up = -dir.normalized();
+				left = up.safe_normalized();
+				up = -dir.safe_normalized();
 				dir = left;
-				left  = (dir.cross(up)).normalized();
+				left  = (dir.cross(up)).safe_normalized();
 				mat.setValue (
 					left[0], dir[0],up[0], 
 					left[1], dir[1],up[1],
@@ -345,8 +346,8 @@
 		default:
 			{
 				// (1.0 , 0.0 , 0.0 ) -x direction is forward, z (0.0 , 0.0 , 1.0 ) up
-				left  = -dir.normalized();
-				dir = -(left.cross(up)).normalized();
+				left  = -dir.safe_normalized();
+				dir = -(left.cross(up)).safe_normalized();
 				mat.setValue (
 					left[0], dir[0],up[0], 
 					left[1], dir[1],up[1],





More information about the Bf-blender-cvs mailing list