Beispiel #1
0
        /// <inheritdoc />
        /// <summary>
        ///     Ctor
        /// </summary>
        /// <param name="type"></param>
        /// <param name="processor"></param>
        internal HealthBar(HealthBarType type, ScoreProcessor processor) : base(SkinManager.Skin.HealthBarBackground)
        {
            Type      = type;
            Processor = processor;

            Size = new ScalableVector2(Frames.First().Width, Frames.First().Height);

            // Start animation
            StartLoop(Direction.Forward, 60);

            // Create the foreground bar (the one that'll serve as the gauge progress).
            ForegroundBar = new AnimatableSprite(SkinManager.Skin.HealthBarForeground)
            {
                Parent             = this,
                SpriteBatchOptions = new SpriteBatchOptions()
                {
                    SortMode          = SpriteSortMode.Deferred,
                    BlendState        = BlendState.NonPremultiplied,
                    SamplerState      = SamplerState.PointClamp,
                    DepthStencilState = DepthStencilState.Default,
                    RasterizerState   = RasterizerState.CullNone,
                    Shader            = new Shader(GameBase.Game.Resources.Get("Quaver.Resources/Shaders/semi-transparent.mgfxo"), new Dictionary <string, object>()
                    {
                        { "p_position", new Vector2() },
                        { "p_rectangle", new Vector2() },
                        { "p_dimensions", new Vector2() },
                        { "p_alpha", 0f }
                    })
                }
            };

            ForegroundBar.Size = new ScalableVector2(ForegroundBar.Frames.First().Width, ForegroundBar.Frames.First().Height);

            // Start animation.
            ForegroundBar.StartLoop(Direction.Forward, 60);

            switch (Type)
            {
            case HealthBarType.Horizontal:
                Alignment = Alignment.TopLeft;
                ForegroundBar.Alignment = Alignment.TopLeft;

                ForegroundBar.SpriteBatchOptions.Shader.SetParameter("p_position", new Vector2(ForegroundBar.Width, 0f), true);
                break;

            case HealthBarType.Vertical:
                Alignment = Alignment.BotLeft;
                ForegroundBar.Alignment = Alignment.TopLeft;

                ForegroundBar.SpriteBatchOptions.Shader.SetParameter("p_position", new Vector2(0, 0), true);
                break;

            default:
                throw new NotImplementedException();
            }

            // Set default shader params.
            ForegroundBar.SpriteBatchOptions.Shader.SetParameter("p_rectangle", new Vector2(Width, Height), true);
            ForegroundBar.SpriteBatchOptions.Shader.SetParameter("p_dimensions", new Vector2(Width, Height), true);
        }
Beispiel #2
0
        public override void Update(GameTime gameTime = null)
        {
            //foreach (var piece in Pieces)
            //{
            //    piece.Update();
            //}

            TimeUntilNextFrame -= Global.GameTime.ElapsedGameTime.TotalSeconds;

            if (TimeUntilNextFrame <= 0)
            {
                var frame = Frames.Find(ActiveFrame);

                if (frame.Next != null)
                {
                    ActiveFrame = frame.Next.Value;
                }
                else
                {
                    ActiveFrame = Frames.First();
                }

                TimeUntilNextFrame = Interval;
            }

            ActiveFrame.Update();
        }
Beispiel #3
0
        private void InterpolatePP3()
        {
            PP3[]    npp3;
            double[] ys = new double[Frames.Count];

            if (KeyframeCount > 1)
            {
                npp3 = Interpolation.Do(this);
                double[] y = Frames.Where(t => t.IsKeyframe).Select(t => ((FrameRT)t).PP3File.Compensation).ToArray();
                double[] x = new double[y.Length];
                int      k = 0;
                for (int j = 0; j < Frames.Count; j++)
                {
                    if (Frames[j].IsKeyframe)
                    {
                        x[k] = j; k++;
                    }
                }
                ys = Interpolation.Do(x, y, Frames.Count);
            }
            else
            {
                PP3 firstpp3 = ((FrameRT)Frames.First(t => t.IsKeyframe)).PP3File;
                npp3 = new PP3[Frames.Count];
                for (int j = 0; j < Frames.Count; j++)
                {
                    npp3[j] = firstpp3.Copy();
                    ys[j]   = firstpp3.Compensation;
                }
            }

            for (int i = 0; i < npp3.Length; i++)
            {
                if (IsBrightnessCalculated)
                {
                    if (i == 0 || i == npp3.Length - 1)
                    {
                        npp3[i].NewCompensation = ys[i];
                    }
                    else
                    {
                        npp3[i].NewCompensation = Math.Log(Frames[i].NewBrightness / Frames[i].AlternativeBrightness, 2) + ys[i];
                        if (double.IsNaN(npp3[i].NewCompensation))
                        {
                            throw new NotFiniteNumberException();
                        }
                    }
                }
                else
                {
                    npp3[i].NewCompensation = ys[i];
                }

                npp3[i].NewCompensation = (npp3[i].NewCompensation > 10) ? 10 : (npp3[i].NewCompensation < -5) ? -5 : npp3[i].NewCompensation;
                string path = Frames[i].FilePath + ".pp3";
                npp3[i].Write(path);
                MainWorker.ReportProgress(0, new ProgressChangeEventArgs(i * 100 / (npp3.Length - 1), ProgressType.WritePP3));
            }
        }
