From ed9e9efdab2cc7d3b49bf919def211b3e8594607 Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Fri, 29 Mar 2024 16:50:00 -0400 Subject: [PATCH] Implement/match LegoBackgroundColor::SetLightColor and related (#758) --- .../legoomni/include/legobackgroundcolor.h | 4 +-- .../src/common/legobackgroundcolor.cpp | 33 +++++++++++++++---- .../legoomni/src/common/legogamestate.cpp | 4 +-- LEGO1/lego/legoomni/src/common/legoutils.cpp | 4 +-- LEGO1/lego/sources/3dmanager/legoview1.cpp | 27 +++++++++++++-- LEGO1/lego/sources/3dmanager/legoview1.h | 6 ++-- 6 files changed, 61 insertions(+), 17 deletions(-) diff --git a/LEGO1/lego/legoomni/include/legobackgroundcolor.h b/LEGO1/lego/legoomni/include/legobackgroundcolor.h index 015d51b5..3e8b4457 100644 --- a/LEGO1/lego/legoomni/include/legobackgroundcolor.h +++ b/LEGO1/lego/legoomni/include/legobackgroundcolor.h @@ -10,8 +10,8 @@ class LegoBackgroundColor : public MxVariable { LegoBackgroundColor(const char* p_key, const char* p_value); void SetValue(const char* p_colorString) override; - void SetLights(float p_r, float p_g, float p_b); - void SetLights(); + void SetLightColor(float p_r, float p_g, float p_b); + void SetLightColor(); void ToggleDayNight(MxBool); void ToggleSkyColor(); diff --git a/LEGO1/lego/legoomni/src/common/legobackgroundcolor.cpp b/LEGO1/lego/legoomni/src/common/legobackgroundcolor.cpp index 5cf43c65..fa5795d7 100644 --- a/LEGO1/lego/legoomni/src/common/legobackgroundcolor.cpp +++ b/LEGO1/lego/legoomni/src/common/legobackgroundcolor.cpp @@ -91,7 +91,7 @@ void LegoBackgroundColor::ToggleDayNight(MxBool p_sun) float convertedR, convertedG, convertedB; ConvertHSVToRGB(m_h, m_s, m_v, &convertedR, &convertedG, &convertedB); VideoManager()->SetSkyColor(convertedR, convertedG, convertedB); - SetLights(convertedR, convertedG, convertedB); + SetLightColor(convertedR, convertedG, convertedB); } // FUNCTION: LEGO1 0x1003c330 @@ -110,18 +110,39 @@ void LegoBackgroundColor::ToggleSkyColor() float convertedR, convertedG, convertedB; ConvertHSVToRGB(m_h, m_s, m_v, &convertedR, &convertedG, &convertedB); VideoManager()->SetSkyColor(convertedR, convertedG, convertedB); - SetLights(convertedR, convertedG, convertedB); + SetLightColor(convertedR, convertedG, convertedB); } -// STUB: LEGO1 0x1003c400 -void LegoBackgroundColor::SetLights(float p_r, float p_g, float p_b) +// FUNCTION: LEGO1 0x1003c400 +void LegoBackgroundColor::SetLightColor(float p_r, float p_g, float p_b) { + if (!VideoManager()->GetVideoParam().Flags().GetF2bit0()) { + // TODO: Computed constants based on what? + p_r *= 4.3478260869565215; + p_g *= 1.5873015873015872; + p_b *= 1.1764705882352942; + + if (p_r > 1.0) { + p_r = 1.0; + } + + if (p_g > 1.0) { + p_g = 1.0; + } + + if (p_b > 1.0) { + p_b = 1.0; + } + + VideoManager()->Get3DManager()->GetLego3DView()->SetLightColor(FALSE, p_r, p_g, p_b); + VideoManager()->Get3DManager()->GetLego3DView()->SetLightColor(TRUE, p_r, p_g, p_b); + } } // FUNCTION: LEGO1 0x1003c4b0 -void LegoBackgroundColor::SetLights() +void LegoBackgroundColor::SetLightColor() { float convertedR, convertedG, convertedB; ConvertHSVToRGB(m_h, m_s, m_v, &convertedR, &convertedG, &convertedB); - SetLights(convertedR, convertedG, convertedB); + SetLightColor(convertedR, convertedG, convertedB); } diff --git a/LEGO1/lego/legoomni/src/common/legogamestate.cpp b/LEGO1/lego/legoomni/src/common/legogamestate.cpp index 09ebf305..d149d4e6 100644 --- a/LEGO1/lego/legoomni/src/common/legogamestate.cpp +++ b/LEGO1/lego/legoomni/src/common/legogamestate.cpp @@ -350,7 +350,7 @@ MxResult LegoGameState::Load(MxULong p_slot) } } while (status != 2); - m_backgroundColor->SetLights(); + m_backgroundColor->SetLightColor(); lightPosition = VariableTable()->GetVariable("lightposition"); if (lightPosition) { @@ -1072,7 +1072,7 @@ void LegoGameState::RegisterState(LegoState* p_state) void LegoGameState::Init() { m_backgroundColor->SetValue("set 56 54 68"); - m_backgroundColor->SetLights(); + m_backgroundColor->SetLightColor(); m_tempBackgroundColor->SetValue("set 56 54 68"); VariableTable()->SetVariable("lightposition", "2"); SetLightPosition(2); diff --git a/LEGO1/lego/legoomni/src/common/legoutils.cpp b/LEGO1/lego/legoomni/src/common/legoutils.cpp index b5f7fde1..86242395 100644 --- a/LEGO1/lego/legoomni/src/common/legoutils.cpp +++ b/LEGO1/lego/legoomni/src/common/legoutils.cpp @@ -403,8 +403,8 @@ void SetLightPosition(MxS32 p_index) CalcLocalTransform(position, direction, up, transform); SETMAT4(in, transform); - VideoManager()->Get3DManager()->GetLego3DView()->SetLight(FALSE, matrix); - VideoManager()->Get3DManager()->GetLego3DView()->SetLight(TRUE, matrix); + VideoManager()->Get3DManager()->GetLego3DView()->SetLightTransform(FALSE, matrix); + VideoManager()->Get3DManager()->GetLego3DView()->SetLightTransform(TRUE, matrix); } // FUNCTION: LEGO1 0x1003f3b0 diff --git a/LEGO1/lego/sources/3dmanager/legoview1.cpp b/LEGO1/lego/sources/3dmanager/legoview1.cpp index fa78e155..ac2aed33 100644 --- a/LEGO1/lego/sources/3dmanager/legoview1.cpp +++ b/LEGO1/lego/sources/3dmanager/legoview1.cpp @@ -184,7 +184,7 @@ void LegoView1::Destroy() } // FUNCTION: LEGO1 0x100abb60 -void LegoView1::SetLight(BOOL bDirectionalLight, Tgl::FloatMatrix4& rMatrix) +void LegoView1::SetLightTransform(BOOL bDirectionalLight, Tgl::FloatMatrix4& rMatrix) { Tgl::Light* pLight; @@ -195,11 +195,32 @@ void LegoView1::SetLight(BOOL bDirectionalLight, Tgl::FloatMatrix4& rMatrix) pLight = m_pDirectionalLight; } - SetLight(pLight, rMatrix); + SetLightTransform(pLight, rMatrix); } // FUNCTION: LEGO1 0x100abb80 -void LegoView1::SetLight(Tgl::Light* pLight, Tgl::FloatMatrix4& rMatrix) +void LegoView1::SetLightTransform(Tgl::Light* pLight, Tgl::FloatMatrix4& rMatrix) { pLight->SetTransformation(rMatrix); } + +// FUNCTION: LEGO1 0x100abba0 +void LegoView1::SetLightColor(BOOL bDirectionalLight, float red, float green, float blue) +{ + Tgl::Light* pLight; + + if (bDirectionalLight == FALSE) { + pLight = m_pSunLight; + } + else { + pLight = m_pDirectionalLight; + } + + SetLightColor(pLight, red, green, blue); +} + +// FUNCTION: LEGO1 0x100abbd0 +void LegoView1::SetLightColor(Tgl::Light* pLight, float red, float green, float blue) +{ + pLight->SetColor(red, green, blue); +} diff --git a/LEGO1/lego/sources/3dmanager/legoview1.h b/LEGO1/lego/sources/3dmanager/legoview1.h index b8ad225f..fb1aa5bd 100644 --- a/LEGO1/lego/sources/3dmanager/legoview1.h +++ b/LEGO1/lego/sources/3dmanager/legoview1.h @@ -65,10 +65,12 @@ class LegoView1 : public LegoView { BOOL Create(const TglSurface::CreateStruct&, Tgl::Renderer*); void Destroy() override; // vtable+0x08 - void SetLight(BOOL bDirectionalLight, Tgl::FloatMatrix4& rMatrix); + void SetLightTransform(BOOL bDirectionalLight, Tgl::FloatMatrix4& rMatrix); + void SetLightColor(BOOL bDirectionalLight, float red, float green, float blue); private: - void SetLight(Tgl::Light* pLight, Tgl::FloatMatrix4& rMatrix); + void SetLightTransform(Tgl::Light* pLight, Tgl::FloatMatrix4& rMatrix); + void SetLightColor(Tgl::Light* pLight, float red, float green, float blue); Tgl::Light* m_pSunLight; // 0x78 Tgl::Light* m_pDirectionalLight; // 0x7c