private void UpdateFollowCameraData(float deltaTime, FollowCameraNode cameraNode, CameraTargetNode targetNode, TankNode tank, MouseControlStateHolderComponent mouseControlStateHolder)
        {
            GameObject targetObject = targetNode.cameraTarget.TargetObject;

            if (targetObject != null)
            {
                CameraTransformDataComponent cameraTransformData = cameraNode.cameraTransformData;
                Transform             target         = targetObject.transform;
                FollowCameraComponent followCamera   = cameraNode.followCamera;
                BezierPosition        bezierPosition = cameraNode.bezierPosition.BezierPosition;
                CameraData            cameraData     = followCamera.cameraData;
                this.UpdateBezierPosition(bezierPosition, followCamera.verticalCameraSpeed, deltaTime, targetNode.weaponRotationControl.MouseRotationCumulativeVerticalAngle, mouseControlStateHolder.MouseVerticalInverted);
                targetNode.weaponRotationControl.MouseRotationCumulativeVerticalAngle = 0f;
                float mouseRotationCumulativeHorizontalAngle = targetNode.weaponRotationControl.MouseRotationCumulativeHorizontalAngle;
                if (Mathf.Abs(MathUtil.ClampAngle180(Vector3.Angle(target.up, Vector3.up))) > 90f)
                {
                    mouseRotationCumulativeHorizontalAngle *= -1f;
                }
                bool mouse = targetNode.weaponRotationControl.MouseRotationCumulativeHorizontalAngle != 0f;
                CameraOffsetConfigComponent cameraOffsetConfig = cameraNode.cameraOffsetConfig;
                Vector3 cameraOffset     = new Vector3(cameraOffsetConfig.XOffset, cameraOffsetConfig.YOffset, cameraOffsetConfig.ZOffset);
                Vector3 cameraCalculated = CameraPositionCalculator.CalculateCameraPosition(target, tank.baseRenderer, tank.tankColliders.BoundsCollider.bounds.center, bezierPosition, cameraData, cameraOffset, mouseRotationCumulativeHorizontalAngle);
                Vector3 rotation         = cameraTransformData.Data.Rotation.eulerAngles * 0.01745329f;
                CameraPositionCalculator.CalculatePitchMovement(ref rotation, bezierPosition, deltaTime, cameraData, mouse);
                CameraPositionCalculator.CalculateYawMovement((Vector3)(Quaternion.Euler(new Vector3(0f, mouseRotationCumulativeHorizontalAngle, 0f)) * target.forward), ref rotation, deltaTime, cameraData, mouse);
                CameraPositionCalculator.SmoothReturnRoll(ref rotation, followCamera.rollReturnSpeedDegPerSec, deltaTime);
                TransformData data4 = new TransformData {
                    Position = CameraPositionCalculator.CalculateLinearMovement(deltaTime, cameraCalculated, cameraTransformData.Data.Position, cameraData, target, mouse),
                    Rotation = Quaternion.Euler(rotation * 57.29578f)
                };
                cameraTransformData.Data = data4;
            }
        }
        public void Follow(CameraFollowEvent e, CameraTargetNode cameraTargetNode, [JoinByTank] TankNode tank, [JoinAll] CameraNode cameraNode, [JoinAll] Optional <SingleNode <FollowCameraComponent> > followCameraOptionalNode)
        {
            CameraTransformDataComponent cameraTransformData = cameraNode.cameraTransformData;
            CameraOffsetConfigComponent  cameraOffsetConfig  = cameraNode.cameraOffsetConfig;
            Vector3        cameraOffset   = new Vector3(cameraOffsetConfig.XOffset, cameraOffsetConfig.YOffset, cameraOffsetConfig.ZOffset);
            BezierPosition bezierPosition = cameraNode.bezierPosition.BezierPosition;

            cameraTransformData.Data = CameraPositionCalculator.GetTargetFollowCameraTransformData(cameraTargetNode.cameraTarget.TargetObject.transform, tank.baseRenderer, tank.tankColliders.BoundsCollider.bounds.center, bezierPosition, cameraOffset);
            cameraNode.cameraRootTransform.Root.SetPositionSafe(cameraTransformData.Data.Position);
            cameraNode.cameraRootTransform.Root.SetRotationSafe(cameraTransformData.Data.Rotation);
        }
        public static void CalculatePitchMovement(ref Vector3 rotation, BezierPosition bezierPosition, float dt, CameraData cameraData, bool mouse = false)
        {
            float angleError = MathUtil.ClampAngleFast(-GetPitchAngle(cameraData, bezierPosition) - MathUtil.ClampAngle(rotation.x));

            cameraData.pitchSpeed = GetAngularSpeed(angleError, cameraData.pitchSpeed, mouse);
            float num4 = cameraData.pitchSpeed * dt;

            if (((angleError > 0f) && (num4 > angleError)) || ((angleError < 0f) && (num4 < angleError)))
            {
                num4 = angleError;
            }
            rotation.x           += num4;
            cameraData.pitchSpeed = MathUtil.Snap(cameraData.pitchSpeed, 0f, 0.1f);
        }
