상속: MonoBehaviour
예제 #1
0
        private void AnimateCamera(Point3D newTargetPosition, double newDistance)
        {
            // See samples in Animations folder for more info about animations

            // Create a new CameraAnimationNode that will animate the Camera1
            var cameraAnimationNode = new CameraAnimationNode(Camera1);

            if ((Camera1.TargetPosition - newTargetPosition).Length > 5)                                       // We animate the TargetPosition if the difference is bigger the 5
            {
                cameraAnimationNode.PositionTrack.Keys.Add(new Position3DKeyFrame(0, Camera1.TargetPosition)); // Start with current TargetPosition
                cameraAnimationNode.PositionTrack.Keys.Add(new Position3DKeyFrame(100, newTargetPosition));    // End at newTargetPosition

                // Set easing function to smooth the transition
                cameraAnimationNode.PositionTrack.SetEasingFunctionToAllKeys(Ab3d.Animation.EasingFunctions.QuadraticEaseInOutFunction);
            }

            if (Math.Abs(Camera1.Distance - newDistance) > 5)                                                                  // We animate the Distance if the difference is bigger the 5
            {
                cameraAnimationNode.DistanceTrack.Keys.Add(new DoubleKeyFrame(frameNumber: 0, doubleValue: Camera1.Distance)); // Start with current Distance
                cameraAnimationNode.DistanceTrack.Keys.Add(new DoubleKeyFrame(frameNumber: 100, doubleValue: newDistance));    // End with newDistance

                cameraAnimationNode.DistanceTrack.SetEasingFunctionToAllKeys(Ab3d.Animation.EasingFunctions.QuadraticEaseInOutFunction);
            }

            Camera1.AnimationController.AnimationNodes.Clear();
            Camera1.AnimationController.AnimationNodes.Add(cameraAnimationNode);

            Camera1.AnimationController.AutoRepeat      = false;
            Camera1.AnimationController.AutoReverse     = false;
            Camera1.AnimationController.FramesPerSecond = 100; // Take 1 second for the whole animation

            Camera1.AnimationController.StartAnimation();
        }
예제 #2
0
 // Update is called once per frame
 void Update()
 {
     if(Input.anyKeyDown){
         stop();
         return;
     }
     float lerp = 1f-Vector3.Distance(trans.position,node.transform.position)/distanceToNextNode;
     float curSpeed=baseSpeed;
     if(!fixedSpeed&&node.useAnimationCurve){
         curSpeed*=node.curve.Evaluate(lerp);
         curSpeed = Mathf.Max(curSpeed,0.001f);//the camera must be moving at all times!
     }
     trans.position = Vector3.MoveTowards(trans.position,node.transform.position,curSpeed*Time.deltaTime);
     trans.rotation = Quaternion.Slerp (oldRot,node.transform.rotation,lerp);
     if(trans.position.Equals(node.transform.position)){
     //			velocity = Vector3.zero;
     //			oldPos = node.transform.position;
         oldRot = node.transform.rotation;
         if(node.HasNext){
             distanceToNextNode = node.DistanceToNextNode;
             node = node.nextNode;
             if(node.instantFade){
                 trans.position = node.transform.position;
                 trans.rotation = node.transform.rotation;
             }
         }else{
             stop();
         }
     }
 }