Beispiel #4
0
        protected override void WriteFiles()
        {
            XMP[]    nxmp;
            double[] ys = new double[Frames.Count];

            if (KeyframeCount > 1)
            {
                nxmp = Interpolation.Do(this);
                double[] y = Frames.Where(t => t.IsKeyframe).Select(t => ((FrameACR)t).XMPFile.Exposure).ToArray();
                double[] x = new double[y.Length];
                int      k = 0;
                for (int j = 0; j < Frames.Count; j++)
                {
                    if (Frames[j].IsKeyframe)
                    {
                        x[k] = j; k++;
                    }
                }
                ys = Interpolation.Do(x, y, Frames.Count);
            }
            else
            {
                XMP firstxmp = ((FrameACR)Frames.First(t => t.IsKeyframe)).XMPFile;
                nxmp = new XMP[Frames.Count];
                for (int j = 0; j < Frames.Count; j++)
                {
                    nxmp[j]      = firstxmp.Copy();
                    nxmp[j].Path = ((FrameACR)Frames[j]).XMPFile.Path;
                    ys[j]        = firstxmp.Exposure;
                }
            }

            for (int i = 0; i < nxmp.Length; i++)
            {
                if (IsBrightnessCalculated)
                {
                    if (i == 0 || i == nxmp.Length - 1)
                    {
                        nxmp[i].NewExposure = (ys[i] > 10) ? 10 : (ys[i] < -5) ? -5 : ys[i];
                    }
                    else
                    {
                        nxmp[i].NewExposure = Math.Log(Frames[i].NewBrightness / Frames[i].AlternativeBrightness, 2) + ((ys[i] > 5) ? 5 : (ys[i] < -5) ? -5 : ys[i]);
                        if (double.IsNaN(nxmp[i].NewExposure))
                        {
                            throw new NotFiniteNumberException();
                        }
                    }
                }
                else
                {
                    nxmp[i].NewExposure = (ys[i] > 5) ? 5 : (ys[i] < -5) ? -5 : ys[i];
                }
                nxmp[i].Write();
                MainWorker.ReportProgress(0, new ProgressChangeEventArgs(i * 100 / (nxmp.Length - 1), ProgressType.WriteXMP));
            }
        }
Beispiel #5
0
        /// <summary>
        /// Gets the specified frame by its name.
        /// </summary>
        /// <param name="findBy">The name of the frame.</param>
        /// <exception cref="FrameNotFoundException">Thrown if the given name isn't found.</exception>
        public virtual Frame Frame(Constraint findBy)
        {
            var frame = Frames.First(findBy);

            if (frame == null)
            {
                throw new FrameNotFoundException(findBy.ToString());
            }
            return(frame);
        }
Beispiel #6
0
        private void CreateFrames()
        {
            ObservableCollection <WhiskerSpreadFrameViewModel> frames = new ObservableCollection <WhiskerSpreadFrameViewModel>();

            foreach (IWhiskerSpreadFrame frame in Model.Frames)
            {
                frames.Add(new WhiskerSpreadFrameViewModel(frame, this));
            }

            Frames       = frames;
            CurrentFrame = Frames.First();
        }
