public void AssignToCharacterBone() { if (m_assignedBone != null) { Quaternion rotation = Rotation; Quaternion additionalRotation = Player.m_skinnedEntity.GetAdditionalRotation(m_assignedBone.Name); rotation = Rotation * additionalRotation; m_assignedBone.SetCompleteTransform(ref Translation, ref rotation, Player.Weight); } }
/// <summary> /// Set the bone based on the supplied position value /// </summary> /// <param name="position"></param> public void SetPosition(float position) { if (ClipBone == null) { return; } List <AnimationClip.Keyframe> keyframes = ClipBone.Keyframes; if (keyframes.Count == 0) { return; } if (!m_isConst) { // If our current position is less that the first keyframe // we move the position backward until we get to the right keyframe while (position < Keyframe1.Time && m_currentKeyframe > 0) { // We need to move backwards in time m_currentKeyframe--; SetKeyframes(); } // If our current position is greater than the second keyframe // we move the position forward until we get to the right keyframe while (position >= Keyframe2.Time && m_currentKeyframe < ClipBone.Keyframes.Count - 2) { // We need to move forwards in time m_currentKeyframe++; SetKeyframes(); } if (Keyframe1 == Keyframe2) { // Keyframes are equal m_rotation = Keyframe1.Rotation; m_translation = Keyframe1.Translation; } else { // Interpolate between keyframes float t = (float)((position - Keyframe1.Time) * Keyframe2.TimeDiff); t = MathHelper.Clamp(t, 0, 1); Quaternion.Slerp(ref Keyframe1.Rotation, ref Keyframe2.Rotation, t, out m_rotation); Vector3.Lerp(ref Keyframe1.Translation, ref Keyframe2.Translation, t, out m_translation); } } if (m_assignedBone != null) { Quaternion rotation = m_rotation; Quaternion additionalRotation = Player.m_skinnedEntity.GetAdditionalRotation(m_assignedBone.Name); rotation = m_rotation * additionalRotation; m_assignedBone.SetCompleteTransform(ref m_translation, ref rotation, Player.Weight); } }