Skip to content

Commit

Permalink
IVA Look Window action re-implemented and enabled
Browse files Browse the repository at this point in the history
More robust implementation. Should not be possible to bug out the
camera.
  • Loading branch information
ddaf committed Nov 30, 2014
1 parent e2d7405 commit 044cc09
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 16 deletions.
44 changes: 33 additions & 11 deletions CameraController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<InternalCameraSwitch>())
//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<InternalCameraSwitch>())
{
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<ProtoCrewMember> 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()
Expand Down
2 changes: 1 addition & 1 deletion ControllerPreset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public enum DiscreteAction
NavballToggle,

IVANextCamera,
// IVALookWindow, // has issues, disabled for now
IVALookWindow, // has issues, disabled for now
TogglePrecisionControls,
ResetTrim,
}
Expand Down
4 changes: 2 additions & 2 deletions FlightManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions Stringify.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down

0 comments on commit 044cc09

Please sign in to comment.