Example #1
0
 private void CopyClientOutputToComponent(CameraStateUploadComponent input,
                                          CameraFinalOutputNewComponent output)
 {
     output.Position            = input.Position;
     output.EulerAngle          = input.EulerAngle;
     output.Fov                 = input.Fov;
     output.Far                 = input.Far;
     output.Near                = input.Near;
     output.PlayerFocusPosition = input.PlayerFocusPosition;
 }
Example #2
0
        private void UpdateCollisions(CameraStateOutputNewComponent calsOut, CameraFinalOutputNewComponent camera,
                                      Vector3 punchRotation, PlayerEntity player, int curTime)
        {
            var doLag        = !player.appearanceInterface.Appearance.IsFirstPerson;
            var realRotation = Quaternion.Euler(calsOut.ArchorEulerAngle + calsOut.EulerAngle + punchRotation);

            var postOffset       = calsOut.ArchorPostOffset + calsOut.PostOffset;
            var realArchorOffset = calsOut.ArchorOffset;
            var realPostOffset   = postOffset;
            var archorRotation   = Quaternion.Euler(0, calsOut.ArchorEulerAngle.y, 0);

            //计算头顶位置
            _archoroffsetArm.Offset = realArchorOffset / 2;
            var heightTestStart = calsOut.ArchorPosition + archorRotation * realArchorOffset / 2;

            _archoroffsetArm.Update(heightTestStart, archorRotation, curTime - LastTime, doLag, calsOut.NeedDetectDistance);
            realArchorOffset = _archoroffsetArm.LastLoc - calsOut.ArchorPosition;

            //计算锚点位置
            _postOffsetArm.Offset = realPostOffset;
            _postOffsetArm.Update(_archoroffsetArm.LastLoc, archorRotation, curTime - LastTime, false, calsOut.NeedDetectDistance);
            realPostOffset = _postOffsetArm.LastLoc - _archoroffsetArm.LastLoc;
            var postOffsetFactor = Mathf.Max(realPostOffset.magnitude / postOffset.magnitude, 1);
            var startingPosition = calsOut.FinalArchorPosition =
                calsOut.ArchorPosition + postOffsetFactor * realArchorOffset + realPostOffset;

            //封闭建筑内拉近摄像机距离
//            if(BuildingRestrictTest(calsOut, player))
//                calsOut.Offset = calsOut.Offset.normalized * OffsetInBuilding;

            //相机位置计算
            _offsetArm.Offset = calsOut.Offset;
            _offsetArm.Update(startingPosition, realRotation, curTime - LastTime, doLag, true);

            camera.PlayerFocusPosition = startingPosition;
            camera.Position            = _offsetArm.LastLoc;
            camera.EulerAngle          = calsOut.ArchorEulerAngle + calsOut.EulerAngle + punchRotation;
            camera.EulerAngle.x        = YawPitchUtility.Normalize(camera.EulerAngle.x);
            camera.EulerAngle.y        = YawPitchUtility.Normalize(camera.EulerAngle.y);
            camera.EulerAngle.z        = YawPitchUtility.Normalize(camera.EulerAngle.z);
            camera.Fov  = calsOut.Fov;
            camera.Far  = calsOut.Far;
            camera.Near = calsOut.Near;

#if UNITY_EDITOR
            var p1 = calsOut.ArchorPosition;
            var p2 = _archoroffsetArm.LastLoc;
            var p3 = startingPosition;
            var p4 = _offsetArm.LastLoc;

            Debug.DrawLine(p1, p2, Color.red);
            Debug.DrawLine(p2, p3, Color.green);
            Debug.DrawLine(p3, p4, Color.blue);
#endif
        }
