synched with trunk at revision 32129
[blender.git] / source / gameengine / Ketsji / KX_SG_NodeRelationships.cpp
index 87ff3b539118b1874fbb66c05569fe06d89cc48e..ccdaac8edb75045e7bf7c84ec94e126f12a2404d 100644 (file)
@@ -14,7 +14,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
  * All rights reserved.
 
 #include "KX_SG_NodeRelationships.h"
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 /**
  * Implementation of classes defined in KX_SG_NodeRelationships.h
  */
@@ -63,7 +59,7 @@ UpdateChildCoordinates(
 
        if (parent==NULL) { /* Simple case */
                child->SetWorldFromLocalTransform();
-               child->SetModified(false);
+               child->ClearModified();
                return true; //false;
        }
        else {
@@ -75,7 +71,7 @@ UpdateChildCoordinates(
                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()));
-               child->SetModified(false);
+               child->ClearModified();
                return true;
        }
 }
@@ -137,7 +133,7 @@ UpdateChildCoordinates(
                child->SetWorldPosition(child->GetLocalPosition());
        
        child->SetWorldOrientation(child->GetLocalOrientation());
-       child->SetModified(false);
+       child->ClearModified();
        return true; //parent != NULL;
 }
 
@@ -235,23 +231,12 @@ UpdateChildCoordinates(
                        // now 'interpolate' the normal coordinates with the last 
                        // world coordinates to get the new world coordinates.
 
-                       // problem 1:
-                       // The child world scale needs to be initialized in some way for this 
-                       // to make sense
-                       // problem 2:
-                       // This is way of doing interpolation is nonsense
-
-                       int i;
-
                        MT_Scalar weight = MT_Scalar(1)/(m_relax + 1);
-                       for (i=0;i <3 ;i++) {
-                               child_w_scale[i] = (m_relax * child_w_scale[i] + child_n_scale[i]) * weight;
-                               child_w_pos[i] = (m_relax * child_w_pos[i] + child_n_pos[i]) * weight;
-                               child_w_rotation[0][i] = (m_relax * child_w_rotation[0][i] + child_n_rotation[0][i]) * weight;
-                               child_w_rotation[1][i] = (m_relax * child_w_rotation[1][i] + child_n_rotation[1][i]) * weight;
-                               child_w_rotation[2][i] = (m_relax * child_w_rotation[2][i] + child_n_rotation[2][i]) * weight;
-                       }
-                       
+                       child_w_scale = (m_relax * child_w_scale + child_n_scale) * weight;
+                       child_w_pos = (m_relax * child_w_pos + child_n_pos) * weight;
+                       // for rotation we must go through quaternion
+                       MT_Quaternion child_w_quat = child_w_rotation.getRotation().slerp(child_n_rotation.getRotation(), weight);
+                       child_w_rotation.setRotation(child_w_quat);
                        //FIXME: update physics controller.
                } else {
                        child_w_scale = child_n_scale;
@@ -270,7 +255,9 @@ UpdateChildCoordinates(
        child->SetWorldScale(child_w_scale);
        child->SetWorldPosition(child_w_pos);
        child->SetWorldOrientation(child_w_rotation);
-       child->SetModified(false);
+       child->ClearModified();
+       // this node must always be updated, so reschedule it for next time
+       child->ActivateRecheduleUpdateCallback();
        
        return true; //parent != NULL;
 }