Example #1
0
        void UpdateCamera()
        {
            if (flightCamera.updateActive)
            {
                // The FlightCamera is reactivated by the VesselSwitching class when the user
                // tries to switch vessels even if there is no other vessel to switch to. Make
                // sure the FlightCamera stays deactivated.
                flightCamera.SetTargetNone();
                flightCamera.DeactivateUpdate();
            }

            Transform tr = flightCamera.transform;

            Vector3 origin    = vessel.transform.TransformPoint(local_origin);
            Vector3 direction = target_quaternion * Vector3.back;

            RaycastHit[] hits = Physics.RaycastAll(origin, direction, maxDistance, Physics.DefaultRaycastLayers);

            distance = maxDistance;
            foreach (RaycastHit hit in hits)
            {
                if (hit.distance > minDistance && hit.distance < distance)
                {
                    distance = hit.distance;
                }
            }

            tr.SetPositionAndRotation(origin + distance * direction, target_quaternion);
        }
        public void enable(GameObject target)
        {
            cam = FlightCamera.fetch;
            if (cam)
            {
                active = true;
                if (KerbalKonstructs.useLegacyCamera)
                {
                    InputLockManager.SetControlLock(ControlTypes.CAMERACONTROLS, "KKCamControls");

                    cam.DeactivateUpdate();
                    oldTarget = cam.transform.parent;
                    //cam.updateActive = false;
                    cam.transform.parent   = target.transform;
                    cam.transform.position = target.transform.position;
                }
                else
                {
                    // new camera code
                    cam.SetTargetTransform(target.transform);
                }
            }
            else
            {
                Log.UserError("FlightCamera doesn't exist!");
            }
        }
Example #3
0
 public void enable(GameObject targ)
 {
     cam = FlightCamera.fetch;
     if (cam)
     {
         cam.DeactivateUpdate();
         oldTarget            = cam.transform.parent;
         cam.transform.parent = targ.transform;
         active = true;
     }
     else
     {
         Debug.LogError("KK: FlightCamera doesn't exist!");
     }
 }
		public void enable(GameObject targ)
		{
			cam = FlightCamera.fetch;
			if (cam)
			{
				cam.DeactivateUpdate();
				oldTarget = cam.transform.parent;
				cam.transform.parent = targ.transform;
				active = true;
			}
			else
			{
				Debug.LogError("FlightCamera doesn't exist!");
			}
		}
Example #5
0
        public void FixedUpdate()
        {
            if (vessel == null)
            {
                return;
            }

            if (MapView.MapIsEnabled)
            {
                return;
            }

            if (_cam == null)
            {
                _cam = FlightCamera.fetch;

                // Just a safety check
                if (_cam == null)
                {
                    return;
                }
            }

            if ((_cam != null) && (_origParent == null))
            {
                SaveMainCamera();
            }

            if (ltCamActive && (part.State == PartStates.DEAD))
            {
                LeaveCamera();
                CleanUp();
            }

            if ((_origParent != null) && (_cam != null) && ltCamActive)
            {
                _cam.SetTargetNone();
                _cam.transform.parent = cameraTransformName.Length > 0 ? part.FindModelTransform(cameraTransformName) : part.transform;
                _cam.DeactivateUpdate();
                _cam.transform.localPosition = cameraPosition;
                _cam.transform.localRotation = Quaternion.LookRotation(cameraForward, cameraUp);
                _cam.SetFoV(cameraFoV);
                Camera.main.nearClipPlane = cameraClip;
            }

            OnFixedUpdate();
        }
Example #6
0
        //private float _OriginHelmetColliderRadius = -1.0f; // Not used anymore but might be used again later

        public void Start(KerbalInfo kerbalInfo)
        {
            PressedMove = false;

            FlightCamera flightCam = FlightCamera.fetch;
            Vessel       vessel    = kerbalInfo.Vessel;
            KerbalEVA    evaInst   = kerbalInfo.EVA;

            foreach (Component component in vessel.transform.GetComponentsInChildren(typeof(Transform), true))
            {
                /*if (component.name.Contains(BeKerbal.Settings.EVA_HelmetColliderComponentName) && _OriginHelmetColliderRadius == -1.0f)
                 * {
                 *  _OriginHelmetColliderRadius = component.GetComponent<SphereCollider>().radius;
                 *  component.GetComponent<SphereCollider>().radius *= BeKerbal.Settings.EVA_HelmetColliderRadiusFactor;
                 * }*/

                if (component.name.Contains(BeKerbal.Settings.EVA_RagdollComponentReferenceName))
                {
                    _HeadTransform = component.transform;
                }

                foreach (string name in BeKerbal.Settings.EVA_HiddenComponentsName)
                {
                    if (component.name.Contains(name) && component.renderer != null)
                    {
                        component.renderer.enabled = false;
                        break;
                    }
                }
            }

            flightCam.DeactivateUpdate();

            _Pitch = 0.0f;
            _Yaw   = 0.0f;

            _Forward = evaInst.transform.forward;
            _Up      = evaInst.transform.up;

            _CursorLocked = true;

            flightCam.transform.position = Vector3.zero;
        }
