Skip to content

Commit

Permalink
Merge pull request #1307 from maxq519/Flashlight
Browse files Browse the repository at this point in the history
Add working flashlight in the VC for both vehicles
  • Loading branch information
ThymoNL authored Nov 5, 2024
2 parents 5ac53e2 + 1915c99 commit 4a93a57
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Orbitersdk/samples/ProjectApollo/src_csm/saturn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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) {
Expand Down
15 changes: 15 additions & 0 deletions Orbitersdk/samples/ProjectApollo/src_csm/saturn.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:

///
Expand Down
34 changes: 34 additions & 0 deletions Orbitersdk/samples/ProjectApollo/src_csm/saturnvc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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);
}
}
19 changes: 19 additions & 0 deletions Orbitersdk/samples/ProjectApollo/src_lm/LEM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
}
}


Expand Down
13 changes: 13 additions & 0 deletions Orbitersdk/samples/ProjectApollo/src_lm/LEM.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:

//
Expand Down
34 changes: 34 additions & 0 deletions Orbitersdk/samples/ProjectApollo/src_lm/lemvc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 4a93a57

Please sign in to comment.