[Bf-blender-cvs] [2e5bd8d] soc-2014-bge: gameengine scenegraph: correction of relative postition computation, fixes T28908

Ines Almeida noreply at git.blender.org
Sat Jul 12 20:16:39 CEST 2014


Commit: 2e5bd8d41821007cf91cf0c711cb5809b4600a91
Author: Ines Almeida
Date:   Mon Jul 7 11:52:39 2014 +0100
https://developer.blender.org/rB2e5bd8d41821007cf91cf0c711cb5809b4600a91

gameengine scenegraph: correction of relative postition computation, fixes T28908

===================================================================

M	source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp

===================================================================

diff --git a/source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp b/source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp
index fb15905..7e734ac 100644
--- a/source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp
+++ b/source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp
@@ -46,25 +46,32 @@ bool KX_NormalParentRelation::UpdateChildCoordinates(SG_Spatial *child, const SG
 {
 	MT_assert(child != NULL);
 
+	/* If nothing changed in the parent or child, there is nothing to do here */
 	if (!parentUpdated && !child->IsModified())
 		return false;
 
-	parentUpdated = true;
+	parentUpdated = true;  //XXX why??
 
-	if (parent==NULL) { /* Simple case */
+	/* The child has no parent, it is a root object.
+	 * The world and local coordinates should be the same and applied directly. */
+	if (parent==NULL) {
 		child->SetWorldFromLocalTransform();
 		child->ClearModified();
-		return true; //false;
+		return true;
 	}
+	/* The child has a parent. The child's coordinates are defined relative to the parent's.
+	 * The parent's coordinates should be applied to the child's local ones to calculate the real world position. */
 	else {
-		// the childs world locations which we will update.
 		const MT_Vector3 & p_world_scale = parent->GetWorldScaling();
 		const MT_Point3 & p_world_pos = parent->GetWorldPosition();
-		const MT_Matrix3x3 & p_world_rotation = parent->GetWorldOrientation();
-
-		child->SetWorldScale(p_world_scale * child->GetLocalScale());
-		child->SetWorldOrientation(p_world_rotation * child->GetLocalOrientation());
-		child->SetWorldPosition(p_world_pos + p_world_scale * (p_world_rotation * child->GetLocalPosition()));
+		const MT_Matrix3x3 & p_world_orientation = parent->GetWorldOrientation();
+		const MT_Vector3 & local_scale = child->GetLocalScale();
+		const MT_Point3 & local_pos = child->GetLocalPosition();
+		const MT_Matrix3x3 & local_orientation = child->GetLocalOrientation();
+
+		child->SetWorldScale(p_world_scale * local_scale);
+		child->SetWorldOrientation(p_world_orientation * local_orientation);
+		child->SetWorldPosition(p_world_pos + p_world_scale * local_scale * (p_world_orientation * local_orientation * local_pos));
 		child->ClearModified();
 		return true;
 	}




More information about the Bf-blender-cvs mailing list