diff --git a/CameraController.cs b/CameraController.cs index 23e9bb2..ee1a2e7 100644 --- a/CameraController.cs +++ b/CameraController.cs @@ -92,27 +92,49 @@ public void FocusIVAWindow() switch (CameraManager.Instance.currentCameraMode) { case CameraManager.CameraMode.IVA: - case CameraManager.CameraMode.Internal: { - InternalModel intModel = FlightGlobals.ActiveVessel.rootPart.internalModel; - Transform camTransform = InternalCamera.Instance.transform; - Ray ray = new Ray(camTransform.position, camTransform.forward); - RaycastHit hit; - // Use RayCastAll to catch far-away windows. - if (Physics.Raycast(ray, out hit, 5f)) + Kerbal kerbal = GetActiveIVAKerbal(); + + if (kerbal != null && kerbal.InPart != null && kerbal.InPart.internalModel != null) { - Debug.Log("RaycastHit: " + hit.collider.name + " (dist: " + hit.distance + ")"); - foreach (InternalCameraSwitch intCam in intModel.FindModelComponents()) + //Debug.Log("Kerbal: " + kerbal.crewMemberName + " inside "+ kerbal.InPart.internalModel.internalName); + InternalModel intModel = kerbal.InPart.internalModel; + Transform camTransform = InternalCamera.Instance.transform; + Ray ray = new Ray(camTransform.position, camTransform.forward); + RaycastHit hit; + if (Physics.Raycast(ray, out hit, 5f)) { - if (hit.collider.name.Equals(intCam.colliderTransformName)) + //Debug.Log("RaycastHit: " + hit.collider.name + " (dist: " + hit.distance + ")"); + foreach (InternalCameraSwitch intCam in intModel.FindModelComponents()) { - intCam.Button_OnDoubleTap(); + if (hit.collider.name.Equals(intCam.colliderTransformName)) + { + intCam.Button_OnDoubleTap(); + } } } } break; } + case CameraManager.CameraMode.Internal: + { + CameraManager.Instance.SetCameraIVA(); + break; + } + } + } + + private Kerbal GetActiveIVAKerbal() + { + List vesselCrew = FlightGlobals.fetch.activeVessel.GetVesselCrew(); + foreach (ProtoCrewMember pcm in vesselCrew) + { + if (pcm.KerbalRef.eyeTransform == InternalCamera.Instance.transform.parent) + { + return pcm.KerbalRef; + } } + return null; } private void LoadReflectionFields() diff --git a/ControllerPreset.cs b/ControllerPreset.cs index 99ce4df..62a53fc 100644 --- a/ControllerPreset.cs +++ b/ControllerPreset.cs @@ -91,7 +91,7 @@ public enum DiscreteAction NavballToggle, IVANextCamera, - // IVALookWindow, // has issues, disabled for now + IVALookWindow, // has issues, disabled for now TogglePrecisionControls, ResetTrim, } diff --git a/FlightManager.cs b/FlightManager.cs index 5746d5a..fb94a15 100644 --- a/FlightManager.cs +++ b/FlightManager.cs @@ -404,9 +404,9 @@ public void EvaluateDiscreteAction(ControllerConfiguration controller, DiscreteA case DiscreteAction.IVANextCamera: CameraController.Instance.NextIVACamera(); return; - /* case DiscreteAction.IVALookWindow: + case DiscreteAction.IVALookWindow: CameraController.Instance.FocusIVAWindow(); - return;*/ + return; case DiscreteAction.EVAInteract: EVAController.Instance.DoInteract(); return; diff --git a/Stringify.cs b/Stringify.cs index a3a97d6..e1d1216 100644 --- a/Stringify.cs +++ b/Stringify.cs @@ -136,8 +136,8 @@ public static string DiscreteActionToString(DiscreteAction action) return "Reset Trim"; case DiscreteAction.IVANextCamera: return "IVA Next Kerbal"; - /* case DiscreteAction.IVALookWindow: - return "IVA Focus Window";*/ + case DiscreteAction.IVALookWindow: + return "IVA Focus Window"; default: return "Unknown Action"; }