Пример #1
0
        public override void Tick()
        {
            base.Tick();
            if (!player.IsValid())
            {
                Delete(true);
                return;
            }

            if (player.IsPlayerDead)
            {
                SetClass("obscured", true);
                return;
            }

            const float vertOffset = 40;
            const float baseSize   = 100;
            var         worldPos   = player.Position + Vector3.Up * 32;

            SetClass("obscured", Trace.Ray(CurrentView.Position, worldPos).WorldOnly().Run().Hit);

            var screenPos = (player.Position + Vector3.Up * vertOffset).ToScreen();

            Style.Left = Length.Fraction(screenPos.x);
            Style.Top  = Length.Fraction(screenPos.y);

            var transform = new PanelTransform();

            transform.AddScale(baseSize / Vector3.DistanceBetween(CurrentView.Position, worldPos));
            transform.AddTranslateY(Length.Fraction(-0.5f));
            transform.AddTranslateX(Length.Fraction(-0.5f));

            Style.Transform = transform;
            Style.Dirty();
        }
Пример #2
0
        public bool UpdateNameTag(Entity entity)
        {
            // Don't draw local player
            if (entity == Local.Pawn)
            {
                return(false);
            }

            var ball = entity.ActiveChild;

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

            var labelPos = ball.Position + Vector3.Up * 16;

            // Are we looking in this direction?
            var lookDir = (labelPos - CurrentView.Position).Normal;

            if (CurrentView.Rotation.Forward.Dot(lookDir) < 0.5)
            {
                return(false);
            }

            float dist       = labelPos.Distance(CurrentView.Position);
            var   objectSize = 0.05f / dist / (2.0f * MathF.Tan((CurrentView.FieldOfView / 2.0f).DegreeToRadian())) * 3000.0f;

            objectSize = objectSize.Clamp(0.25f, 0.5f);

            if (!ActiveTags.TryGetValue(entity, out var tag))
            {
                tag = CreateNameTag(entity);
                ActiveTags[entity] = tag;
            }

            tag.UpdateFromPlayer(entity);

            var screenPos = labelPos.ToScreen();

            tag.Style.Left    = Length.Fraction(screenPos.x);
            tag.Style.Top     = Length.Fraction(screenPos.y);
            tag.Style.Opacity = 1;

            var transform = new PanelTransform();

            transform.AddTranslateY(Length.Fraction(-1.0f));
            transform.AddScale(objectSize);
            transform.AddTranslateX(Length.Fraction(-0.5f));

            tag.Style.Transform = transform;
            tag.Style.Dirty();

            return(true);
        }
Пример #3
0
        public override void Tick()
        {
            base.Tick();

            var wpos = CurrentView.Rotation.Inverse * (Position.WithZ(0) - CurrentView.Position.WithZ(0)).Normal;

            wpos = wpos.WithZ(0).Normal;

            var angle = MathF.Atan2(wpos.y, -1.0f * wpos.x);

            var pt = new PanelTransform();

            pt.AddTranslateX(Length.Percent(-50.0f));
            pt.AddTranslateY(Length.Percent(-50.0f));
            pt.AddRotation(0, 0, angle.RadianToDegree());

            Style.Transform = pt;
            Style.Dirty();
        }
Пример #4
0
        public override void Tick()
        {
            base.Tick();

            var screenPos = WorldPos.ToScreen();

            // this is probably all wrong, it's based on the position on the screen
            // but I think the original hl1 one did kind of a top down view thing, so
            // at the top meant in front, at the back meant behind. We could probably make
            // that mostly work the same here by rotating worldpos by our view pitch

            // TODO - we need screen width and height to make this proper accurate

            var angle = MathF.Atan2(0.5f - screenPos.x, -1.0f * (0.5f - screenPos.y));

            var pt = new PanelTransform();

            pt.AddTranslateX(Length.Percent(-50.0f));
            pt.AddTranslateY(Length.Percent(-50.0f));
            pt.AddRotation(0, 0, angle.RadianToDegree());

            Style.Transform = pt;
            Style.Dirty();
        }
Пример #5
0
        public bool UpdateNameTag(Player player)
        {
            // Don't draw local player
            if (player.IsLocalPlayer)
            {
                return(false);
            }

            if (player.LifeState != LifeState.Alive)
            {
                return(false);
            }

            //
            // Where we putting the label, in world coords
            //
            var head = player.GetAttachment("hat");

            if (head.Pos == Vector3.Zero)
            {
                head.Pos = player.EyePos;
            }

            var labelPos = head.Pos + head.Rot.Up * 5;


            //
            // Are we too far away?
            //
            float dist = labelPos.Distance(Camera.LastPos);

            if (dist > MaxDrawDistance)
            {
                return(false);
            }

            //
            // Are we looking in this direction?
            //
            var lookDir = (labelPos - Camera.LastPos).Normal;

            if (Camera.LastRot.Forward.Dot(lookDir) < 0.5)
            {
                return(false);
            }

            // TODO - can we see them


            MaxDrawDistance = 400;

            // Max Draw Distance


            var alpha = dist.LerpInverse(MaxDrawDistance, MaxDrawDistance * 0.1f, true);

            // If I understood this I'd make it proper function
            var objectSize = 0.05f / dist / (2.0f * MathF.Tan((Camera.LastFieldOfView / 2.0f).DegreeToRadian())) * 1500.0f;

            objectSize = objectSize.Clamp(0.05f, 1.0f);

            if (!ActiveTags.TryGetValue(player, out var tag))
            {
                tag = CreateNameTag(player);
                ActiveTags[player] = tag;
            }

            tag.UpdateFromPlayer(player);

            var screenPos = labelPos.ToScreen();

            tag.Style.Left    = Length.Fraction(screenPos.x);
            tag.Style.Top     = Length.Fraction(screenPos.y);
            tag.Style.Opacity = alpha;

            var transform = new PanelTransform();

            transform.AddTranslateY(Length.Fraction(-1.0f));
            transform.AddScale(objectSize);
            transform.AddTranslateX(Length.Fraction(-0.5f));

            tag.Style.Transform = transform;
            tag.Style.Dirty();

            return(true);
        }
