Esempio n. 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);
        }
Esempio n. 2
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();
        }
Esempio n. 3
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();
        }
Esempio n. 4
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();
        }