public void RotationGauche() { animation.From = angleX; animation.To = angleX -= 0.5; animation.Duration = TimeSpan.FromSeconds(0.2); rotationX.BeginAnimation(AxisAngleRotation3D.AngleProperty, animation); }
public void SetCameraRotationMode(bool enableAutoRotation) { ModelAutoRotationEnabled = enableAutoRotation; if (CurrentModelVisual == null || CurrentAxisRotation == null) { return; } if (ModelAutoRotationEnabled) { DoubleAnimation animation1 = new DoubleAnimation(CurrentAxisRotation.Angle, CurrentAxisRotation.Angle + 420d, TimeSpan.FromMilliseconds(500)); animation1.EasingFunction = new ExponentialEase(); DoubleAnimation animation2 = new DoubleAnimation(CurrentAxisRotation.Angle + 420d, CurrentAxisRotation.Angle + 420d + 360d, TimeSpan.FromMilliseconds(7000)); animation2.RepeatBehavior = RepeatBehavior.Forever; animation1.Completed += (o, e) => CurrentAxisRotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, animation2); CurrentAxisRotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, animation1); } else { DoubleAnimation animation1 = new DoubleAnimation(CurrentAxisRotation.Angle % 360f, 0, TimeSpan.FromMilliseconds(500)); animation1.EasingFunction = new ExponentialEase(); CurrentAxisRotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, animation1); } }
private void BtnGoFront_Click(object sender, RoutedEventArgs e) { DoubleAnimation animation = new DoubleAnimation() { Duration = new Duration(TimeSpan.FromMilliseconds(300)), To = 0 }; Axis3D.BeginAnimation(AxisAngleRotation3D.AngleProperty, animation); }
protected override void BeginTransition3D(TransitionPresenter transitionElement, ContentPresenter oldContent, ContentPresenter newContent, Viewport3D viewport) { Brush clone = CreateBrush(oldContent); Size size = transitionElement.RenderSize; MeshGeometry3D leftDoor = CreateMesh(new Point3D(), new Vector3D(size.Width / 2, 0, 0), new Vector3D(0, size.Height, 0), 1, 1, new Rect(0, 0, 0.5, 1)); GeometryModel3D leftDoorGeometry = new GeometryModel3D(); leftDoorGeometry.Geometry = leftDoor; leftDoorGeometry.Material = new DiffuseMaterial(clone); AxisAngleRotation3D leftRotation = new AxisAngleRotation3D(new Vector3D(0, 1, 0), 0); leftDoorGeometry.Transform = new RotateTransform3D(leftRotation); GeometryModel3D rightDoorGeometry = new GeometryModel3D(); MeshGeometry3D rightDoor = CreateMesh(new Point3D(size.Width / 2, 0, 0), new Vector3D(size.Width / 2, 0, 0), new Vector3D(0, size.Height, 0), 1, 1, new Rect(0.5, 0, 0.5, 1)); rightDoorGeometry.Geometry = rightDoor; rightDoorGeometry.Material = new DiffuseMaterial(clone); AxisAngleRotation3D rightRotation = new AxisAngleRotation3D(new Vector3D(0, 1, 0), 0); rightDoorGeometry.Transform = new RotateTransform3D(rightRotation, size.Width, 0, 0); Model3DGroup doors = new Model3DGroup(); doors.Children.Add(leftDoorGeometry); doors.Children.Add(rightDoorGeometry); ModelVisual3D model = new ModelVisual3D(); model.Content = doors; viewport.Children.Add(model); DoubleAnimation da = new DoubleAnimation(90 - 0.5 * FieldOfView, Duration); leftRotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, da); da = new DoubleAnimation(-(90 - 0.5 * FieldOfView), Duration); rightRotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, da); da = new DoubleAnimation(0, Duration); da.Completed += delegate { EndTransition(transitionElement, oldContent, newContent); }; clone.BeginAnimation(Brush.OpacityProperty, da); }
private ModelVisual3D MakeSide(ContentPresenter content, Point3D origin, Vector3D u, Vector3D v, double endAngle, Point3D rotationCenter, Vector3D rotationAxis, EventHandler onCompleted) { MeshGeometry3D sideMesh = CreateMesh(origin, u, v, 1, 1, new Rect(0, 0, 1, 1)); GeometryModel3D sideModel = new GeometryModel3D(); sideModel.Geometry = sideMesh; Brush clone = CreateBrush(content); sideModel.Material = new DiffuseMaterial(clone); AxisAngleRotation3D rotation = new AxisAngleRotation3D(rotationAxis, 0); sideModel.Transform = new RotateTransform3D(rotation, rotationCenter); DoubleAnimation da = new DoubleAnimation(endAngle, Duration); if (onCompleted != null) { da.Completed += onCompleted; } rotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, da); ModelVisual3D side = new ModelVisual3D(); side.Content = sideModel; return(side); }
/// <summary> /// Gets the center of the viewport. Transforms the body 3d model around the center. /// Is activated after the scan is done to show the scanned 3d model on the screen. /// </summary> private void SetupViewportTransforms() { var geometry = ViewModel.Body3DModel; if (geometry == null) { return; } var center = new Vector3D( (geometry.Bounds.X + geometry.Bounds.SizeX) / 2, 0, (geometry.Bounds.Z + geometry.Bounds.SizeZ) / 2); var translate = new TranslateTransform3D(-center); // TODO: Invert Y and align with floor normal in MeshConverter instead var invertY = new ScaleTransform3D(1, -1, 1); var alignWithFloor = new RotateTransform3D(GetFloorAlignment()); var rotation = new AxisAngleRotation3D(new Vector3D(0, 1, 0), 0); var animation = (AnimationTimeline)FindResource("AngleAnimation"); rotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, animation); var rotate = new RotateTransform3D(rotation); model.Transform = new Transform3DGroup { Children = { translate, invertY, alignWithFloor, rotate } }; }
/// <summary> /// /// </summary> /// <param name="CurrentPosition3D"></param> void Track(Vector3D CurrentPosition3D) { Vector3D axisOfRotation = Vector3D.CrossProduct(_previousPosition3D, CurrentPosition3D); double rotationAngle = Vector3D.AngleBetween(_previousPosition3D, CurrentPosition3D); Quaternion quaternion = new Quaternion(axisOfRotation, -rotationAngle); Quaternion quaternion2 = new Quaternion(_rotation.Axis, _rotation.Angle); quaternion2 *= quaternion; _rotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, null);//new DoubleAnimation(0, 130d, TimeSpan.FromMilliseconds(3000)) _rotation.BeginAnimation(AxisAngleRotation3D.AxisProperty, null); _rotation.Axis = quaternion2.Axis; _rotation.Angle = quaternion2.Angle; _previousPosition3D = CurrentPosition3D; }
private static void Animate(double position, double rate, AxisAngleRotation3D axisAngleRotation3D, TimeSpan animationDuration) { if (Math.Abs(rate) > 0.1 * animationDuration.TotalSeconds) { // Simulate future movement with given rate var newPosition = position + (rate * animationDuration.TotalSeconds); axisAngleRotation3D.BeginAnimation( AxisAngleRotation3D.AngleProperty, new DoubleAnimation(position, newPosition, new Duration(animationDuration))); } else { // Jump to current position axisAngleRotation3D.BeginAnimation( AxisAngleRotation3D.AngleProperty, new DoubleAnimation(position, new Duration(TimeSpan.Zero))); } }
/// <summary> /// 移动 /// </summary> internal void Move(int currentIndex) { _rotation3D.BeginAnimation(AxisAngleRotation3D.AngleProperty, AnimationHelper.CreateAnimation(GetAngleByPos(currentIndex), AnimationSpeed)); _transform3D.BeginAnimation(TranslateTransform3D.OffsetXProperty, AnimationHelper.CreateAnimation(GetXByPos(currentIndex), AnimationSpeed)); _transform3D.BeginAnimation(TranslateTransform3D.OffsetZProperty, AnimationHelper.CreateAnimation(GetZByPos(currentIndex), AnimationSpeed)); }
public void Animate(int index) { var rotateAnimation = new DoubleAnimation(RotationAngle(index), AnimationDuration); var xAnimation = new DoubleAnimation(TranslationX(index), AnimationDuration); var zAnimation = new DoubleAnimation(TranslationZ(index), AnimationDuration); rotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, rotateAnimation); translation.BeginAnimation(TranslateTransform3D.OffsetXProperty, xAnimation); translation.BeginAnimation(TranslateTransform3D.OffsetZProperty, zAnimation); }
public void Animate(int index) { TimeSpan duration = TimeSpan.FromMilliseconds(500); var rotateAnimation = new DoubleAnimation(RotationAngle(index), duration); var xAnimation = new DoubleAnimation(TranslationX(index), duration); var zAnimation = new DoubleAnimation(TranslationZ(index), duration); rotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, rotateAnimation); translation.BeginAnimation(TranslateTransform3D.OffsetXProperty, xAnimation); translation.BeginAnimation(TranslateTransform3D.OffsetZProperty, zAnimation); }
void animate(int i) { Dictionary <Move, CubeFace> dominantFaces = new Dictionary <Move, CubeFace> { { Move.B, CubeFace.R }, { Move.D, CubeFace.R }, { Move.E, CubeFace.R }, { Move.F, CubeFace.R }, { Move.L, CubeFace.F }, { Move.M, CubeFace.F }, { Move.R, CubeFace.F }, { Move.S, CubeFace.R }, { Move.U, CubeFace.F }, }; HashSet <Move> possibleMoves = new HashSet <Move>(); Vector3D axis = new Vector3D(); double angle = 90 * Convert.ToInt32(moves[i].Value); axis = getRotationAxis(moves[i].Key); AxisAngleRotation3D rotation = new AxisAngleRotation3D(axis, angle); RotateTransform3D transform = new RotateTransform3D(rotation, new Point3D(0, 0, 0)); DoubleAnimation animation = new DoubleAnimation(0, angle, animationDuration); foreach (Cube c in this.Children) { possibleMoves = new HashSet <Move>(c.possibleMoves); possibleMoves.Remove((Move)dominantFaces[moves[i].Key]); if (possibleMoves.Contains(moves[i].Key)) { c.possibleMoves = getNextPossibleMoves(c.possibleMoves, moves[i].Key, moves[i].Value); c.rotations.Children.Add(transform); rotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, animation); } } animation.Completed += new EventHandler(animation_Completed); rotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, animation); projection.rotate(moves[i]); }
private void AnimationVisualElement(AxisAngleRotation3D rotate, double angel) { Duration duration = new Duration(TimeSpan.FromSeconds(.1)); //对AxisAngleRotation3D的Angle属性应用动画 DoubleAnimation animationAngel = new DoubleAnimation(); animationAngel.To = angel; animationAngel.AccelerationRatio = 0.3; animationAngel.DecelerationRatio = 0.7; animationAngel.Duration = duration; rotate.BeginAnimation(AxisAngleRotation3D.AngleProperty, animationAngel); }
private void Image_MouseLeave(object sender, MouseEventArgs e) { DoubleAnimation da = new DoubleAnimation(); da.Duration = new Duration(TimeSpan.FromSeconds(1)); da.To = 0d; AxisAngleRotation3D aar = this.FindName("MyAxisAngleRotation3D") as AxisAngleRotation3D; if (aar != null) { aar.BeginAnimation(AxisAngleRotation3D.AngleProperty, da); } }
/// <summary> /// 命中的模型移动动画 /// </summary> /// <param name="axisname"></param> /// <param name="rayresultname"></param> public void AxisRatationEvent(AxisAngleRotation3D axisname, RayMeshGeometry3DHitTestResult rayresultname, Vector3D vec) { ///axisname.Axis = new Vector3D(rayresultname.PointHit.X, -rayresultname.PointHit.Y, rayresultname.PointHit.Z); axisname.Axis = vec; DoubleAnimation animation = new DoubleAnimation(); animation.To = 20; animation.DecelerationRatio = 1; animation.Duration = TimeSpan.FromSeconds(0.15); animation.AutoReverse = true; axisname.BeginAnimation(AxisAngleRotation3D.AngleProperty, animation); }
private void Update3DCover() { Material coverMaterial = FindResource("CoverMaterial") as Material; Model3DGroup myModel3DGroup = new Model3DGroup(); ModelVisual3D myModelVisual3D = new ModelVisual3D(); AmbientLight light = new AmbientLight(Colors.White); myModel3DGroup.Children.Add(light); myModel3DGroup.Children.Add(Create3DRectangle(new Point3D(-10, 10, 0), new Point3D(10, 10, 0), new Point3D(-10, -10, 0), new Point3D(10, -10, 0), coverMaterial)); myModelVisual3D.Content = myModel3DGroup; this.ViewPort3D.Children.Add(myModelVisual3D); // Y-Rotation Transform3DGroup transformGroup = new Transform3DGroup(); AxisAngleRotation3D rotationY = new AxisAngleRotation3D(new Vector3D(0, 1, 0), 0); transformGroup.Children.Add(new RotateTransform3D(rotationY)); DoubleAnimation daY = new DoubleAnimation(-10, 10, TimeSpan.FromSeconds(5).Duration()); daY.EasingFunction = new PowerEase() { EasingMode = EasingMode.EaseInOut }; daY.AutoReverse = true; daY.RepeatBehavior = RepeatBehavior.Forever; rotationY.BeginAnimation(AxisAngleRotation3D.AngleProperty, daY); // X-Rotation AxisAngleRotation3D rotationX = new AxisAngleRotation3D(new Vector3D(0, 0, 1), 0); transformGroup.Children.Add(new RotateTransform3D(rotationX)); DoubleAnimation daX = new DoubleAnimation(-5, 5, TimeSpan.FromSeconds(10).Duration()); daX.EasingFunction = new PowerEase() { EasingMode = EasingMode.EaseInOut }; daX.AutoReverse = true; daX.RepeatBehavior = RepeatBehavior.Forever; rotationX.BeginAnimation(AxisAngleRotation3D.AngleProperty, daX); myModel3DGroup.Transform = transformGroup; }
public void Spin() { Front.InvalidateVisual(); Back.InvalidateVisual(); //DoubleAnimation rotationAnimation = new DoubleAnimation(FrontVisible ? 0 : 180, new Duration(TimeSpan.FromSeconds(SpinTime))); DoubleAnimation rotationAnimation = new DoubleAnimation(rotation.Angle - 180, new Duration(TimeSpan.FromSeconds(SpinTime))); rotationAnimation.Completed += new EventHandler(rotationAnimation_Completed); rotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, rotationAnimation); //DoubleAnimationUsingKeyFrames translationAnimation = new DoubleAnimationUsingKeyFrames(); //translationAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(-0.5, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(SpinTime / 2.0)), new SineEase())); //translationAnimation.KeyFrames.Add(new EasingDoubleKeyFrame(0, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(SpinTime)), new SineEase { EasingMode = EasingMode.EaseIn })); //translation.BeginAnimation(TranslateTransform3D.OffsetZProperty, translationAnimation); }
public void Rotate() { if (_isRotating) { ++_rotationRequests; return; } else { _isRotating = true; } if (_viewport != null) { // Find front rotation Viewport2DVisual3D backContentSurface = _viewport.Children[1] as Viewport2DVisual3D; RotateTransform3D backTransform = backContentSurface.Transform as RotateTransform3D; AxisAngleRotation3D backRotation = backTransform.Rotation as AxisAngleRotation3D; // Find back rotation Viewport2DVisual3D frontContentSurface = _viewport.Children[2] as Viewport2DVisual3D; RotateTransform3D frontTransform = frontContentSurface.Transform as RotateTransform3D; AxisAngleRotation3D frontRotation = frontTransform.Rotation as AxisAngleRotation3D; // Create a new camera each time, to avoid trying to animate a frozen instance. PerspectiveCamera camera = this.CreateCamera(); _viewport.Camera = camera; // Create animations. DoubleAnimation rotationAnim = new DoubleAnimation { Duration = new Duration(TimeSpan.FromMilliseconds(this.AnimationLength)), By = 180 }; Point3DAnimation cameraZoomAnim = new Point3DAnimation { To = new Point3D(0, 0, 2.5), Duration = new Duration(TimeSpan.FromMilliseconds(this.AnimationLength / 2)), AutoReverse = true }; cameraZoomAnim.Completed += this.OnRotationCompleted; // Start the animations. frontRotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, rotationAnim); backRotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, rotationAnim); camera.BeginAnimation(PerspectiveCamera.PositionProperty, cameraZoomAnim); } }
/// <summary> /// Rotates the control in 3D space in the direction specified by the RotationDirection property /// over the amount of time specified by the AnimationLength property. Set the EasingMode property /// before calling this method to specify how the animated rotation should behave. /// </summary> public void Rotate() { if (!this.CanRotate) { throw new InvalidOperationException("You cannot call the Rotate method of ContentControl3D when CanRotate is set to false."); } if (_viewport == null) { throw new InvalidOperationException("The ContentControl3D's control template does not contain a Viewport3D whose name is PART_Viewport."); } if (_frontRotation == null) { throw new InvalidOperationException("The ContentControl3D's control template does not contain a Visual2DViewport3D with an AxisAngleRotation3D for the front side."); } if (_backRotation == null) { throw new InvalidOperationException("The ContentControl3D's control template does not contain a Visual2DViewport3D with an AxisAngleRotation3D for the back side."); } if (this.IsRotating) { return; } // Avoid trying to animate a frozen instance. if (_viewport.Camera.IsFrozen) { _viewport.Camera = this.CreateCamera(); } PerspectiveCamera camera = _viewport.Camera as PerspectiveCamera; // Create the animations. DoubleAnimation frontAnimation, backAnimation; this.PrepareForRotation(out frontAnimation, out backAnimation); Point3DAnimation cameraZoomAnim = this.CreateCameraAnimation(); // Start the animations. _frontRotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, frontAnimation); _backRotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, backAnimation); camera.BeginAnimation(PerspectiveCamera.PositionProperty, cameraZoomAnim); this.IsRotating = true; }
private void InitAnimations() { foreach (GradientBall ball in _balls) { var animation = new DoubleAnimation(0, 360, new Duration(new TimeSpan(0, 0, 5))) { By = 0.5, RepeatBehavior = RepeatBehavior.Forever }; var vect = new Vector3D(0, 1, 0); var rt3D = new AxisAngleRotation3D(vect, 0); var transform = new RotateTransform3D(rt3D); ball.TransformGroup.Children.Add(transform); rt3D.BeginAnimation(AxisAngleRotation3D.AngleProperty, animation); } }
private void Grid_MouseDown(object sender, MouseButtonEventArgs e) { DoubleAnimation da = new DoubleAnimation(); da.Duration = new Duration(TimeSpan.FromSeconds(1)); if (e.ClickCount == 2) { da.To = 0d; } else { da.To = 180d; } AxisAngleRotation3D aar = this.FindName("aar") as AxisAngleRotation3D; aar.BeginAnimation(AxisAngleRotation3D.AngleProperty, da); }
public bool rotate(KeyValuePair <Move, RotationDirection> move) { if (animation_lock) { return(false); } Dictionary <Move, CubeFace> dominantFaces = new Dictionary <Move, CubeFace> { { Move.B, CubeFace.R }, { Move.D, CubeFace.R }, { Move.E, CubeFace.R }, { Move.F, CubeFace.R }, { Move.L, CubeFace.F }, { Move.M, CubeFace.F }, { Move.R, CubeFace.F }, { Move.S, CubeFace.R }, { Move.U, CubeFace.F }, }; HashSet <Move> possibleMoves = new HashSet <Move>(); Vector3D axis = getRotationAxis(move.Key); double angle = 90 * Convert.ToInt32(move.Value); AxisAngleRotation3D rotation = new AxisAngleRotation3D(axis, angle); RotateTransform3D transform = new RotateTransform3D(rotation, new Point3D(0, 0, 0)); DoubleAnimation animation = new DoubleAnimation(0, angle, animationDuration); foreach (Cube c in this.Children) { possibleMoves = new HashSet <Move>(c.possibleMoves); possibleMoves.Remove((Move)dominantFaces[move.Key]); if (possibleMoves.Contains(move.Key)) { c.possibleMoves = getNextPossibleMoves(c.possibleMoves, move.Key, move.Value); c.rotations.Children.Add(transform); } } projection.rotate(move); rotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, animation); return(true); }
public void Animate(int index, bool animate) { if (animate || rotation.HasAnimatedProperties) { var rotateAnimation = new DoubleAnimation(RotationAngle(index), AnimationDuration); var xAnimation = new DoubleAnimation(TranslationX(index), AnimationDuration); var zAnimation = new DoubleAnimation(TranslationZ(index), AnimationDuration); rotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, rotateAnimation); translation.BeginAnimation(TranslateTransform3D.OffsetXProperty, xAnimation); translation.BeginAnimation(TranslateTransform3D.OffsetZProperty, zAnimation); } else { rotation.Angle = RotationAngle(index); translation.OffsetX = TranslationX(index); translation.OffsetZ = TranslationZ(index); } }
private void Image_MouseMove(object sender, MouseEventArgs e) { var moveX = (e.GetPosition(this.img).X / this.img.ActualWidth - 0.5) * (-25); var moveY = -(e.GetPosition(this.img).Y / this.img.ActualHeight - 0.5) * (-20); DoubleAnimation da = new DoubleAnimation(); da.Duration = new Duration(TimeSpan.FromSeconds(1)); da.To = 10d; Vector3D axis = new Vector3D(moveX, moveY, 0); AxisAngleRotation3D aar = this.FindName("MyAxisAngleRotation3D") as AxisAngleRotation3D; if (aar != null) { aar.Axis = axis; aar.BeginAnimation(AxisAngleRotation3D.AngleProperty, da); } }
/// <summary> /// 移动 /// </summary> internal void Move(int currentIndex, bool animated) { if (animated || _rotation3D.HasAnimatedProperties) { _rotation3D.BeginAnimation(AxisAngleRotation3D.AngleProperty, AnimationHelper.CreateAnimation(GetAngleByPos(currentIndex), AnimationSpeed)); _transform3D.BeginAnimation(TranslateTransform3D.OffsetXProperty, AnimationHelper.CreateAnimation(GetXByPos(currentIndex), AnimationSpeed)); _transform3D.BeginAnimation(TranslateTransform3D.OffsetZProperty, AnimationHelper.CreateAnimation(GetZByPos(currentIndex), AnimationSpeed)); } else { _rotation3D.Angle = GetAngleByPos(currentIndex); _transform3D.OffsetX = GetXByPos(currentIndex); _transform3D.OffsetZ = GetZByPos(currentIndex); } }
/// <summary> /// Adds ModelVisual3D object to the viewport so it can render. Applies rotation animation if the element isn't a 3d text object. /// </summary> /// <returns>deepest Y value of any child node</returns> internal float BuildTreeMesh() { float minY = 0.35f; var meshList = TreeMeshGenerator.BuildModelVisual3DTree(((MainWindow)Application.Current.MainWindow).RootTreeNode, 0f, minY, 0f, ref minY); ui_viewport.Children.Clear(); // re-add light as we just burned it ui_viewport.Children.Add(new ModelVisual3D() { Content = new DirectionalLight(Colors.White, new Vector3D(3, -4, -5)) }); // add children to viewport and apply animation foreach (var entry in meshList) { ui_viewport.Children.Add(entry); // sneaky sneaky $10, we're world transforming the text manually for now, skip anims if (entry.Transform == Transform3D.Identity) { continue; } Transform3D currentTransform = entry.Transform.Clone(); DoubleAnimation angleAnimation = new DoubleAnimation(180, TimeSpan.FromSeconds(2)); angleAnimation.RepeatBehavior = RepeatBehavior.Forever; AxisAngleRotation3D rotateAxis = new AxisAngleRotation3D(new Vector3D(0, 1, 0), 0); RotateTransform3D rotationTransform = new RotateTransform3D(rotateAxis); // use a transform group to reorder the rotation to be local axis Transform3DGroup transform3DGroup = new Transform3DGroup(); transform3DGroup.Children.Add(rotationTransform); transform3DGroup.Children.Add(currentTransform); entry.Transform = transform3DGroup; rotateAxis.BeginAnimation(AxisAngleRotation3D.AngleProperty, angleAnimation); } return(minY); }
public void Animate(double aRotationAngle, double aTranslationX, double aTranslationY, double aTranslationZ, TimeSpan aAnimationDuration) { var rotateAnimation = new DoubleAnimation(aRotationAngle, aAnimationDuration); var xAnimation = new DoubleAnimation(aTranslationX, aAnimationDuration); var yAnimation = new DoubleAnimation(aTranslationY, aAnimationDuration); var zAnimation = new DoubleAnimation(aTranslationZ, aAnimationDuration); if (_Rotation != null) { _Rotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, rotateAnimation); } if (_Translation != null) { _Translation.BeginAnimation(TranslateTransform3D.OffsetXProperty, xAnimation); _Translation.BeginAnimation(TranslateTransform3D.OffsetYProperty, yAnimation); _Translation.BeginAnimation(TranslateTransform3D.OffsetZProperty, zAnimation); } }
public void ApplyAnimation(string path, bool loop = true) { var ean = EAN.FromFile(path); var transforms = new Transform3DGroup(); AxisAngleRotation3D x, y, z; transforms.Children.Add(new ScaleTransform3D(ean.BlockScaleX.DefaultValue, ean.BlockScaleY.DefaultValue, ean.BlockScaleZ.DefaultValue)); transforms.Children.Add(new RotateTransform3D( z = new AxisAngleRotation3D(new Vector3D(0, 0, 1), ean.BlockRotateZ.DefaultValue * ToDegree))); transforms.Children.Add(new RotateTransform3D( y = new AxisAngleRotation3D(new Vector3D(0, 1, 0), ean.BlockRotateY.DefaultValue * ToDegree))); transforms.Children.Add(new RotateTransform3D( x = new AxisAngleRotation3D(new Vector3D(1, 0, 0), ean.BlockRotateX.DefaultValue * ToDegree))); transforms.Children.Add(new TranslateTransform3D(ean.BlockTranslateX.DefaultValue, ean.BlockTranslateY.DefaultValue, ean.BlockTranslateZ.DefaultValue)); foreach (var child in Model.Children) { child.Transform = transforms; } var repeatBehavior = loop ? RepeatBehavior.Forever : new RepeatBehavior(1); transforms.Children[0].BeginAnimation(ScaleTransform3D.ScaleZProperty, GetAnimation(repeatBehavior, ean.Header.Duration, ean.BlockScaleZ)); transforms.Children[0].BeginAnimation(ScaleTransform3D.ScaleYProperty, GetAnimation(repeatBehavior, ean.Header.Duration, ean.BlockScaleY)); transforms.Children[0].BeginAnimation(ScaleTransform3D.ScaleXProperty, GetAnimation(repeatBehavior, ean.Header.Duration, ean.BlockScaleX)); z.BeginAnimation(AxisAngleRotation3D.AngleProperty, GetAnimation(repeatBehavior, ean.Header.Duration, ean.BlockRotateZ, ToDegree)); y.BeginAnimation(AxisAngleRotation3D.AngleProperty, GetAnimation(repeatBehavior, ean.Header.Duration, ean.BlockRotateY, ToDegree)); x.BeginAnimation(AxisAngleRotation3D.AngleProperty, GetAnimation(repeatBehavior, ean.Header.Duration, ean.BlockRotateX, ToDegree)); transforms.Children[4].BeginAnimation(TranslateTransform3D.OffsetZProperty, GetAnimation(repeatBehavior, ean.Header.Duration, ean.BlockTranslateZ)); transforms.Children[4].BeginAnimation(TranslateTransform3D.OffsetYProperty, GetAnimation(repeatBehavior, ean.Header.Duration, ean.BlockTranslateY)); transforms.Children[4].BeginAnimation(TranslateTransform3D.OffsetXProperty, GetAnimation(repeatBehavior, ean.Header.Duration, ean.BlockTranslateX)); }
private void OnFrame(object sender, EventArgs e) { if (TimeValue >= Count) { if (frameTimer != null) { frameTimer.Stop(); } return; } if (TimeValue == Count - 1) { this.bottomControl.BottomText = 0.ToString(); } //List<MyCardControl> cardList = GetChildObjects<MyCardControl>(this.mainGrid); foreach (var item in cardList) { if (item.ShowValue == Count - TimeValue) { Canvas.SetZIndex(item, Count + TimeValue); DoubleAnimation da = new DoubleAnimation(); da.Duration = new Duration(TimeSpan.FromSeconds(1)); da.To = 180d; item.ShowValue--; item.backControl.BackText = item.ShowValue.ToString(); AxisAngleRotation3D aar = item.FindName("MyAxisAngleRotation3D") as AxisAngleRotation3D; if (aar != null) { aar.BeginAnimation(AxisAngleRotation3D.AngleProperty, da); } break; } } TimeValue++; }
private void AnimationVisualElement(AxisAngleRotation3D rotate, ScaleTransform3D scale, double angel, double scaleX, double scaleY, double scaleZ) { Duration duration = new Duration(TimeSpan.FromSeconds(.1)); //对AxisAngleRotation3D的Angle属性应用动画 DoubleAnimation animationAngel = new DoubleAnimation(); animationAngel.To = angel; animationAngel.AccelerationRatio = 0.3; animationAngel.DecelerationRatio = 0.7; animationAngel.Duration = duration; rotate.BeginAnimation(AxisAngleRotation3D.AngleProperty, animationAngel); //对ScaleTransform3D的scaleX属性应用动画 DoubleAnimation animationScaleX = new DoubleAnimation(); animationScaleX.To = scaleX; animationScaleX.AccelerationRatio = 0.3; animationScaleX.DecelerationRatio = 0.7; animationScaleX.Duration = duration; scale.BeginAnimation(ScaleTransform3D.ScaleXProperty, animationScaleX); DoubleAnimation animationScaleY = new DoubleAnimation(); animationScaleY.To = scaleY; animationScaleY.AccelerationRatio = 0.3; animationScaleY.DecelerationRatio = 0.7; animationScaleY.Duration = duration; scale.BeginAnimation(ScaleTransform3D.ScaleYProperty, animationScaleY); scale.ScaleZ = scaleZ; /* * //对ScaleTransform3D的scaleZ属性应用动画 * DoubleAnimation animationScaleZ = new DoubleAnimation(); * animationScaleZ.To = scaleZ; * animationScaleZ.AccelerationRatio = 0.3; * animationScaleZ.DecelerationRatio = 0.7; * animationScaleZ.Duration = duration; * scale.BeginAnimation(ScaleTransform3D.ScaleXProperty, animationScaleZ); */ }