From feef4c1453a6428cbd895cb36335939659fd4ae5 Mon Sep 17 00:00:00 2001 From: Vladislav Khorev Date: Sun, 27 Jan 2013 21:31:32 +0000 Subject: [PATCH] Almost removed Halibut Engine --- Android_Salmon_Engine.mk | 1 + Halibut Engine/Halibut Engine.vcxproj | 3 + Salmon Engine/Salmon Engine.vcxproj | 17 +- include/PhysicsManager/PhysicsManager.h | 50 +++ include/Render/SalmonRender/Cameras.h | 123 +++++++ .../SalmonRender/SalmonRenderInterface.h | 117 +------ include/SalmonEngineInterface.h | 10 +- include/SalmonEngineWindows.h | 7 +- include/Utils/DataTypes/DataTypes.h | 2 +- src/ApplicationInterface.cpp | 9 +- src/FrameManager/FrameManager.cpp | 7 +- src/PhysicsManager/PhysicsManager.cpp | 138 ++++++++ src/Render/SalmonRender/Cameras.cpp | 222 ++++++++++++ .../SalmonRender/SalmonRenderInterface.cpp | 321 ++---------------- src/SalmonEngineInterface.cpp | 19 +- src/SalmonEngineWindows.cpp | 16 +- 16 files changed, 636 insertions(+), 426 deletions(-) create mode 100644 include/PhysicsManager/PhysicsManager.h create mode 100644 include/Render/SalmonRender/Cameras.h create mode 100644 src/PhysicsManager/PhysicsManager.cpp create mode 100644 src/Render/SalmonRender/Cameras.cpp diff --git a/Android_Salmon_Engine.mk b/Android_Salmon_Engine.mk index e4b15d3..a9345f6 100644 --- a/Android_Salmon_Engine.mk +++ b/Android_Salmon_Engine.mk @@ -324,6 +324,7 @@ LOCAL_SRC_FILES += src/SmartValueManager/SmartValueManager.cpp LOCAL_SRC_FILES += src/ModelManager/ModelManager.cpp LOCAL_SRC_FILES += src/ModelManager/NewModelManager.cpp LOCAL_SRC_FILES += src/SimpleLand/SimpleLand.cpp +LOCAL_SRC_FILES += src/PhysicsManager/PhysicsManager.cpp LOCAL_SRC_FILES += src/Render/RenderMisc.cpp diff --git a/Halibut Engine/Halibut Engine.vcxproj b/Halibut Engine/Halibut Engine.vcxproj index 37620a9..a855184 100644 --- a/Halibut Engine/Halibut Engine.vcxproj +++ b/Halibut Engine/Halibut Engine.vcxproj @@ -66,6 +66,7 @@ Disabled TARGET_HALIBUT;TARGET_WIN32;WIN32_LEAN_AND_MEAN;_WIN32_WINNT=0x0501;DEBUG $(SalmonEnginePath);$(LibsPath)\boost_1_52_0;$(LibsPath)\openal\OpenAL11_windows_sdk;$(LibsPath)\libogg-1.3.0\include;$(LibsPath)\libvorbis-1.3.2\include;$(LibsPath)\sqplus\sqplus;$(LibsPath)\sqplus\include;$(LibsPath)\DirectXsdk\Include;$(LibsPath)\lpng1510 + 4503 true @@ -77,6 +78,7 @@ Disabled TARGET_HALIBUT;TARGET_WIN32;NOSOUND;WIN32_LEAN_AND_MEAN;_WIN32_WINNT=0x0501;DEBUG $(SalmonEnginePath);$(LibsPath)\boost_1_52_0;$(LibsPath)\openal\OpenAL11_windows_sdk;$(LibsPath)\libogg-1.3.0\include;$(LibsPath)\libvorbis-1.3.2\include;$(LibsPath)\sqplus\sqplus;$(LibsPath)\sqplus\include;$(LibsPath)\lpng1510 + 4503 true @@ -90,6 +92,7 @@ true TARGET_HALIBUT;TARGET_WIN32;WIN32_LEAN_AND_MEAN;_WIN32_WINNT=0x0501;NDEBUG $(SalmonEnginePath);$(LibsPath)\boost_1_52_0;$(LibsPath)\openal\OpenAL11_windows_sdk;$(LibsPath)\libogg-1.3.0\include;$(LibsPath)\libvorbis-1.3.2\include;$(LibsPath)\sqplus\sqplus;$(LibsPath)\sqplus\include;$(LibsPath)\DirectXsdk\Include;$(LibsPath)\lpng1510 + 4503 true diff --git a/Salmon Engine/Salmon Engine.vcxproj b/Salmon Engine/Salmon Engine.vcxproj index 11fe607..33c8103 100644 --- a/Salmon Engine/Salmon Engine.vcxproj +++ b/Salmon Engine/Salmon Engine.vcxproj @@ -20,14 +20,21 @@ + + + + + + + @@ -57,14 +64,20 @@ + + + + + + @@ -161,10 +174,10 @@ MaxSpeed true true - MultiThreaded + MultiThreadedDLL TARGET_SALMON;TARGET_WIN32;WIN32_LEAN_AND_MEAN;_WIN32_WINNT=0x0501;NDEBUG $(SalmonEnginePath);$(LibsPath)\boost_1_52_0;$(LibsPath)\openal\OpenAL11_windows_sdk;$(LibsPath)\libogg-1.3.0\include;$(LibsPath)\libvorbis-1.3.2\include;$(LibsPath)\sqplus\sqplus;$(LibsPath)\sqplus\include;$(LibsPath)\DirectXsdk\Include;$(LibsPath)\lpng1510 - /wd 4503 + 4503 true diff --git a/include/PhysicsManager/PhysicsManager.h b/include/PhysicsManager/PhysicsManager.h new file mode 100644 index 0000000..eddf538 --- /dev/null +++ b/include/PhysicsManager/PhysicsManager.h @@ -0,0 +1,50 @@ +#ifndef PHYSICS_MANAGER_H_INCLUDED +#define PHYSICS_MANAGER_H_INCLUDED + + +#include "include/Utils/Utils.h" +#include "include/ModelManager/NewModelManager.h" + +namespace SE +{ + +class TVolumeBody +{ +protected: + + std::stack> SmpTriangleArrStack; + + std::vector SmpTriangleArr; + + vec3 DimensionalMinPos; + vec3 DimensionalMaxPos; + +public: + + void PushData(); + void PopData(); + + void Move(const vec3& v); + void Rotate(const mat3& r); + void Scale(float s); + void Scale(const vec3& s); + + void AssignFromFlexModel(TFlexModel& flexModel); + + bool CheckCollision(const vec3& a, const vec3& b); +}; + + +class TPhysicsManager +{ +protected: +public: +}; + + + +} //namespace SE + +#endif + + diff --git a/include/Render/SalmonRender/Cameras.h b/include/Render/SalmonRender/Cameras.h new file mode 100644 index 0000000..a250f93 --- /dev/null +++ b/include/Render/SalmonRender/Cameras.h @@ -0,0 +1,123 @@ +#ifndef CAMERAS_H_INCLUDED +#define CAMERAS_H_INCLUDED + +#include "include/Utils/Utils.h" + +namespace SE +{ + + +struct TCameraInterface +{ + vec3 CamVec; + + vec3 CamShift; + + TCameraInterface(); + + virtual ~TCameraInterface() + { + } + +}; + +struct TPanoramicCamera : public TCameraInterface +{ + + float CamAlpha; + float CamPhi; + float CamDist; + + TPanoramicCamera(); + + void MoveAlpha(float dAlpha); + void MovePhi(float dPhi); + void MoveDist(float dDist); + void SetAlpha(float alpha); + + void MoveForward(); + void MoveBackward(); + void MoveLeft(); + void MoveRight(); + + void CalcCamVec(); + + void SetCamView(); +}; + +struct TPitCamera : public TCameraInterface +{ + vec4 CameraQuat; + + void SetCamView(); + + void CalcCamVec(); + + void RotateByQuat(vec4 quat); +}; + + +typedef boost::variant TCamera; + + +struct TSetCameraViewVisitor : public boost::static_visitor +{ + void operator()(TPanoramicCamera& panoramicCamera) + { + panoramicCamera.SetCamView(); + } + + void operator()(TPitCamera& pitCamera) + { + pitCamera.SetCamView(); + } +}; + + +struct TCalcCamVecVisitor : public boost::static_visitor +{ + void operator()(TPanoramicCamera& panoramicCamera) + { + panoramicCamera.CalcCamVec(); + } + + void operator()(TPitCamera& pitCamera) + { + pitCamera.CalcCamVec(); + } +}; + + +struct TGetCamVecVisitor : public boost::static_visitor +{ + vec3& operator()(TPanoramicCamera& panoramicCamera) const + { + return panoramicCamera.CamVec; + } + + vec3& operator()(TPitCamera& pitCamera) const + { + return pitCamera.CamVec; + } +}; + +struct TGetCamShiftVisitor : public boost::static_visitor +{ + vec3& operator()(TPanoramicCamera& panoramicCamera) const + { + return panoramicCamera.CamShift; + } + + vec3& operator()(TPitCamera& pitCamera) const + { + return pitCamera.CamShift; + } +}; + + + + + +} //namespace SE + +#endif \ No newline at end of file diff --git a/include/Render/SalmonRender/SalmonRenderInterface.h b/include/Render/SalmonRender/SalmonRenderInterface.h index f2d06e6..7aabbd5 100644 --- a/include/Render/SalmonRender/SalmonRenderInterface.h +++ b/include/Render/SalmonRender/SalmonRenderInterface.h @@ -11,127 +11,17 @@ #include "include/Render/RenderInterface.h" +#include "include/Render/SalmonRender/Cameras.h" + namespace SE { -struct TCameraInterface -{ - vec3 CamVec; - - vec3 CamShift; - - TCameraInterface(); - - virtual ~TCameraInterface() - { - } - -}; - -struct TPanoramicCamera : public TCameraInterface -{ - - float CamAlpha; - float CamPhi; - float CamDist; - - TPanoramicCamera(); - - void MoveAlpha(float dAlpha); - void MovePhi(float dPhi); - void MoveDist(float dDist); - void SetAlpha(float alpha); - - void MoveForward(); - void MoveBackward(); - void MoveLeft(); - void MoveRight(); - - void CalcCamVec(); - - void SetCamView(); -}; - -struct TPitCamera : public TCameraInterface -{ - vec4 CameraQuat; - - void SetCamView(); - - void CalcCamVec(); - - void RotateByQuat(vec4 quat); -}; - - -typedef boost::variant TCamera; - - -struct TSetCameraViewVisitor : public boost::static_visitor -{ - void operator()(TPanoramicCamera& panoramicCamera) - { - panoramicCamera.SetCamView(); - } - - void operator()(TPitCamera& pitCamera) - { - pitCamera.SetCamView(); - } -}; - - -struct TCalcCamVecVisitor : public boost::static_visitor -{ - void operator()(TPanoramicCamera& panoramicCamera) - { - panoramicCamera.CalcCamVec(); - } - - void operator()(TPitCamera& pitCamera) - { - pitCamera.CalcCamVec(); - } -}; - - -struct TGetCamVecVisitor : public boost::static_visitor -{ - vec3& operator()(TPanoramicCamera& panoramicCamera) const - { - return panoramicCamera.CamVec; - } - - vec3& operator()(TPitCamera& pitCamera) const - { - return pitCamera.CamVec; - } -}; - -struct TGetCamShiftVisitor : public boost::static_visitor -{ - vec3& operator()(TPanoramicCamera& panoramicCamera) const - { - return panoramicCamera.CamShift; - } - - vec3& operator()(TPitCamera& pitCamera) const - { - return pitCamera.CamShift; - } -}; class TSalmonRendererInterface : public TRendererInterface { protected: - /* - float CamAlpha; - float CamPhi; - float CamDist; - vec3 CamShift;*/ - mat4 CamModelViewMatrix; mat4 CamInversedModelViewMatrix; @@ -167,6 +57,9 @@ public: void SetPerspectiveFullScreenViewport(); void SetOrthoFullScreenViewport(); + void SetPerspectiveProjection(float angle = pi/6.f, float zNear = 1.f, float zFar = 100.f); + void SetOrthoProjection(); + mat4 GetModelviewMatrix(); void SetPerspectiveProjectionMatrix(float angle, float aspect, float zNear, float zFar); diff --git a/include/SalmonEngineInterface.h b/include/SalmonEngineInterface.h index b22315f..b4373b7 100644 --- a/include/SalmonEngineInterface.h +++ b/include/SalmonEngineInterface.h @@ -43,7 +43,9 @@ This code combines all headers for Salmon engine into one header file #include "include/SmartValueManager/SmartValueManager.h" #include "include/ModelManager/NewModelManager.h" - +#include "include/PhysicsManager/PhysicsManager.h" +#include "include/GUIManager/GUIManager.h" +#include "include/HalibutAnimation/HalibutAnimation.h" namespace SE { @@ -64,6 +66,8 @@ public: TScriptManager ScriptManager; TFontManager FontManager; TSmartValueManager SmartValueManager; + TGUIManager GUIManager; + THalibutAnimationManager HalibutAnimationManager; #ifdef TARGET_ANDROID TSoundManagerAndroid SoundManager; @@ -115,11 +119,15 @@ public: virtual void OuterOnTapUp(vec2 p); + virtual void OuterOnTapUpAfterShift(vec2 p); + virtual void OuterOnMove(vec2 shift); virtual void InnerOnTapDown(vec2 p) { } virtual void InnerOnTapUp(vec2 p) { } + + virtual void InnerOnTapUpAfterShift(vec2 p) { } virtual void InnerOnMove(vec2 shift) { } diff --git a/include/SalmonEngineWindows.h b/include/SalmonEngineWindows.h index 5ac6523..fb8a295 100644 --- a/include/SalmonEngineWindows.h +++ b/include/SalmonEngineWindows.h @@ -60,4 +60,9 @@ public: int MainLoop(TApplication& application); -} //namespace SE \ No newline at end of file +} //namespace SE + +//This file includes templates that call any of three singletones: Console, ResourceManager or Renderer + +#include "include/GUIManager/WidgetTemplatesImpl.h" + diff --git a/include/Utils/DataTypes/DataTypes.h b/include/Utils/DataTypes/DataTypes.h index 294d697..f9ea8e5 100644 --- a/include/Utils/DataTypes/DataTypes.h +++ b/include/Utils/DataTypes/DataTypes.h @@ -74,7 +74,7 @@ mat4 MultMatrixMatrix(const mat4& m1, const mat4& m2); bool IsFloatEqual(float a, float b); -bool LineCouldCrossTriangle(const vec3& a, const vec3& b, const TSmpTriangle& tr); //overall test +bool LineCouldCrossTriangle(const vec3& a, const vec3& b, const TSmpTriangle& tr); //overall (dimensional) test int LineCrossTriangle(const vec3& a, const vec3& b, const TSmpTriangle& tr); diff --git a/src/ApplicationInterface.cpp b/src/ApplicationInterface.cpp index 99d1a32..925b27b 100644 --- a/src/ApplicationInterface.cpp +++ b/src/ApplicationInterface.cpp @@ -12,13 +12,10 @@ TApplicationInterface::TApplicationInterface() void TApplicationInterface::OuterInit(int screenWidth, int screenHeight, float matrixWidth, float matrixHeight) { ResourceManager->ScriptManager.BindBasicFunctions(); + + Renderer->InitOpenGL(screenWidth, screenHeight, matrixWidth, matrixHeight); + InnerInit(); -#ifdef TARGET_HALIBUT - Renderer->InitOpenGL(screenWidth, screenHeight, matrixWidth, matrixHeight); -#endif -#ifdef TARGET_SALMON - Renderer->InitOpenGL(screenWidth, screenHeight, matrixWidth, matrixHeight); -#endif CheckGlError(); diff --git a/src/FrameManager/FrameManager.cpp b/src/FrameManager/FrameManager.cpp index af029e2..ace8f44 100644 --- a/src/FrameManager/FrameManager.cpp +++ b/src/FrameManager/FrameManager.cpp @@ -87,6 +87,8 @@ cardinal TFrameManager::AddFrameRenderBuffer(const std::string& frameName,cardin FrameMap[frameName].Width = width; FrameMap[frameName].Height = height; FrameMap[frameName].TexName = texName; + + glBindFramebuffer(GL_FRAMEBUFFER, 0); return FrameMap[frameName].FrameBuffer; @@ -180,7 +182,8 @@ cardinal TFrameManager::AddCubemapBuffer(const std::string& frameName,cardinal w FrameMap[frameName].Height = height; FrameMap[frameName].TexName = texName; - //return FrameMap[frameName].TexID; //That is easier + glBindFramebuffer(GL_FRAMEBUFFER, 0); + return FrameMap[frameName].FrameBuffer; break; @@ -262,6 +265,8 @@ cardinal TFrameManager::AddDepthBuffer(const std::string& frameName, cardinal wi FrameMap[frameName].Height = height; FrameMap[frameName].TexName = texName; + glBindFramebuffer(GL_FRAMEBUFFER, 0); + return FrameMap[frameName].FrameBuffer; break; default: diff --git a/src/PhysicsManager/PhysicsManager.cpp b/src/PhysicsManager/PhysicsManager.cpp new file mode 100644 index 0000000..c9f2233 --- /dev/null +++ b/src/PhysicsManager/PhysicsManager.cpp @@ -0,0 +1,138 @@ +#include "include/PhysicsManager/PhysicsManager.h" +#include "include/ModelManager/NewModelManager.h" +#include "include/ShaderManager/ShaderManager.h" + +namespace SE +{ + + const int CONST_MAX_VOLUME_STACK = 64; + +void TVolumeBody::AssignFromFlexModel(TFlexModel& flexModel) +{ + SmpTriangleArr.clear(); + + TDataTriangleList& dataTriangleList = flexModel.GetDataTriangleList(); + + if (dataTriangleList.Vec3CoordArr.count(CONST_STRING_POSITION_ATTRIB) == 0) + { + throw ErrorToLog("Error in AssignFromFlexModel - empty flexModel!"); + } + + if (dataTriangleList.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].size() == 0) + { + throw ErrorToLog("Error in AssignFromFlexModel - empty flexModel! size == 0!"); + } + + DimensionalMinPos = dataTriangleList.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB][0]; + DimensionalMaxPos = dataTriangleList.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB][0]; + + + for (size_t j = 0; j < dataTriangleList.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB].size(); j+=3) + { + TSmpTriangle smpTriangle; + + smpTriangle.p[0] = dataTriangleList.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB][j]; + smpTriangle.p[1] = dataTriangleList.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB][j + 1]; + smpTriangle.p[2] = dataTriangleList.Vec3CoordArr[CONST_STRING_POSITION_ATTRIB][j + 2]; + + smpTriangle.v = smpTriangle.p[1] - smpTriangle.p[0]; + smpTriangle.w = smpTriangle.p[2] - smpTriangle.p[1]; + + smpTriangle.n = CrossProduct(smpTriangle.v, smpTriangle.w); + + SmpTriangleArr.push_back(smpTriangle); + + DimensionalMinPos.v[0] = min(min(min(DimensionalMinPos.v[0], smpTriangle.p[0].v[0]), smpTriangle.p[1].v[0]), smpTriangle.p[2].v[0]); + DimensionalMinPos.v[1] = min(min(min(DimensionalMinPos.v[1], smpTriangle.p[0].v[1]), smpTriangle.p[1].v[1]), smpTriangle.p[2].v[1]); + DimensionalMinPos.v[2] = min(min(min(DimensionalMinPos.v[2], smpTriangle.p[0].v[2]), smpTriangle.p[1].v[2]), smpTriangle.p[2].v[2]); + + DimensionalMaxPos.v[0] = max(max(max(DimensionalMaxPos.v[0], smpTriangle.p[0].v[0]), smpTriangle.p[1].v[0]), smpTriangle.p[2].v[0]); + DimensionalMaxPos.v[1] = max(max(max(DimensionalMaxPos.v[1], smpTriangle.p[0].v[1]), smpTriangle.p[1].v[1]), smpTriangle.p[2].v[1]); + DimensionalMaxPos.v[2] = max(max(max(DimensionalMaxPos.v[2], smpTriangle.p[0].v[2]), smpTriangle.p[1].v[2]), smpTriangle.p[2].v[2]); + } + +} + +void TVolumeBody::PushData() +{ + if (SmpTriangleArrStack.size() >= CONST_MAX_VOLUME_STACK) + { + throw ErrorToLog("TVolumeBody::PushData - stack overflow"); + } + + SmpTriangleArrStack.push(SmpTriangleArr); +} + +void TVolumeBody::PopData() +{ + if (SmpTriangleArrStack.size() <= 0) + { + throw ErrorToLog("TVolumeBody::PushData - stack underflow"); + } + + SmpTriangleArr = SmpTriangleArrStack.top(); + + SmpTriangleArrStack.pop(); +} + + +void TVolumeBody::Move(const vec3& v) +{ + BOOST_FOREACH(TSmpTriangle& smpTriangle, SmpTriangleArr) + { + smpTriangle.p[0] -= v; + smpTriangle.p[1] -= v; + smpTriangle.p[2] -= v; + } +} + +void TVolumeBody::Rotate(const mat3& r) +{ + throw ErrorToLog("TVolumeBody::Rotate not implemented yet!"); +} + +void TVolumeBody::Scale(float s) +{ + throw ErrorToLog("TVolumeBody::Scale not implemented yet!"); +} + +void TVolumeBody::Scale(const vec3& s) +{ + throw ErrorToLog("TVolumeBody::Scale not implemented yet!"); +} + + + +bool TVolumeBody::CheckCollision(const vec3& a, const vec3& b) +{ + + for (int i=0; i<3; i++) + { + if (max(a.v[i], b.v[i]) < DimensionalMinPos.v[i]) + { + return false; + } + + if (min(a.v[i], b.v[i]) > DimensionalMaxPos.v[i]) + { + return false; + } + } + + BOOST_FOREACH(TSmpTriangle& smpTriangle, SmpTriangleArr) + { + if (LineCouldCrossTriangle(a, b, smpTriangle)) + { + if (LineCrossTriangle(a, b, smpTriangle) == 1) + { + return true; + } + } + } + + return false; +} + + + +} //namespace SE \ No newline at end of file diff --git a/src/Render/SalmonRender/Cameras.cpp b/src/Render/SalmonRender/Cameras.cpp new file mode 100644 index 0000000..76e3718 --- /dev/null +++ b/src/Render/SalmonRender/Cameras.cpp @@ -0,0 +1,222 @@ +#include "include/Render/SalmonRender/Cameras.h" +#include "include/Engine.h" + +namespace SE +{ + +TCameraInterface::TCameraInterface() + : CamShift(ZeroVec3) +{ + CamVec = vec3(0,0,-1); +} + +TPanoramicCamera::TPanoramicCamera() + : CamAlpha(0.0f) + , CamPhi(0.0f) + , CamDist(0.0f) +{ +} + + +void TPanoramicCamera::MoveAlpha(float dAlpha) +{ + if (dAlpha == 0.0f) + return; + + CamAlpha += dAlpha; + + while (CamAlpha >= 2*pi) + { + CamAlpha -= 2*pi; + } + + while (CamAlpha<0.0f) + { + CamAlpha += 2*pi; + } + + //Possibly refactor??? + Renderer->CalcCamPosVec(); + +} + +void TPanoramicCamera::MovePhi(float dPhi) +{ + if (dPhi == 0.0f) + return; + + //float oldCamPhi = CamPhi; + CamPhi += dPhi; + + if (CamPhi > CONST_MAX_CAM_PHI) + { + CamPhi = CONST_MAX_CAM_PHI; + } + + if (CamPhi < CONST_MIN_CAM_PHI) + { + CamPhi = CONST_MIN_CAM_PHI; + } + + //Possibly refactor??? + Renderer->CalcCamPosVec(); + +} + +void TPanoramicCamera::MoveDist(float dDist) +{ + CamDist += dDist; + + if (CamDistCalcCamPosVec(); + +} + +void TPanoramicCamera::SetAlpha(float alpha) +{ + if (alpha == CamAlpha) + return; + + CamAlpha = alpha; + + while (CamAlpha >= 2*pi) + { + CamAlpha -= 2*pi; + } + + while (CamAlpha<0.0f) + { + CamAlpha += 2*pi; + } + + //Possibly refactor??? + Renderer->CalcCamPosVec(); +} + +void TPanoramicCamera::MoveForward() +{ + vec3 mov; + + float sina = sinf(CamAlpha); + float cosa = cosf(CamAlpha); + + mov.v[0] = sina; + mov.v[1] = 0; + mov.v[2] = - cosa; + + CamShift = CamShift + mov; + + //Possibly refactor??? + Renderer->CalcCamPosVec(); +} + +void TPanoramicCamera::MoveBackward() +{ + vec3 mov; + + float sina = sinf(CamAlpha); + float cosa = cosf(CamAlpha); + + mov.v[0] = - sina; + mov.v[1] = 0; + mov.v[2] = cosa; + + CamShift = CamShift + mov; + //Possibly refactor??? + Renderer->CalcCamPosVec(); + +} + +void TPanoramicCamera::MoveLeft() +{ + vec3 mov; + + float sina = sinf(CamAlpha); + float cosa = cosf(CamAlpha); + + mov.v[0] = - cosa; + mov.v[1] = 0; + mov.v[2] = - sina; + + CamShift = CamShift + mov; + + //Possibly refactor??? + Renderer->CalcCamPosVec(); + +} + +void TPanoramicCamera::MoveRight() +{ + vec3 mov; + + float sina = sinf(CamAlpha); + float cosa = cosf(CamAlpha); + + mov.v[0] = cosa; + mov.v[1] = 0; + mov.v[2] = sina; + + CamShift = CamShift + mov; + + //Possibly refactor??? + Renderer->CalcCamPosVec(); + +} + + +void TPanoramicCamera::CalcCamVec() +{ + vec3 camPos; + vec3 camVec; + + float sina = sinf(CamAlpha); + float cosa = cosf(CamAlpha); + float sinp = sinf(CamPhi); + float cosp = cosf(CamPhi); + + CamVec.v[0] = CamDist * cosp * sina; + CamVec.v[1] = - CamDist * sinp; + CamVec.v[2] = - CamDist * cosp * cosa; + +} + +void TPanoramicCamera::SetCamView() +{ + + Renderer->LoadIdentity(); + Renderer->TranslateMatrix(vec3(0.0f, 0.0f, -CamDist)); + Renderer->RotateMatrix(vec4(1.f * sin(CamPhi/2.f), 0.f, 0.f, 1.f * cos(CamPhi/2.f))); + Renderer->RotateMatrix(vec4(0.f, 1.f * sin(CamAlpha/2.f), 0.f, 1.f * cos(CamAlpha/2.f))); + Renderer->TranslateMatrix(-CamShift); +} + + +void TPitCamera::SetCamView() +{ + Renderer->LoadIdentity(); + Renderer->RotateMatrix(InverseQuat(CameraQuat)); + + Renderer->TranslateMatrix(-CamShift); +} + +void TPitCamera::CalcCamVec() +{ + vec3 r = vec3(0,0,-1); + + CamVec = Normalize(CameraQuat * vec4(r) * InverseQuat(CameraQuat)); +} + +void TPitCamera::RotateByQuat(vec4 quat) +{ + CameraQuat = quat * CameraQuat; + //float len = Length(CameraQuat); +} + + +} //namespace SE \ No newline at end of file diff --git a/src/Render/SalmonRender/SalmonRenderInterface.cpp b/src/Render/SalmonRender/SalmonRenderInterface.cpp index 4a3b81e..2014447 100644 --- a/src/Render/SalmonRender/SalmonRenderInterface.cpp +++ b/src/Render/SalmonRender/SalmonRenderInterface.cpp @@ -6,220 +6,6 @@ namespace SE { -TCameraInterface::TCameraInterface() - : CamShift(ZeroVec3) - , CamVec(ZeroVec3) -{ -} - -TPanoramicCamera::TPanoramicCamera() - : CamAlpha(0.0f) - , CamPhi(0.0f) - , CamDist(0.0f) -{ -} - - -void TPanoramicCamera::MoveAlpha(float dAlpha) -{ - if (dAlpha == 0.0f) - return; - - CamAlpha += dAlpha; - - while (CamAlpha >= 2*pi) - { - CamAlpha -= 2*pi; - } - - while (CamAlpha<0.0f) - { - CamAlpha += 2*pi; - } - - //Possibly refactor??? - Renderer->CalcCamPosVec(); - -} - -void TPanoramicCamera::MovePhi(float dPhi) -{ - if (dPhi == 0.0f) - return; - - //float oldCamPhi = CamPhi; - CamPhi += dPhi; - - if (CamPhi > CONST_MAX_CAM_PHI) - { - CamPhi = CONST_MAX_CAM_PHI; - } - - if (CamPhi < CONST_MIN_CAM_PHI) - { - CamPhi = CONST_MIN_CAM_PHI; - } - - //Possibly refactor??? - Renderer->CalcCamPosVec(); - -} - -void TPanoramicCamera::MoveDist(float dDist) -{ - CamDist += dDist; - - if (CamDistCalcCamPosVec(); - -} - -void TPanoramicCamera::SetAlpha(float alpha) -{ - if (alpha == CamAlpha) - return; - - CamAlpha = alpha; - - while (CamAlpha >= 2*pi) - { - CamAlpha -= 2*pi; - } - - while (CamAlpha<0.0f) - { - CamAlpha += 2*pi; - } - - //Possibly refactor??? - Renderer->CalcCamPosVec(); -} - -void TPanoramicCamera::MoveForward() -{ - vec3 mov; - - float sina = sinf(CamAlpha); - float cosa = cosf(CamAlpha); - - mov.v[0] = sina; - mov.v[1] = 0; - mov.v[2] = - cosa; - - CamShift = CamShift + mov; - - //Possibly refactor??? - Renderer->CalcCamPosVec(); -} - -void TPanoramicCamera::MoveBackward() -{ - vec3 mov; - - float sina = sinf(CamAlpha); - float cosa = cosf(CamAlpha); - - mov.v[0] = - sina; - mov.v[1] = 0; - mov.v[2] = cosa; - - CamShift = CamShift + mov; - //Possibly refactor??? - Renderer->CalcCamPosVec(); - -} - -void TPanoramicCamera::MoveLeft() -{ - vec3 mov; - - float sina = sinf(CamAlpha); - float cosa = cosf(CamAlpha); - - mov.v[0] = - cosa; - mov.v[1] = 0; - mov.v[2] = - sina; - - CamShift = CamShift + mov; - - //Possibly refactor??? - Renderer->CalcCamPosVec(); - -} - -void TPanoramicCamera::MoveRight() -{ - vec3 mov; - - float sina = sinf(CamAlpha); - float cosa = cosf(CamAlpha); - - mov.v[0] = cosa; - mov.v[1] = 0; - mov.v[2] = sina; - - CamShift = CamShift + mov; - - //Possibly refactor??? - Renderer->CalcCamPosVec(); - -} - - -void TPanoramicCamera::CalcCamVec() -{ - vec3 camPos; - vec3 camVec; - - float sina = sinf(CamAlpha); - float cosa = cosf(CamAlpha); - float sinp = sinf(CamPhi); - float cosp = cosf(CamPhi); - - CamVec.v[0] = CamDist * cosp * sina; - CamVec.v[1] = - CamDist * sinp; - CamVec.v[2] = - CamDist * cosp * cosa; - -} - -void TPanoramicCamera::SetCamView() -{ - - Renderer->LoadIdentity(); - Renderer->TranslateMatrix(vec3(0.0f, 0.0f, -CamDist)); - Renderer->RotateMatrix(vec4(1.f * sin(CamPhi/2.f), 0.f, 0.f, 1.f * cos(CamPhi/2.f))); - Renderer->RotateMatrix(vec4(0.f, 1.f * sin(CamAlpha/2.f), 0.f, 1.f * cos(CamAlpha/2.f))); - Renderer->TranslateMatrix(-CamShift); -} - - -void TPitCamera::SetCamView() -{ - Renderer->LoadIdentity(); - Renderer->RotateMatrix(InverseQuat(CameraQuat)); - - Renderer->TranslateMatrix(-CamShift); -} - -void TPitCamera::CalcCamVec() -{ - vec3 r = vec3(0,0,-1); - - CamVec = Normalize(CameraQuat * vec4(r) * InverseQuat(CameraQuat)); -} - -void TPitCamera::RotateByQuat(vec4 quat) -{ - CameraQuat = quat * CameraQuat; - //float len = Length(CameraQuat); -} - //============================================ //============================================ //============================================ @@ -273,6 +59,11 @@ void TSalmonRendererInterface::SetUniforms() RenderUniform3fv(CONST_STRING_CAMPOS_UNIFORM, GetCamPos().v); + RenderUniform1f(CONST_STRING_TRANSPARENCY_UNIFORM, 1.f); + + RenderUniform4fv(CONST_STRING_MATERIAL_COLOR_UNIFORM, WhiteColor); + + ResourceManager->LightManager.SetLightUniforms(); } @@ -289,10 +80,6 @@ void TSalmonRendererInterface::InitOpenGL(int screenWidth, int screenHeight, flo MatrixWidth = matrixWidth; MatrixHeight = matrixHeight; - SetPerspectiveProjectionMatrix(pi / 6.f, 1.0, 1.0f, 100.0f); //Baad =( - - SetPerspectiveFullScreenViewport(); - glEnable(GL_DEPTH_TEST); #ifdef TARGET_WIN32 glEnable(GL_LIGHTING); @@ -331,14 +118,24 @@ void TSalmonRendererInterface::SetPerspectiveFullScreenViewport() SetPerspectiveProjectionMatrix(pi / 6.f, float(MatrixWidth) / float(MatrixHeight), 1.0f, 100.0f); } +void TSalmonRendererInterface::SetPerspectiveProjection(float angle, float zNear, float zFar) +{ + SetPerspectiveProjectionMatrix(angle, float(MatrixWidth) / float(MatrixHeight), zNear, zFar); +} + + void TSalmonRendererInterface::SetOrthoFullScreenViewport() { - glViewport(0, 0, ScreenWidth, ScreenHeight); SetProjectionMatrix(static_cast(MatrixWidth), static_cast(MatrixHeight)); } +void TSalmonRendererInterface::SetOrthoProjection() +{ + SetProjectionMatrix(static_cast(MatrixWidth), static_cast(MatrixHeight)); +} + mat4 TSalmonRendererInterface::GetModelviewMatrix() { @@ -394,15 +191,7 @@ void TSalmonRendererInterface::SetGLCamView() void TSalmonRendererInterface::SetGlIdentityView() { - /* - glLoadIdentity(); - - glGetFloatv(GL_MODELVIEW_MATRIX,CamModelViewMatrix.m); - - CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix); - - RenderUniform3fv(CONST_STRING_CAMPOS_UNIFORM, (float*)ZeroVec3.v);*/ - + LoadIdentity(); CamModelViewMatrix = ModelviewMatrixStack.top(); @@ -413,16 +202,6 @@ void TSalmonRendererInterface::SetGlIdentityView() void TSalmonRendererInterface::SetGlPosXView() { - /* - glLoadIdentity(); - glRotatef ( 90.0, 0.0, 1.0, 0.0 ); - glRotatef ( 180.0, 1.0, 0.0, 0.0 ); - glTranslatef(-CamPos.v[0], -CamPos.v[1], -CamPos.v[2]); - - glGetFloatv(GL_MODELVIEW_MATRIX,CamModelViewMatrix.m); - - CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix);*/ - LoadIdentity(); RotateMatrix(vec4(0.f, 1.f * sin(pi / 4.f), 0.f, 1.f * cos(pi / 4.f))); @@ -439,16 +218,7 @@ void TSalmonRendererInterface::SetGlPosXView() void TSalmonRendererInterface::SetGlNegXView() { - /* - glLoadIdentity(); - glRotatef ( -90.0, 0.0, 1.0, 0.0 ); - glRotatef ( 180.0, 1.0, 0.0, 0.0 ); - glTranslatef(-CamPos.v[0], -CamPos.v[1], -CamPos.v[2]); - - glGetFloatv(GL_MODELVIEW_MATRIX,CamModelViewMatrix.m); - - CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix);*/ - + LoadIdentity(); RotateMatrix(vec4(0.f, -1.f * sin(pi / 4.f), 0.f, 1.f * cos(pi / 4.f))); @@ -464,15 +234,7 @@ void TSalmonRendererInterface::SetGlNegXView() void TSalmonRendererInterface::SetGlPosYView() { - /* - glLoadIdentity(); - glRotatef ( -90.0, 1.0, 0.0, 0.0 ); - glTranslatef(-CamPos.v[0], -CamPos.v[1], -CamPos.v[2]); - - glGetFloatv(GL_MODELVIEW_MATRIX,CamModelViewMatrix.m); - - CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix);*/ - + LoadIdentity(); RotateMatrix(vec4(-1.f * sin(pi / 4.f), 0.f, 0.f, 1.f * cos(pi / 4.f))); @@ -487,15 +249,7 @@ void TSalmonRendererInterface::SetGlPosYView() void TSalmonRendererInterface::SetGlNegYView() { - /* - glLoadIdentity(); - glRotatef ( 90.0, 1.0, 0.0, 0.0 ); - glTranslatef(-CamPos.v[0], -CamPos.v[1], -CamPos.v[2]); - - glGetFloatv(GL_MODELVIEW_MATRIX,CamModelViewMatrix.m); - - CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix);*/ - + LoadIdentity(); RotateMatrix(vec4(1.f * sin(pi / 4.f), 0.f, 0.f, 1.f * cos(pi / 4.f))); @@ -509,17 +263,7 @@ void TSalmonRendererInterface::SetGlNegYView() void TSalmonRendererInterface::SetGlPosZView() { - /* - glLoadIdentity(); - glRotatef ( 180.0, 0.0, 1.0, 0.0 ); - glRotatef ( 180.0, 0.0, 0.0, 1.0 ); - glTranslatef(-CamPos.v[0], -CamPos.v[1], -CamPos.v[2]); - - glGetFloatv(GL_MODELVIEW_MATRIX,CamModelViewMatrix.m); - - CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix); - */ - + LoadIdentity(); RotateMatrix(vec4(0.f, 1.f * sin(pi / 2.f), 0.f, 1.f * cos(pi / 2.f))); @@ -535,15 +279,7 @@ void TSalmonRendererInterface::SetGlPosZView() void TSalmonRendererInterface::SetGlNegZView() { - /* - glLoadIdentity(); - glRotatef ( 180.0, 0.0, 0.0, 1.0 ); - glTranslatef(-CamPos.v[0], -CamPos.v[1], -CamPos.v[2]); - - glGetFloatv(GL_MODELVIEW_MATRIX,CamModelViewMatrix.m); - - CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix);*/ - + LoadIdentity(); RotateMatrix(vec4(0.f, 0.f, 1.f * sin(pi / 2.f), 1.f * cos(pi / 2.f))); @@ -567,8 +303,6 @@ vec3 TSalmonRendererInterface::GetCamPos() void TSalmonRendererInterface::SwitchToScreen() { glBindFramebuffer(GL_FRAMEBUFFER, 0); - SetPerspectiveFullScreenViewport(); - SetGLCamView(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } @@ -583,7 +317,6 @@ void TSalmonRendererInterface::SwitchToFrameBuffer(const std::string& frameName) SetFrameViewport(frameName); - SetGLCamView(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } } @@ -598,15 +331,7 @@ void TSalmonRendererInterface::SwitchToCubemapBuffer(const std::string& frameNam glBindFramebuffer(GL_FRAMEBUFFER, Frame.FrameBuffer); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + cubeSide, Frame.TexID, 0); - /* - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluPerspective(90, 1, 1, 100); - glViewport(0, 0, Frame.Width, Frame.Height); - glMatrixMode(GL_MODELVIEW);*/ - - SetPerspectiveProjectionMatrix(90, 1, 1, 100); - + SetFrameViewport(frameName); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //IS A MUST!!! diff --git a/src/SalmonEngineInterface.cpp b/src/SalmonEngineInterface.cpp index 2b6ec6c..9d5cb8e 100644 --- a/src/SalmonEngineInterface.cpp +++ b/src/SalmonEngineInterface.cpp @@ -44,6 +44,12 @@ void TApplicationAncestor::OuterDraw() InnerDraw(); glDisable(GL_DEPTH_TEST); + + Renderer->SetOrthoProjection(); + Renderer->LoadIdentity(); + + ResourceManager->GUIManager.Draw(); + Renderer->PushShader("DefaultShader"); if (IsConsoleOut) @@ -59,6 +65,8 @@ void TApplicationAncestor::OuterUpdate(cardinal timer) { ResourceManager->SoundManager.Update(timer); + ResourceManager->GUIManager.Update(timer); + InnerUpdate(timer); CheckGlError(); @@ -67,19 +75,24 @@ void TApplicationAncestor::OuterUpdate(cardinal timer) void TApplicationAncestor::OuterOnTapDown(vec2 p) { - //ResourceManager->GUIManager.OnMouseDown(p); + ResourceManager->GUIManager.OnMouseDown(p); InnerOnTapDown(p); } void TApplicationAncestor::OuterOnTapUp(vec2 p) { - //ResourceManager->GUIManager.OnMouseUp(p); + ResourceManager->GUIManager.OnMouseUp(p); InnerOnTapUp(p); } +void TApplicationAncestor::OuterOnTapUpAfterShift(vec2 p) +{ + InnerOnTapUpAfterShift(p); +} + void TApplicationAncestor::OuterOnMove(vec2 shift) { - //ResourceManager->GUIManager.OnMove(shift); + ResourceManager->GUIManager.OnMove(shift); InnerOnMove(shift); } diff --git a/src/SalmonEngineWindows.cpp b/src/SalmonEngineWindows.cpp index abae2f1..c8e4343 100644 --- a/src/SalmonEngineWindows.cpp +++ b/src/SalmonEngineWindows.cpp @@ -132,13 +132,23 @@ void DrawScene() void ProcessTickCount() { + //Can't choose witch one is better + /* App->UpdateQuick(); NewTickCount = GetTickCount(); if (NewTickCount - LastTickCount > CONST_TIMER_INTERVAL) { LastTickCount = NewTickCount; App->OuterUpdate(CONST_TIMER_INTERVAL); + }*/ + + + NewTickCount = GetTickCount(); + if (NewTickCount - LastTickCount > CONST_TIMER_INTERVAL) + { + App->OuterUpdate(NewTickCount - LastTickCount); + LastTickCount = NewTickCount; } } @@ -247,7 +257,11 @@ case WM_MOUSEMOVE: mouseState.MiddleButtonPressed = (wParam & MK_MBUTTON); mouseState.MiddleButtonPressed = (wParam & MK_RBUTTON); - if (!MouseMoved) + if (MouseMoved) + { + App->OuterOnTapUpAfterShift(vec2(static_cast(mouseState.X), static_cast(App->Height - mouseState.Y))); + } + else { App->OuterOnTapUp(vec2(static_cast(mouseState.X), static_cast(App->Height - mouseState.Y))); }