Beispiel #7
0
        public override void LoadContent(Texture2D texture = null)
        {
            var position = Vector2.Zero;

            for (int i = 0, frameNumber = 0; i < RowCount; i++)
            {
                for (int k = 0; k < ColumnCount; k++, frameNumber++)
                {
                    Image image = new Image(Texture);

                    image.SetRowAndColumnCount(RowCount, ColumnCount);

                    var piece = image.Pieces.FirstOrDefault(p => p.ImageNumber == frameNumber);

                    //piece.SetSize(FrameSize);

                    //piece.SetPosition(position + new Vector2(position.X + k * FrameSize.X, position.Y + i * FrameSize.Y));

                    var frame = new AnimationFrame(this, frameNumber);

                    frame.SetTexture(piece.Texture);

                    frame.SetSize(Size);

                    frame.SetPosition(position + new Vector2(position.X + k * Size.X, position.Y + i * Size.Y));

                    AddFrame(frame);
                }
            }

            Frames.ToList().ForEach(f => f.SetPosition(Position));

            ActiveFrame = Frames.First();

            //var firstFrame = Frames.First();
            //var lastFrame = Frames.Last();

            //for (int i = 0; i < Frames.Count; i++)
            //{
            //    if (firstFrame.Number != Frames[i].Number)
            //    {
            //        Frames[i].Previous = Fra
            //    }
            //}
        }
Beispiel #8
0
        private void CreateFrames()
        {
            ObservableCollection <HeadOrientationFrameViewModel> frames = new ObservableCollection <HeadOrientationFrameViewModel>();

            foreach (IHeadOrientationFrame frame in Model.Frames)
            {
                frames.Add(new HeadOrientationFrameViewModel(frame, this));
            }

            Frames = frames;
            HeadOrientationFrameViewModel firstFrame = Frames.First();
            ObservableCollection <WhiskersEnabledViewModel> displayWhiskers = new ObservableCollection <WhiskersEnabledViewModel>();

            foreach (SingleHeadOrientationViewModel whisker in firstFrame.Whiskers)
            {
                WhiskersEnabledViewModel displayWhisker = new WhiskersEnabledViewModel(this, whisker);
                displayWhiskers.Add(displayWhisker);
            }

            DisplayWhiskers = displayWhiskers;

            CurrentFrame = firstFrame;
        }
        /// <summary>
        /// 判断某时刻指针是否在某物件上
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="time"></param>
        /// <returns></returns>
        public bool Contains(OsuHitObject obj, double time, double?judgement_radius = null)
        {
            if (obj.StartTime == 10752)
            {
            }

            var frame = Frames.LastOrDefault(f => time >= f.Time);

            if (frame == null)
            {
                frame = Frames.First().PreviousFrame;
            }

            var next_frame = frame?.NextFrame;

            if (next_frame == null)
            {
                return(false);
            }

            //插值计算
            var cur_timestramp = (time - frame.Time) / (next_frame.Time - frame.Time);//归一化
            var temp_offset    = (next_frame.Position - frame.Position) * (float)cur_timestramp;

            //指针位置
            var cur_position = frame.Position + temp_offset;

            cur_position = Vector2.Clamp(
                cur_position,
                frame.Position,
                next_frame.Position
                );

            var dist = Vector2.Distance(obj.Position, cur_position);

            return(dist <= (judgement_radius ?? obj.Radius));
        }
