private void UpdateGyroscopeData(WeaponGyroscopeNode weaponGyroscope, TankNode tank) { WeaponGyroscopeRotationComponent weaponGyroscopeRotation = weaponGyroscope.weaponGyroscopeRotation; Transform transform = tank.hullInstance.HullInstance.transform; weaponGyroscopeRotation.ForwardDir = transform.forward; weaponGyroscopeRotation.UpDir = transform.up; }
private void UpdateWeaponRotation(WeaponNode weapon, SingleNode <MouseControlStateHolderComponent> mouseControlStateHolder, float dt, bool rem = false) { WeaponRotationControlComponent weaponRotationControl = weapon.weaponRotationControl; weaponRotationControl.EffectiveControl = !weaponRotationControl.Centering ? weaponRotationControl.Control : ((weaponRotationControl.Rotation >= 180f) ? ((float)1) : ((float)(-1))); WeaponGyroscopeRotationComponent weaponGyroscopeRotation = weapon.weaponGyroscopeRotation; bool flag = (mouseControlStateHolder != null) && mouseControlStateHolder.component.MouseControlEnable; if (flag && (weaponRotationControl.BlockRotate && !weaponRotationControl.ForceGyroscopeEnabled)) { weaponRotationControl.MouseRotationCumulativeHorizontalAngle -= weaponGyroscopeRotation.DeltaAngleOfHullRotation; weaponRotationControl.MouseRotationCumulativeHorizontalAngle = MathUtil.ClampAngle(weaponRotationControl.MouseRotationCumulativeHorizontalAngle * 0.01745329f) * 57.29578f; weaponGyroscopeRotation.DeltaAngleOfHullRotation = 0f; } float num2 = (weapon.weaponRotation.Acceleration * weaponGyroscopeRotation.WeaponTurnCoeff) * dt; float max = weapon.weaponRotation.Speed * weaponGyroscopeRotation.WeaponTurnCoeff; float num4 = 0f; float f = 0f; bool flag2 = false; while (true) { float mouseRotationCumulativeHorizontalAngle = weaponRotationControl.MouseRotationCumulativeHorizontalAngle; float effectiveControl = weaponRotationControl.EffectiveControl; weaponRotationControl.Speed += num2; weaponRotationControl.Speed = Mathf.Clamp(weaponRotationControl.Speed, 0f, max); num4 = weaponRotationControl.Speed * dt; if (!flag) { f = effectiveControl * num4; if (weaponRotationControl.ForceGyroscopeEnabled) { f -= weaponGyroscopeRotation.DeltaAngleOfHullRotation; } } else { if (weaponRotationControl.ForceGyroscopeEnabled) { if (!weaponRotationControl.BlockRotate) { if (weaponRotationControl.Centering) { f = Mathf.Clamp(-MathUtil.ClampAngle180(weaponRotationControl.Rotation + weaponGyroscopeRotation.DeltaAngleOfHullRotation), -num4, num4); effectiveControl = (Mathf.Abs(num4) > 0.001f) ? (f / num4) : 0f; } else { f = Mathf.Clamp(mouseRotationCumulativeHorizontalAngle, -num4, num4); effectiveControl = (Mathf.Abs(num4) > 0.001f) ? (f / num4) : 0f; } mouseRotationCumulativeHorizontalAngle -= f; } f -= weaponGyroscopeRotation.DeltaAngleOfHullRotation; } else if (!weaponRotationControl.BlockRotate) { if (!weaponRotationControl.Centering) { f = Mathf.Clamp(mouseRotationCumulativeHorizontalAngle - weaponGyroscopeRotation.DeltaAngleOfHullRotation, -num4, num4); effectiveControl = (Mathf.Abs(num4) > 0.001f) ? (f / num4) : 0f; } else { f = effectiveControl * num4; float num9 = MathUtil.ClampAngle180(weaponRotationControl.Rotation); if (Mathf.Abs(num9) < Mathf.Abs(f)) { f = -num9; effectiveControl = (Mathf.Abs(num4) > 0.001f) ? (f / num4) : 0f; } } mouseRotationCumulativeHorizontalAngle = (mouseRotationCumulativeHorizontalAngle - f) - weaponGyroscopeRotation.DeltaAngleOfHullRotation; } if (weaponRotationControl.BlockRotate) { effectiveControl = 0f; } } if (flag2) { flag2 = false; } else if (Math.Sign(weaponRotationControl.PrevDeltaRotaion) != Math.Sign(f)) { weaponRotationControl.Speed = 0f; flag2 = true; } if (!flag2) { float num11; weaponRotationControl.MouseRotationCumulativeHorizontalAngle = mouseRotationCumulativeHorizontalAngle; weaponRotationControl.EffectiveControl = effectiveControl; weaponRotationControl.PrevDeltaRotaion = f; float rotation = weaponRotationControl.Rotation; if (!weaponRotationControl.Centering || ((rotation >= -f) && ((360f - rotation) >= f))) { num11 = this.ClampAngle(rotation + f); } else { weaponRotationControl.Centering = false; num11 = 0f; } weapon.weaponInstance.WeaponInstance.transform.SetLocalRotationSafe(Quaternion.AngleAxis(num11, Vector3.up)); weapon.weaponInstance.WeaponInstance.transform.localPosition = Vector3.zero; weaponRotationControl.Rotation = num11; weaponRotationControl.EffectiveControl = Mathf.Round(weaponRotationControl.EffectiveControl); if (!Mathf.Approximately(weaponRotationControl.PrevEffectiveControl, weaponRotationControl.EffectiveControl) && ((PreciseTime.Time - weaponRotationControl.PrevControlChangedTime) > 0.1)) { weaponRotationControl.PrevControlChangedTime = PreciseTime.Time; weaponRotationControl.PrevEffectiveControl = weaponRotationControl.EffectiveControl; base.ScheduleEvent <WeaponRotationControlChangedEvent>(weapon); } return; } } }