Example #7
0
        public void SetFirstPersonCameraSettings(KerbalEVA eva)
        {
            FlightCamera flightCam = FlightCamera.fetch;

            flightCam.transform.parent = eva.transform;
            //flightCam.transform.parent = FlightGlobals.ActiveVessel.transform;

            //enableRenderers(pVessel.transform, false);
            enableRenderers(eva.transform, false);

            flightCam.mainCamera.nearClipPlane = 0.01f;

            isFirstPerson = true;
            if (showSightAngle)
            {
                fpgui = flightCam.gameObject.AddOrGetComponent <FPGUI>();
            }
            flightCam.SetTargetNone();
            flightCam.DeactivateUpdate();
            viewToNeutral();
            reorient();
        }
Example #8
0
        public static void SetCameraParent(Transform parentTransform)
        {
            // Assign FlightCamera instance to public var.
            ActiveFlightCamera = FlightCamera.fetch;

            // For replacing the camera when done editing.
            if (_originalParentTransform == null)
            {
                _originalParentTransform = ActiveFlightCamera.transform.parent;
            }

            // For translating the camera
            if (ActiveCameraPivot != null)
            {
                Object.Destroy(ActiveCameraPivot);
            }
            ActiveCameraPivot = new GameObject("KtCamPivot");
            ActiveCameraPivot.transform.parent        = parentTransform;
            ActiveCameraPivot.transform.localPosition = Vector3.zero;
            ActiveCameraPivot.transform.localRotation = Quaternion.identity;

            // Switch to active object.
            ActiveFlightCamera.transform.parent = ActiveCameraPivot.transform;

            // Use the FlightCamera sensitivity for the speed.
            CameraSpeed = ActiveFlightCamera.orbitSensitivity;

            // Take control of the flight camera.
            ActiveFlightCamera.DeactivateUpdate();

            // Instruct LateUpdate that we're controlling the camera manually now.
            ManualControl = true;

            // Say something.
            Extensions.PostScreenMessage("[KerbTown] FlightCamera switched to: " + parentTransform.name);
        }
Example #9
0
        public void FixedUpdate()
        {
            if (vessel == null || MapView.MapIsEnabled)
            {
                return;
            }

            if (part.State == PartStates.DEAD)
            {
                if (ltCamActive)
                {
                    LeaveCamera();
                }

                Events["ActivateCameraEvent"].guiActive  = false;
                Events["DeployExperiment"].guiActive     = false;
                Events["DetectAnomaliesEvent"].guiActive = false;
                ltCamActive = false;
                CleanUp();
                return;
            }

            if (GameSettings.CAMERA_RESET.GetKeyDown() || GameSettings.CAMERA_NEXT.GetKeyDown())
            {
                LeaveCamera();
            }


            Events["ActivateCameraEvent"].guiName = ltCamActive ? Localizer.Format("#autoLOC_LTech_Hullcam_009") : Localizer.Format("#autoLOC_LTech_Hullcam_006");
            Events["DeployExperiment"].guiActive  = ltCamActive;

            if (!ltCamActive)
            {
                return;
            }

            if (_cam == null)
            {
                _cam = FlightCamera.fetch;

                // Just a safety check
                if (_cam == null)
                {
                    return;
                }
            }

            if (_origParent == null)
            {
                SaveMainCamera();
            }

            _cam.SetTargetNone();
            _cam.transform.parent = cameraTransformName.Length > 0 ? part.FindModelTransform(cameraTransformName) : part.transform;
            _cam.DeactivateUpdate();
            _cam.transform.localPosition = cameraPosition;
            _cam.transform.localRotation = Quaternion.LookRotation(cameraForward, cameraUp);
            _cam.SetFoV(cameraFoV);
            Camera.main.nearClipPlane = cameraClip;

            OnFixedUpdate();
        }
        public void FixedUpdate()
        {
            // In the VAB
            if (vessel == null)
            {
                return;
            }
            // following "if" added by jbb
            if (MapView.MapIsEnabled)
            {
                return;
            }

            if (part.State == PartStates.DEAD)
            {
                if (camActive)
                {
                    LeaveCamera();
                }
                Events["ActivateCamera"].guiActive = false;
                Events["EnableCamera"].guiActive   = false;
                camEnabled = false;
                camActive  = false;
                DirtyWindow();
                CleanUp();
                return;
            }

            if (!sAllowMainCamera && sCurrentCamera == null && !vessel.isEVA)
            {
                camActive      = true;
                sCurrentCamera = this;
            }

            if (!camActive)
            {
                return;
            }

            if (!camEnabled)
            {
                DebugOutput(" 3");
                CycleCamera(1);
                return;
            }

            if (sCam == null)
            {
                sCam = FlightCamera.fetch;
                // No idea if fetch returns null in normal operation (i.e. when there isn't a game breaking bug going on already)
                // but the original code had similar logic.
                if (sCam == null)
                {
                    return;
                }
            }

            // Either we haven't set sOriginParent, or we've nulled it when restoring the main camera, so we save it again here.
            if (sOrigParent == null)
            {
                SaveMainCamera();
            }


            //sCam.SetTarget(null);
            sCam.SetTargetNone();
            sCam.transform.parent = (cameraTransformName.Length > 0) ? part.FindModelTransform(cameraTransformName) : part.transform;
            sCam.DeactivateUpdate();
            sCam.transform.localPosition = cameraPosition;



            sCam.transform.localRotation = Quaternion.LookRotation(cameraForward, cameraUp);
            sCam.SetFoV(cameraFoV);
            Camera.main.nearClipPlane = cameraClip;

            // If we're only allowed to cycle the active vessel and viewing through a camera that's not the active vessel any more, then cycle to one that is.
            if (sCycleOnlyActiveVessel && FlightGlobals.ActiveVessel != null && FlightGlobals.ActiveVessel != vessel)
            {
                DebugOutput(" 4");
                CycleCamera(1);
            }

            base.OnFixedUpdate();
        }
