From 737b30e8ecceb47a5ef243676d8cb6c61af6af92 Mon Sep 17 00:00:00 2001 From: Vladislav Khorev Date: Sun, 9 Jun 2024 01:09:40 +0300 Subject: [PATCH] Working with sky boxes --- .../SalmonRender/SalmonRenderInterface.h | 12 ++-- .../SalmonRender/SalmonRenderInterface.cpp | 60 ++++++++++++------- 2 files changed, 46 insertions(+), 26 deletions(-) diff --git a/include/Render/SalmonRender/SalmonRenderInterface.h b/include/Render/SalmonRender/SalmonRenderInterface.h index 283156b..f01e4ef 100644 --- a/include/Render/SalmonRender/SalmonRenderInterface.h +++ b/include/Render/SalmonRender/SalmonRenderInterface.h @@ -60,12 +60,12 @@ public: void SetGLCamAngleView(); void SetGLCamView(); void SetGlIdentityView(); - void SetGlPosXView(bool renderToFrame = false); - void SetGlNegXView(bool renderToFrame = false); - void SetGlPosYView(bool renderToFrame = false); - void SetGlNegYView(bool renderToFrame = false); - void SetGlPosZView(bool renderToFrame = false); - void SetGlNegZView(bool renderToFrame = false); + void SetGlPosXView(bool translate = true, bool renderToFrame = false); + void SetGlNegXView(bool translate = true, bool renderToFrame = false); + void SetGlPosYView(bool translate = true, bool renderToFrame = false); + void SetGlNegYView(bool translate = true, bool renderToFrame = false); + void SetGlPosZView(bool translate = true, bool renderToFrame = false); + void SetGlNegZView(bool translate = true, bool renderToFrame = false); void MoveAlpha(float dAlpha); diff --git a/src/Render/SalmonRender/SalmonRenderInterface.cpp b/src/Render/SalmonRender/SalmonRenderInterface.cpp index 70c188a..64bb0f0 100644 --- a/src/Render/SalmonRender/SalmonRenderInterface.cpp +++ b/src/Render/SalmonRender/SalmonRenderInterface.cpp @@ -5,6 +5,7 @@ namespace SE { + const float speed_coef = 0.1; TSalmonRendererInterface::TSalmonRendererInterface() @@ -198,6 +199,7 @@ void TSalmonRendererInterface::SetGLCamAngleView() TranslateMatrix(CamPos); + CamModelViewMatrix = ModelviewMatrixStack.top(); CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix); @@ -251,7 +253,7 @@ void TSalmonRendererInterface::SetGlIdentityView() SetUniforms(); } -void TSalmonRendererInterface::SetGlPosXView(bool renderToFrame) +void TSalmonRendererInterface::SetGlPosXView(bool translate, bool renderToFrame) { /* glLoadIdentity(); @@ -273,7 +275,10 @@ void TSalmonRendererInterface::SetGlPosXView(bool renderToFrame) { RotateMatrix(vec4(0.f, 1.f * sin(pi / 4.f), 0.f, 1.f * cos(pi / 4.f))); } - TranslateMatrix(-CamPos); + if (translate) + { + TranslateMatrix(-CamPos); + } CamModelViewMatrix = ModelviewMatrixStack.top(); CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix); @@ -282,7 +287,7 @@ void TSalmonRendererInterface::SetGlPosXView(bool renderToFrame) } -void TSalmonRendererInterface::SetGlNegXView(bool renderToFrame) +void TSalmonRendererInterface::SetGlNegXView(bool translate, bool renderToFrame) { /* glLoadIdentity(); @@ -304,7 +309,10 @@ void TSalmonRendererInterface::SetGlNegXView(bool renderToFrame) { RotateMatrix(vec4(0.f, 1.f * sin(pi / 4.f), 0.f, 1.f * cos(pi / 4.f))); } - TranslateMatrix(-CamPos); + if (translate) + { + TranslateMatrix(-CamPos); + } CamModelViewMatrix = ModelviewMatrixStack.top(); CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix); @@ -312,7 +320,7 @@ void TSalmonRendererInterface::SetGlNegXView(bool renderToFrame) SetUniforms(); } -void TSalmonRendererInterface::SetGlPosYView(bool renderToFrame) +void TSalmonRendererInterface::SetGlPosYView(bool translate, bool renderToFrame) { /* glLoadIdentity(); @@ -326,7 +334,10 @@ void TSalmonRendererInterface::SetGlPosYView(bool renderToFrame) LoadIdentity(); RotateMatrix(vec4(-1.f * sin(pi / 4.f), 0.0f, 0.f, 1.f * cos(pi / 4.f))); - TranslateMatrix(-CamPos); + if (translate) + { + TranslateMatrix(-CamPos); + } CamModelViewMatrix = ModelviewMatrixStack.top(); CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix); @@ -335,7 +346,7 @@ void TSalmonRendererInterface::SetGlPosYView(bool renderToFrame) } -void TSalmonRendererInterface::SetGlNegYView(bool renderToFrame) +void TSalmonRendererInterface::SetGlNegYView(bool translate, bool renderToFrame) { /* glLoadIdentity(); @@ -348,7 +359,10 @@ void TSalmonRendererInterface::SetGlNegYView(bool renderToFrame) LoadIdentity(); RotateMatrix(vec4(1.f * sin(pi / 4.f), 0.0f, 0.f, 1.f * cos(pi / 4.f))); - TranslateMatrix(-CamPos); + if (translate) + { + TranslateMatrix(-CamPos); + } CamModelViewMatrix = ModelviewMatrixStack.top(); CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix); @@ -356,7 +370,7 @@ void TSalmonRendererInterface::SetGlNegYView(bool renderToFrame) SetUniforms(); } -void TSalmonRendererInterface::SetGlPosZView(bool renderToFrame) +void TSalmonRendererInterface::SetGlPosZView(bool translate, bool renderToFrame) { /* glLoadIdentity(); @@ -376,7 +390,10 @@ void TSalmonRendererInterface::SetGlPosZView(bool renderToFrame) { RotateMatrix(vec4(0.f, 0.f, 1.f * sin(pi / 2.f), 1.f * cos(pi / 2.f))); } - TranslateMatrix(-CamPos); + if (translate) + { + TranslateMatrix(-CamPos); + } /*LoadIdentity(); @@ -391,7 +408,7 @@ void TSalmonRendererInterface::SetGlPosZView(bool renderToFrame) SetUniforms(); } -void TSalmonRendererInterface::SetGlNegZView(bool renderToFrame) +void TSalmonRendererInterface::SetGlNegZView(bool translate, bool renderToFrame) { /* glLoadIdentity(); @@ -409,7 +426,10 @@ void TSalmonRendererInterface::SetGlNegZView(bool renderToFrame) RotateMatrix(vec4(0.f, 0.f, 1.f * sin(pi / 2.f), 1.f * cos(pi / 2.f))); } - TranslateMatrix(-CamPos); + if (translate) + { + TranslateMatrix(-CamPos); + } CamModelViewMatrix = ModelviewMatrixStack.top(); CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix); @@ -605,9 +625,9 @@ void TSalmonRendererInterface::MoveForward() float sina = sinf(CamAlpha); float cosa = cosf(CamAlpha); - mov.v[0] = sina; + mov.v[0] = speed_coef * sina; mov.v[1] = 0; - mov.v[2] = - cosa; + mov.v[2] = -speed_coef * cosa; CamShift = CamShift + mov; @@ -652,9 +672,9 @@ void TSalmonRendererInterface::MoveBackward() float sina = sinf(CamAlpha); float cosa = cosf(CamAlpha); - mov.v[0] = - sina; + mov.v[0] = -speed_coef*sina; mov.v[1] = 0; - mov.v[2] = cosa; + mov.v[2] = speed_coef * cosa; CamShift = CamShift + mov; //Possibly refactor??? @@ -698,9 +718,9 @@ void TSalmonRendererInterface::MoveLeft() float sina = sinf(CamAlpha); float cosa = cosf(CamAlpha); - mov.v[0] = - cosa; + mov.v[0] = -speed_coef * cosa; mov.v[1] = 0; - mov.v[2] = - sina; + mov.v[2] = -speed_coef * sina; CamShift = CamShift + mov; @@ -742,8 +762,8 @@ void TSalmonRendererInterface::MoveRight() { vec3 mov; - float sina = sinf(CamAlpha); - float cosa = cosf(CamAlpha); + float sina = speed_coef * sinf(CamAlpha); + float cosa = speed_coef * cosf(CamAlpha); mov.v[0] = cosa; mov.v[1] = 0;