private void FindGazeProjection(out Vector3 shootCoord, out Vector3 shootCoordSnap, out Vector3 shootMissileCoord, out Ped ped, out Entity target) { //debug Geometry.ScreenRelToWorld(new Vector2(0, 0)); var result = GameplayCamera.Position; _debugOutput.DebugText3.Caption = "Point: " + Math.Round(result.X, 1) + " | " + Math.Round(result.Y, 1) + " | " + Math.Round(result.Z, 1); //end Debug target = null; 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; Entity unfilteredEntity; Entity filteredEntity; var hitUnfiltered = Geometry.ConecastPedsAndVehicles(_unfilteredgazePlusJoystickDelta, out unfilteredEntity); shootMissileCoord = hitUnfiltered; shootCoordSnap = hitUnfiltered; var hitFiltered = Geometry.RaycastEverything(_gazePlusJoystickDelta, out filteredEntity, true); shootCoord = hitFiltered; if (unfilteredEntity != null && Util.IsEntityAPed(unfilteredEntity)) { ped = unfilteredEntity as Ped; } else { ped = Geometry.SearchPed(_unfilteredgazePlusJoystickDelta); } if ((ped != null) && (ped.Handle != Game.Player.Character.Handle)) { shootCoordSnap = ped.GetBoneCoord(Bone.SKEL_L_Clavicle); target = ped; if (_settings.SnapAtPedestriansEnabled) { shootCoord = shootCoordSnap; } } else { Vehicle vehicle; if (unfilteredEntity != null && Util.IsEntityAPed(unfilteredEntity)) { vehicle = unfilteredEntity as Vehicle; } else { vehicle = Geometry.SearchVehicle(_unfilteredgazePlusJoystickDelta); } _debugOutput.DebugText5.Caption = "raycasing veh " + DateTime.Now; if (vehicle != null && !((Game.Player.Character.IsInVehicle()) && (vehicle.Handle == Game.Player.Character.CurrentVehicle.Handle))) { shootCoordSnap = vehicle.Position + vehicle.Velocity * 0.06f; shootMissileCoord = shootCoordSnap; target = vehicle; _debugOutput.DebugText4.Caption = "veh " + vehicle.Handle; } } 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 } } }
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 ThirdPersonAimFreelook(Vector2 gazeNormalizedCenterDelta, Ped ped, double aspectRatio) { _relativeHeadingVehicle = 0; _relativePitchVehicle = 0; if (!GameplayCamera.IsRendering) return; double deltaX = 0; double deltaY = 0; if (_settings.ThirdPersonFreelookEnabled && (!IsInFixedDeadzone(gazeNormalizedCenterDelta, aspectRatio))) { var freelookDeltaVector = new Vector2(gazeNormalizedCenterDelta.X, gazeNormalizedCenterDelta.Y); if (ped != null && ped != Game.Player.Character) { Vector2 screenCoords; var pos = ped.GetBoneCoord(Bone.SKEL_L_Clavicle); Geometry.WorldToScreenRel(pos, out screenCoords); freelookDeltaVector = screenCoords; } deltaX = freelookDeltaVector.X * (float)(_settings.AimingSensitivity); deltaY = freelookDeltaVector.Y * (float)(_settings.AimingSensitivity); } EmulateHid(deltaX, deltaY); }
public void FindGazeProjection( Vector2 gazePoint, Vector2 joystickDelta, out Vector3 shootCoord, out Vector3 shootCoordSnap, out Vector3 shootMissileCoord, out Ped ped, out Entity missileTarget ) { Entity target = null; var w = (float)(1 - _settings.GazeFiltering * 0.9); _filteredGazePoint = new Vector2(_filteredGazePoint.X + (gazePoint.X - _filteredGazePoint.X) * w, _filteredGazePoint.Y + (gazePoint.Y - _filteredGazePoint.Y) * w); var filteredGazePointPlusJoystickDelta = _filteredGazePoint + joystickDelta; var unfilteredGazePointPlusJoystickDelta = gazePoint; Entity unfilteredEntity; Entity filteredEntity; var hitUnfiltered = Geometry.ConecastPedsAndVehicles(unfilteredGazePointPlusJoystickDelta, out unfilteredEntity); shootMissileCoord = hitUnfiltered; shootCoordSnap = hitUnfiltered; var hitFiltered = Geometry.RaycastEverything(filteredGazePointPlusJoystickDelta, out filteredEntity, true); shootCoord = hitFiltered; if (unfilteredEntity != null && ScriptHookExtensions.IsEntityAPed(unfilteredEntity) && unfilteredEntity.IsAlive) { ped = unfilteredEntity as Ped; } else { if (_frameSkip == 0) { ped = Geometry.SearchPed(unfilteredGazePointPlusJoystickDelta); //Too slow :( _lastPed = ped; } else { ped = _lastPed; } } if ((ped != null) && (ped.Handle != Game.Player.Character.Handle)) { shootCoordSnap = ped.GetBoneCoord(Bone.SKEL_L_Clavicle); target = ped; if (_settings.SnapAtTargetsEnabled) { shootCoord = shootCoordSnap; } } else { Vehicle vehicle; if (unfilteredEntity != null && ScriptHookExtensions.IsEntityAVehicle(unfilteredEntity) && unfilteredEntity.IsAlive) { vehicle = unfilteredEntity as Vehicle; } else { if (_frameSkip == 0) { vehicle = Geometry.SearchVehicle(unfilteredGazePointPlusJoystickDelta); // Too slow :( _lastVehicle = vehicle; } else { vehicle = _lastVehicle; } } if (vehicle != null && !((Game.Player.Character.IsInVehicle()) && (vehicle.Handle == Game.Player.Character.CurrentVehicle.Handle))) { shootCoordSnap = vehicle.Position + vehicle.Velocity * 0.06f; shootMissileCoord = shootCoordSnap; target = vehicle; } } ProcessMissileLock(target); missileTarget = _missileTarget; _frameSkip++; if (_frameSkip > _maxSkipFrames) { _frameSkip = 0; } }