예제 #3
0
        private void AnimateCameraRotationToWithCameraAnimationNode(double targetHeading, double targetAttitude, bool useShortestPath = true)
        {
            var lookDirection = Camera1.TargetPosition - Camera1.CameraPosition;
            var distance      = lookDirection.Length;

            lookDirection /= distance; // Normalize


            // IMPORTANT:
            // FreeCamera allows rotation around arbitrary axes and cannot be always converted reliably into heading, attitude and bank.
            // This means that angles (heading, attitude and bank) at the start of the animation may not be always correct.

            double startHeading, startAttitude, startBank;

            Ab3d.Utilities.CameraUtils.CalculateCameraAngles(lookDirection, Camera1.UpDirection, out startHeading, out startAttitude, out startBank);


            if (double.IsNaN(targetHeading))
            {
                targetHeading = startHeading;
            }

            if (double.IsNaN(targetAttitude))
            {
                targetAttitude = startAttitude;
            }


            // Adjust start heading and attitude so that we will come with the shortest path to the target heading and attitude
            if (useShortestPath)
            {
                startHeading  = Ab3d.Utilities.CameraUtils.GetClosestPathStartAngle(startHeading, targetHeading);
                startAttitude = Ab3d.Utilities.CameraUtils.GetClosestPathStartAngle(startAttitude, targetAttitude);
            }


            // Create a new CameraAnimationNode that will animate the Camera1
            var cameraAnimationNode = new CameraAnimationNode(Camera1);

            // Start with current camera Heading and Attitude
            cameraAnimationNode.RotationTrack.Keys.Add(new CameraRotationKeyFrame(0, startHeading, startAttitude));

            // Animate to the specified heading and attitude in 100 frames
            cameraAnimationNode.RotationTrack.Keys.Add(new CameraRotationKeyFrame(100, targetHeading, targetAttitude));


            // It is possible to set different interpolation mode to each KeyFrame, but it is easier
            // to set the same interpolation mode to all key frames with SetInterpolationToAllKeys method.
            cameraAnimationNode.RotationTrack.SetEasingFunctionToAllKeys(Ab3d.Animation.EasingFunctions.QuadraticEaseInOutFunction);


            // Set this animation as one-time only
            _animationController.AutoRepeat  = false;
            _animationController.AutoReverse = false;

            // Use StartAnimation helper method to stop current animation and start the animation defined in cameraAnimationNode
            StartAnimation(cameraAnimationNode);
        }
예제 #4
0
        private void Animation2Button_OnClick(object sender, RoutedEventArgs e)
        {
            // Create a new CameraAnimationNode that will animate the Camera1
            var cameraAnimationNode = new CameraAnimationNode(Camera1);

            // Start with current camera Heading and Attitude

            int startFrameNumber;

            // If animation camera's Heading is not 30 and Attitude is not -20 (with 0.5 degree of tolerance),
            // Than start with CameraRotationKeyFrame that will rotate camera from the current position to the
            // animation start position: Heading = 30; Attitude = -20
            //
            // We also check if the distance is 300
            if (Math.Abs(Camera1.Heading - 30) > 0.5 ||
                Math.Abs(Camera1.Attitude - -20) > 0.5 ||
                Math.Abs(Camera1.Distance - 300) > 1.0)
            {
                cameraAnimationNode.RotationTrack.Keys.Add(new CameraRotationKeyFrame(frameNumber: 0, heading: Camera1.Heading, attitude: Camera1.Attitude));
                cameraAnimationNode.DistanceTrack.Keys.Add(new DoubleKeyFrame(frameNumber: 0, doubleValue: Camera1.Distance));
                startFrameNumber = 100;
            }
            else
            {
                // Camera is already at desired start orientation
                startFrameNumber = 0;
            }

            // Move the predefined camera rotation in 200 frames (2 seconds in default 100 animation frames per second setting - see constructor of this sample)
            cameraAnimationNode.RotationTrack.Keys.Add(new CameraRotationKeyFrame(frameNumber: startFrameNumber, heading: 30, attitude: -20));
            cameraAnimationNode.RotationTrack.Keys.Add(new CameraRotationKeyFrame(startFrameNumber + 300, -90, -30));
            cameraAnimationNode.RotationTrack.Keys.Add(new CameraRotationKeyFrame(startFrameNumber + 400, -90, -30));
            cameraAnimationNode.RotationTrack.Keys.Add(new CameraRotationKeyFrame(startFrameNumber + 500, -90, -30, bank: 360));

            // It is possible to set different interpolation mode to each KeyFrame, but it is easier
            // to set the same interpolation mode to all key frames with SetInterpolationToAllKeys method.
            cameraAnimationNode.RotationTrack.SetEasingFunctionToAllKeys(Ab3d.Animation.EasingFunctions.QuadraticEaseInOutFunction);


            cameraAnimationNode.DistanceTrack.Keys.Add(new DoubleKeyFrame(frameNumber: startFrameNumber, doubleValue: 300));
            cameraAnimationNode.DistanceTrack.Keys.Add(new DoubleKeyFrame(frameNumber: startFrameNumber + 150, doubleValue: 500));
            cameraAnimationNode.DistanceTrack.Keys.Add(new DoubleKeyFrame(frameNumber: startFrameNumber + 300, doubleValue: 200));
            cameraAnimationNode.DistanceTrack.Keys.Add(new DoubleKeyFrame(frameNumber: startFrameNumber + 400, doubleValue: 120));

            // Note that rotation animation is longer then distance animation (last frame number is 500 vs 400).
            // This is not a problem when reversing the animation because the distance value will stay the same on all frame numbers bigger then 400.

            cameraAnimationNode.DistanceTrack.SetEasingFunctionToAllKeys(Ab3d.Animation.EasingFunctions.QuadraticEaseInOutFunction);


            // Set this animation to revert but not to repeat
            _animationController.AutoReverse = true;
            _animationController.AutoRepeat  = false;

            // Use StartAnimation helper method to stop current animation and start the animation defined in cameraAnimationNode
            StartAnimation(cameraAnimationNode);
        }
