/// <summary> /// Modifies the specified model to align to this animation at the specified frame and then renders it. /// </summary> /// <param name="renderContext"> /// The current render context. /// </param> /// <param name="transform"> /// The world transformation to apply. /// </param> /// <param name="model"> /// The model to update. /// </param> /// <param name="frame"> /// The frame to draw at. /// </param> public void Render(IRenderContext renderContext, Matrix transform, Model model, double frame) { var calculatedSeconds = (float)(frame / this.TicksPerSecond); this.Render(renderContext, transform, model, calculatedSeconds, 1); }
/// <summary> /// Modifies the specified model to align to this animation at the specified frame and then renders it. /// </summary> /// <param name="renderContext"> /// The current render context. /// </param> /// <param name="transform"> /// The world transformation to apply. /// </param> /// <param name="model"> /// The model to update. /// </param> /// <param name="totalSeconds"> /// The time elapsed. /// </param> /// <param name="multiply"> /// The multiplication factor to apply to the animation speed. /// </param> public void Render( IRenderContext renderContext, Matrix transform, Model model, float totalSeconds, float multiply) { this.Apply(model, totalSeconds, multiply); // Render the model. model.Render(renderContext, transform); }
/// <summary> /// Applies the animation at a specified time to the model. /// </summary> /// <param name="model"> /// The model to apply the animation to. /// </param> /// <param name="frame"> /// The frame to draw at. /// </param> public void Apply(Model model, double frame) { var calculatedSeconds = (float)(frame / this.TicksPerSecond); this.Apply(model, calculatedSeconds, 1); }
/// <summary> /// Modifies the specified model to align to this animation at the specified frame and then renders it. /// </summary> /// <param name="renderContext"> /// The current render context. /// </param> /// <param name="transform"> /// The world transformation to apply. /// </param> /// <param name="model"> /// The model to update. /// </param> /// <param name="secondFraction"> /// The time elapsed. /// </param> /// <param name="multiply"> /// The multiplication factor to apply to the animation speed. /// </param> public void Render( IRenderContext renderContext, Matrix transform, Model model, TimeSpan secondFraction, float multiply) { this.Render(renderContext, transform, model, (float)(secondFraction.TotalSeconds % (this.DurationInTicks / this.TicksPerSecond)), multiply); }
/// <summary> /// Applies the animation at a specified time to the model. /// </summary> /// <param name="model"> /// The model to apply the animation to. /// </param> /// <param name="totalSeconds"> /// The time elapsed. /// </param> /// <param name="multiply"> /// The multiplication factor to apply to the animation speed. /// </param> public void Apply(Model model, float totalSeconds, float multiply) { totalSeconds = (float)(totalSeconds * this.TicksPerSecond * multiply); foreach (var bone in model.Bones.Keys) { var boneObj = model.Bones[bone]; if (this.m_TranslationKeys.ContainsKey(bone)) { double translationKeyPrevious, translationKeyNext; this.FindSurroundingTickValues( this.m_TranslationKeys[bone], totalSeconds, out translationKeyPrevious, out translationKeyNext); if (Math.Abs(translationKeyPrevious - (-1)) < 0.0001f || Math.Abs(translationKeyNext - (-1)) < 0.0001f) { if (Math.Abs(translationKeyPrevious - (-1)) >= 0.0001f) { boneObj.CurrentTranslation = this.m_TranslationForBones[bone][translationKeyPrevious]; } else if (Math.Abs(translationKeyNext - (-1)) >= 0.0001f) { boneObj.CurrentTranslation = this.m_TranslationForBones[bone][translationKeyNext]; } } else { var previousTranslation = this.m_TranslationForBones[bone][translationKeyPrevious]; var nextTranslation = this.m_TranslationForBones[bone][translationKeyNext]; var actualTranslation = previousTranslation; if (Math.Abs(translationKeyPrevious - translationKeyNext) > 0.0001f) { var amount = (float) -((translationKeyPrevious - totalSeconds) / (translationKeyNext - translationKeyPrevious)); actualTranslation = Vector3.Lerp(previousTranslation, nextTranslation, amount); } boneObj.CurrentTranslation = actualTranslation; } } if (this.m_RotationKeys.ContainsKey(bone)) { double rotationKeyPrevious, rotationKeyNext; this.FindSurroundingTickValues( this.m_RotationKeys[bone], totalSeconds, out rotationKeyPrevious, out rotationKeyNext); if (Math.Abs(rotationKeyPrevious - (-1)) < 0.0001f || Math.Abs(rotationKeyNext - (-1)) < 0.0001f) { if (Math.Abs(rotationKeyPrevious - (-1)) >= 0.0001f) { boneObj.CurrentRotation = this.m_RotationForBones[bone][rotationKeyPrevious]; } else if (Math.Abs(rotationKeyNext - (-1)) >= 0.0001f) { boneObj.CurrentRotation = this.m_RotationForBones[bone][rotationKeyNext]; } } else { var previousRotation = this.m_RotationForBones[bone][rotationKeyPrevious]; var nextRotation = this.m_RotationForBones[bone][rotationKeyNext]; var actualRotation = previousRotation; if (Math.Abs(rotationKeyPrevious - rotationKeyNext) > 0.0001f) { actualRotation = Quaternion.Lerp( previousRotation, nextRotation, (float)-((rotationKeyPrevious - totalSeconds) / (rotationKeyNext - rotationKeyPrevious))); } boneObj.CurrentRotation = actualRotation; } } if (this.m_ScaleKeys.ContainsKey(bone)) { double scaleKeyPrevious, scaleKeyNext; this.FindSurroundingTickValues(this.m_ScaleKeys[bone], totalSeconds, out scaleKeyPrevious, out scaleKeyNext); if (Math.Abs(scaleKeyPrevious - (-1)) < 0.0001f || Math.Abs(scaleKeyNext - (-1)) < 0.0001f) { if (Math.Abs(scaleKeyPrevious - (-1)) >= 0.0001f) { boneObj.CurrentScale = this.m_ScaleForBones[bone][scaleKeyPrevious]; } else if (Math.Abs(scaleKeyNext - (-1)) >= 0.0001f) { boneObj.CurrentScale = this.m_ScaleForBones[bone][scaleKeyNext]; } } else { var previousScale = this.m_ScaleForBones[bone][scaleKeyPrevious]; var nextScale = this.m_ScaleForBones[bone][scaleKeyNext]; var actualScale = previousScale; if (Math.Abs(scaleKeyPrevious - scaleKeyNext) > 0.0001f) { actualScale = Vector3.Lerp( previousScale, nextScale, (float)-((scaleKeyPrevious - totalSeconds) / (scaleKeyNext - scaleKeyPrevious))); } boneObj.CurrentScale = actualScale; } } } }