Пример #6
0
        // Feel free to change how we update tags I guess
        public virtual bool UpdateTag(T entity)
        {
            //
            // Where we putting the label, in world coords
            //
            var position = entity.Position + Offset;

            var currentCamera = Local.Client.Pawn.Camera as Camera;

            if (currentCamera is null)
            {
                return(false);
            }

            //
            // Are we too far away?
            //
            var dist = position.Distance(currentCamera.Pos);

            if (dist > MaxDistance)
            {
                return(false);
            }

            //
            // Are we looking in this direction?
            //
            var lookDir = (position - currentCamera.Pos).Normal;

            if (currentCamera.Rot.Forward.Dot(lookDir) < 0.5)
            {
                return(false);
            }

            var alpha = dist.LerpInverse(MaxDistance, MaxDistance * 0.1f, true);

            // If I understood this I'd make it proper function
            var objectSize = 0.05f / dist / (2.0f * MathF.Tan((currentCamera.FieldOfView / 2.0f).DegreeToRadian())) * 1500.0f;

            objectSize = objectSize.Clamp(0.05f, 1.0f);

            if (!PanelCollection.TryGetValue(entity, out var tag))
            {
                tag = CreateNametag(entity);
                PanelCollection[entity] = tag;

                Log.Warning($"Created a new tag for ({entity.NetworkIdent})!");
            }

            Vector3 screenPos = position.ToScreen();

            tag.UpdateFromEnt(entity);

            tag.Style.Position = PositionMode.Absolute;
            tag.Style.Left     = Length.Fraction(screenPos.x);
            tag.Style.Top      = Length.Fraction(screenPos.y);
            tag.Style.Opacity  = alpha;

            var transform = new PanelTransform();

            transform.AddTranslateY(Length.Fraction(-1.0f));
            transform.AddScale(objectSize);
            transform.AddTranslateX(Length.Fraction(-0.5f));

            tag.Style.Transform = transform;
            tag.Style.Dirty();

            return(true);
        }
Пример #7
0
        public bool UpdateNameTag(Player player)
        {
            // Don't draw local player
            if (player == Local.Pawn)
            {
                return(false);
            }

            if (player.LifeState != LifeState.Alive)
            {
                return(false);
            }

            //
            // Where we putting the label, in world coords
            //

            var head     = player.GetAttachment("hat") ?? new Transform(player.EyePos);
            var labelPos = head.Position + Vector3.Up * 5;


            //
            // Are we too far away?
            //
            float dist = labelPos.Distance(CurrentView.Position);

            if (dist > MaxDrawDistance)
            {
                return(false);
            }

            //
            // Are we looking in this direction?
            //
            var lookDir = (labelPos - CurrentView.Position).Normal;

            if (CurrentView.Rotation.Forward.Dot(lookDir) < 0.5)
            {
                return(false);
            }

            // Max Draw Distance


            var alpha = dist.LerpInverse(MaxDrawDistance, MaxDrawDistance * 0.1f, true);

            // If I understood this I'd make it proper function
            var objectSize = 0.05f / dist / (2.0f * MathF.Tan((CurrentView.FieldOfView / 2.0f).DegreeToRadian())) * 2000.0f;

            objectSize = objectSize.Clamp(0.05f, 1.0f);

            if (!ActiveTags.TryGetValue(player, out var tag))
            {
                tag = CreateNameTag(player);
                if (tag != null)
                {
                    ActiveTags[player] = tag;
                }
            }

            tag.UpdateFromPlayer(player);

            var screenPos = labelPos.ToScreen();

            tag.Style.Left = Length.Fraction(screenPos.x);
            tag.Style.Top  = Length.Fraction(screenPos.y);

            var checkVisibilityTrace = Trace
                                       .Ray(Local.Pawn.EyePos, player.EyePos)
                                       .WorldOnly()
                                       .Run();

            // And this
            tag.Style.Opacity = !checkVisibilityTrace.Hit && checkVisibilityTrace.Entity != player ? alpha : 0f;

            var transform = new PanelTransform();

            transform.AddTranslateY(Length.Fraction(-1.0f));
            transform.AddScale(objectSize);
            transform.AddTranslateX(Length.Fraction(-0.5f));

            tag.Style.Transform = transform;
            tag.Style.Dirty();

            return(true);
        }