Beispiel #10
0
        public void ToHeatmap()
        {
            var teams   = Frames.First().ActorStates.Where(x => x.ClassName == "TAGame.Team_TA");
            var players = Frames.SelectMany(x => x.ActorStates.Where(a => a.ClassName == "TAGame.PRI_TA" && a.Properties != null && a.Properties.Any()))
                          .Select(a => new
            {
                Id          = a.Id,
                Name        = a.Properties.Where(p => p.PropertyName == "Engine.PlayerReplicationInfo:PlayerName").Single().Data[0].ToString(),
                TeamActorId = (int)a.Properties.Where(p => p.PropertyName == "Engine.PlayerReplicationInfo:Team").Single().Data[1]
            })
                          .Distinct();

            var positions = Frames.SelectMany(x => x.ActorStates.Where(a => a.ClassName == "TAGame.Car_TA" && a.Properties != null && a.Properties.Any(p => p.PropertyName == "TAGame.RBActor_TA:ReplicatedRBState")))
                            .Select(a => new
            {
                //PlayerActorId = (int)a.Properties.Where(p => p.PropertyName == "Engine.Pawn:PlayerReplicationInfo").Single().Data[1],
                Position = ((RigidBodyState)a.Properties.Where(p => p.PropertyName == "TAGame.RBActor_TA:ReplicatedRBState").Single().Data[0]).Position
            });


            var minX = positions.Min(x => x.Position.X);
            var minY = positions.Min(x => x.Position.Y);
            var minZ = positions.Min(x => x.Position.Z);
            var maxX = positions.Max(x => x.Position.X);
            var maxY = positions.Max(x => x.Position.Y);
            var maxZ = positions.Max(x => x.Position.Z);

            var maxValue      = 0;
            int heatMapWidth  = (int)(maxX - minX) + 1;
            int heatMapHeight = (int)(maxY - minY) + 1;
            var heatmap       = new byte[heatMapWidth, heatMapHeight];

            foreach (var p in positions)
            {
                int x = (int)(p.Position.X - minX);
                int y = (int)(p.Position.Y - minY);

                var radius        = 50;
                var squaredRadius = Math.Pow(radius, 2);
                for (int cy = y - radius; cy <= y + radius; ++cy)
                {
                    for (int cx = x - radius; cx <= x + radius; ++cx)
                    {
                        var distanceSquared = Math.Pow(cx - x, 2) + Math.Pow(cy - y, 2);

                        if ((cx >= 0) && (cx < heatMapWidth) && (cy >= 0) && (cy < heatMapHeight) && (distanceSquared <= squaredRadius))
                        {
                            heatmap[cx, cy]++;
                            maxValue = Math.Max(maxValue, heatmap[cx, cy]);
                        }
                    }
                }
            }

            System.Drawing.Bitmap bm = new System.Drawing.Bitmap(heatMapWidth, heatMapHeight);
            for (int x = 0; x < heatMapWidth; x++)
            {
                for (int y = 0; y < heatMapHeight; y++)
                {
                    var value = ((double)heatmap[x, y] / (double)maxValue); //(int)(255 * ((double)heatmap[x, y]) / (double)maxValue);
                    bm.SetPixel(x, y, HeatMapColor(value));                 // System.Drawing.Color.FromArgb(value, value, value));
                }
            }
            bm.Save(@"D:\MyData\CodeProjects\RocketLeagueReplayParser\RocketLeagueReplayParserWeb\test.jpg");

            /*
             * var heatMapData = new List<object>();
             * foreach(var p in players)
             * {
             *  heatMapData.Add(new {
             *      PlayerName = p.Name,
             *      Team = teams.Where(x => x.Id == p.TeamActorId).Single().TypeName == "Archetypes.Teams.Team0" ? 0 : 1,
             *      Positions = positions.Where(x=>x.PlayerActorId == p.Id).Select(x=>x.Position)
             *  });
             * }
             * *
             */
        }
Beispiel #11
0
        private void SaveAll()
        {
            try
            {
                if (Frames == null || Frames.Count < 1)
                {
                    Status = new AppStatusInfo()
                    {
                        Status = Enums.Status.Ready
                    };
                    return;
                }
                Status = new AppStatusInfo()
                {
                    Status = Enums.Status.Working
                };
                var dirName = Path.GetDirectoryName(Frames.First().Patch);
                if (string.IsNullOrEmpty(dirName) || !Directory.Exists(dirName))
                {
                    Status = new AppStatusInfo()
                    {
                        Status = Enums.Status.Ready
                    };
                    return;
                }

                foreach (var frame in Frames)
                {
                    if (frame.Rectangles == null || frame.Rectangles.Count <= 0)
                    {
                        continue;
                    }
                    var annotation = new Annotation();
                    annotation.Filename  = Path.GetFileName(frame.Patch);
                    annotation.Folder    = Path.GetRelativePath(dirName, Path.GetDirectoryName(frame.Patch));
                    annotation.Segmented = 0;
                    annotation.Size      = new Models.Size()
                    {
                        Depth  = 3,
                        Height = frame.Height,
                        Width  = frame.Width
                    };
                    foreach (var rectangle in frame.Rectangles)
                    {
                        var o = new Models.Object();
                        o.Name = "Pedestrian";
                        o.Box  = new Box()
                        {
                            Xmax = rectangle.XBase + rectangle.WidthBase,
                            Ymax = rectangle.YBase + rectangle.HeightBase,
                            Xmin = rectangle.XBase,
                            Ymin = rectangle.YBase
                        };
                        annotation.Objects.Add(o);
                    }

                    annotation.SaveToXml(Path.Join(dirName, $"{annotation.Filename}.xml"));
                }
                Console.WriteLine($"Saved to {dirName}");
                Status = new AppStatusInfo()
                {
                    Status = Enums.Status.Ready, StringStatus = $"Success | saved to {dirName}"
                };
            }
            catch (Exception ex)
            {
                Status = new AppStatusInfo()
                {
                    Status       = Enums.Status.Error,
                    StringStatus = $"Error | {ex.Message.Replace('\n', ' ')}"
                };
            }
        }