Ejemplo n.º 1
0
        public static Media3D.Transform3D CreateAnimatedTransform1(Media3D.Transform3DGroup transformGroup, Media3D.Vector3D center, Media3D.Vector3D axis, double speed = 4)
        {
            var rotateAnimation = new Rotation3DAnimation
            {
                RepeatBehavior = RepeatBehavior.Forever,
                By             = new Media3D.AxisAngleRotation3D(axis, 90),
                Duration       = TimeSpan.FromSeconds(speed / 2),
                IsCumulative   = true,
            };

            var rotateTransform = new Media3D.RotateTransform3D();

            rotateTransform.BeginAnimation(Media3D.RotateTransform3D.RotationProperty, rotateAnimation);

            transformGroup.Children.Add(rotateTransform);

            var rotateAnimation1 = new Rotation3DAnimation
            {
                RepeatBehavior = RepeatBehavior.Forever,
                By             = new Media3D.AxisAngleRotation3D(axis, 240),
                Duration       = TimeSpan.FromSeconds(speed / 4),
                IsCumulative   = true,
            };

            var rotateTransform1 = new Media3D.RotateTransform3D();

            rotateTransform1.CenterX = center.X;
            rotateTransform1.CenterY = center.Y;
            rotateTransform1.CenterZ = center.Z;
            rotateTransform1.BeginAnimation(Media3D.RotateTransform3D.RotationProperty, rotateAnimation1);

            transformGroup.Children.Add(rotateTransform1);

            return(transformGroup);
        }
Ejemplo n.º 2
0
        protected override Storyboard PrepareItemAnimation(ElementFlow owner, int index, ElementFlow.ElementAnimationType type)
        {
            // Initialize storyboard
            Storyboard sb = owner.PrepareTemplateStoryboard(index);

            // Child animations
            Rotation3DAnimation rotAnim = sb.Children[0] as Rotation3DAnimation;
            DoubleAnimation     xAnim   = sb.Children[1] as DoubleAnimation;
            DoubleAnimation     yAnim   = sb.Children[2] as DoubleAnimation;
            DoubleAnimation     zAnim   = sb.Children[3] as DoubleAnimation;

            switch (type)
            {
            case ElementFlow.ElementAnimationType.Left:
                (rotAnim.To as AxisAngleRotation3D).Angle = owner.TiltAngle;
                (rotAnim.To as AxisAngleRotation3D).Axis  = new Vector3D(1, 0, 0);
                yAnim.To = -1 * owner.ItemGap * (owner.SelectedIndex - index) - owner.FrontItemGap;
                break;

            case ElementFlow.ElementAnimationType.Right:
                (rotAnim.To as AxisAngleRotation3D).Angle = -1 * owner.TiltAngle;
                (rotAnim.To as AxisAngleRotation3D).Axis  = new Vector3D(1, 0, 0);
                yAnim.To = owner.ItemGap * (index - owner.SelectedIndex) + owner.FrontItemGap;
                break;

            case ElementFlow.ElementAnimationType.Selection:
                (rotAnim.To as AxisAngleRotation3D).Angle = 0;
                yAnim.To = 0;
                zAnim.To = owner.PopoutDistance;
                break;
            }

            return(sb);
        }
        protected override Storyboard PrepareItemAnimation(UIFlow3D owner, int index, UIFlow3D.ElementAnimationType type)
        {
            // Initialize storyboard
            Storyboard sb = (owner.InternalResources["ItemAnimator"] as Storyboard).Clone();

            owner.PrepareTemplateStoryboard(sb, index);

            // Child animations
            Rotation3DAnimation rotAnim = sb.Children[0] as Rotation3DAnimation;
            DoubleAnimation     xAnim   = sb.Children[1] as DoubleAnimation;
            DoubleAnimation     yAnim   = sb.Children[2] as DoubleAnimation;
            DoubleAnimation     zAnim   = sb.Children[3] as DoubleAnimation;

            switch (type)
            {
            case UIFlow3D.ElementAnimationType.Left:
                xAnim.To = -1 * owner.ItemGap * (owner.SelectedIndex - index);
                zAnim.To = owner.ItemGap * (owner.SelectedIndex - index);
                break;

            case UIFlow3D.ElementAnimationType.Selection:
                (rotAnim.To as AxisAngleRotation3D).Angle = -1 * 45;
                (rotAnim.To as AxisAngleRotation3D).Axis  = new Vector3D(0, 0, 1);
                xAnim.To = 2 * owner.ItemGap;
                break;

            case UIFlow3D.ElementAnimationType.Right:
                xAnim.To = owner.ItemGap * (index - owner.SelectedIndex);
                zAnim.To = -1 * owner.ItemGap * (index - owner.SelectedIndex);
                break;
            }

            return(sb);
        }