Example #3
0
        private void UpdateCollisions(CameraStateOutputNewComponent calsOut, CameraFinalOutputNewComponent camera,
                                      Vector3 punchRotation, PlayerEntity player, bool doLag, int curTime)
        {
            var realRotation = Quaternion.Euler(calsOut.ArchorEulerAngle + calsOut.EulerAngle + punchRotation);
            var index        = (player.gamePlay.JobAttribute == (int)EJobAttribute.EJob_Variant) ? 0.75f : 1f;

            var postOffset       = calsOut.ArchorPostOffset + calsOut.PostOffset;
            var realArchorOffset = calsOut.ArchorOffset;
            var realPostOffset   = postOffset;
            var archorRotation   = Quaternion.Euler(0, calsOut.ArchorEulerAngle.y, 0);

            //计算头顶位置
            _archoroffsetArm.Offset = realArchorOffset / 2 * index;
            var heightTestStart = calsOut.ArchorPosition + archorRotation * realArchorOffset / 2 * index;

            _archoroffsetArm.Update(heightTestStart, archorRotation, curTime - LastTime, doLag, calsOut.NeedDetectDistance);
            realArchorOffset = (_archoroffsetArm.LastLoc - calsOut.ArchorPosition);

            //计算锚点位置
            _postOffsetArm.Offset = realPostOffset * index;
            _postOffsetArm.Update(_archoroffsetArm.LastLoc, archorRotation, curTime - LastTime, false, calsOut.NeedDetectDistance);
            realPostOffset = (_postOffsetArm.LastLoc - _archoroffsetArm.LastLoc);
            var postOffsetFactor = Mathf.Max(realPostOffset.magnitude / postOffset.magnitude, 1);
            var startingPosition = calsOut.FinalArchorPosition =
                calsOut.ArchorPosition + postOffsetFactor * realArchorOffset + realPostOffset;

            //相机位置计算
            _offsetArm.Offset = calsOut.Offset * index;
            _offsetArm.Update(startingPosition, realRotation, curTime - LastTime, doLag, true);

            camera.PlayerFocusPosition = startingPosition;
            camera.Position            = _offsetArm.LastLoc;
            camera.EulerAngle          = calsOut.ArchorEulerAngle + calsOut.EulerAngle + punchRotation;
            camera.EulerAngle.x        = YawPitchUtility.Normalize(camera.EulerAngle.x);
            camera.EulerAngle.y        = YawPitchUtility.Normalize(camera.EulerAngle.y);
            camera.EulerAngle.z        = YawPitchUtility.Normalize(camera.EulerAngle.z);
            camera.Fov  = calsOut.Fov;
            camera.Far  = calsOut.Far;
            camera.Near = calsOut.Near;

#if UNITY_EDITOR
            var p1 = calsOut.ArchorPosition;
            var p2 = _archoroffsetArm.LastLoc;
            var p3 = startingPosition;
            var p4 = _offsetArm.LastLoc;

            Debug.DrawLine(p1, p2, Color.red);
            Debug.DrawLine(p2, p3, Color.green);
            Debug.DrawLine(p3, p4, Color.blue);
#endif
        }
Example #4
0
 private static void CalcuFreeMoveEularAngle(FreeMoveEntity observedFreeMove, CameraFinalOutputNewComponent camera,
                                             CameraStateOutputNewComponent calsOut)
 {
     if (observedFreeMove.hasFreeMoveController && observedFreeMove.freeMoveController.ControllType ==
         (byte)EFreeMoveControllType.FixFocusPos)
     {
         var aimAt = observedFreeMove.freeMoveController.FocusOnPosition.ShiftedVector3();
         var vect  = aimAt - observedFreeMove.position.Value;
         camera.EulerAngle = Quaternion.LookRotation(vect).eulerAngles;
     }
     else
     {
         camera.EulerAngle = calsOut.ArchorEulerAngle + calsOut.EulerAngle;
     }
 }
