Beispiel #1
0
        public void InvalidateFrame(int frame)
        {
            if (frame <= 0)
            {
                throw new Exception("Cannot invalidate frame 0 for camera");
            }
            if (frame < _frames.Count)
            {
                _frames.RemoveRange(
                    frame,
                    _frames.Count - frame);
                if (_prevframe <= frame)
                {
                    _prevframe = -1;
                }
            }
            var cachepos = (frame / cacherate);

            if (frame % cacherate != 0)
            {
                cachepos++;
            }

            if (cachepos < _framecache.Count)
            {
                _framecache.RemoveRange(cachepos, _framecache.Count - cachepos);
            }
            if (frame == 1)
            {
                Rider firstframe = _timeline.GetFrame(0);
                var   entry      = new CameraEntry(firstframe.CalculateCenter());
                _frames[0]     = entry;
                _framecache[0] = Vector2d.Zero;
            }
        }
        protected override Vector2d StepCamera(CameraBoundingBox box, ref Vector2d prev, int frame)
        {
            const double push = 0.8;
            const double pull = 0.01;

            CameraEntry entry      = _frames[frame];
            var         ret        = box.Clamp(prev + entry.CameraOffset);
            Angle       a          = Angle.FromVector(ret);
            double      length     = ret.Length;
            double      prevlength = prev.Length;
            var         edge       = a.MovePoint(
                Vector2d.Zero,
                Math.Max(box.Bounds.Width, box.Bounds.Height));
            double maxlength   = box.Clamp(edge).Length;
            double lengthratio = length / maxlength;
            double prevratio   = prevlength / maxlength;
            double diffratio   = Math.Abs(lengthratio - prevratio);

            if (length > prevlength)
            {
                var dr     = lengthratio - prevratio;
                var damper = lengthratio - (dr / 2);

                var delta = length - prevlength;
                delta *= Math.Max(0.05, push * (1 - Math.Max(0, damper)));
                length = prevlength + delta;
            }

            length -= length * pull;
            return(box.Clamp(a.MovePoint(Vector2d.Zero, length)));
        }
Beispiel #3
0
        private CameraEntry GetNext(CameraEntry prev, Rider rider)
        {
            // todo i really wish this cared about angles
            // it shouldnt center if the next step is going towards the center
            // of the previous
            // something like that
            var center   = rider.CalculateCenter();
            var prevoffs = prev.Position;
            var offset   = (center - prev.Position);

            offset = Vector2d.Lerp(prevoffs, center, 0.15);
            return(new CameraEntry(center, offset, rider.CalculateMomentum()));
        }
 private void EnsureFrame(int frame)
 {
     //ensure timeline has the frames for us
     //also timeline might invalidate our prev frames when calling
     //so we do this at the top so it doesnt invalidate while calculating
     _timeline.GetFrame(frame);
     if (frame >= _frames.Count)
     {
         var diff   = frame - (_frames.Count - 1);
         var frames = _timeline.GetFrames(_frames.Count, diff);
         for (int i = 0; i < diff; i++)
         {
             var rider  = frames[i];
             var center = rider.CalculateCenter();
             var entry  = new CameraEntry(center, center, rider.CalculateMomentum());
             _frames.Add(entry);
         }
     }
 }
Beispiel #5
0
 public override void InvalidateFrame(int frame)
 {
     if (frame <= 0)
     {
         throw new Exception("Cannot invalidate frame 0 for camera");
     }
     if (frame < _frames.Count)
     {
         _frames.RemoveRange(
             frame,
             _frames.Count - frame);
     }
     if (frame == 1)
     {
         var firstframe = _timeline.GetFrame(0);
         var entry      = new CameraEntry(firstframe.CalculateCenter());
         _frames[0] = entry;
     }
 }
Beispiel #6
0
 protected void EnsureFrame(int frame)
 {
     //ensure timeline has the frames for us
     //also timeline might invalidate our prev frames when calling
     //so we do this at the top so it doesnt invalidate while calculating
     _timeline.GetFrame(frame);
     if (frame >= _frames.Count)
     {
         var diff      = frame - (_frames.Count - 1);
         var frames    = _timeline.GetFrames(_frames.Count, diff);
         var camoffset = _frames[_frames.Count - 1];
         for (int i = 0; i < diff; i++)
         {
             var center = frames[i].CalculateCenter();
             var offset = camoffset.RiderCenter - center;
             camoffset = new CameraEntry(center, offset, Vector2d.Zero);
             _frames.Add(camoffset);
         }
     }
 }
Beispiel #7
0
 private Vector2d Clamp(Vector2d pos, CameraEntry entry)
 {
     return(Clamp(pos, entry.RiderCenter, entry.ppf));
 }