diff --git a/LEGO1/lego/legoomni/include/legoutils.h b/LEGO1/lego/legoomni/include/legoutils.h index 5d495665..55b65bea 100644 --- a/LEGO1/lego/legoomni/include/legoutils.h +++ b/LEGO1/lego/legoomni/include/legoutils.h @@ -25,8 +25,8 @@ void FUN_1003ef00(MxBool); void SetAppCursor(WPARAM p_wparam); MxBool FUN_1003ef60(); MxBool RemoveFromWorld(MxAtomId& p_entityAtom, MxS32 p_entityId, MxAtomId& p_worldAtom, MxS32 p_worldEntityId); -MxS32 UpdateLightPosition(MxS32 p_value); -void SetLightPosition(MxU32); +MxS32 UpdateLightPosition(MxS32 p_increase); +void SetLightPosition(MxS32 p_index); LegoNamedTexture* ReadNamedTexture(LegoFile* p_file); void FUN_1003f540(LegoFile* p_file, const char* p_filename); void WriteNamedTexture(LegoFile* p_file, LegoNamedTexture* p_texture); diff --git a/LEGO1/lego/legoomni/src/common/legoutils.cpp b/LEGO1/lego/legoomni/src/common/legoutils.cpp index be85e1f6..b5f7fde1 100644 --- a/LEGO1/lego/legoomni/src/common/legoutils.cpp +++ b/LEGO1/lego/legoomni/src/common/legoutils.cpp @@ -14,9 +14,11 @@ #include "mxnotificationmanager.h" #include "mxstreamer.h" #include "mxtypes.h" +#include "realtime/realtime.h" #include #include +#include // STUB: LEGO1 0x1003e050 void FUN_1003e050(LegoAnimPresenter* p_presenter) @@ -340,16 +342,12 @@ MxBool FUN_1003ef60() } // FUNCTION: LEGO1 0x1003f050 -MxS32 UpdateLightPosition(MxS32 p_value) +MxS32 UpdateLightPosition(MxS32 p_increase) { - // This function updates the light position - // relatively by the amount passed in p_value. - // Because it operates relatively, it does not set - // the light position to an arbitrary value. - MxS32 lightPosition = atoi(VariableTable()->GetVariable("lightposition")); - if (p_value > 0) { + // Only ever increases by 1 irrespective of p_increase + if (p_increase > 0) { lightPosition += 1; if (lightPosition > 5) { lightPosition = 5; @@ -372,9 +370,41 @@ MxS32 UpdateLightPosition(MxS32 p_value) return lightPosition; } -// STUB: LEGO1 0x1003f0d0 -void SetLightPosition(MxU32) +// FUNCTION: LEGO1 0x1003f0d0 +void SetLightPosition(MxS32 p_index) { + float lights[6][6] = { + {1.0, 0.0, 0.0, -150.0, 50.0, -50.0}, + {0.809, -0.588, 0.0, -75.0, 50.0, -50.0}, + {0.0, -1.0, 0.0, 0.0, 150.0, -150.0}, + {-0.309, -0.951, 0.0, 25.0, 50.0, -50.0}, + {-0.809, -0.588, 0.0, 75.0, 50.0, -50.0}, + {-1.0, 0.0, 0.0, 150.0, 50.0, -50.0} + }; + + Mx3DPointFloat up(1.0, 0.0, 0.0); + Mx3DPointFloat direction; + Mx3DPointFloat position; + + Tgl::FloatMatrix4 matrix; + Matrix4 in(matrix); + MxMatrix transform; + + if (p_index < 0) { + p_index = 0; + } + else if (p_index > 5) { + p_index = 5; + } + + direction = lights[p_index]; + position = &lights[p_index][3]; + + CalcLocalTransform(position, direction, up, transform); + SETMAT4(in, transform); + + VideoManager()->Get3DManager()->GetLego3DView()->SetLight(FALSE, matrix); + VideoManager()->Get3DManager()->GetLego3DView()->SetLight(TRUE, matrix); } // FUNCTION: LEGO1 0x1003f3b0 diff --git a/LEGO1/lego/sources/3dmanager/legoview1.cpp b/LEGO1/lego/sources/3dmanager/legoview1.cpp index 033afce7..fa78e155 100644 --- a/LEGO1/lego/sources/3dmanager/legoview1.cpp +++ b/LEGO1/lego/sources/3dmanager/legoview1.cpp @@ -182,3 +182,24 @@ void LegoView1::Destroy() LegoView::Destroy(); } + +// FUNCTION: LEGO1 0x100abb60 +void LegoView1::SetLight(BOOL bDirectionalLight, Tgl::FloatMatrix4& rMatrix) +{ + Tgl::Light* pLight; + + if (bDirectionalLight == FALSE) { + pLight = m_pSunLight; + } + else { + pLight = m_pDirectionalLight; + } + + SetLight(pLight, rMatrix); +} + +// FUNCTION: LEGO1 0x100abb80 +void LegoView1::SetLight(Tgl::Light* pLight, Tgl::FloatMatrix4& rMatrix) +{ + pLight->SetTransformation(rMatrix); +} diff --git a/LEGO1/lego/sources/3dmanager/legoview1.h b/LEGO1/lego/sources/3dmanager/legoview1.h index 34b8f026..b8ad225f 100644 --- a/LEGO1/lego/sources/3dmanager/legoview1.h +++ b/LEGO1/lego/sources/3dmanager/legoview1.h @@ -8,7 +8,8 @@ namespace Tgl { class Camera; -} +class Light; +} // namespace Tgl ///////////////////////////////////////////////////////////////////////////// // LegoView @@ -64,7 +65,11 @@ class LegoView1 : public LegoView { BOOL Create(const TglSurface::CreateStruct&, Tgl::Renderer*); void Destroy() override; // vtable+0x08 + void SetLight(BOOL bDirectionalLight, Tgl::FloatMatrix4& rMatrix); + private: + void SetLight(Tgl::Light* pLight, Tgl::FloatMatrix4& rMatrix); + Tgl::Light* m_pSunLight; // 0x78 Tgl::Light* m_pDirectionalLight; // 0x7c Tgl::Light* m_pAmbientLight; // 0x80