Example #5
0
        private void CalcuFreeMovePos(FreeMoveEntity observedFreeMove, CameraFinalOutputNewComponent camera)
        {
            if (observedFreeMove == null || !observedFreeMove.hasPosition)
            {
                return;
            }

            var archorPos = observedFreeMove.position.Value +
                            (observedFreeMove.hasFreeMoveController ? Vector3.zero : observeOffset);
            var rotation = Quaternion.Euler(camera.EulerAngle);

            if (observedFreeMove.hasFreeMoveController && observedFreeMove.freeMoveController.ControllType ==
                (byte)EFreeMoveControllType.FixFocusPos)
            {
                camera.Position = archorPos;
            }
            else
            {
                float actualDistance = CameraUtility.ScatterCast(archorPos, rotation, observeDistance,
                                                                 _samplePoints, _collisionLayers);
                var finalPostOffset = -rotation.Forward() * actualDistance;
                camera.Position = archorPos + finalPostOffset;
            }
        }
        private void UpdateCollisions(CameraStateOutputNewComponent calsOut, CameraFinalOutputNewComponent camera,
                                      Vector3 punchRotation, PlayerEntity player)
        {
            Vector3 lToCamera  = calsOut.Offset;
            var     clientTime = player.time.ClientTime;

            float lNewDistance = lToCamera.magnitude;

            bool collided = false;

            var startingRotation = Quaternion.Euler(calsOut.ArchorEulerAngle + calsOut.EulerAngle + punchRotation);
            var realArchorStart  = calsOut.ArchorOffset;

            if (player.stateInterface.State.GetActionState() != ActionInConfig.Gliding &&
                player.stateInterface.State.GetActionState() != ActionInConfig.Parachuting &&
                player.gamePlay.GameState != Components.GameState.AirPlane)
            {
                TestArchorOffset(calsOut, player, ref realArchorStart);
            }

            var archorRotation   = Quaternion.Euler(0, calsOut.ArchorEulerAngle.y, 0);
            var postOffsetFactor = ActualStartingPosition(
                calsOut.ArchorPosition + archorRotation * realArchorStart, archorRotation,
                calsOut.ArchorPostOffset + calsOut.PostOffset, _collisionLayers);

            var startingPosition = calsOut.FinalArchorPosition =
                calsOut.ArchorPosition + archorRotation * (realArchorStart +
                                                           calsOut.ArchorPostOffset * postOffsetFactor +
                                                           calsOut.PostOffset * postOffsetFactor);

            float actualDistance = ActualDistance(startingRotation, startingPosition, lNewDistance, _collisionLayers);
            var   factor         = 1f;

            if (actualDistance < lNewDistance)
            {
                collided = true;
                if (actualDistance < _collisionOffsetStartDistance)
                {
                    factor           = Mathf.Lerp(_collisionOffsetStartDistance, actualDistance, actualDistance / lNewDistance) / lNewDistance;
                    startingPosition = calsOut.ArchorPosition + archorRotation * (realArchorStart +
                                                                                  calsOut.ArchorPostOffset * factor *
                                                                                  postOffsetFactor +
                                                                                  calsOut.PostOffset * postOffsetFactor *
                                                                                  factor);
                    actualDistance = ActualDistance(startingRotation, startingPosition, lNewDistance, _collisionLayers);
                    if (actualDistance >= lNewDistance)
                    {
                        collided = false;
                    }
                }
            }

            var finalPostOffset = calsOut.Offset.normalized * actualDistance;

            if (collided && !player.appearanceInterface.Appearance.IsFirstPerson)
            {
                camera.LastCollisionOffset = finalPostOffset;
                camera.LastCollisionTime   = clientTime;
            }
            else if (clientTime - camera.LastCollisionTime < camera.PostTransitionTime &&
                     !player.appearanceInterface.Appearance.IsFirstPerson)
            {
                finalPostOffset = PositionLerp(camera.LastCollisionOffset, finalPostOffset,
                                               (float)(clientTime - camera.LastCollisionTime) / camera.PostTransitionTime);
            }

            camera.PlayerFocusPosition = startingPosition;
            camera.Position            = startingPosition + startingRotation * (finalPostOffset);
            camera.EulerAngle          = calsOut.ArchorEulerAngle + calsOut.EulerAngle + punchRotation;
            camera.EulerAngle.x        = YawPitchUtility.Normalize(camera.EulerAngle.x);
            camera.EulerAngle.y        = YawPitchUtility.Normalize(camera.EulerAngle.y);
            camera.EulerAngle.z        = YawPitchUtility.Normalize(camera.EulerAngle.z);
            camera.Fov  = calsOut.Fov;
            camera.Far  = calsOut.Far;
            camera.Near = calsOut.Near;

#if UNITY_EDITOR
            var p1 = calsOut.ArchorPosition;
            var p2 = calsOut.ArchorPosition + archorRotation * calsOut.ArchorOffset;
            var p3 = calsOut.ArchorPosition +
                     archorRotation * (calsOut.ArchorOffset + calsOut.ArchorPostOffset * factor * postOffsetFactor);
            var p4 = calsOut.ArchorPosition +
                     archorRotation * (calsOut.ArchorOffset + calsOut.ArchorPostOffset * factor * postOffsetFactor +
                                       calsOut.PostOffset * postOffsetFactor * factor);
            var p5 = p4 + startingRotation * (calsOut.Offset.normalized * actualDistance);
            Debug.DrawLine(p1, p2, Color.red);
            Debug.DrawLine(p2, p3, Color.green);
            Debug.DrawLine(p3, p4, Color.blue);
            Debug.DrawLine(p4, p5, Color.yellow);
#endif
        }