Ejemplo n.º 4
0
        private Rotation3DAnimation FlipOutAnimation()
        {
            Rotation3D fromValue = new AxisAngleRotation3D(new Vector3D(0, 1, 0), 0);
            Rotation3D toValue   = new AxisAngleRotation3D(new Vector3D(0, 1, 0), 90);
            var        t         = new Rotation3DAnimation(null, toValue, new Duration(TimeSpan.FromSeconds(1)), FillBehavior.HoldEnd);

            return(t);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Called when this MainWindow is first loaded.  Starts the cursor spinning.
        /// </summary>
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            Rotation3DAnimation cursorSpinner
                = new Rotation3DAnimation(new AxisAngleRotation3D(new Vector3D(0, 0, 1), 0.0),
                                          new AxisAngleRotation3D(new Vector3D(0, 0, 1), 90.0),
                                          new Duration(TimeSpan.FromMilliseconds(500)));

            cursorSpinner.RepeatBehavior = RepeatBehavior.Forever;
            rotatorPointer.BeginAnimation(RotateTransform3D.RotationProperty, cursorSpinner);
        }
Ejemplo n.º 6
0
        public void Rotate(double angle)
        {
            RotateTransform3D _rotateTransform = new RotateTransform3D();
            var _axisAngleRotation3D           = new AxisAngleRotation3D {
                Axis = new Vector3D(0, 1, 0), Angle = 360 - angle
            };

            this.DressCamera.Transform = _rotateTransform;
            Rotation3DAnimation _rotateAnimation = new Rotation3DAnimation(_axisAngleRotation3D, TimeSpan.FromSeconds(0));

            _rotateTransform.BeginAnimation(RotateTransform3D.RotationProperty, _rotateAnimation);
        }
        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);
        }
Ejemplo n.º 8
0
        private Transform3D CreateAnimatedTransform1(Vector3D translate, Vector3D axis, double speed = 4)
        {
            var lightTrafo = new Transform3DGroup();

            lightTrafo.Children.Add(new TranslateTransform3D(translate));

            var rotateAnimation = new Rotation3DAnimation {
                RepeatBehavior = RepeatBehavior.Forever,
                By             = new AxisAngleRotation3D(axis, 90),
                Duration       = TimeSpan.FromSeconds(speed / 4),
                IsCumulative   = true,
            };

            var rotateTransform = new RotateTransform3D();

            rotateTransform.BeginAnimation(RotateTransform3D.RotationProperty, rotateAnimation);
            lightTrafo.Children.Add(rotateTransform);

            return(lightTrafo);
        }
Ejemplo n.º 9
0
        internal Storyboard PrepareTemplateStoryboard(int index)
        {
            // Initialize storyboard
            var sb = InternalResources["ElementAnimator"] as Storyboard;
            Rotation3DAnimation rotAnim = sb.Children[0] as Rotation3DAnimation;

            Storyboard.SetTargetProperty(rotAnim, BuildTargetPropertyPath(index, AnimationType.Rotation));

            if (index == SelectedIndex)
            {
                if (sb.Children.Count >= 7)
                {
                    for (int x = 0; x < 3; x++)
                    {
                        // Remove items 1,2,3, making 4,5,6 to be 1,2,3
                        sb.Children.RemoveAt(1);
                    }
                }
            }

            while (sb.Children.Count > 4)
            {
                // Remove all items after 3
                sb.Children.RemoveAt(4);
            }

            DoubleAnimation xAnim = sb.Children[1] as DoubleAnimation;

            Storyboard.SetTargetProperty(xAnim, BuildTargetPropertyPath(index, AnimationType.TranslationX));

            DoubleAnimation yAnim = sb.Children[2] as DoubleAnimation;

            Storyboard.SetTargetProperty(yAnim, BuildTargetPropertyPath(index, AnimationType.TranslationY));

            DoubleAnimation zAnim = sb.Children[3] as DoubleAnimation;

            Storyboard.SetTargetProperty(zAnim, BuildTargetPropertyPath(index, AnimationType.TranslationZ));

            return(sb);
        }
