/// <summary> /// Calculates the value this animation believes should be the current value for the property. /// </summary> /// <param name="defaultOriginValue"> /// This value is the suggested origin value provided to the animation /// to be used if the animation does not have its own concept of a /// start value. If this animation is the first in a composition chain /// this value will be the snapshot value if one is available or the /// base property value if it is not; otherise this value will be the /// value returned by the previous animation in the chain with an /// animationClock that is not Stopped. /// </param> /// <param name="defaultDestinationValue"> /// This value is the suggested destination value provided to the animation /// to be used if the animation does not have its own concept of an /// end value. This value will be the base value if the animation is /// in the first composition layer of animations on a property; /// otherwise this value will be the output value from the previous /// composition layer of animations for the property. /// </param> /// <param name="animationClock"> /// This is the animationClock which can generate the CurrentTime or /// CurrentProgress value to be used by the animation to generate its /// output value. /// </param> /// <returns> /// The value this animation believes should be the current value for the property. /// </returns> public Rotation3D GetCurrentValue(Rotation3D defaultOriginValue, Rotation3D defaultDestinationValue, AnimationClock animationClock) { ReadPreamble(); if (animationClock == null) { throw new ArgumentNullException("animationClock"); } // We check for null above but presharp doesn't notice so we suppress the // warning here. #pragma warning suppress 6506 if (animationClock.CurrentState == ClockState.Stopped) { return(defaultDestinationValue); } /* * if (!AnimatedTypeHelpers.IsValidAnimationValueRotation3D(defaultDestinationValue)) * { * throw new ArgumentException( * SR.Get( * SRID.Animation_InvalidBaseValue, * defaultDestinationValue, * defaultDestinationValue.GetType(), * GetType()), * "defaultDestinationValue"); * } */ return(GetCurrentValueCore(defaultOriginValue, defaultDestinationValue, animationClock)); }
/// <summary> /// Creates a new Rotation3DAnimation that will animate a /// Rotation3D property from its base value to the value specified /// by the "toValue" parameter of this constructor. /// </summary> public Rotation3DAnimation(Rotation3D toValue, Duration duration, FillBehavior fillBehavior) : this() { To = toValue; Duration = duration; FillBehavior = fillBehavior; }
/// <summary> /// Creates a new Rotation3DAnimation that will animate a /// Rotation3D property from the "fromValue" parameter of this constructor /// to the "toValue" parameter. /// </summary> public Rotation3DAnimation(Rotation3D fromValue, Rotation3D toValue, Duration duration) : this() { From = fromValue; To = toValue; Duration = duration; }
private void LoadPosition() { properties.TryGetValue("Location", out string loc); properties.TryGetValue("Rotation", out string rot); // Assign location if (loc != null) { Location = Point3D.FromProperty(loc); } else { // No location supplied, so return the default = all zero Location = new Point3D(0.0, 0.0, 0.0); } // Assign rotation if (rot != null) { Rotation = Rotation3D.FromProperty(rot); } else { // No rotation supplied, so return the default = all zero Rotation = new Rotation3D(0.0, 0.0, 0.0); } }
/// <summary> /// Aula 10 /// </summary> private void RotateElements() { var acd = NavisworksApp.ActiveDocument; double a = 0; double inc = 3; if (LbTurnRigth.BackColor.Equals(FocusedColor)) { a = inc * (Math.PI / 180.0); } if (LbTurnLeft.BackColor.Equals(FocusedColor)) { a = -inc * (Math.PI / 180.0); } if (a == 0) { return; } try { var se = acd.CurrentSelection.SelectedItems; foreach (var item in se) { var loc = item.BoundingBox().Center; var mb = new Vector3D(loc.X, loc.Y, loc.Z); var mo = new Vector3D(-loc.X, -loc.Y, -loc.Z); var transVec = Transform3D.CreateTranslation(mo); acd.Models.OverridePermanentTransform(new List <ModelItem> { item }, transVec, true); //Rotate var rt = new Rotation3D(new UnitVector3D(0, 0, 1), a); var transRotate = new Transform3D(rt, mb); acd.Models.OverridePermanentTransform(new List <ModelItem> { item }, transRotate, true); this.lbCenterLogEixos.Text = string.Format("X = {0}\n Y = {1}\n Z = {2}", item.BoundingBox().Center.X.ToString(), item.BoundingBox().Center.Y.ToString(), item.BoundingBox().Center.Z.ToString()); } } catch (Exception) { // } }
public static Rotation3D Multiply(Rotation3D r1, Rotation3D r2) { Rotation3D res = new Rotation3D(r2.D * r1.A + r2.A * r1.D + r2.B * r1.C - r2.C * r1.B, r2.D * r1.B + r2.B * r1.D + r2.C * r1.A - r2.A * r1.C, r2.D * r1.C + r2.C * r1.D + r2.A * r1.B - r2.B * r1.A, r2.D * r1.D - r2.A * r1.A - r2.B * r1.B - r2.C * r1.C); return(res); }
public override int Execute(params string[] parameters) { // document Document doc = Application.ActiveDocument; // make a copy of current viewpoint Viewpoint vpoint = doc.CurrentViewpoint.CreateCopy(); #region MoveCamera /* * * // move to the new position * Point3D curPos = vpoint.Position; * Point3D newPos = new Point3D(curPos.X + 10, curPos.Y, curPos.Z); * vpoint.Position = newPos; * * doc.CurrentViewpoint.CopyFrom(vpoint); * */ #endregion MoveCamera #region RotateCamera // collect the rotational axis and angle AxisAndAngleResult axisAngleResult = vpoint.Rotation.ToAxisAndAngle(); // A vector with unit length, represents a direction in 3D space. UnitVector3D axis = axisAngleResult.Axis; // angle in radians double angle = axisAngleResult.Angle; // to set values // creates a new angle value (90 degree) double newAngle = 10 * (3.14 / 180); // creates a new axis to rotate (z axis) UnitVector3D newAxis = new UnitVector3D(0, 0, 1); // creates rotation about given axis by angle in radians (Quaternion) Rotation3D newRotation = new Rotation3D(newAxis, newAngle); // multiply the current 3D Rotation value with the new value vpoint.Rotation = Multiply(vpoint.Rotation, newRotation); // update the current viewpoint doc.CurrentViewpoint.CopyFrom(vpoint); //f.MessageBox.Show(String.Format("Axis : {0} , Angle : {1} ", //axis.ToString(),angle.ToString())); #endregion RotateCamera return(0); }
private void RenderMesh(Rotation3D rotation3D) { MeshGroup.Children.Clear(); if (!aiScene.HasMeshes) { return; } var material = new DiffuseMaterial(new SolidColorBrush(Colors.SandyBrown)); material.AmbientColor = Colors.SaddleBrown; foreach (var aiMesh in aiScene.Meshes) { var geoModel = new GeometryModel3D(); geoModel.Material = material; //geoModel.BackMaterial = material; var mesh = new MeshGeometry3D(); aiMesh.Vertices.ForEach(m => { mesh.Positions.Add(new Point3D(m.X, m.Y, m.Z)); }); aiMesh.Normals.ForEach(m => { mesh.Normals.Add(new System.Windows.Media.Media3D.Vector3D(m.X, m.Y, m.Z)); }); aiMesh.Faces.ForEach(m => { mesh.TriangleIndices.Add(m.Indices[0]); mesh.TriangleIndices.Add(m.Indices[1]); mesh.TriangleIndices.Add(m.Indices[2]); if (m.IndexCount == 4) { mesh.TriangleIndices.Add(m.Indices[2]); mesh.TriangleIndices.Add(m.Indices[3]); mesh.TriangleIndices.Add(m.Indices[0]); } }); geoModel.Geometry = mesh; MeshGroup.Children.Add(geoModel); } var model = new ModelVisual3D(); model.Content = MeshGroup; viewport3D.Children.Add(model); viewport3D.Children[2].Transform = GetTransform(MeshGroup.Bounds, rotation3D); LightCamera.Lookat(new Point3D(0, 0, 0), 64); }
// We don't need to override CloneCore because it won't do anything #endregion #region Rotation3DKeyFrame /// <summary> /// Implemented to linearly interpolate between the baseValue and the /// Value of this KeyFrame using the keyFrameProgress. /// </summary> protected override Rotation3D InterpolateValueCore(Rotation3D baseValue, double keyFrameProgress) { if (keyFrameProgress < 1.0) { return(baseValue); } else { return(Value); } }
private static Vector3D GetViewUp(Viewpoint v) { Rotation3D oRot = v.Rotation; // calculate view direction Rotation3D oNegtiveZ = new Rotation3D(0, 1, 0, 0); Rotation3D otempRot = MultiplyRotation3D(oNegtiveZ, oRot.Invert()); Rotation3D oViewDirRot = MultiplyRotation3D(oRot, otempRot); // get view direction Vector3D oViewDir = new Vector3D(oViewDirRot.A, oViewDirRot.B, oViewDirRot.C); return(oViewDir.Normalize()); }
internal static Rotation3D AddRotation3D(Rotation3D value1, Rotation3D value2) { if (value1 == null) { value1 = Rotation3D.Identity; } if (value2 == null) { value2 = Rotation3D.Identity; } return(new QuaternionRotation3D(AddQuaternion(value1.InternalQuaternion, value2.InternalQuaternion))); }
void SetDisplay(Vector3D position, Rotation3D rotation, Vector3D scale, bool always) { if (Model != null) { ContentAnimator.SetPosition(Model, Position, position, always); ContentAnimator.SetScale(Model, Scale, scale, position, always); ContentAnimator.SetRotation(Model, Rotation, rotation, position, always); } Position = position; Rotation = rotation; Scale = scale; }
static bool RotationEquals(Rotation3D rotationX, Rotation3D rotationY) { AxisAngleRotation3D x = (AxisAngleRotation3D)rotationX; AxisAngleRotation3D y = (AxisAngleRotation3D)rotationY; bool angleEqual = x.Angle == y.Angle; if (angleEqual) { return(x.Axis == y.Axis); } return(angleEqual); }
private static bool ValidateFromToOrByValue(object value) { Rotation3D typedValue = (Rotation3D)value; if (typedValue != null) { return(AnimatedTypeHelpers.IsValidAnimationValueRotation3D(typedValue)); } else { return(true); } }
/// <summary> /// Get View Normal /// </summary> /// <param name="oVP"></param> /// <returns></returns> private Vector3D getViewUp(Viewpoint oVP) { double units = GetGunits(); Rotation3D oRot = oVP.Rotation; // calculate view direction Rotation3D oNegtiveZ = new Rotation3D(0, 1, 0, 0); Rotation3D otempRot = MultiplyRotation3D(oNegtiveZ, oRot.Invert()); Rotation3D oViewDirRot = MultiplyRotation3D(oRot, otempRot); // get view direction Vector3D oViewDir = new Vector3D(oViewDirRot.A, oViewDirRot.B, oViewDirRot.C); return(oViewDir.Normalize()); }
public static void SetRotation(ModelVisual3D model, Rotation3D oldRotation, Rotation3D newRotation, Vector3D center, bool always) { if (always || !RotationEquals(newRotation, oldRotation)) { if (AnimationDuration.TimeSpan == TimeSpan.Zero) { ContentAnimator.AddTransformation(model, new RotateTransform3D(newRotation)); } else { AnimateRotation(model, oldRotation, newRotation, center); } } }
/// <summary> /// Implemented to linearly interpolate between the baseValue and the /// Value of this KeyFrame using the keyFrameProgress. /// </summary> protected override Rotation3D InterpolateValueCore(Rotation3D baseValue, double keyFrameProgress) { if (keyFrameProgress == 0.0) { return(baseValue); } else if (keyFrameProgress == 1.0) { return(Value); } else { return(AnimatedTypeHelpers.InterpolateRotation3D(baseValue, Value, keyFrameProgress)); } }
public static void AnimateRotation(ModelVisual3D model, Rotation3D oldRotation, Rotation3D newRotation, Vector3D center) { RotateTransform3D transform = new RotateTransform3D(oldRotation, center.ToPoint3D()); Rotation3DAnimation animation = new Rotation3DAnimation(oldRotation, newRotation, AnimationDuration) { AccelerationRatio = AnimationAccelerationRatio, DecelerationRatio = AnimationDecelerationRatio, FillBehavior = FillBehavior.HoldEnd }; transform.BeginAnimation(RotateTransform3D.RotationProperty, animation); AddTransformationAnimation(model, transform); }
//multiply two Rotation3D private static Rotation3D MultiplyRotation3D(Rotation3D r2, Rotation3D r1) { Rotation3D rot = new Rotation3D( r2.D * r1.A + r2.A * r1.D + r2.B * r1.C - r2.C * r1.B, r2.D * r1.B + r2.B * r1.D + r2.C * r1.A - r2.A * r1.C, r2.D * r1.C + r2.C * r1.D + r2.A * r1.B - r2.B * r1.A, r2.D * r1.D - r2.A * r1.A - r2.B * r1.B - r2.C * r1.C); rot.Normalize(); return(rot); }
private void RotateModel(double start, double end, int duration) { RotateTransform3D rt3D = _GroupRotateTransformY; Rotation3D r3d = rt3D.Rotation; DoubleAnimation anim = new DoubleAnimation(); anim.From = start; anim.To = end; anim.BeginTime = null; anim.AccelerationRatio = 0.1; anim.DecelerationRatio = 0.6; anim.Duration = new TimeSpan(0, 0, 0, 0, duration); AnimationClock ac = anim.CreateClock(); ac.CurrentStateInvalidated += new EventHandler(OnRotateEnded); ac.Controller.Begin(); r3d.ApplyAnimationClock(AxisAngleRotation3D.AngleProperty, ac); }
internal SLShapeProperties Clone() { var sp = new SLShapeProperties(listThemeColors); sp.HasBlackWhiteMode = HasBlackWhiteMode; sp.vBlackWhiteMode = vBlackWhiteMode; sp.HasTransform2D = HasTransform2D; sp.Transform2D = Transform2D.Clone(); sp.HasPresetGeometry = HasPresetGeometry; sp.vPresetGeometry = vPresetGeometry; sp.Fill = Fill.Clone(); sp.Outline = Outline.Clone(); sp.EffectList = EffectList.Clone(); sp.Rotation3D = Rotation3D.Clone(); sp.Format3D = Format3D.Clone(); return(sp); }
/// <summary> /// Creates a new renderable Cube3D object based on the given play model. /// </summary> public Cube3D(Cube model) { if (model.IsFood) { throw new ArgumentException("Cannot create a Cube3D from a food model."); } //Get the newly created shape for this Cube3D Mesh = GetUnitCube(Squash, Twist); //Set up the first materials this.Materials = new MaterialGroup(); Brush = new SolidColorBrush(model.Color); this.Materials.Children.Add(new DiffuseMaterial(Brush)); //Load up the Geometry with the materials and the created mesh. GeometryModel3D geom = new GeometryModel3D(Mesh, Materials); geom.BackMaterial = new DiffuseMaterial(Brushes.Yellow); //Set the current content to the new Geometry. this.Content = geom; //Set up transforms. Sweller = new ScaleTransform3D(1, 1, 1, 0, 0, 0); Sizer = new ScaleTransform3D(0.1, 0.1, 0.1, 0, 0, 0); Rotator = new AxisAngleRotation3D(new Vector3D(0, 0, 1), 0); Translation = new TranslateTransform3D(0, 0, 0); Transform3DGroup tg = new Transform3DGroup(); tg.Children.Add(new RotateTransform3D(Rotator)); tg.Children.Add(Sizer); tg.Children.Add(Sweller); tg.Children.Add(Translation); this.Transform = tg; //Set up the name tag. SetupNameTag(model.Name); //Set this model to the new model. this.Model = model; }
public static Quaternion QuaternionFromRotation3D(Rotation3D rotation3D) { if (rotation3D == null) { return(Quaternion.Identity); } QuaternionRotation3D quaternionRotation3D = rotation3D as QuaternionRotation3D; Quaternion quaternion; if (quaternionRotation3D != null) { quaternion = quaternionRotation3D.Quaternion; } else { AxisAngleRotation3D axisAngleRotation3D = (AxisAngleRotation3D)rotation3D; quaternion = new Quaternion(axisAngleRotation3D.Axis, axisAngleRotation3D.Angle); } return(quaternion); }
private Transform3DGroup GetTransform(Rect3D bounds, Rotation3D rotation3D) { var center = new Point3D((bounds.X + bounds.SizeX / 2), (bounds.Y + bounds.SizeY / 2), (bounds.Z + bounds.SizeZ / 2)); var radius = (center - bounds.Location).Length; var s = 32 / radius; if (bounds.SizeZ * s > 64) { s = 32 / bounds.SizeZ; } var model = new ModelVisual3D(); model.Content = MeshGroup; var g = new Transform3DGroup(); g.Children.Add(new TranslateTransform3D(-center.X, -center.Y, -center.Z)); g.Children.Add(new ScaleTransform3D(s, s, s)); g.Children.Add(new RotateTransform3D(rotation3D)); return(g); }
private Vector3D getViewUp(Viewpoint oVP) { double units = GetGunits(); Rotation3D oRot = oVP.Rotation; // calculate view direction Rotation3D oNegtiveZ = new Rotation3D(0, 1, 0, 0); Rotation3D otempRot = MultiplyRotation3D(oNegtiveZ, oRot.Invert()); Rotation3D oViewDirRot = MultiplyRotation3D(oRot, otempRot); // get view direction Vector3D oViewDir = new Vector3D(oViewDirRot.A, oViewDirRot.B, oViewDirRot.C); return oViewDir.Normalize(); }
private static Vector3D GetViewUp(Viewpoint v) { Rotation3D oRot = v.Rotation; // calculate view direction Rotation3D oNegtiveZ = new Rotation3D(0, 1, 0, 0); Rotation3D otempRot = MultiplyRotation3D(oNegtiveZ, oRot.Invert()); Rotation3D oViewDirRot = MultiplyRotation3D(oRot, otempRot); // get view direction Vector3D oViewDir = new Vector3D(oViewDirRot.A, oViewDirRot.B, oViewDirRot.C); return oViewDir.Normalize(); }
public void SetDisplay(Vector3D position, Rotation3D rotation, Vector3D scale) { SetDisplay(position, rotation, scale, false); }
/// <summary> /// This should only be called from ResolveKeyTimes and only at the /// appropriate time. /// </summary> private void ResolvePacedKeyTimes() { Debug.Assert(_keyFrames != null && _keyFrames.Count > 2, "Caller must guard against calling this method when there are insufficient keyframes."); // If the first key frame is paced its key time has already // been resolved, so we start at index 1. int index = 1; int maxKeyFrameIndex = _sortedResolvedKeyFrames.Length - 1; do { if (_keyFrames[index].KeyTime.Type == KeyTimeType.Paced) { // // We've found a paced key frame so this is the // beginning of a paced block. // // The first paced key frame in this block. int firstPacedBlockKeyFrameIndex = index; // List of segment lengths for this paced block. List <Double> segmentLengths = new List <Double>(); // The resolved key time for the key frame before this // block which we'll use as our starting point. TimeSpan prePacedBlockKeyTime = _sortedResolvedKeyFrames[index - 1]._resolvedKeyTime; // The total of the segment lengths of the paced key // frames in this block. Double totalLength = 0.0; // The key value of the previous key frame which will be // used to determine the segment length of this key frame. Rotation3D prevKeyValue = _keyFrames[index - 1].Value; do { Rotation3D currentKeyValue = _keyFrames[index].Value; // Determine the segment length for this key frame and // add to the total length. totalLength += AnimatedTypeHelpers.GetSegmentLengthRotation3D(prevKeyValue, currentKeyValue); // Temporarily store the distance into the total length // that this key frame represents in the resolved // key times array to be converted to a resolved key // time outside of this loop. segmentLengths.Add(totalLength); // Prepare for the next iteration. prevKeyValue = currentKeyValue; index++; }while (index < maxKeyFrameIndex && _keyFrames[index].KeyTime.Type == KeyTimeType.Paced); // index is currently set to the index of the key frame // after the last paced key frame. This will always // be a valid index because we limit ourselves with // maxKeyFrameIndex. // We need to add the distance between the last paced key // frame and the next key frame to get the total distance // inside the key frame block. totalLength += AnimatedTypeHelpers.GetSegmentLengthRotation3D(prevKeyValue, _keyFrames[index].Value); // Calculate the time available in the resolved key time space. TimeSpan pacedBlockDuration = _sortedResolvedKeyFrames[index]._resolvedKeyTime - prePacedBlockKeyTime; // Convert lengths in segmentLengths list to resolved // key times for the paced key frames in this block. for (int i = 0, currentKeyFrameIndex = firstPacedBlockKeyFrameIndex; i < segmentLengths.Count; i++, currentKeyFrameIndex++) { // The resolved key time for each key frame is: // // The key time of the key frame before this paced block // + ((the percentage of the way through the total length) // * the resolved key time space available for the block) _sortedResolvedKeyFrames[currentKeyFrameIndex]._resolvedKeyTime = prePacedBlockKeyTime + TimeSpan.FromMilliseconds( (segmentLengths[i] / totalLength) * pacedBlockDuration.TotalMilliseconds); } } else { index++; } }while (index < maxKeyFrameIndex); }
/// <summary> /// Calculates the value this animation believes should be the current value for the property. /// </summary> /// <param name="defaultOriginValue"> /// This value is the suggested origin value provided to the animation /// to be used if the animation does not have its own concept of a /// start value. If this animation is the first in a composition chain /// this value will be the snapshot value if one is available or the /// base property value if it is not; otherise this value will be the /// value returned by the previous animation in the chain with an /// animationClock that is not Stopped. /// </param> /// <param name="defaultDestinationValue"> /// This value is the suggested destination value provided to the animation /// to be used if the animation does not have its own concept of an /// end value. This value will be the base value if the animation is /// in the first composition layer of animations on a property; /// otherwise this value will be the output value from the previous /// composition layer of animations for the property. /// </param> /// <param name="animationClock"> /// This is the animationClock which can generate the CurrentTime or /// CurrentProgress value to be used by the animation to generate its /// output value. /// </param> /// <returns> /// The value this animation believes should be the current value for the property. /// </returns> protected sealed override Rotation3D GetCurrentValueCore( Rotation3D defaultOriginValue, Rotation3D defaultDestinationValue, AnimationClock animationClock) { Debug.Assert(animationClock.CurrentState != ClockState.Stopped); if (_keyFrames == null) { return(defaultDestinationValue); } // We resolved our KeyTimes when we froze, but also got notified // of the frozen state and therefore invalidated ourselves. if (!_areKeyTimesValid) { ResolveKeyTimes(); } if (_sortedResolvedKeyFrames == null) { return(defaultDestinationValue); } TimeSpan currentTime = animationClock.CurrentTime.Value; Int32 keyFrameCount = _sortedResolvedKeyFrames.Length; Int32 maxKeyFrameIndex = keyFrameCount - 1; Rotation3D currentIterationValue; Debug.Assert(maxKeyFrameIndex >= 0, "maxKeyFrameIndex is less than zero which means we don't actually have any key frames."); Int32 currentResolvedKeyFrameIndex = 0; // Skip all the key frames with key times lower than the current time. // currentResolvedKeyFrameIndex will be greater than maxKeyFrameIndex // if we are past the last key frame. while (currentResolvedKeyFrameIndex < keyFrameCount && currentTime > _sortedResolvedKeyFrames[currentResolvedKeyFrameIndex]._resolvedKeyTime) { currentResolvedKeyFrameIndex++; } // If there are multiple key frames at the same key time, be sure to go to the last one. while (currentResolvedKeyFrameIndex < maxKeyFrameIndex && currentTime == _sortedResolvedKeyFrames[currentResolvedKeyFrameIndex + 1]._resolvedKeyTime) { currentResolvedKeyFrameIndex++; } if (currentResolvedKeyFrameIndex == keyFrameCount) { // Past the last key frame. currentIterationValue = GetResolvedKeyFrameValue(maxKeyFrameIndex); } else if (currentTime == _sortedResolvedKeyFrames[currentResolvedKeyFrameIndex]._resolvedKeyTime) { // Exactly on a key frame. currentIterationValue = GetResolvedKeyFrameValue(currentResolvedKeyFrameIndex); } else { // Between two key frames. Double currentSegmentProgress = 0.0; Rotation3D fromValue; if (currentResolvedKeyFrameIndex == 0) { // The current key frame is the first key frame so we have // some special rules for determining the fromValue and an // optimized method of calculating the currentSegmentProgress. // If we're additive we want the base value to be a zero value // so that if there isn't a key frame at time 0.0, we'll use // the zero value for the time 0.0 value and then add that // later to the base value. if (IsAdditive) { fromValue = AnimatedTypeHelpers.GetZeroValueRotation3D(defaultOriginValue); } else { fromValue = defaultOriginValue; } // Current segment time divided by the segment duration. // Note: the reason this works is that we know that we're in // the first segment, so we can assume: // // currentTime.TotalMilliseconds = current segment time // _sortedResolvedKeyFrames[0]._resolvedKeyTime.TotalMilliseconds = current segment duration currentSegmentProgress = currentTime.TotalMilliseconds / _sortedResolvedKeyFrames[0]._resolvedKeyTime.TotalMilliseconds; } else { Int32 previousResolvedKeyFrameIndex = currentResolvedKeyFrameIndex - 1; TimeSpan previousResolvedKeyTime = _sortedResolvedKeyFrames[previousResolvedKeyFrameIndex]._resolvedKeyTime; fromValue = GetResolvedKeyFrameValue(previousResolvedKeyFrameIndex); TimeSpan segmentCurrentTime = currentTime - previousResolvedKeyTime; TimeSpan segmentDuration = _sortedResolvedKeyFrames[currentResolvedKeyFrameIndex]._resolvedKeyTime - previousResolvedKeyTime; currentSegmentProgress = segmentCurrentTime.TotalMilliseconds / segmentDuration.TotalMilliseconds; } currentIterationValue = GetResolvedKeyFrame(currentResolvedKeyFrameIndex).InterpolateValue(fromValue, currentSegmentProgress); } // If we're cumulative, we need to multiply the final key frame // value by the current repeat count and add this to the return // value. if (IsCumulative) { Double currentRepeat = (Double)(animationClock.CurrentIteration - 1); if (currentRepeat > 0.0) { currentIterationValue = AnimatedTypeHelpers.AddRotation3D( currentIterationValue, AnimatedTypeHelpers.ScaleRotation3D(GetResolvedKeyFrameValue(maxKeyFrameIndex), currentRepeat)); } } // If we're additive we need to add the base value to the return value. if (IsAdditive) { return(AnimatedTypeHelpers.AddRotation3D(defaultOriginValue, currentIterationValue)); } return(currentIterationValue); }
// help function: Multiply two Rotation3D private Rotation3D MultiplyRotation3D( Rotation3D r2, Rotation3D r1) { Rotation3D oRot = new Rotation3D(r2.D * r1.A + r2.A * r1.D + r2.B * r1.C - r2.C * r1.B, r2.D * r1.B + r2.B * r1.D + r2.C * r1.A - r2.A * r1.C, r2.D * r1.C + r2.C * r1.D + r2.A * r1.B - r2.B * r1.A, r2.D * r1.D - r2.A * r1.A - r2.B * r1.B - r2.C * r1.C); oRot.Normalize(); return oRot; }
/// <summary> /// Creates a new DiscreteRotation3DKeyFrame. /// </summary> public DiscreteRotation3DKeyFrame(Rotation3D value, KeyTime keyTime) : base(value, keyTime) { }
private void Start() { rotator = gameObject.GetComponent <Rotation3D>(); placedElements = GetComponentsInChildren <ElementCollision>(); molConstructed = false; }
/// <summary> /// Creates a new DiscreteRotation3DKeyFrame. /// </summary> public DiscreteRotation3DKeyFrame(Rotation3D value) : base(value) { }