protected override void UpdateControlsInternal(VehicleSpotlight spotlight) { if (modifierKey == Keys.None || Game.IsKeyDownRightNow(modifierKey)) { Vector3 camPos, camDir; if (Camera.RenderingCamera) { Camera cam = Camera.RenderingCamera; camPos = cam.Position; camDir = cam.Direction; } else { camPos = NativeFunction.Natives.xA200EB1EE790F448 <Vector3>(); // _GET_GAMEPLAY_CAM_COORDS Vector3 camRotAsVec = NativeFunction.Natives.x5B4E4C817FCC2DFB <Vector3>(0); // _GET_GAMEPLAY_CAM_ROT Rotator camRot = new Rotator(camRotAsVec.X, camRotAsVec.Y, camRotAsVec.Z); camDir = camRot.ToVector(); } Vector3 end = camPos + camDir * 2000.0f; HitResult result = World.TraceLine(camPos, end, TraceFlags.IntersectWorld, spotlight.Vehicle); Vector3 targetPosition; if (result.Hit) { targetPosition = result.HitPosition; } else { targetPosition = end; } Vector3 worldDir = (targetPosition - spotlight.Position).ToNormalized(); Quaternion worldRot = worldDir.ToQuaternion(); Quaternion r = worldRot * Quaternion.Invert(spotlight.Vehicle.Orientation); if (MovementSpeed == 0.0f) { spotlight.RelativeRotation = r; } else { Quaternion diff = r * Quaternion.Invert(spotlight.RelativeRotation); float diffAngle = MathHelper.ConvertRadiansToDegrees(diff.Angle); if (diffAngle >= 180.0f) { diffAngle = 360.0f - diffAngle; } if (diffAngle > float.Epsilon) { float secondsToFinish = diffAngle / MovementSpeed; float t = Math.Min(1.0f, Game.FrameTime / secondsToFinish); spotlight.RelativeRotation = Quaternion.Slerp(spotlight.RelativeRotation, r, t); } } } }
public bool GetUpdatedRotationDelta(VehicleSpotlight spotlight, out Rotator rotation) { if (LastUpdatedSpotlight != spotlight) { throw new System.InvalidOperationException(); } bool result = GetUpdatedRotationDeltaInternal(spotlight, out rotation); LastUpdatedSpotlight = null; return(result); }
protected override void UpdateControlsInternal(VehicleSpotlight spotlight) { hasMoved = false; float pitch = 0.0f, yaw = 0.0f; switch (method) { case ControllerMethod.LeftStick: if (modifierButton == ControllerButtons.None || Game.IsControllerButtonDownRightNow(modifierButton)) { yaw -= Utility.GetDisabledControlNormal(GameControl.FrontendAxisX) * spotlight.Data.MovementSpeed; pitch -= Utility.GetDisabledControlNormal(GameControl.FrontendAxisY) * spotlight.Data.MovementSpeed; } break; case ControllerMethod.RightStick: if (modifierButton == ControllerButtons.None || Game.IsControllerButtonDownRightNow(modifierButton)) { yaw -= Utility.GetDisabledControlNormal(GameControl.FrontendRightAxisX) * spotlight.Data.MovementSpeed; pitch -= Utility.GetDisabledControlNormal(GameControl.FrontendRightAxisY) * spotlight.Data.MovementSpeed; } break; case ControllerMethod.DPad: if (modifierButton == ControllerButtons.None || Game.IsControllerButtonDownRightNow(modifierButton)) { if (Game.IsControllerButtonDownRightNow(ControllerButtons.DPadLeft)) { yaw += spotlight.Data.MovementSpeed; } else if (Game.IsControllerButtonDownRightNow(ControllerButtons.DPadRight)) { yaw -= spotlight.Data.MovementSpeed; } if (Game.IsControllerButtonDownRightNow(ControllerButtons.DPadUp)) { pitch += spotlight.Data.MovementSpeed; } else if (Game.IsControllerButtonDownRightNow(ControllerButtons.DPadDown)) { pitch -= spotlight.Data.MovementSpeed; } } break; } if (pitch != 0.0f || yaw != 0.0f) { hasMoved = true; } rotationDelta = new Rotator(pitch, 0.0f, yaw); }
protected override void UpdateControlsInternal(VehicleSpotlight spotlight) { hasMoved = false; float pitch = 0.0f, yaw = 0.0f; if (Utility.IsKeyDownRightNowWithModifier(moveLeftKey, modifierKey)) { hasMoved = true; yaw += GetMovementAmountForThisFrame(); } else if (Utility.IsKeyDownRightNowWithModifier(moveRightKey, modifierKey)) { hasMoved = true; yaw -= GetMovementAmountForThisFrame(); } if (Utility.IsKeyDownRightNowWithModifier(moveUpKey, modifierKey)) { hasMoved = true; pitch += GetMovementAmountForThisFrame(); } else if (Utility.IsKeyDownRightNowWithModifier(moveDownKey, modifierKey)) { hasMoved = true; pitch -= GetMovementAmountForThisFrame(); } if (Utility.IsKeyDownWithModifier(toggleTrackingKey, modifierKey)) { if (spotlight.IsTrackingEntity) { spotlight.SetTrackedEntityAndDisplayNotification(null); } else { Entity e = GetClosestEntityToSpotlight(spotlight, true, true); if (e) { spotlight.SetTrackedEntityAndDisplayNotification(e); } } } else if (Utility.IsKeyDownWithModifier(searchModeKey, modifierKey)) { spotlight.IsInSearchMode = !spotlight.IsInSearchMode; } rotationDelta = new Rotator(pitch, 0.0f, yaw); }
private Entity GetClosestEntityToSpotlight(VehicleSpotlight spotlight, bool peds, bool vehicles) { HitResult result = World.TraceCapsule(spotlight.Position, spotlight.Position + spotlight.Direction * 2000.0f, 6.5f, (peds ? TraceFlags.IntersectPedsSimpleCollision : TraceFlags.None) | (vehicles ? TraceFlags.IntersectVehicles : TraceFlags.None), spotlight.Vehicle); if (result.Hit) { return(result.HitEntity); } return(null); }
protected override void UpdateControlsInternal(VehicleSpotlight spotlight) { hasMoved = false; if (modifierKey == Keys.None || Game.IsKeyDownRightNow(modifierKey)) { float pitch = 0.0f, yaw = 0.0f; Game.DisableControlAction(0, GameControl.LookLeftRight, true); Game.DisableControlAction(0, GameControl.LookUpDown, true); float leftRight = Utility.GetDisabledControlNormal(GameControl.LookLeftRight) * spotlight.Data.MovementSpeed; float upDown = Utility.GetDisabledControlNormal(GameControl.LookUpDown) * spotlight.Data.MovementSpeed; yaw = -leftRight; pitch = -upDown; if (pitch != 0.0f || yaw != 0.0f) { hasMoved = true; } rotationDelta = new Rotator(pitch, 0.0f, yaw); } }
protected override bool GetUpdatedRotationDeltaInternal(VehicleSpotlight spotlight, out Rotator rotation) { rotation = rotationDelta; return(hasMoved); }
protected abstract bool GetUpdatedRotationDeltaInternal(VehicleSpotlight spotlight, out Rotator rotation);
protected abstract void UpdateControlsInternal(VehicleSpotlight spotlight);
public void UpdateControls(VehicleSpotlight spotlight) { LastUpdatedSpotlight = spotlight; UpdateControlsInternal(spotlight); }
protected override void UpdateControlsInternal(VehicleSpotlight spotlight) { hasMoved = false; float pitch = 0.0f, yaw = 0.0f; if (modifierButton == ControllerButtons.None || Game.IsControllerButtonDownRightNow(modifierButton)) { switch (method) { case ControllerMethod.LeftStick: yaw -= Utility.GetDisabledControlNormal(GameControl.FrontendAxisX) * GetMovementAmountForThisFrame(); pitch -= Utility.GetDisabledControlNormal(GameControl.FrontendAxisY) * GetMovementAmountForThisFrame(); break; case ControllerMethod.RightStick: yaw -= Utility.GetDisabledControlNormal(GameControl.FrontendRightAxisX) * GetMovementAmountForThisFrame(); pitch -= Utility.GetDisabledControlNormal(GameControl.FrontendRightAxisY) * GetMovementAmountForThisFrame(); break; case ControllerMethod.DPad: if (Game.IsControllerButtonDownRightNow(ControllerButtons.DPadLeft)) { yaw += GetMovementAmountForThisFrame(); } else if (Game.IsControllerButtonDownRightNow(ControllerButtons.DPadRight)) { yaw -= GetMovementAmountForThisFrame(); } if (Game.IsControllerButtonDownRightNow(ControllerButtons.DPadUp)) { pitch += GetMovementAmountForThisFrame(); } else if (Game.IsControllerButtonDownRightNow(ControllerButtons.DPadDown)) { pitch -= GetMovementAmountForThisFrame(); } break; } if (modifierButton != ControllerButtons.None) { Disable(ButtonToScriptControl(modifierButton)); switch (method) { case ControllerMethod.LeftStick: Disable(GameControl.ScriptLeftAxisX); Disable(GameControl.ScriptLeftAxisY); break; case ControllerMethod.RightStick: Disable(GameControl.ScriptRightAxisX); Disable(GameControl.ScriptRightAxisY); break; case ControllerMethod.DPad: Disable(ButtonToScriptControl(ControllerButtons.DPadUp)); Disable(ButtonToScriptControl(ControllerButtons.DPadDown)); Disable(ButtonToScriptControl(ControllerButtons.DPadLeft)); Disable(ButtonToScriptControl(ControllerButtons.DPadRight)); break; } } } if (pitch != 0.0f || yaw != 0.0f) { hasMoved = true; } rotationDelta = new Rotator(pitch, 0.0f, yaw); }
protected override void UpdateControlsInternal(VehicleSpotlight spotlight) { hasMoved = false; float pitch = 0.0f, yaw = 0.0f; if (Utility.IsKeyDownRightNowWithModifier(moveLeftKey, modifierKey)) { hasMoved = true; yaw += spotlight.Data.MovementSpeed; } else if (Utility.IsKeyDownRightNowWithModifier(moveRightKey, modifierKey)) { hasMoved = true; yaw -= spotlight.Data.MovementSpeed; } if (Utility.IsKeyDownRightNowWithModifier(moveUpKey, modifierKey)) { hasMoved = true; pitch += spotlight.Data.MovementSpeed; } else if (Utility.IsKeyDownRightNowWithModifier(moveDownKey, modifierKey)) { hasMoved = true; pitch -= spotlight.Data.MovementSpeed; } if (Utility.IsKeyDownWithModifier(trackVehicleKey, modifierKey)) { if (spotlight.IsTrackingVehicle) { spotlight.TrackedVehicle = null; } else { Vehicle v = World.GetClosestEntity(spotlight.Position, 130.0f, GetEntitiesFlags.ConsiderAllVehicles | GetEntitiesFlags.ExcludeEmergencyVehicles | GetEntitiesFlags.ExcludePlayerVehicle) as Vehicle; if (v) { spotlight.TrackedVehicle = v; } } } else if (Utility.IsKeyDownWithModifier(trackPedKey, modifierKey)) { if (spotlight.IsTrackingPed) { spotlight.TrackedPed = null; } else { Ped p = World.GetEntities(Game.LocalPlayer.Character.Position, 130.0f, GetEntitiesFlags.ConsiderHumanPeds | GetEntitiesFlags.ExcludePlayerPed) .Where(x => !((Ped)x).IsInAnyVehicle(false)) .OrderBy(x => Vector3.DistanceSquared(x.Position, spotlight.Position)) .FirstOrDefault() as Ped; if (p) { spotlight.TrackedPed = p; } } } rotationDelta = new Rotator(pitch, 0.0f, yaw); }
protected override bool GetUpdatedRotationDeltaInternal(VehicleSpotlight spotlight, out Rotator rotation) { rotation = Rotator.Zero; return(false); }