Ejemplo n.º 10
0
        internal Storyboard PrepareTemplateStoryboard(int index)
        {
            // Initialize storyboard
            Storyboard          sb      = (InternalResources["ItemAnimator"] as Storyboard).Clone();
            Rotation3DAnimation rotAnim = sb.Children[0] as Rotation3DAnimation;

            Storyboard.SetTargetName(rotAnim, ElementIdentifier + index);

            DoubleAnimation xAnim = sb.Children[1] as DoubleAnimation;

            Storyboard.SetTargetName(xAnim, ElementIdentifier + index);

            DoubleAnimation yAnim = sb.Children[2] as DoubleAnimation;

            Storyboard.SetTargetName(yAnim, ElementIdentifier + index);

            DoubleAnimation zAnim = sb.Children[3] as DoubleAnimation;

            Storyboard.SetTargetName(zAnim, ElementIdentifier + index);

            return(sb);
        }
        internal Storyboard PrepareTemplateStoryboard(int index)
        {
            // Initialize storyboard
            var sb = InternalResources["ElementAnimator"] as Storyboard;
            Rotation3DAnimation rotAnim = sb.Children[0] as Rotation3DAnimation;

            Storyboard.SetTargetProperty(rotAnim, BuildTargetPropertyPath(index, AnimationType.Rotation));

            DoubleAnimation xAnim = sb.Children[1] as DoubleAnimation;

            Storyboard.SetTargetProperty(xAnim, BuildTargetPropertyPath(index, AnimationType.TranslationX));

            DoubleAnimation yAnim = sb.Children[2] as DoubleAnimation;

            Storyboard.SetTargetProperty(yAnim, BuildTargetPropertyPath(index, AnimationType.TranslationY));

            DoubleAnimation zAnim = sb.Children[3] as DoubleAnimation;

            Storyboard.SetTargetProperty(zAnim, BuildTargetPropertyPath(index, AnimationType.TranslationZ));

            return(sb);
        }
Ejemplo n.º 12
0
        internal Storyboard PrepareTemplateStoryboard(int index)
        {
            // Initialize storyboard
            Storyboard          sb      = (InternalResources["ElementAnimator"] as Storyboard).Clone();
            Rotation3DAnimation rotAnim = sb.Children[0] as Rotation3DAnimation;

            Storyboard.SetTargetProperty(rotAnim, BuildTargetPropertyPath(index, "Rotation"));

            DoubleAnimation xAnim = sb.Children[1] as DoubleAnimation;

            Storyboard.SetTargetProperty(xAnim, BuildTargetPropertyPath(index, "Translation-X"));

            DoubleAnimation yAnim = sb.Children[2] as DoubleAnimation;

            Storyboard.SetTargetProperty(yAnim, BuildTargetPropertyPath(index, "Translation-Y"));

            DoubleAnimation zAnim = sb.Children[3] as DoubleAnimation;

            Storyboard.SetTargetProperty(zAnim, BuildTargetPropertyPath(index, "Translation-Z"));

            return(sb);
        }
Ejemplo n.º 13
0
        private Media3D.Transform3D CreateAnimatedTransform2(Vector3D translate, Vector3D axis, double speed = 4)
        {
            var lightTrafo = new Media3D.Transform3DGroup();

            lightTrafo.Children.Add(new Media3D.TranslateTransform3D(translate));

            var rotateAnimation = new Rotation3DAnimation
            {
                RepeatBehavior = RepeatBehavior.Forever,
                //By = new Media3D.AxisAngleRotation3D(axis, 180),
                From        = new Media3D.AxisAngleRotation3D(axis, 135),
                To          = new Media3D.AxisAngleRotation3D(axis, 225),
                AutoReverse = true,
                Duration    = TimeSpan.FromSeconds(speed / 4),
                //IsCumulative = true,
            };

            var rotateTransform = new Media3D.RotateTransform3D();

            rotateTransform.BeginAnimation(Media3D.RotateTransform3D.RotationProperty, rotateAnimation);
            lightTrafo.Children.Add(rotateTransform);
            return(lightTrafo);
        }