Exemple #4
0
        private void InitFollowCamera(TransitionCameraNode cameraNode, WeaponNode weapon, TankNode tank, float flyTimeSec, float flyHeight)
        {
            TransitionCameraComponent transitionCamera = cameraNode.transitionCamera;
            Transform      target         = weapon.cameraTarget.TargetObject.transform;
            BezierPosition bezierPosition = cameraNode.bezierPosition.BezierPosition;
            CameraOffsetConfigComponent cameraOffsetConfig = cameraNode.cameraOffsetConfig;
            Vector3    cameraOffset = new Vector3(cameraOffsetConfig.XOffset, cameraOffsetConfig.YOffset, cameraOffsetConfig.ZOffset);
            CameraData cameraData   = new CameraData();
            Vector3    position     = CameraPositionCalculator.CalculateCameraPosition(target, tank.baseRenderer, tank.tankColliders.BoundsCollider.bounds.center, bezierPosition, cameraData, cameraOffset, 0f);
            Vector3    zero         = Vector3.zero;

            zero.x = -CameraPositionCalculator.GetPitchAngle(cameraData, bezierPosition) * 57.29578f;
            zero.y = target.transform.rotation.eulerAngles.y;
            InitCamera(cameraNode, position, zero, flyTimeSec, flyHeight);
        }
        private void UpdateBezierPosition(BezierPosition bezierPosition, float verticalCameraSpeed, float dt, float vertical, bool mouseInvert)
        {
            float axisOrKey = InputManager.GetAxisOrKey(CameraRotationActions.ROTATE_CAMERA_UP_LEFT);
            float num2      = InputManager.GetAxisOrKey(CameraRotationActions.ROTATE_CAMERA_DOWN_RIGHT);
            float num3      = InputManager.GetAxis(CameraRotationActions.MOUSEWHEEL_MOVE, false) * MOUSE_WHEEL_RATIO;

            if (mouseInvert)
            {
                num3 *= -1f;
            }
            float num5 = (((axisOrKey - num2) * verticalCameraSpeed) * dt) + num3;

            bezierPosition.SetBaseRatio(bezierPosition.GetBaseRatio() + num5);
            float num6 = BEZIER_SPEED_BY_MOUSE_VERTICAL / 180f;

            bezierPosition.SetRatioOffset(bezierPosition.GetRatioOffset() + (vertical * num6));
        }
        public static float GetPitchAngle(CameraData cameraData, BezierPosition bezierPosition)
        {
            float f = bezierPosition.elevationAngle - 0.1745329f;

            if (f < 0f)
            {
                f = 0f;
            }
            float collisionDistanceRatio = cameraData.collisionDistanceRatio;

            if ((collisionDistanceRatio >= 1f) || ((f < 0.08726647f) || !cameraData.pitchCorrectionEnabled))
            {
                return(-f);
            }
            float num3 = bezierPosition.GetDistanceToPivot() * Mathf.Sin(f);

            return(-Mathf.Atan2(collisionDistanceRatio * num3, (1f * num3) * ((1f / Mathf.Tan(f)) - ((1f - collisionDistanceRatio) / Mathf.Tan(bezierPosition.elevationAngle)))));
        }
        public static Vector3 CalculateCameraPosition(Transform target, BaseRendererComponent tankRendererComponent, Vector3 tankBoundsCenter, BezierPosition bezierPosition, CameraData cameraData, Vector3 cameraOffset, float additionalAngle)
        {
            GameObject gameObject    = target.gameObject;
            Vector3    position      = target.position;
            Vector3    localPosition = target.parent.localPosition;
            float      z             = tankRendererComponent.Mesh.bounds.extents.z;
            float      num3          = z * Mathf.Max((float)0f, (float)((z - 1.2f) / 1.981962f));

            if (target.parent != null)
            {
                Vector3 vector4 = target.parent.InverseTransformPoint(tankBoundsCenter);
                num3 -= vector4.z - localPosition.z;
            }
            Vector3    vector5        = new Vector3(0f, 0f, -num3);
            Quaternion quaternion     = Quaternion.Euler(target.rotation.eulerAngles + new Vector3(0f, additionalAngle, 0f));
            Vector3    vector6        = (Vector3)(quaternion * (vector5 - new Vector3(0f, 0f, localPosition.z)));
            Vector3    targetPosition = (position + (quaternion * (localPosition + cameraOffset))) + (Vector3.up * 0.2f);
            bool       hasCollision   = false;
            bool       flag2          = false;
            Vector3    vector11       = CalculateCollisionPoint(targetPosition, CalculateCameraDirection(bezierPosition.GetCameraHeight() / bezierPosition.GetCameraHorizontalDistance(), (Vector3)(Quaternion.Euler(new Vector3(0f, additionalAngle, 0f)) * target.forward)), bezierPosition.GetDistanceToPivot(), gameObject, out hasCollision);
            float      magnitude      = (targetPosition - vector11).magnitude;

            cameraData.collisionDistanceRatio = magnitude / bezierPosition.GetDistanceToPivot();
            if (magnitude < 3f)
            {
                float rayLength = 3f - magnitude;
                vector11 = CalculateCollisionPoint(vector11, -Vector3.up, rayLength, gameObject, out flag2);
            }
            else
            {
                RaycastHit hit;
                int        layerMask  = LayerMasksUtils.RemoveLayerFromMask(LayerMasks.STATIC, gameObject.layer);
                Vector3    normalized = vector6.normalized;
                vector11 = !Physics.Raycast(vector11, normalized, out hit, vector6.magnitude, layerMask) ? (vector11 + vector6) : (vector11 + (Mathf.Max((float)(hit.distance - 0.5f), (float)0f) * normalized));
            }
            return(vector11);
        }
        public static TransformData GetTargetFollowCameraTransformData(Transform target, BaseRendererComponent tankRendererComponent, Vector3 tankBoundsCenter, BezierPosition bezierPosition, Vector3 cameraOffset)
        {
            CameraData cameraData   = new CameraData();
            float      cameraHeight = bezierPosition.GetCameraHeight();
            Vector3    vector2      = target.TransformDirection(Vector3.forward);
            Vector3    vector3      = new Vector3(-GetPitchAngle(cameraData, bezierPosition), Mathf.Atan2(vector2.x, vector2.z), 0f);

            return(new TransformData {
                Position = CalculateCameraPosition(target, tankRendererComponent, tankBoundsCenter, bezierPosition, cameraData, cameraOffset, 0f),
                Rotation = Quaternion.Euler(vector3 * 57.29578f)
            });
        }