Example #7
0
        private void UpdateCollisions(CameraStateOutputNewComponent calsOut, CameraFinalOutputNewComponent camera,
                                      Vector3 punchRotation)
        {
            Vector3 lToCamera = calsOut.Offset;

            float lNewDistance = lToCamera.magnitude;

            bool collided = false;

            var archorRotation   = Quaternion.Euler(0, calsOut.ArchorEulerAngle.y, 0);
            var postOffsetFactor = ActualStartingPosition(
                calsOut.ArchorPosition + archorRotation * calsOut.ArchorOffset, archorRotation,
                calsOut.ArchorPostOffset + calsOut.PostOffset, _collisionLayers);
            var startingPosition = calsOut.FinalArchorPosition =
                calsOut.ArchorPosition + archorRotation * (calsOut.ArchorOffset +
                                                           calsOut.ArchorPostOffset * postOffsetFactor +
                                                           calsOut.PostOffset * postOffsetFactor);
            var startingRotation = Quaternion.Euler(calsOut.ArchorEulerAngle + calsOut.EulerAngle + punchRotation);

            float actualDistance = ActualDistance(startingRotation, startingPosition, lNewDistance, _collisionLayers);
            var   factor         = 1f;

            if (actualDistance < lNewDistance)
            {
                if (actualDistance < _collisionOffsetStartDistance)
                {
                    factor           = actualDistance / lNewDistance;
                    startingPosition = calsOut.ArchorPosition + archorRotation * (calsOut.ArchorOffset +
                                                                                  calsOut.ArchorPostOffset * factor *
                                                                                  postOffsetFactor +
                                                                                  calsOut.PostOffset * postOffsetFactor *
                                                                                  factor);
                    actualDistance = ActualDistance(startingRotation, startingPosition, lNewDistance, _collisionLayers);
                }
            }


            camera.PlayerFocusPosition = startingPosition;
            camera.Position            = startingPosition + startingRotation * (calsOut.Offset.normalized * actualDistance);
            camera.EulerAngle          = calsOut.ArchorEulerAngle + calsOut.EulerAngle + punchRotation;
            camera.EulerAngle.x        = YawPitchUtility.Normalize(camera.EulerAngle.x);
            camera.EulerAngle.y        = YawPitchUtility.Normalize(camera.EulerAngle.y);
            camera.EulerAngle.z        = YawPitchUtility.Normalize(camera.EulerAngle.z);
            camera.Fov  = calsOut.Fov;
            camera.Far  = calsOut.Far;
            camera.Near = calsOut.Near;

#if UNITY_EDITOR
            var p1 = calsOut.ArchorPosition;
            var p2 = calsOut.ArchorPosition + archorRotation * calsOut.ArchorOffset;
            var p3 = calsOut.ArchorPosition +
                     archorRotation * (calsOut.ArchorOffset + calsOut.ArchorPostOffset * factor * postOffsetFactor);
            var p4 = calsOut.ArchorPosition +
                     archorRotation * (calsOut.ArchorOffset + calsOut.ArchorPostOffset * factor * postOffsetFactor +
                                       calsOut.PostOffset * postOffsetFactor * factor);
            var p5 = p4 + startingRotation * (calsOut.Offset.normalized * actualDistance);
            Debug.DrawLine(p1, p2, Color.red);
            Debug.DrawLine(p2, p3, Color.green);
            Debug.DrawLine(p3, p4, Color.blue);
            Debug.DrawLine(p4, p5, Color.yellow);
#endif
        }