From 1915c993ef86e70e39246e724bee0247276e12a2 Mon Sep 17 00:00:00 2001 From: Max-Q <97061245+maxq519@users.noreply.github.com> Date: Wed, 16 Oct 2024 17:20:06 -0400 Subject: [PATCH] Add working flashlight in the VC for both vehicles --- .../samples/ProjectApollo/src_csm/saturn.cpp | 21 ++++++++++++ .../samples/ProjectApollo/src_csm/saturn.h | 15 ++++++++ .../ProjectApollo/src_csm/saturnvc.cpp | 34 +++++++++++++++++++ .../samples/ProjectApollo/src_lm/LEM.cpp | 19 +++++++++++ Orbitersdk/samples/ProjectApollo/src_lm/LEM.h | 13 +++++++ .../samples/ProjectApollo/src_lm/lemvc.cpp | 34 +++++++++++++++++++ 6 files changed, 136 insertions(+) diff --git a/Orbitersdk/samples/ProjectApollo/src_csm/saturn.cpp b/Orbitersdk/samples/ProjectApollo/src_csm/saturn.cpp index 839eeccdec..6e68cb2e31 100644 --- a/Orbitersdk/samples/ProjectApollo/src_csm/saturn.cpp +++ b/Orbitersdk/samples/ProjectApollo/src_csm/saturn.cpp @@ -999,6 +999,18 @@ void Saturn::initSaturn() FovExternal = false; FovSave = 0; + // + // Flashlight + // + flashlight = 0; + flashlightColor = { 1,1,1,0 }; + flashlightColor2 = { 0,0,0,0 }; + flashlightPos = { 0,0,0 }; + vesselPosGlobal = { 0,0,0 }; + flashlightDirGlobal = { 0,0,1 }; + flashlightDirLocal = { 0,0,1 }; + flashlightOn = 0; + // // Save the last view offset set. // @@ -1567,6 +1579,11 @@ void Saturn::clbkPreStep(double simt, double simdt, double mjd) dsky.SendNetworkPacketDSKY(); } + if ((oapiGetFocusObject() == GetHandle()) && (oapiCockpitMode() == COCKPIT_VIRTUAL) && (oapiCameraMode() == CAM_COCKPIT)) { + //We have focus on this vessel, and are in the VC + MoveFlashlight(); + } + sprintf(buffer, "End time(0) %lld", time(0)); TRACE(buffer); } @@ -3686,6 +3703,10 @@ int Saturn::clbkConsumeBufferedKey(DWORD key, bool down, char *kstate) { } } + if ((down) && (key == OAPI_KEY_F)) { + ToggleFlashlight(); + } + // MCC CAPCOM interface key handling if (down && !KEYMOD_SHIFT(kstate)) { switch (key) { diff --git a/Orbitersdk/samples/ProjectApollo/src_csm/saturn.h b/Orbitersdk/samples/ProjectApollo/src_csm/saturn.h index 1ef4f739c6..e7cfff014f 100644 --- a/Orbitersdk/samples/ProjectApollo/src_csm/saturn.h +++ b/Orbitersdk/samples/ProjectApollo/src_csm/saturn.h @@ -1285,6 +1285,21 @@ class Saturn: public ProjectApolloConnectorVessel, public PanelSwitchListener { void ClearMeshes(); + // + // Flashlight for VC + // + void MoveFlashlight(); + void SetFlashlightOn(bool state); + void ToggleFlashlight(); + SpotLight* flashlight; + COLOUR4 flashlightColor; + COLOUR4 flashlightColor2; + VECTOR3 flashlightPos; + VECTOR3 vesselPosGlobal; + VECTOR3 flashlightDirGlobal; + VECTOR3 flashlightDirLocal; + bool flashlightOn; + protected: /// diff --git a/Orbitersdk/samples/ProjectApollo/src_csm/saturnvc.cpp b/Orbitersdk/samples/ProjectApollo/src_csm/saturnvc.cpp index b85835cb23..b900c5ac24 100644 --- a/Orbitersdk/samples/ProjectApollo/src_csm/saturnvc.cpp +++ b/Orbitersdk/samples/ProjectApollo/src_csm/saturnvc.cpp @@ -805,6 +805,12 @@ bool Saturn::clbkLoadVC (int id) vcFreeCamy = 0; vcFreeCamz = 0; + //Flashlight + DelLightEmitter(flashlight); + flashlight = (::SpotLight*)AddSpotLight(flashlightPos, flashlightDirLocal, 3, 0, 0, 3, 0, RAD * 45, flashlightColor, flashlightColor, flashlightColor2); + flashlight->SetVisibility(LightEmitter::VIS_COCKPIT); + flashlight->Activate(flashlightOn); + switch (id) { case SATVIEW_LEFTSEAT: @@ -5022,3 +5028,31 @@ void Saturn::SetCMVCIntegralLight(UINT meshidx, DWORD *matList, int EmissionMode } //sprintf(oapiDebugString(), "%d %lf", m, state); } + +void Saturn::MoveFlashlight() +{ + if (flashlightOn) { //Only move the light emmitter if the flashlight is on + //Huge thanks the Jordan64 for helping get the direction stuff working! :) + GetCameraOffset(flashlightPos); + oapiCameraGlobalDir(&flashlightDirGlobal); + GetGlobalPos(vesselPosGlobal); + Global2Local(vesselPosGlobal + flashlightDirGlobal, flashlightDirLocal); + normalise(flashlightDirLocal); + + flashlight->SetPosition(flashlightPos); + flashlight->SetDirection(flashlightDirLocal); + } +} + +void Saturn::SetFlashlightOn(bool state) +{ + flashlight->Activate(state); + flashlightOn = state; +} + +void Saturn::ToggleFlashlight() +{ + if ((oapiCockpitMode() == COCKPIT_VIRTUAL) && (oapiCameraMode() == CAM_COCKPIT)) { + SetFlashlightOn(!flashlightOn); + } +} diff --git a/Orbitersdk/samples/ProjectApollo/src_lm/LEM.cpp b/Orbitersdk/samples/ProjectApollo/src_lm/LEM.cpp index 40f8ef214d..5b624ad297 100644 --- a/Orbitersdk/samples/ProjectApollo/src_lm/LEM.cpp +++ b/Orbitersdk/samples/ProjectApollo/src_lm/LEM.cpp @@ -590,6 +590,16 @@ void LEM::Init() vcFreeCamSpeed = 0.2; vcFreeCamMaxOffset = 0.5; + // Flashlight + flashlight = 0; + flashlightColor = { 1,1,1,0 }; + flashlightColor2 = { 0,0,0,0 }; + flashlightPos = { 0,0,0 }; + vesselPosGlobal = { 0,0,0 }; + flashlightDirGlobal = { 0,0,1 }; + flashlightDirLocal = { 0,0,1 }; + flashlightOn = 0; + DPSPropellant.SetVessel(this); APSPropellant.SetVessel(this); RCSA.SetVessel(this); @@ -1132,6 +1142,10 @@ int LEM::clbkConsumeBufferedKey(DWORD key, bool down, char *keystate) { } + if ((down) && (key == OAPI_KEY_F)) { + ToggleFlashlight(); + } + if (KEYMOD_SHIFT(keystate) || KEYMOD_CONTROL(keystate) || !down) { return 0; } @@ -1338,6 +1352,11 @@ void LEM::clbkPreStep (double simt, double simdt, double mjd) { if (oapiGetFocusObject() == GetHandle()) { dsky.SendNetworkPacketDSKY(); } + + if ((oapiGetFocusObject() == GetHandle()) && (oapiCockpitMode() == COCKPIT_VIRTUAL) && (oapiCameraMode() == CAM_COCKPIT)) { + //We have focus on this vessel, and are in the VC + MoveFlashlight(); + } } diff --git a/Orbitersdk/samples/ProjectApollo/src_lm/LEM.h b/Orbitersdk/samples/ProjectApollo/src_lm/LEM.h index 78060e7ac6..4c4a7a5018 100644 --- a/Orbitersdk/samples/ProjectApollo/src_lm/LEM.h +++ b/Orbitersdk/samples/ProjectApollo/src_lm/LEM.h @@ -667,6 +667,19 @@ class LEM : public Payload, public PanelSwitchListener { // Variables for checklists char Checklist_Variable[16][32]; + // Flashlight for VC + void MoveFlashlight(); + void SetFlashlightOn(bool state); + void ToggleFlashlight(); + SpotLight* flashlight; + COLOUR4 flashlightColor; + COLOUR4 flashlightColor2; + VECTOR3 flashlightPos; + VECTOR3 vesselPosGlobal; + VECTOR3 flashlightDirGlobal; + VECTOR3 flashlightDirLocal; + bool flashlightOn; + protected: // diff --git a/Orbitersdk/samples/ProjectApollo/src_lm/lemvc.cpp b/Orbitersdk/samples/ProjectApollo/src_lm/lemvc.cpp index bad8c911b2..089e2ce6a6 100644 --- a/Orbitersdk/samples/ProjectApollo/src_lm/lemvc.cpp +++ b/Orbitersdk/samples/ProjectApollo/src_lm/lemvc.cpp @@ -725,6 +725,12 @@ bool LEM::clbkLoadVC (int id) vcFreeCamy = 0; vcFreeCamz = 0; + //Flashlight + DelLightEmitter(flashlight); + flashlight = (::SpotLight*)AddSpotLight(flashlightPos, flashlightDirLocal, 3, 0, 0, 3, 0, RAD * 45, flashlightColor, flashlightColor, flashlightColor2); + flashlight->SetVisibility(LightEmitter::VIS_COCKPIT); + flashlight->Activate(flashlightOn); + switch (id) { case LMVIEW_CDR: viewpos = LMVIEW_CDR; @@ -3465,3 +3471,31 @@ void LEM::SetLMVCIntegralLight(UINT meshidx, DWORD *matList, int EmissionMode, d } //sprintf(oapiDebugString(), "%d %lf", m, state); } + +void LEM::MoveFlashlight() +{ + if (flashlightOn) { //Only move the light emmitter if the flashlight is on + //Huge thanks the Jordan64 for helping get the direction stuff working! :) + GetCameraOffset(flashlightPos); + oapiCameraGlobalDir(&flashlightDirGlobal); + GetGlobalPos(vesselPosGlobal); + Global2Local(vesselPosGlobal + flashlightDirGlobal, flashlightDirLocal); + normalise(flashlightDirLocal); + + flashlight->SetPosition(flashlightPos); + flashlight->SetDirection(flashlightDirLocal); + } +} + +void LEM::SetFlashlightOn(bool state) +{ + flashlight->Activate(state); + flashlightOn = state; +} + +void LEM::ToggleFlashlight() +{ + if ((oapiCockpitMode() == COCKPIT_VIRTUAL) && (oapiCameraMode() == CAM_COCKPIT)) { + SetFlashlightOn(!flashlightOn); + } +}