예제 #5
0
        private void Animation3Button_OnClick(object sender, RoutedEventArgs e)
        {
            // Create a new CameraAnimationNode that will animate the Camera1
            var cameraAnimationNode = new CameraAnimationNode(Camera1);

            // Start with current camera Heading and Attitude

            // Move the predefined camera rotation in 200 frames (2 seconds in default 100 animation frames per second setting - see constructor of this sample)
            cameraAnimationNode.RotationTrack.Keys.Add(new CameraRotationKeyFrame(frameNumber: 0, heading: Camera1.Heading, attitude: Camera1.Attitude));
            cameraAnimationNode.RotationTrack.Keys.Add(new CameraRotationKeyFrame(100, 30, -30));
            cameraAnimationNode.RotationTrack.Keys.Add(new CameraRotationKeyFrame(200, 120, -30));
            cameraAnimationNode.RotationTrack.Keys.Add(new CameraRotationKeyFrame(300, 210, -30));
            cameraAnimationNode.RotationTrack.Keys.Add(new CameraRotationKeyFrame(400, 300, -30));
            cameraAnimationNode.RotationTrack.Keys.Add(new CameraRotationKeyFrame(500, 300, -20));
            cameraAnimationNode.RotationTrack.Keys.Add(new CameraRotationKeyFrame(600, 30, 0));
            cameraAnimationNode.RotationTrack.Keys.Add(new CameraRotationKeyFrame(700, 30, -20));

            // It is possible to set different interpolation mode to each KeyFrame, but it is easier
            // to set the same interpolation mode to all key frames with SetInterpolationToAllKeys method.
            cameraAnimationNode.RotationTrack.SetEasingFunctionToAllKeys(Ab3d.Animation.EasingFunctions.QuadraticEaseInOutFunction);


            cameraAnimationNode.DistanceTrack.Keys.Add(new DoubleKeyFrame(0, Camera1.Distance));
            cameraAnimationNode.DistanceTrack.Keys.Add(new DoubleKeyFrame(100, 150));
            cameraAnimationNode.DistanceTrack.Keys.Add(new DoubleKeyFrame(200, 150));
            cameraAnimationNode.DistanceTrack.Keys.Add(new DoubleKeyFrame(250, 400));
            cameraAnimationNode.DistanceTrack.Keys.Add(new DoubleKeyFrame(300, 150));
            cameraAnimationNode.DistanceTrack.Keys.Add(new DoubleKeyFrame(400, 150));
            cameraAnimationNode.DistanceTrack.Keys.Add(new DoubleKeyFrame(500, 150));
            cameraAnimationNode.DistanceTrack.Keys.Add(new DoubleKeyFrame(600, 40));
            cameraAnimationNode.DistanceTrack.Keys.Add(new DoubleKeyFrame(700, 300));

            cameraAnimationNode.DistanceTrack.SetEasingFunctionToAllKeys(Ab3d.Animation.EasingFunctions.QuadraticEaseInOutFunction);


            cameraAnimationNode.PositionTrack.Keys.Add(new Position3DKeyFrame(0, Camera1.TargetPosition));
            cameraAnimationNode.PositionTrack.Keys.Add(new Position3DKeyFrame(100, new Point3D(-50, 50, 0)));
            cameraAnimationNode.PositionTrack.Keys.Add(new Position3DKeyFrame(200, new Point3D(-50, 50, 0)));
            cameraAnimationNode.PositionTrack.Keys.Add(new Position3DKeyFrame(300, new Point3D(50, 50, 0)));
            cameraAnimationNode.PositionTrack.Keys.Add(new Position3DKeyFrame(400, new Point3D(50, 50, 0)));
            cameraAnimationNode.PositionTrack.Keys.Add(new Position3DKeyFrame(500, new Point3D(0, 50, 0)));
            cameraAnimationNode.PositionTrack.Keys.Add(new Position3DKeyFrame(600, new Point3D(0, 50, 0)));
            cameraAnimationNode.PositionTrack.Keys.Add(new Position3DKeyFrame(700, new Point3D(0, 0, 0)));

            cameraAnimationNode.PositionTrack.SetEasingFunctionToAllKeys(Ab3d.Animation.EasingFunctions.QuadraticEaseInOutFunction);


            // Set this animation to revert but not to repeat
            _animationController.AutoReverse = false;
            _animationController.AutoRepeat  = false;

            _animationController.FramesPerSecond = 100;

            // Use StartAnimation helper method to stop current animation and start the animation defined in cameraAnimationNode
            StartAnimation(cameraAnimationNode);
        }