Example #11
0
        public static void SetCameraParent(Transform parentTransform)
        {
            // Assign FlightCamera instance to public var.
            ActiveFlightCamera = FlightCamera.fetch;

            // For replacing the camera when done editing.
            if (_originalParentTransform == null)
                _originalParentTransform = ActiveFlightCamera.transform.parent;

            // For translating the camera
            if (ActiveCameraPivot != null) Object.Destroy(ActiveCameraPivot);
            ActiveCameraPivot = new GameObject("KtCamPivot");
            ActiveCameraPivot.transform.parent = parentTransform;
            ActiveCameraPivot.transform.localPosition = Vector3.zero;
            ActiveCameraPivot.transform.localRotation = Quaternion.identity;

            // Switch to active object.
            ActiveFlightCamera.transform.parent = ActiveCameraPivot.transform;

            // Use the FlightCamera sensitivity for the speed.
            CameraSpeed = ActiveFlightCamera.orbitSensitivity;

            // Take control of the flight camera.
            ActiveFlightCamera.DeactivateUpdate();

            // Instruct LateUpdate that we're controlling the camera manually now.
            ManualControl = true;

            // Say something.
            Extensions.PostScreenMessage("[KerbTown] FlightCamera switched to: " + parentTransform.name);
        }
Example #12
0
        public void Update(KerbalInfo kerbalInfo)
        {
            FlightCamera flightCam = FlightCamera.fetch;
            Vessel       vessel    = kerbalInfo.Vessel;
            KerbalEVA    evaInst   = kerbalInfo.EVA;

            if (flightCam.updateActive)
            {
                flightCam.DeactivateUpdate();
            }

            float yaw   = 0.0f;
            float pitch = 0.0f;

            if (Input.GetKeyDown(KeyCode.LeftAlt))
            {
                _CursorLocked = !_CursorLocked;
            }

            Screen.lockCursor = _CursorLocked;
            if (_CursorLocked && !evaInst.isRagdoll)
            {
                yaw   = Input.GetAxis("Mouse X") * BeKerbal.Settings.EVA_LookSentivity;
                pitch = Input.GetAxis("Mouse Y") * BeKerbal.Settings.EVA_LookSentivity;
            }

            if (!evaInst.isRagdoll)
            {
                evaInst.fFwd = _Forward;
                evaInst.fUp  = _Up;
            }

            flightCam.mainCamera.nearClipPlane = BeKerbal.Settings.EVA_NearClip;
            flightCam.transform.position       = vessel.ReferenceTransform.position;
            flightCam.transform.rotation       = Quaternion.identity;

            if (!evaInst.isRagdoll)
            {
                if (vessel.LandedOrSplashed || evaInst.OnALadder) // Is walking on a surface or climbing a ladder
                {
                    evaInst.CharacterFrameMode       = false;
                    evaInst.CharacterFrameModeToggle = true;

                    _Yaw += yaw;
                    float absYaw    = Mathf.Abs(_Yaw);
                    float yawExceed = Mathf.Max(0.0f, Mathf.Abs(_Yaw) - BeKerbal.Settings.EVA_MaxYaw) * Mathf.Sign(_Yaw);
                    _Yaw = Mathf.Clamp(_Yaw, BeKerbal.Settings.EVA_MinYaw, BeKerbal.Settings.EVA_MaxYaw);

                    _Pitch -= pitch;
                    _Pitch  = Mathf.Clamp(_Pitch, BeKerbal.Settings.EVA_MinPitch, BeKerbal.Settings.EVA_MaxPitch);

                    if (evaInst.OnALadder)
                    {
                        flightCam.transform.rotation = Quaternion.LookRotation(evaInst.transform.forward, evaInst.transform.up) * SpaceNavigator.Rotation;
                    }
                    else
                    {
                        flightCam.transform.rotation = Quaternion.LookRotation(evaInst.fFwd, evaInst.transform.up) * SpaceNavigator.Rotation;

                        if (PressedMove)
                        {
                            float partYaw = _Yaw * BeKerbal.Settings.EVA_ViewTurnPercent;
                            _Yaw -= partYaw;
                            flightCam.transform.Rotate(Vector3.up * (yawExceed + partYaw), Space.Self);
                        }
                    }

                    _Forward = flightCam.transform.forward;
                    _Up      = flightCam.transform.up;
                }
                else if (evaInst.JetpackDeployed) // Is using jetpack in the air
                {
                    evaInst.CharacterFrameMode       = false;
                    evaInst.CharacterFrameModeToggle = true;

                    //flightCam.transform.rotation = Quaternion.LookRotation(-_HeadTransform.up, -_HeadTransform.right) * SpaceNavigator.Rotation;
                    flightCam.transform.rotation = Quaternion.LookRotation(evaInst.fFwd, evaInst.fUp) * SpaceNavigator.Rotation;

                    if (_CursorLocked)
                    {
                        _Yaw += yaw;
                        _Yaw  = Mathf.Clamp(_Yaw, BeKerbal.Settings.EVA_MinYaw, BeKerbal.Settings.EVA_MaxYaw);

                        _Pitch -= pitch;
                        _Pitch  = Mathf.Clamp(_Pitch, BeKerbal.Settings.EVA_MinPitch, BeKerbal.Settings.EVA_MaxPitch);

                        if (PressedMove)
                        {
                            float partYaw   = _Yaw * BeKerbal.Settings.EVA_ViewTurnPercent;
                            float partPitch = _Pitch * BeKerbal.Settings.EVA_ViewTurnPercent;
                            _Yaw   -= partYaw;
                            _Pitch -= partPitch;

                            flightCam.transform.rotation *= Quaternion.Euler(-(pitch - partPitch), yaw + partYaw, 0.0f);
                        }
                    }

                    _Forward = flightCam.transform.forward;
                    _Up      = flightCam.transform.up;
                }
                else // Is falling without jetpack and not in ragdoll yet (probably jumping or drifting in the void)
                {
                    evaInst.CharacterFrameMode       = true;
                    evaInst.CharacterFrameModeToggle = false;

                    _Yaw += yaw;
                    _Yaw  = Mathf.Clamp(_Yaw, BeKerbal.Settings.EVA_MinYaw, BeKerbal.Settings.EVA_MaxYaw);

                    _Pitch -= pitch;
                    _Pitch  = Mathf.Clamp(_Pitch, BeKerbal.Settings.EVA_MinPitch, BeKerbal.Settings.EVA_MaxPitch);

                    flightCam.transform.rotation = Quaternion.LookRotation(-_HeadTransform.up, -_HeadTransform.right) * SpaceNavigator.Rotation;

                    _Forward = evaInst.transform.forward;
                }
            }
            else // Is in ragdoll or TODO(is recovering from ragdoll)
            {
                evaInst.CharacterFrameMode       = true;
                evaInst.CharacterFrameModeToggle = false;

                _Yaw   = Mathf.Lerp(_Yaw, 0.0f, 2.0f * Time.deltaTime);
                _Pitch = Mathf.Lerp(_Pitch, 0.0f, 2.0f * Time.deltaTime);

                if (!evaInst.animation.enabled) // true ragdoll
                {
                    flightCam.transform.rotation = Quaternion.LookRotation(-_HeadTransform.up, -_HeadTransform.right) * SpaceNavigator.Rotation;
                }
                else // recovering
                {
                    flightCam.transform.rotation = Quaternion.LookRotation(-_HeadTransform.up, -_HeadTransform.right) * SpaceNavigator.Rotation;
                    _Forward = evaInst.transform.forward;
                    _Up      = evaInst.transform.up;
                }
            }

            flightCam.transform.Translate(BeKerbal.Settings.EVA_HeadLocation + BeKerbal.Settings.EVA_EyeOffset, Space.Self);

            flightCam.transform.Rotate(Vector3.up * _Yaw, Space.Self);
            flightCam.transform.Rotate(Vector3.right * _Pitch, Space.Self);
        }