Ejemplo n.º 1
0
        public override void Update(GameTime gameTime, IActor actor)
        {
            Actor3D      parentActor      = actor as Actor3D;
            DrawnActor3D targetDrawnActor = this.TargetActor as DrawnActor3D;

            if (this.bFirstUpdate)
            {
                //set the initial position of the camera
                parentActor.Transform3D.Translation = railParameters.MidPoint;
                this.bFirstUpdate = false;
            }

            //get look vector to target
            Vector3 cameraToTarget = MathUtility.GetNormalizedObjectToTargetVector(parentActor.Transform3D, targetDrawnActor.Transform3D);

            //new position for camera if it is positioned between start and the end points of the rail
            Vector3 projectedCameraPosition = parentActor.Transform3D.Translation
                                              + Vector3.Dot(cameraToTarget, railParameters.Look) * railParameters.Look * gameTime.ElapsedGameTime.Milliseconds;

            //do not allow the camera to move outside the rail
            if (railParameters.InsideRail(projectedCameraPosition))
            {
                parentActor.Transform3D.Translation = projectedCameraPosition;
            }

            //set the camera to look at the object
            parentActor.Transform3D.Look = cameraToTarget;

            //set the camera to look at the target object
            parentActor.Transform3D.Look = Vector3.Lerp(this.oldCameraToTarget, cameraToTarget, lerpSpeed);

            //store old values for lerp
            this.oldCameraToTarget = cameraToTarget;
        }
        public override void Update(GameTime gameTime, IActor actor)
        {
            Actor3D      parentActor      = actor as Actor3D;
            DrawnActor3D targetDrawnActor = this.TargetActor as DrawnActor3D;

            if (targetDrawnActor != null)
            {
                if (this.bFirstUpdate)
                {
                    //set the initial position of the camera
                    parentActor.Transform.Translation = railParameters.MidPoint;
                    this.bFirstUpdate = false;
                }

                //get look vector to target
                Vector3 cameraToTarget = MathUtility.GetNormalizedObjectToTargetVector(parentActor.Transform, targetDrawnActor.Transform);
                cameraToTarget = MathUtility.Round(cameraToTarget, 3); //round to prevent floating-point precision errors across updates

                //new position for camera if it is positioned between start and the end points of the rail
                Vector3 projectedCameraPosition = parentActor.Transform.Translation + Vector3.Dot(cameraToTarget, railParameters.Look) * railParameters.Look; // gameTime.ElapsedGameTime.Milliseconds; //removed gameTime multiplier - was causing camera judder when object close to camera
                projectedCameraPosition = MathUtility.Round(projectedCameraPosition, 3);                                                                      //round to prevent floating-point precision errors across updates

                //do not allow the camera to move outside the rail
                if (railParameters.InsideRail(projectedCameraPosition))
                {
                    parentActor.Transform.Translation = projectedCameraPosition;
                }

                //set the camera to look at the object
                parentActor.Transform.Look = cameraToTarget;
            }
        }