예제 #6
0
        private void Animation1Button_OnClick(object sender, RoutedEventArgs e)
        {
            // Create a new CameraAnimationNode that will animate the Camera1
            var cameraAnimationNode = new CameraAnimationNode(Camera1);

            // Start with current camera Heading and Attitude

            int startFrameNumber;

            // If animation camera's Heading is not 30 and Attitude is not -20 (with 0.5 degree of tolerance),
            // Than start with CameraRotationKeyFrame that will rotate camera from the current position to the
            // animation start position: Heading = 30; Attitude = -20
            if (Math.Abs(Camera1.Heading - 30) > 0.5 ||
                Math.Abs(Camera1.Attitude - -20) > 0.5)
            {
                cameraAnimationNode.RotationTrack.Keys.Add(new CameraRotationKeyFrame(frameNumber: 0, heading: Camera1.Heading, attitude: Camera1.Attitude));
                startFrameNumber = 100;
            }
            else
            {
                // Camera is already at desired start orientation
                startFrameNumber = 0;
            }

            // Move the predefined camera rotation in 200 frames (2 seconds in when using 100 animation frames per second setting - see constructor of this sample)
            cameraAnimationNode.RotationTrack.Keys.Add(new CameraRotationKeyFrame(frameNumber: startFrameNumber, heading: 30, attitude: -20));
            cameraAnimationNode.RotationTrack.Keys.Add(new CameraRotationKeyFrame(100 + startFrameNumber, 90, -20));
            cameraAnimationNode.RotationTrack.Keys.Add(new CameraRotationKeyFrame(300 + startFrameNumber, 90, 90));
            cameraAnimationNode.RotationTrack.Keys.Add(new CameraRotationKeyFrame(400 + startFrameNumber, 180, -20));
            cameraAnimationNode.RotationTrack.Keys.Add(new CameraRotationKeyFrame(600 + startFrameNumber, 30, -20));

            // It is possible to set different interpolation mode to each KeyFrame, but it is easier
            // to set the same interpolation mode to all key frames with SetInterpolationToAllKeys method.
            cameraAnimationNode.RotationTrack.SetEasingFunctionToAllKeys(Ab3d.Animation.EasingFunctions.QuadraticEaseInOutFunction);


            // Set this animation to revert but not to repeat
            _animationController.AutoReverse = true;
            _animationController.AutoRepeat  = false;

            // Use StartAnimation helper method to stop current animation and start the animation defined in cameraAnimationNode
            StartAnimation(cameraAnimationNode);
        }
