Ejemplo n.º 1
0
        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 ApplyCameraTransform(ApplyCameraTransformEvent e, BattleCameraNode battleCamera)
        {
            CameraComponent camera = battleCamera.camera;
            CameraTransformDataComponent cameraTransformData = battleCamera.cameraTransformData;
            Transform  root     = battleCamera.cameraRootTransform.Root;
            Vector3    position = cameraTransformData.Data.Position;
            Quaternion rotation = cameraTransformData.Data.Rotation;
            float      t        = 1f;
            float      num2     = 1f;

            if (e.DeltaTimeValid)
            {
                float deltaTime = e.DeltaTime;
                t    = !e.PositionSmoothingRatioValid ? battleCamera.applyCameraTransform.positionSmoothingRatio : e.PositionSmoothingRatio;
                num2 = !e.RotationSmoothingRatioValid ? battleCamera.applyCameraTransform.rotationSmoothingRatio : e.RotationSmoothingRatio;
                battleCamera.applyCameraTransform.positionSmoothingRatio = t;
                battleCamera.applyCameraTransform.rotationSmoothingRatio = num2;
                t    *= deltaTime;
                num2 *= deltaTime;
            }
            root.SetPositionSafe(Vector3.Lerp(root.position, position, t));
            Vector3 eulerAngles = rotation.eulerAngles;
            Vector3 vector3     = root.rotation.eulerAngles;

            root.rotation = Quaternion.Euler(new Vector3(Mathf.LerpAngle(vector3.x, eulerAngles.x, num2), Mathf.LerpAngle(vector3.y, eulerAngles.y, num2), 0f));
            base.ScheduleEvent <TransformTimeSmoothingEvent>(battleCamera);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        public void ResetCamera(NodeAddedEvent evt, AimingIdleStateNode weapon, AimingCameraNode cameraNode)
        {
            ShaftAimingCameraComponent   shaftAimingCamera   = cameraNode.shaftAimingCamera;
            CameraTransformDataComponent cameraTransformData = cameraNode.cameraTransformData;
            CameraComponent camera = cameraNode.camera;
            Transform       root   = cameraNode.cameraRootTransform.Root;

            root.SetPositionSafe(cameraTransformData.Data.Position);
            root.SetRotationSafe(cameraTransformData.Data.Rotation);
            Entity entity = cameraNode.Entity;

            entity.RemoveComponent <ShaftAimingCameraComponent>();
            entity.AddComponent <ShaftAimingCameraFOVRecoveringComponent>();
            entity.AddComponent <ApplyCameraTransformComponent>();
        }
Ejemplo n.º 5
0
        public void CreateBattleCamera(NodeAddedEvent evt, SingleNode <MapInstanceComponent> node)
        {
            Transform  transform  = new GameObject("BattleCameraRoot").transform;
            GameObject obj3       = GameObject.Find(ClientGraphicsConstants.MAIN_CAMERA_NAME);
            Transform  transform2 = obj3.transform;

            transform.SetPositionSafe(transform2.position);
            transform.SetRotationSafe(transform2.rotation);
            transform.SetParent(node.component.SceneRoot.transform, true);
            transform2.SetParent(transform, true);
            Entity          entity    = base.CreateEntity(typeof(CameraTemplate), "camera");
            EntityBehaviour component = obj3.GetComponent <EntityBehaviour>();

            if (component.Entity != null)
            {
                component.DestroyEntity();
            }
            component.BuildEntity(entity);
            entity.AddComponent(new CameraRootTransformComponent(transform));
            entity.AddComponent <BattleCameraComponent>();
            Camera unityCamera = obj3.GetComponent <Camera>();

            entity.AddComponent(new CameraComponent(unityCamera));
            CameraTransformDataComponent component2 = new CameraTransformDataComponent();
            TransformData data = new TransformData {
                Position = transform2.position,
                Rotation = transform2.rotation
            };

            component2.Data = data;
            entity.AddComponent(component2);
            entity.AddComponent <CameraFOVUpdateComponent>();
            entity.AddComponent <BezierPositionComponent>();
            entity.AddComponent <ApplyCameraTransformComponent>();
            entity.AddComponent <TransitionCameraComponent>();
            entity.AddComponent(new CameraShakerComponent(obj3.AddComponent <CameraShaker>()));
            BurningTargetBloomComponent component4 = new BurningTargetBloomComponent {
                burningTargetBloom = unityCamera.GetComponent <BurningTargetBloom>()
            };

            entity.AddComponent(component4);
            this.SetupCameraESM(entity);
        }
Ejemplo n.º 6
0
        private static void UpdateCamera(float dt, TransitionCameraNode cameraNode)
        {
            TransitionCameraComponent    transitionCamera    = cameraNode.transitionCamera;
            CameraTransformDataComponent cameraTransformData = cameraNode.cameraTransformData;

            if (transitionCamera.TotalDistance == 0f)
            {
                transitionCamera.TransitionComplete = true;
            }
            else if (transitionCamera.Speed < 0f)
            {
                transitionCamera.TransitionComplete = true;
            }
            else
            {
                if ((transitionCamera.Distance > (0.5f * transitionCamera.TotalDistance)) && (transitionCamera.Acceleration > 0f))
                {
                    transitionCamera.Acceleration = -transitionCamera.Acceleration;
                    transitionCamera.AngleValuesX.ReverseAcceleration();
                    transitionCamera.AngleValuesY.ReverseAcceleration();
                }
                float num = transitionCamera.Acceleration * dt;
                transitionCamera.Distance += (transitionCamera.Speed + (0.5f * num)) * dt;
                transitionCamera.Speed    += num;
                if (transitionCamera.Distance > transitionCamera.TotalDistance)
                {
                    transitionCamera.Distance = transitionCamera.TotalDistance;
                }
                TransformData data2 = new TransformData {
                    Position = Bezier.PointOnCurve(transitionCamera.Distance / transitionCamera.TotalDistance, transitionCamera.P1, transitionCamera.P2, transitionCamera.P3, transitionCamera.P4),
                    Rotation = Quaternion.Euler(cameraTransformData.Data.Rotation.eulerAngles + new Vector3(transitionCamera.AngleValuesX.Update(dt), transitionCamera.AngleValuesY.Update(dt), 0f))
                };
                cameraTransformData.Data = data2;
                if (Mathf.Abs((float)(transitionCamera.Distance - transitionCamera.TotalDistance)) < 0.01f)
                {
                    transitionCamera.TransitionComplete = true;
                }
            }
        }
Ejemplo n.º 7
0
        private static void InitCamera(TransitionCameraNode transitionCameraNode, Vector3 position, Vector3 angles, float flyTimeSec, float flyHeight)
        {
            TransitionCameraComponent    transitionCamera    = transitionCameraNode.transitionCamera;
            CameraTransformDataComponent cameraTransformData = transitionCameraNode.cameraTransformData;

            transitionCamera.P1 = cameraTransformData.Data.Position;
            transitionCamera.P2 = transitionCamera.P1;
            transitionCamera.P4 = position;
            transitionCamera.P3 = transitionCamera.P4;
            float y = ((transitionCamera.P1.y <= transitionCamera.P4.y) ? transitionCamera.P4.y : transitionCamera.P1.y) + flyHeight;

            transitionCamera.P2 = new Vector3(transitionCamera.P2.x, y, transitionCamera.P2.z);
            transitionCamera.P3 = new Vector3(transitionCamera.P3.x, y, transitionCamera.P3.z);
            float   accelerationCoeff = 4f / (flyTimeSec * flyTimeSec);
            Vector3 eulerAngles       = cameraTransformData.Data.Rotation.eulerAngles;

            transitionCamera.AngleValuesX = new AngleValues(eulerAngles.x, angles.x, accelerationCoeff);
            transitionCamera.AngleValuesY = new AngleValues(eulerAngles.y, angles.y, accelerationCoeff);
            Vector3 vector10 = transitionCamera.P4 - transitionCamera.P1;

            transitionCamera.TotalDistance = vector10.magnitude;
            transitionCamera.Acceleration  = transitionCamera.TotalDistance * accelerationCoeff;
        }
Ejemplo n.º 8
0
        public unsafe void RecieveInput(TimeUpdateEvent evt, FreeCameraNode cameraNode, [JoinAll] UserNode user)
        {
            float deltaTime = evt.DeltaTime;
            FreeCameraComponent          freeCamera          = cameraNode.freeCamera;
            CameraTransformDataComponent cameraTransformData = cameraNode.cameraTransformData;
            Quaternion rotation = freeCamera.Data.Rotation;
            Vector3    position = freeCamera.Data.Position;
            bool       flag     = freeCamera.Data != cameraTransformData.Data;
            float      num2     = 1f;
            float      num3     = 1f;

            if (InputManager.CheckAction(SpectatorCameraActions.AccelerateMovement))
            {
                num3 *= freeCamera.speedUp;
            }
            if (InputManager.CheckAction(SpectatorCameraActions.SlowMovement))
            {
                num2 *= freeCamera.slowDown;
                num3 *= freeCamera.slowDown;
            }
            if (InputManager.GetActionKeyDown(FreeCameraActions.FIXED_HEIGHT))
            {
                freeCamera.fixedHeight ^= true;
            }
            float num4 = ((!InputManager.CheckAction(FreeCameraActions.UP_TURN) ? 0 : -1) + (!InputManager.CheckAction(FreeCameraActions.DOWN_TURN) ? 0 : 1)) * 0.5f;
            float num5 = ((!InputManager.CheckAction(FreeCameraActions.RIGHT_TURN) ? 0 : 1) + (!InputManager.CheckAction(FreeCameraActions.LEFT_TURN) ? 0 : -1)) * 0.5f;

            if (InputManager.CheckMouseButtonInAllActiveContexts(FreeCameraActions.MOUSE_BUTTON_DOWN, UnityInputConstants.MOUSE_BUTTON_LEFT))
            {
                num4 += -InputManager.GetUnityAxis(UnityInputConstants.MOUSE_Y);
                num5 += InputManager.GetUnityAxis(UnityInputConstants.MOUSE_X);
            }
            Vector3  eulerAngles = rotation.eulerAngles;
            Vector3 *vectorPtr1  = &eulerAngles;

            vectorPtr1->x += ((num4 * freeCamera.xRotationSpeed) * num2) * deltaTime;
            Vector3 *vectorPtr2 = &eulerAngles;

            vectorPtr2->y += ((num5 * freeCamera.yRotationSpeed) * num2) * deltaTime;
            rotation       = Quaternion.Euler(NormalizeEuler(eulerAngles, freeCamera.xMinAngle, freeCamera.xMaxAngle));
            float   num6    = (!InputManager.CheckAction(FreeCameraActions.FORWARD_MOVING) ? 0 : 1) + (!InputManager.CheckAction(FreeCameraActions.BACK_MOVING) ? 0 : -1);
            float   num7    = (!InputManager.CheckAction(FreeCameraActions.RIGHT_MOVING) ? 0 : 1) + (!InputManager.CheckAction(FreeCameraActions.LEFT_MOVING) ? 0 : -1);
            float   num8    = (InputManager.GetAxis(FreeCameraActions.MOUSE_SCROLL_WHEEL_UP, true) - InputManager.GetAxis(FreeCameraActions.MOUSE_SCROLL_WHEEL_DOWN, true)) + (InputManager.GetAxis(FreeCameraActions.UP_MOVING, false) - InputManager.GetAxis(FreeCameraActions.DOWN_MOVING, false));
            Vector3 forward = Vector3.forward;
            Vector3 right   = Vector3.right;
            Vector3 up      = Vector3.up;

            if (!freeCamera.fixedHeight)
            {
                forward = (Vector3)(rotation * forward);
                right   = (Vector3)(rotation * right);
                up      = (Vector3)(rotation * up);
            }
            else
            {
                Vector3 euler = rotation.eulerAngles;
                euler.x = 0f;
                Quaternion quaternion2 = Quaternion.Euler(euler);
                forward = (Vector3)(quaternion2 * forward);
                right   = (Vector3)(quaternion2 * right);
            }
            TransformData data3 = new TransformData {
                Position = GetClippedPosition(position, position + (((Vector3.ClampMagnitude(((forward * num6) + (right * num7)) + (up * num8), 1f) * freeCamera.flySpeed) * num3) * deltaTime)),
                Rotation = rotation
            };
            ApplyCameraTransformEvent eventInstance = ApplyCameraTransformEvent.ResetApplyCameraTransformEvent();

            if (data3 != freeCamera.Data)
            {
                cameraNode.cameraTransformData.Data = data3;
                freeCamera.Data = data3;
                eventInstance.PositionSmoothingRatio = freeCamera.positionSmoothingSpeed;
                eventInstance.RotationSmoothingRatio = freeCamera.rotationSmoothingSpeed;
            }
            eventInstance.DeltaTime = deltaTime;
            base.ScheduleEvent(eventInstance, cameraNode);
        }