Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxgurugamer committed Aug 19, 2022
2 parents f9fd22c + fee7966 commit 1d04a69
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 53 deletions.
30 changes: 15 additions & 15 deletions ThroughTheEyes/FPStateFloating.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,37 +77,37 @@ public void evtHook_PreOnFixedUpdate (KerbalEVA eva)
if ((FlightGlobals.ActiveVessel.situation != Vessel.Situations.SPLASHED
//&& FlightGlobals.ActiveVessel.situation != Vessel.Situations.LANDED //Allow landed jetpack operation
)
&& FlightGlobals.ActiveVessel.evaController.JetpackDeployed) {
&& eva.JetpackDeployed) {

//************Rotation************
Quaternion manualRotation = Quaternion.identity;
Vector3 commandedManualRotation = Vector3.zero;
if (GameSettings.YAW_LEFT.GetKey (false)) {
manualRotation = manualRotation * Quaternion.AngleAxis ((float)(-(double)FlightGlobals.ActiveVessel.evaController.turnRate * Mathf.Rad2Deg) * Time.deltaTime, FlightGlobals.ActiveVessel.evaController.transform.up);
manualRotation = manualRotation * Quaternion.AngleAxis ((float)(-(double)eva.turnRate * Mathf.Rad2Deg) * Time.deltaTime, eva.transform.up);
commandedManualRotation -= eva.transform.up;
//KSPLog.print ("YAW LEFT");
} else if (GameSettings.YAW_RIGHT.GetKey (false)) {
manualRotation = manualRotation * Quaternion.AngleAxis ((float)((double)FlightGlobals.ActiveVessel.evaController.turnRate * Mathf.Rad2Deg) * Time.deltaTime, FlightGlobals.ActiveVessel.evaController.transform.up);
manualRotation = manualRotation * Quaternion.AngleAxis ((float)((double)eva.turnRate * Mathf.Rad2Deg) * Time.deltaTime, eva.transform.up);
commandedManualRotation += eva.transform.up;
//KSPLog.print ("YAW RIGHT");
}

if (GameSettings.PITCH_UP.GetKey (false)) {
manualRotation = manualRotation * Quaternion.AngleAxis ((float)(-(double)FlightGlobals.ActiveVessel.evaController.turnRate * Mathf.Rad2Deg) * Time.deltaTime, FlightGlobals.ActiveVessel.evaController.transform.right);
manualRotation = manualRotation * Quaternion.AngleAxis ((float)(-(double)eva.turnRate * Mathf.Rad2Deg) * Time.deltaTime, eva.transform.right);
commandedManualRotation -= eva.transform.right;
//KSPLog.print ("PITCH UP");
} else if (GameSettings.PITCH_DOWN.GetKey (false)) {
manualRotation = manualRotation * Quaternion.AngleAxis ((float)((double)FlightGlobals.ActiveVessel.evaController.turnRate * Mathf.Rad2Deg) * Time.deltaTime, FlightGlobals.ActiveVessel.evaController.transform.right);
manualRotation = manualRotation * Quaternion.AngleAxis ((float)((double)eva.turnRate * Mathf.Rad2Deg) * Time.deltaTime, eva.transform.right);
commandedManualRotation += eva.transform.right;
//KSPLog.print ("PITCH DOWN");
}

if (GameSettings.ROLL_RIGHT.GetKey (false)) {
manualRotation = manualRotation * Quaternion.AngleAxis ((float)(-(double)FlightGlobals.ActiveVessel.evaController.turnRate * Mathf.Rad2Deg) * Time.deltaTime, FlightGlobals.ActiveVessel.evaController.transform.forward);
manualRotation = manualRotation * Quaternion.AngleAxis ((float)(-(double)eva.turnRate * Mathf.Rad2Deg) * Time.deltaTime, eva.transform.forward);
commandedManualRotation -= eva.transform.forward;
//KSPLog.print ("ROLL RIGHT");
} else if (GameSettings.ROLL_LEFT.GetKey (false)) {
manualRotation = manualRotation * Quaternion.AngleAxis ((float)((double)FlightGlobals.ActiveVessel.evaController.turnRate * Mathf.Rad2Deg) * Time.deltaTime, FlightGlobals.ActiveVessel.evaController.transform.forward);
manualRotation = manualRotation * Quaternion.AngleAxis ((float)((double)eva.turnRate * Mathf.Rad2Deg) * Time.deltaTime, eva.transform.forward);
commandedManualRotation += eva.transform.forward;
//KSPLog.print ("ROLL LEFT");
}
Expand Down Expand Up @@ -175,40 +175,40 @@ public void evtHook_PreOnFixedUpdate (KerbalEVA eva)
Vector3 manualTranslation = Vector3.zero;
if (GameSettings.TRANSLATE_LEFT.GetKey (false)) {
manualTranslation += Vector3.left;
//manualRotation = manualRotation * Quaternion.AngleAxis((float) (-(double) FlightGlobals.ActiveVessel.evaController.turnRate * Mathf.Rad2Deg) * Time.deltaTime, FlightGlobals.ActiveVessel.evaController.transform.up);
//manualRotation = manualRotation * Quaternion.AngleAxis((float) (-(double) eva.turnRate * Mathf.Rad2Deg) * Time.deltaTime, eva.transform.up);
//KSPLog.print ("TRANSLATE LEFT");
} else if (GameSettings.TRANSLATE_RIGHT.GetKey (false)) {
manualTranslation += Vector3.right;
//manualRotation = manualRotation * Quaternion.AngleAxis((float) ((double) FlightGlobals.ActiveVessel.evaController.turnRate * Mathf.Rad2Deg) * Time.deltaTime, FlightGlobals.ActiveVessel.evaController.transform.up);
//manualRotation = manualRotation * Quaternion.AngleAxis((float) ((double) eva.turnRate * Mathf.Rad2Deg) * Time.deltaTime, eva.transform.up);
//KSPLog.print ("TRANSLATE RIGHT");
}

if (GameSettings.TRANSLATE_UP.GetKey (false)) {
manualTranslation += Vector3.up;
//manualRotation = manualRotation * Quaternion.AngleAxis((float) (-(double) FlightGlobals.ActiveVessel.evaController.turnRate * Mathf.Rad2Deg) * Time.deltaTime, FlightGlobals.ActiveVessel.evaController.transform.right);
//manualRotation = manualRotation * Quaternion.AngleAxis((float) (-(double) eva.turnRate * Mathf.Rad2Deg) * Time.deltaTime, eva.transform.right);
//KSPLog.print ("TRANSLATE UP");
} else if (GameSettings.TRANSLATE_DOWN.GetKey (false)) {
manualTranslation += Vector3.down;
//manualRotation = manualRotation * Quaternion.AngleAxis((float) ((double) FlightGlobals.ActiveVessel.evaController.turnRate * Mathf.Rad2Deg) * Time.deltaTime, FlightGlobals.ActiveVessel.evaController.transform.right);
//manualRotation = manualRotation * Quaternion.AngleAxis((float) ((double) eva.turnRate * Mathf.Rad2Deg) * Time.deltaTime, eva.transform.right);
//KSPLog.print ("TRANSLATE DOWN");
}

if (GameSettings.TRANSLATE_FWD.GetKey (false)) {
manualTranslation += Vector3.forward;
//manualRotation = manualRotation * Quaternion.AngleAxis((float) (-(double) FlightGlobals.ActiveVessel.evaController.turnRate * Mathf.Rad2Deg) * Time.deltaTime, FlightGlobals.ActiveVessel.evaController.transform.forward);
//manualRotation = manualRotation * Quaternion.AngleAxis((float) (-(double) eva.turnRate * Mathf.Rad2Deg) * Time.deltaTime, eva.transform.forward);
//KSPLog.print ("TRANSLATE RIGHT");
} else if (GameSettings.TRANSLATE_BACK.GetKey (false)) {
manualTranslation += Vector3.back;
//manualRotation = manualRotation * Quaternion.AngleAxis((float) ((double) FlightGlobals.ActiveVessel.evaController.turnRate * Mathf.Rad2Deg) * Time.deltaTime, FlightGlobals.ActiveVessel.evaController.transform.forward);
//manualRotation = manualRotation * Quaternion.AngleAxis((float) ((double) eva.turnRate * Mathf.Rad2Deg) * Time.deltaTime, eva.transform.forward);
//KSPLog.print ("TRANSLATE LEFT");
}

manualTranslation.Normalize ();
manualTranslation = FlightGlobals.ActiveVessel.transform.rotation * manualTranslation;

//KSPLog.print ("Resetting rpos. Old value: " + ((Vector3)ReflectedMembers.eva_packTgtRPos.GetValue (FlightGlobals.ActiveVessel.evaController)).ToString ()
//KSPLog.print ("Resetting rpos. Old value: " + ((Vector3)ReflectedMembers.eva_packTgtRPos.GetValue (eva)).ToString ()
//+ ", new value: " + manualTranslation.ToString ());
ReflectedMembers.eva_packTgtRPos.SetValue (FlightGlobals.ActiveVessel.evaController, manualTranslation);
ReflectedMembers.eva_packTgtRPos.SetValue (eva, manualTranslation);

//************Set power**************
eva.rotPower = 1f * imgr.state.eva_throttle;
Expand Down
39 changes: 19 additions & 20 deletions ThroughTheEyes/FirstPersonCameraManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,27 @@ public static FirstPersonCameraManager initialize(bool showSightAngle = true) {

return instance;
}

public void CheckAndSetFirstPerson(Vessel pVessel)
{
FlightCamera flightCam = FlightCamera.fetch;

if (pVessel.isEVA)
var kerbalEVA = ThroughTheEyes.GetKerbalEVAFromVessel(pVessel);

if (kerbalEVA != null)
{
if (!isFirstPerson
&& !pVessel.packed //this prevents altering camera until EVA is unpacked or else various weird effects are possible
)
{
currentfpeva = pVessel.evaController;
SetFirstPersonCameraSettings (pVessel.evaController);
currentfpeva = kerbalEVA;
SetFirstPersonCameraSettings (currentfpeva);

//Enter first person
FirstPersonEVA.instance.state.Reset (pVessel.evaController);
FirstPersonEVA.instance.state.Reset (currentfpeva);

if (OnEnterFirstPerson != null)
OnEnterFirstPerson (pVessel.evaController);
OnEnterFirstPerson (currentfpeva);
}

KeyDisabler.instance.disableKey (KeyDisabler.eKeyCommand.CAMERA_NEXT, KeyDisabler.eDisableLockSource.FirstPersonEVA);
Expand Down Expand Up @@ -125,14 +127,6 @@ private void enableRenderers(Transform transform, bool enable) {
}
}

private void EnableRenderingOnPrevious(Vessel vessel)
{
if (vessel != null && vessel.isEVA)
{
enableRenderers(FlightGlobals.ActiveVessel.transform, true);
}
}

public void resetCamera(Vessel previousVessel) {
ReflectedMembers.Initialize ();

Expand All @@ -155,7 +149,12 @@ public void resetCamera(Vessel previousVessel) {

isFirstPerson = false;

EnableRenderingOnPrevious(previousVessel);
KerbalEVA previousEVA = ThroughTheEyes.GetKerbalEVAFromVessel(previousVessel);

if (previousEVA != null)
{
enableRenderers(previousEVA.transform, true);
}

//Exit first person

Expand All @@ -164,14 +163,14 @@ public void resetCamera(Vessel previousVessel) {
currentfpeva = null;

//Restore stuff that changed in the evacontroller
if (previousVessel != null && previousVessel.evaController != null) {
if (previousEVA != null) {
//Axis control settings
ReflectedMembers.eva_manualAxisControl.SetValue (previousVessel.evaController, false);
ReflectedMembers.eva_cmdRot.SetValue (previousVessel.evaController, Vector3.zero);
ReflectedMembers.eva_manualAxisControl.SetValue (previousEVA, false);
ReflectedMembers.eva_cmdRot.SetValue (previousEVA, Vector3.zero);

//Pack power (from fine controls)
previousVessel.evaController.rotPower = 1f;
previousVessel.evaController.linPower = 0.3f;
previousEVA.rotPower = 1f;
previousEVA.linPower = 0.3f;
}

KeyDisabler.instance.restoreAllKeys (KeyDisabler.eDisableLockSource.FirstPersonEVA);
Expand Down
21 changes: 11 additions & 10 deletions ThroughTheEyes/FirstPersonEVA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private void onVesselDestroy(Vessel v) {
if (FlightGlobals.fetch == null)
return;

if (v != null && v == FlightGlobals.ActiveVessel && v.isEVA) {
if (v != null && v == FlightGlobals.ActiveVessel && fpCameraManager.isFirstPerson) {
fpCameraManager.resetCamera (v);
}

Expand All @@ -48,7 +48,7 @@ private void onVesselSwitching(Vessel from, Vessel to) {
fpCameraManager.resetCamera((Vessel)from);
lastHookedVessel = null;

if (to != null && to.isEVA) {
if (to != null && ThroughTheEyes.GetKerbalEVAFromVessel(to) != null) {
CameraManager.Instance.SetCameraFlight();
}

Expand Down Expand Up @@ -114,16 +114,17 @@ void Update()

if (pVessel == null)
return;
if (pVessel.isEVA && !pVessel.packed && pVessel.loaded && pVessel.evaController != null) {
if (pVessel != lastHookedVessel) {
lastHookedVessel = pVessel;

//KSPLog.print (string.Format("{0} switched to, hooking vessel for general hooks.", pVessel.GetName()));
EVABoundFix.Hook (pVessel.evaController);
}
if (!pVessel.packed && pVessel.loaded && pVessel != lastHookedVessel) {
lastHookedVessel = pVessel;



//KSPLog.print (string.Format("{0} switched to, hooking vessel for general hooks.", pVessel.GetName()));
EVABoundFix.Hook (ThroughTheEyes.GetKerbalEVAFromVessel(pVessel));
}

if (FlightGlobals.ActiveVessel.isEVA && fpCameraManager.isFirstPerson && needCamReset) {
if (fpCameraManager.isFirstPerson && needCamReset) {
fpCameraManager.isFirstPerson = false;
fpCameraManager.CheckAndSetFirstPerson(pVessel);
}
Expand All @@ -136,7 +137,7 @@ void Update()
}
fpCameraManager.CheckAndSetFirstPerson(pVessel);
}
if (!ThroughTheEyes.CheckControlLocks() && !forceEVA && pVessel.isEVA) {
if (!ThroughTheEyes.CheckControlLocks() && !forceEVA) {
if (Input.GetKeyDown(toggleFirstPersonKey)) {
if (!fpCameraManager.isFirstPerson) {
fpCameraManager.saveCameraState(flightCam);
Expand Down
35 changes: 27 additions & 8 deletions ThroughTheEyes/ThroughTheEyes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,33 @@ class ThroughTheEyes : MonoBehaviour

public static KeyDisabler keyDisabler;

void OnGUI()
public static KerbalEVA GetKerbalEVAFromVessel(Vessel vessel)
{
if (vessel == null)
{
return null;
}

// if the vessel IS a kerbal, we're done
if (vessel.isEVA)
{
return vessel.evaController;
}

// try to find a kerbal in a commmand chair
var referenceTransformPart = vessel.GetReferenceTransformPart();
if (referenceTransformPart != null)
{
var kerbalModule = referenceTransformPart.FindModuleImplementing<KerbalEVA>();

return kerbalModule;
}

return null;
}

void OnGUI()
{
if (HighLogic.LoadedSceneIsFlight && FlightGlobals.ActiveVessel.isEVA)
{
Vessel pVessel = FlightGlobals.ActiveVessel;
KerbalEVA keva = FlightGlobals.ActiveVessel.evaController;
int fuelPercent = (int)(keva.Fuel / keva.FuelCapacity);
}
}

public ThroughTheEyes()
Expand Down Expand Up @@ -78,7 +97,7 @@ void CheckAndSetCamera(Vessel pVessel)
}

private void onVesselChange(Vessel v) {
if (v.isEVA) {
if (ThroughTheEyes.GetKerbalEVAFromVessel(v)) {
CameraManager.Instance.SetCameraFlight(); //Important. Without this switching to EVA from IVA would lead to heavy errors on attempts to return to IVA of originating vessel
}
}
Expand Down

0 comments on commit 1d04a69

Please sign in to comment.