private void FindGazeProjection(out Vector3 shootCoord, out Vector3 shootCoordSnap, out Vector3 shootMissileCoord, out Ped ped) { const float joystickRadius = 0.1f; var controllerState = _controllerEmulation.ControllerState; var joystickDelta = new Vector2(controllerState.Gamepad.RightThumbX, -controllerState.Gamepad.RightThumbY) * (1.0f / 32768.0f) * joystickRadius; var w = (float)(1 - _settings.GazeFiltering * 0.9); _gazePointDelta = new Vector2(_gazePointDelta.X + (_lastNormalizedCenterDelta.X - _gazePointDelta.X) * w, _gazePointDelta.Y + (_lastNormalizedCenterDelta.Y - _gazePointDelta.Y) * w); _gazePlusJoystickDelta = _gazePointDelta + joystickDelta; _unfilteredgazePlusJoystickDelta = _lastNormalizedCenterDelta; var hitUnfiltered = Geometry.RaycastEverything(_unfilteredgazePlusJoystickDelta); shootMissileCoord = hitUnfiltered; shootCoordSnap = hitUnfiltered; var hitFiltered = Geometry.RaycastEverything(_gazePlusJoystickDelta); shootCoord = hitFiltered; ped = Geometry.RaycastPed(_unfilteredgazePlusJoystickDelta); if ((ped != null) && (ped.Handle != Game.Player.Character.Handle)) { shootCoordSnap = ped.GetBoneCoord(Bone.SKEL_L_Clavicle); if (_settings.SnapAtPedestriansEnabled) { shootCoord = shootCoordSnap; } } else { var vehicle = Geometry.RaycastVehicle(_unfilteredgazePlusJoystickDelta); if (vehicle != null && !((Game.Player.Character.IsInVehicle()) && (vehicle.Handle == Game.Player.Character.CurrentVehicle.Handle))) { shootCoordSnap = vehicle.Position + vehicle.Velocity * 0.06f; shootMissileCoord = shootCoordSnap; } } var playerDistToGround = Game.Player.Character.Position.Z - World.GetGroundHeight(Game.Player.Character.Position); var targetDir = shootMissileCoord - Game.Player.Character.Position; targetDir.Normalize(); var justBeforeTarget = shootMissileCoord - targetDir; var targetDistToGround = shootMissileCoord.Z - World.GetGroundHeight(justBeforeTarget); var distToTarget = (Game.Player.Character.Position - shootMissileCoord).Length(); if ((playerDistToGround < 2) && (playerDistToGround >= -0.5)) //on the ground { if (((targetDistToGround < 2) && (targetDistToGround >= -0.5)) || //shoot too low ((targetDistToGround < 5) && (targetDistToGround >= -0.5) && (distToTarget > 70.0))) //far away add near the ground { shootMissileCoord.Z = World.GetGroundHeight(justBeforeTarget) //ground level at target + playerDistToGround; //offset } } if (!_menuOpen && (controllerState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.DPadDown) || User32.IsKeyPressed(VirtualKeyStates.VK_LMENU))) { //character selection } else if (!_isInVehicle && controllerState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.LeftShoulder)) { _radialMenu.Process(_lastNormalizedCenterDelta, _aspectRatio); } else { _freelook.Process(_lastNormalizedCenterDelta, ped, _aspectRatio); } }
public void Process(DateTime tickStopwatch, Vector2 gazePoint, double aspectRatio, Vector3 shootCoord, Vector3 shootCoordSnap, Vector3 shootMissileCoord, Ped ped, Entity missileTarget) { _lastTickTime = tickStopwatch; _isPaused = Game.IsPaused; _isInVehicle = Game.Player.Character.IsInVehicle(); _isInAircraft = Game.Player.Character.IsInPlane || Game.Player.Character.IsInHeli; _isMeleeWeapon = Util.IsMelee(Game.Player.Character.Weapons.Current.Hash); _isThrowableWeapon = Util.IsThrowable(Game.Player.Character.Weapons.Current.Hash); _isSniperWeaponAndZoomed = Util.IsSniper(Game.Player.Character.Weapons.Current.Hash) && (GameplayCamera.IsFirstPersonAimCamActive); _menuOpen = _menuPool.IsAnyMenuOpen(); var controllerState = _controllerEmulation.ControllerState; if (!_menuOpen && (controllerState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.DPadDown) || User32.IsKeyPressed(VirtualKeyStates.VK_LMENU))) { //character selection _isInRadialMenu = true; } else if (!_isInVehicle && controllerState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.LeftShoulder)) { _isInRadialMenu = true; _radialMenu.Process(gazePoint, aspectRatio); } else { _isInRadialMenu = false; _freelook.Process(gazePoint, ped, aspectRatio); } if (controllerState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.LeftThumb) && controllerState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.Start) && !_menuOpen) { _settingsMenu.OpenMenu(); } if (shootCoord.Length() > 0 && Geometry.IsInFrontOfThePlayer(shootCoord)) { var injectRightTrigger = 0; if (_settings.FreelookDevice == FeeelookDevice.Gamepad && _settings.AimWithGazeEnabled && !Game.Player.Character.IsInVehicle() && Game.IsKeyPressed(Keys.B)) { injectRightTrigger += 1; } if (_settings.FreelookDevice == FeeelookDevice.Gamepad && _settings.ThirdPersonFreelookEnabled && Game.Player.Character.IsInVehicle() && Game.IsKeyPressed(Keys.W)) { _injectRightTrigger += 1; //TODO: block keyboard } _injectRightTrigger = injectRightTrigger; if (_settings.AimWithGazeEnabled && ((!_isInVehicle && !_isMeleeWeapon && !_isThrowableWeapon && !_isSniperWeaponAndZoomed && ((!_isInRadialMenu && controllerState.Gamepad.LeftTrigger > 0) || User32.IsKeyPressed(VirtualKeyStates.VK_RBUTTON) ) ))) { if (!_lastAimCameraAtTarget) { _freelook.AimCameraAtTarget(shootCoordSnap); } _lastAimCameraAtTarget = true; } else { _lastAimCameraAtTarget = false; } //If you use mouse - shoot in the middle of the screen if (!_isInVehicle && (User32.IsKeyPressed(VirtualKeyStates.VK_LBUTTON) || User32.IsKeyPressed(VirtualKeyStates.VK_RBUTTON))) { Vector3 camPoint; Geometry.ScreenRelToWorld(new Vector2(0, 0), out camPoint, out shootCoord); } if (_settings.AimWithGazeEnabled && !_isInVehicle && (!_isMeleeWeapon && !_isThrowableWeapon && !_isSniperWeaponAndZoomed && ((!_isInRadialMenu && controllerState.Gamepad.RightTrigger > 0) || (Game.IsKeyPressed(Keys.B)) ) ) ) { _aiming.Shoot(shootCoord); } if (_settings.AimWithGazeEnabled && _isInVehicle && ((!_menuOpen && User32.IsKeyPressed(VirtualKeyStates.VK_LBUTTON)) || (Game.IsKeyPressed(Keys.B)) || (User32.IsKeyPressed(VirtualKeyStates.VK_XBUTTON1)) || (!_isInAircraft && controllerState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.LeftShoulder)) ) ) { _aiming.ShootBullet(shootCoord); } if ((_settings.MissilesAtGazeEnabled && Game.Player.Character.IsInVehicle()) && missileTarget != null) { Vector2 screenCoords; if (Geometry.WorldToScreenRel(missileTarget.Position, out screenCoords)) { _aiming.MoveCrosshair(screenCoords); _aiming.MissileLockedCrosshairVisible = true; } } else { Vector2 screenCoords; if (Geometry.WorldToScreenRel(shootCoord, out screenCoords)) { _aiming.MoveCrosshair(screenCoords); _aiming.MissileLockedCrosshairVisible = false; } } if (_settings.IncinerateAtGazeEnabled && (Game.IsKeyPressed(Keys.J) || (User32.IsKeyPressed(VirtualKeyStates.VK_XBUTTON2)) || (!_menuOpen && controllerState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.A)))) { _aiming.Incinerate(shootCoordSnap); } if (_settings.TaseAtGazeEnabled && (Game.IsKeyPressed(Keys.H) || Game.IsKeyPressed(Keys.PageDown) || (!_isInAircraft && !_menuOpen && controllerState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.RightShoulder)))) { _aiming.Tase(shootCoordSnap); } if (Game.IsKeyPressed(Keys.U)) { _aiming.Water(shootCoord); } } if (shootMissileCoord.Length() > 0 && Geometry.IsInFrontOfThePlayer(shootMissileCoord)) { if (_settings.MissilesAtGazeEnabled && (Game.IsKeyPressed(Keys.N) || Game.IsKeyPressed(Keys.PageUp) || (!_isInRadialMenu && !_menuOpen && controllerState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.B)))) { if (missileTarget != null) { _aiming.ShootMissile(missileTarget); } else { _aiming.ShootMissile(shootMissileCoord); } } } _aiming.Process(_isInRadialMenu); }