[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19762] trunk/blender: BGE: slow parent was causing scaling distortion, now use correct quaternion interpolation.
Benoit Bolsee
benoit.bolsee at online.be
Thu Apr 16 22:13:13 CEST 2009
Revision: 19762
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19762
Author: ben2610
Date: 2009-04-16 22:13:13 +0200 (Thu, 16 Apr 2009)
Log Message:
-----------
BGE: slow parent was causing scaling distortion, now use correct quaternion interpolation.
Modified Paths:
--------------
trunk/blender/intern/moto/include/MT_Quaternion.inl
trunk/blender/source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp
Modified: trunk/blender/intern/moto/include/MT_Quaternion.inl
===================================================================
--- trunk/blender/intern/moto/include/MT_Quaternion.inl 2009-04-16 15:49:31 UTC (rev 19761)
+++ trunk/blender/intern/moto/include/MT_Quaternion.inl 2009-04-16 20:13:13 UTC (rev 19762)
@@ -74,19 +74,27 @@
GEN_INLINE MT_Quaternion MT_Quaternion::slerp(const MT_Quaternion& q, const MT_Scalar& t) const
{
- MT_Scalar theta = angle(q);
-
- if (!MT_fuzzyZero(theta))
+ MT_Scalar d, s0, s1;
+ MT_Scalar s = dot(q);
+ bool neg = (s < 0.0);
+
+ if (neg)
+ s = -s;
+ if ((1.0 - s) > 0.0001)
{
- MT_Scalar d = MT_Scalar(1.0) / sin(theta);
- MT_Scalar s0 = sin((MT_Scalar(1.0) - t) * theta);
- MT_Scalar s1 = sin(t * theta);
-
- return d*(*this * s0 + q * s1);
+ MT_Scalar theta = acos(s);
+ d = MT_Scalar(1.0) / sin(theta);
+ s0 = sin((MT_Scalar(1.0) - t) * theta);
+ s1 = sin(t * theta);
}
else
{
- return *this;
+ d = MT_Scalar(1.0);
+ s0 = MT_Scalar(1.0) - t;
+ s1 = t;
}
+ if (neg)
+ s1 = -s1;
+ return d*(*this * s0 + q * s1);
}
Modified: trunk/blender/source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp 2009-04-16 15:49:31 UTC (rev 19761)
+++ trunk/blender/source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp 2009-04-16 20:13:13 UTC (rev 19762)
@@ -235,23 +235,12 @@
// 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;
More information about the Bf-blender-cvs
mailing list