예제 #1
0
        /// <summary>
        /// On the camera becoming activated, snap to the current view position
        /// </summary>
        public override void Activated()
        {
            base.Activated();

            TargetPos = Camera.LastPos;
            TargetRot = Camera.LastRot;

            Pos         = TargetPos;
            Rot         = TargetRot;
            LookAngles  = Rot.Angles();
            FovOverride = 80;

            DoFPoint    = 0.0f;
            DoFBlurSize = 20.0f;


            if (Overlays)
            {
                var pos      = new Vector3(100, 100);
                var duration = 4.0f;

                DebugOverlay.ScreenText(pos, 0, Color.White, "  .                        ", duration);
                DebugOverlay.ScreenText(pos, 1, Color.White, ",-| ,-. .  , ,-. ,-. ,-,-. ", duration);
                DebugOverlay.ScreenText(pos, 2, Color.White, "| | |-' | /  |   ,-| | | | ", duration);
                DebugOverlay.ScreenText(pos, 3, Color.White, "`-^ `-' `'   `-' `-^ ' ' ' ", duration);

                DebugOverlay.ScreenText(pos, 5, Color.White, "  Free:  WSAD, Run/Crouch for speed", duration);
                DebugOverlay.ScreenText(pos, 6, Color.White, " Pivot:  Hold Walk (Default Alt) - forward + back to zoom in/out", duration);
                DebugOverlay.ScreenText(pos, 8, Color.White, "Reload:  Toggle Overlays", duration);
            }

            //
            // Set the devcamera class on the HUD. It's up to the HUD what it does with it.
            //
            Hud.Current?.RootPanel?.SetClass("devcamera", true);
        }
예제 #2
0
        public override void Update()
        {
            var player = Player.Local;

            if (player == null)
            {
                return;
            }

            var tr = Trace.Ray(Pos, Pos + Rot.Forward * 4096).UseHitboxes().Run();

            // DebugOverlay.Box( tr.EndPos, Vector3.One * -1, Vector3.One, Color.Red );

            FieldOfView = FovOverride;

            Viewer = null;
            {
                var lerpTarget = tr.EndPos.Distance(Pos);

                DoFPoint = lerpTarget;                // DoFPoint.LerpTo( lerpTarget, Time.Delta * 10 );

                var pos = new Vector3(100, 100);
                if (Overlays)
                {
                    DebugOverlay.ScreenText(pos, 10, Color.White, "Focus distance " + DoFPoint.ToString("F"), 0.0f);
                    DebugOverlay.ScreenText(pos, 11, Color.White, "Blur Size " + DoFBlurSize.ToString("F"), 0.0f);
                }
            }

            if (PivotEnabled)
            {
                PivotMove();
            }
            else
            {
                FreeMove();
            }


            if (Overlays)
            {
                var normalRot = Rotation.LookAt(tr.Normal);
                DebugOverlay.Axis(tr.EndPos, normalRot, 3.0f);

                if (tr.Entity != null && !tr.Entity.IsWorld)
                {
                    DebugOverlay.Text(tr.EndPos + Vector3.Up * 20, $"Entity: {tr.Entity} ({tr.Entity.EngineEntityName})\n" +
                                      $" Index: {tr.Entity.NetworkIdent}\n" +
                                      $"Health: {tr.Entity.Health}", Color.White);

                    if (tr.Entity is ModelEntity modelEnt)
                    {
                        var bbox = modelEnt.OOBBox;
                        DebugOverlay.Box(0, tr.Entity.Pos, tr.Entity.Rot, bbox.Mins, bbox.Maxs, Color.Green);

                        for (int i = 0; i < modelEnt.BoneCount; i++)
                        {
                            var tx     = modelEnt.GetBoneTransform(i);
                            var name   = modelEnt.GetBoneName(i);
                            var parent = modelEnt.GetBoneParent(i);


                            if (parent > -1)
                            {
                                var ptx = modelEnt.GetBoneTransform(parent);
                                DebugOverlay.Line(tx.Pos, ptx.Pos, Color.White, depthTest: false);
                            }
                        }
                    }
                }
            }
        }