Ejemplo n.º 14
0
        public MainViewModel()
        {
            EffectsManager  = new DefaultEffectsManager();
            RenderTechnique = EffectsManager[DefaultRenderTechniqueNames.Blinn];


            // ----------------------------------------------
            // titles
            this.Title    = "SwapChain Top Surface Rendering Demo";
            this.SubTitle = "WPF & SharpDX";

            // ----------------------------------------------
            // camera setup
            this.Camera = new PerspectiveCamera {
                Position = new Point3D(100, 100, 100), LookDirection = new Vector3D(-100, -100, -100), UpDirection = new Vector3D(0, 1, 0)
            };

            // ----------------------------------------------
            // setup scene
            this.AmbientLightColor = Colors.DimGray;

            this.Light1Color = Colors.White;
            this.Light2Color = Colors.Red;
            this.Light3Color = Colors.LightYellow;
            this.Light4Color = Colors.LightBlue;

            this.Light2Attenuation = new Vector3D(0.1f, 0.05f, 0.010f);
            this.Light3Attenuation = new Vector3D(0.1f, 0.01f, 0.005f);
            this.Light4Attenuation = new Vector3D(0.1f, 0.02f, 0.0f);

            this.Light1Direction          = new Vector3D(0, -10, -10);
            this.Light1Transform          = new TranslateTransform3D(-Light1Direction);
            this.Light1DirectionTransform = CreateAnimatedTransform2(-Light1Direction, new Vector3D(0, 1, -1), 36);

            this.Light2Transform = CreateAnimatedTransform1(new Vector3D(-100, 50, 0), new Vector3D(0, 0, 1), 3);
            this.Light3Transform = CreateAnimatedTransform1(new Vector3D(0, 50, 100), new Vector3D(0, 1, 0), 5);

            this.Light4Direction          = new Vector3D(0, -100, 0);
            this.Light4Transform          = new TranslateTransform3D(-Light4Direction);
            this.Light4DirectionTransform = CreateAnimatedTransform2(-Light4Direction, new Vector3D(1, 0, 0), 48);

            // ----------------------------------------------
            // light model3d
            var sphere = new MeshBuilder();

            sphere.AddSphere(new Vector3(0, 0, 0), 4);
            Sphere = sphere.ToMeshGeometry3D();
            this.LightModelMaterial = new PhongMaterial
            {
                AmbientColor  = Colors.Gray.ToColor4(),
                DiffuseColor  = Colors.Gray.ToColor4(),
                EmissiveColor = Colors.Yellow.ToColor4(),
                SpecularColor = Colors.Black.ToColor4(),
            };
            Task.Run(() => { LoadFloor(); });
            Task.Run(() => { LoadLander(); });

            var transGroup = new Media3D.Transform3DGroup();

            transGroup.Children.Add(new Media3D.ScaleTransform3D(0.04, 0.04, 0.04));
            var rotateAnimation = new Rotation3DAnimation
            {
                RepeatBehavior = RepeatBehavior.Forever,
                By             = new Media3D.AxisAngleRotation3D(new Vector3D(0, 1, 0), 90),
                Duration       = TimeSpan.FromSeconds(4),
                IsCumulative   = true,
            };
            var rotateTransform = new Media3D.RotateTransform3D();

            transGroup.Children.Add(rotateTransform);
            rotateTransform.BeginAnimation(Media3D.RotateTransform3D.RotationProperty, rotateAnimation);
            transGroup.Children.Add(new Media3D.TranslateTransform3D(0, 60, 0));
            ModelTransform = transGroup;
        }