예제 #7
0
        private void MoveCameraTo(BoxVisual3D selectedBoxVisual3D)
        {
            // We will animate the camera's TargetPosition from the current position to the center of the selected Box
            // We will also animate camera distance (it will increase slightly and then decrease)
            var targetPosition = selectedBoxVisual3D.CenterPosition;

            if (MathUtils.IsSame(targetPosition, Camera1.TargetPosition))
            {
                return; // If camera is already pointing to the desired location, we do not need to create an animation
            }
            // Create a new CameraAnimationNode that will animate the Camera1
            var cameraAnimationNode = new CameraAnimationNode(Camera1);


            // Move the predefined camera rotation in 200 frames (2 seconds in when using 100 animation frames per second setting)
            cameraAnimationNode.PositionTrack.Keys.Add(new Position3DKeyFrame(frameNumber: 0, position: Camera1.TargetPosition));
            cameraAnimationNode.PositionTrack.Keys.Add(new Position3DKeyFrame(frameNumber: 200, position: targetPosition));

            // It is possible to set different interpolation mode to each KeyFrame, but it is easier
            // to set the same interpolation mode to all key frames with SetInterpolationToAllKeys method.
            cameraAnimationNode.PositionTrack.EasingFunction = Ab3d.Animation.EasingFunctions.QuadraticEaseInOutFunction;


            // Animate camera distance from the current distance to 100
            cameraAnimationNode.DistanceTrack.Keys.Add(new DoubleKeyFrame(frameNumber: 0, doubleValue: Camera1.Distance));

            // If camera is close to the box, then we animate distance with increasing it at first and then going closer later.
            // If camera is farther away, then we go directly to the final distance.
            if (Camera1.Distance < 200)
            {
                cameraAnimationNode.DistanceTrack.Keys.Add(new DoubleKeyFrame(frameNumber: 100, doubleValue: 200));
            }

            cameraAnimationNode.DistanceTrack.Keys.Add(new DoubleKeyFrame(frameNumber: 200, doubleValue: 100));

            cameraAnimationNode.DistanceTrack.SetEasingFunctionToAllKeys(Ab3d.Animation.EasingFunctions.SinusoidalEaseInOutFunction);


            // Use StartAnimation helper method to stop current animation and start the animation defined in cameraAnimationNode
            StartAnimation(cameraAnimationNode);
        }
예제 #8
0
        private void AnimateCameraDistanceTo(double newDistance)
        {
            // Create a new CameraAnimationNode that will animate the Camera1
            var cameraAnimationNode = new CameraAnimationNode(Camera1);

            // Start with current camera Heading and Attitude
            cameraAnimationNode.DistanceTrack.Keys.Add(new DoubleKeyFrame(frameNumber: 0, doubleValue: Camera1.Distance));
            cameraAnimationNode.DistanceTrack.Keys.Add(new DoubleKeyFrame(frameNumber: 100, doubleValue: newDistance));

            // It is possible to set different interpolation mode to each KeyFrame, but it is easier
            // to set the same interpolation mode to all key frames with SetInterpolationToAllKeys method.
            cameraAnimationNode.DistanceTrack.SetEasingFunctionToAllKeys(Ab3d.Animation.EasingFunctions.QuadraticEaseInOutFunction);


            // Set this animation as one-time only
            _animationController.AutoRepeat  = false;
            _animationController.AutoReverse = false;

            // Use StartAnimation helper method to stop current animation and start the animation defined in cameraAnimationNode
            StartAnimation(cameraAnimationNode);
        }