예제 #3
0
        public override void Tick()
        {
            ViewOffset = Vector3.Up * EyeHeight;
            UpdateBBox();

            ViewOffset += TraceOffset;

            RestoreGroundPos();

            //Velocity += BaseVelocity * ( 1 + Time.Delta * 0.5f );
            //BaseVelocity = Vector3.Zero;

            //  Rot = Rotation.LookAt( Input.Rot.Forward.WithZ( 0 ), Vector3.Up );

            if (Unstuck.TestAndFix())
            {
                return;
            }

            // Check Stuck
            // Unstuck - or return if stuck

            // Set Ground Entity to null if  falling faster then 250

            // store water level to compare later

            // if not on ground, store fall velocity

            // player->UpdateStepSound( player->m_pSurfaceData, mv->GetAbsOrigin(), mv->m_vecVelocity )


            // RunLadderMode

            Swimming = Player.WaterLevel.Fraction > 0.6f;

            //
            // Start Gravity
            //
            if (!Swimming)
            {
                Velocity -= new Vector3(0, 0, Gravity * 0.5f) * Time.Delta;
                Velocity += new Vector3(0, 0, BaseVelocity.z) * Time.Delta;

                BaseVelocity = BaseVelocity.WithZ(0);
            }


            /*
             * if (player->m_flWaterJumpTime)
             * {
             *  WaterJump();
             *  TryPlayerMove();
             *  // See if we are still in water?
             *  CheckWater();
             *  return;
             * }
             */

            // if ( underwater ) do underwater movement

            if (Input.Pressed(InputButton.Jump))
            {
                CheckJumpButton();
            }

            // Fricion is handled before we add in any base velocity. That way, if we are on a conveyor,
            //  we don't slow when standing still, relative to the conveyor.
            bool bStartOnGround = GroundEntity != null;

            //bool bDropSound = false;
            if (bStartOnGround)
            {
                //if ( Velocity.z < FallSoundZ ) bDropSound = true;

                Velocity = Velocity.WithZ(0);
                //player->m_Local.m_flFallVelocity = 0.0f;

                if (GroundEntity != null)
                {
                    ApplyFriction(GroundFriction * SurfaceFriction);
                }
            }

            //
            // Work out wish velocity.. just take input, rotate it to view, clamp to -1, 1
            //
            WishVelocity = new Vector3(Input.Forward, Input.Left, 0);
            var inSpeed = WishVelocity.Length.Clamp(0, 1);

            WishVelocity *= Input.Rot;

            if (!Swimming)
            {
                WishVelocity = WishVelocity.WithZ(0);
            }

            WishVelocity  = WishVelocity.Normal * inSpeed;
            WishVelocity *= GetWishSpeed();

            Duck.PreTick();

            bool bStayOnGround = false;

            if (Swimming)
            {
                ApplyFriction(1);
                WaterMove();
            }
            else if (GroundEntity != null)
            {
                bStayOnGround = true;
                WalkMove();
            }
            else
            {
                AirMove();
            }

            CategorizePosition(bStayOnGround);

            // FinishGravity
            if (!Swimming)
            {
                Velocity -= new Vector3(0, 0, Gravity * 0.5f) * Time.Delta;
            }


            if (GroundEntity != null)
            {
                Velocity = Velocity.WithZ(0);
            }

            // CheckFalling(); // fall damage etc

            // Land Sound
            // Swim Sounds

            SaveGroundPos();

            if (Debug)
            {
                DebugOverlay.Box(Pos + TraceOffset, mins, maxs, Color.Red);
                DebugOverlay.Box(Pos, mins, maxs, Color.Blue);

                var lineOffset = 0;
                if (Host.IsServer)
                {
                    lineOffset = 10;
                }

                DebugOverlay.ScreenText(lineOffset + 0, $"             Pos: {Pos}");
                DebugOverlay.ScreenText(lineOffset + 1, $"             Vel: {Velocity}");
                DebugOverlay.ScreenText(lineOffset + 2, $"    BaseVelocity: {BaseVelocity}");
                DebugOverlay.ScreenText(lineOffset + 3, $"    GroundEntity: {GroundEntity} [{GroundEntity?.Velocity}]");
                DebugOverlay.ScreenText(lineOffset + 4, $" SurfaceFriction: {SurfaceFriction}");
                DebugOverlay.ScreenText(lineOffset + 5, $"    WishVelocity: {WishVelocity}");
            }
        }