Ejemplo n.º 15
0
        public MainViewModel()
        {
            EffectsManager  = new DefaultEffectsManager();
            RenderTechnique = EffectsManager[DefaultRenderTechniqueNames.Blinn];


            // ----------------------------------------------
            // titles
            this.Title    = "SwapChain Top Surface Rendering Demo";
            this.SubTitle = "WPF & SharpDX";

            // ----------------------------------------------
            // camera setup
            this.Camera = new PerspectiveCamera {
                Position = new Point3D(100, 100, 100), LookDirection = new Vector3D(-100, -100, -100), UpDirection = new Vector3D(0, 1, 0)
            };

            // ----------------------------------------------
            // setup scene
            this.AmbientLightColor = Colors.DimGray;

            this.Light1Color = Colors.White;
            this.Light2Color = Colors.Red;
            this.Light3Color = Colors.LightYellow;
            this.Light4Color = Colors.LightBlue;

            this.Light2Attenuation = new Vector3D(0.1f, 0.05f, 0.010f);
            this.Light3Attenuation = new Vector3D(0.1f, 0.01f, 0.005f);
            this.Light4Attenuation = new Vector3D(0.1f, 0.02f, 0.0f);

            this.Light1Direction          = new Vector3D(0, -10, -10);
            this.Light1Transform          = new TranslateTransform3D(-Light1Direction);
            this.Light1DirectionTransform = CreateAnimatedTransform2(-Light1Direction, new Vector3D(0, 1, -1), 36);

            this.Light2Transform = CreateAnimatedTransform1(new Vector3D(-100, 50, 0), new Vector3D(0, 0, 1), 3);
            this.Light3Transform = CreateAnimatedTransform1(new Vector3D(0, 50, 100), new Vector3D(0, 1, 0), 5);

            this.Light4Direction          = new Vector3D(0, -100, 0);
            this.Light4Transform          = new TranslateTransform3D(-Light4Direction);
            this.Light4DirectionTransform = CreateAnimatedTransform2(-Light4Direction, new Vector3D(1, 0, 0), 48);

            // ----------------------------------------------
            // light model3d
            var sphere = new MeshBuilder();

            sphere.AddSphere(new Vector3(0, 0, 0), 4);
            Sphere = sphere.ToMeshGeometry3D();
            this.LightModelMaterial = new PhongMaterial
            {
                AmbientColor  = Colors.Gray.ToColor4(),
                DiffuseColor  = Colors.Gray.ToColor4(),
                EmissiveColor = Colors.Yellow.ToColor4(),
                SpecularColor = Colors.Black.ToColor4(),
            };
            var models = Load3ds("wall12.obj").Select(x => x.Geometry as MeshGeometry3D).ToArray();

            Floor = models[0];
            Floor.OctreeParameter.EnableParallelBuild = true;
            this.FloorTransform = new Media3D.TranslateTransform3D(0, 0, 0);
            this.FloorMaterial  = new PhongMaterial
            {
                AmbientColor      = Colors.Gray.ToColor4(),
                DiffuseColor      = new Color4(0.75f, 0.75f, 0.75f, 1.0f),
                SpecularColor     = Colors.White.ToColor4(),
                SpecularShininess = 100f
            };

            var landerItems = Load3ds("Car.3ds").Select(x => x.Geometry as MeshGeometry3D).ToArray();

            Model = MeshGeometry3D.Merge(landerItems);
            Model.OctreeParameter.EnableParallelBuild = true;
            ModelMaterial = PhongMaterials.BlackRubber;
            var transGroup = new Media3D.Transform3DGroup();

            transGroup.Children.Add(new Media3D.ScaleTransform3D(0.04, 0.04, 0.04));
            var rotateAnimation = new Rotation3DAnimation
            {
                RepeatBehavior = RepeatBehavior.Forever,
                By             = new Media3D.AxisAngleRotation3D(new Vector3D(0, 1, 0), 90),
                Duration       = TimeSpan.FromSeconds(4),
                IsCumulative   = true,
            };
            var rotateTransform = new Media3D.RotateTransform3D();

            transGroup.Children.Add(rotateTransform);
            rotateTransform.BeginAnimation(Media3D.RotateTransform3D.RotationProperty, rotateAnimation);
            transGroup.Children.Add(new Media3D.TranslateTransform3D(0, 60, 0));
            ModelTransform    = transGroup;
            NumberOfTriangles = Floor.Indices.Count / 3 + Model.Indices.Count / 3;
            NumberOfVertices  = Floor.Positions.Count + Model.Positions.Count;
        }