diff --git a/Salmon Engine/Salmon Engine.vcxproj b/Salmon Engine/Salmon Engine.vcxproj index d651766..11fe607 100644 --- a/Salmon Engine/Salmon Engine.vcxproj +++ b/Salmon Engine/Salmon Engine.vcxproj @@ -137,6 +137,7 @@ Disabled TARGET_SALMON;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 @@ -148,6 +149,7 @@ Disabled TARGET_SALMON;TARGET_WIN32;WIN32_LEAN_AND_MEAN;_WIN32_WINNT=0x0501;DEBUG;NOSOUND $(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;C:\Program Files (x86)\Microsoft DirectX SDK (February 2010)\Include;$(LibsPath)\lpng1510 + /wd 4503 true @@ -162,6 +164,7 @@ MultiThreaded 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 true diff --git a/include/ModelManager/NewModelManager.h b/include/ModelManager/NewModelManager.h index 16986aa..b846150 100644 --- a/include/ModelManager/NewModelManager.h +++ b/include/ModelManager/NewModelManager.h @@ -55,6 +55,8 @@ public: void Draw(); + TDataTriangleList& GetDataTriangleList(); + friend class TFlexModelManager; }; diff --git a/include/Render/SalmonRender/SalmonRenderInterface.h b/include/Render/SalmonRender/SalmonRenderInterface.h index 9fc7483..f2d06e6 100644 --- a/include/Render/SalmonRender/SalmonRenderInterface.h +++ b/include/Render/SalmonRender/SalmonRenderInterface.h @@ -14,31 +14,154 @@ 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; - vec3 CamPos; //Do not change - call CalcCamPosVec instead - vec3 CamVec; //Do not change - call CalcCamPosVec instead + vec3 CamShift;*/ mat4 CamModelViewMatrix; mat4 CamInversedModelViewMatrix; float GlobalShadowAreaHalfSize; - void CalcCamPosVec(); - virtual void DrawQuad(const T2DQuad& quad) = 0; public: + TCamera CameraMover; + + //vec3 CamShift; + vec3 CamPos; //Do not change - call CalcCamPosVec instead + //vec3 CamVec; //Do not change - call CalcCamPosVec instead + + vec3 GetCamShift() + { + return boost::apply_visitor(TGetCamShiftVisitor(), CameraMover); + } + + vec3 GetCamVec() + { + return boost::apply_visitor(TGetCamVecVisitor(), CameraMover); + } + TSalmonRendererInterface(); virtual void InitOpenGL(int screenWidth, int screenHeight, float matrixWidth, float matrixHeight); + void CalcCamPosVec(); + virtual void SetUniforms(); void SetPerspectiveFullScreenViewport(); @@ -59,18 +182,8 @@ public: void SetGlNegZView(); - void MoveAlpha(float dAlpha); - void MovePhi(float dPhi); - void MoveDist(float dDist); - - void SetAlpha(float alpha); vec3 GetCamPos(); - void MoveForward(); - void MoveBackward(); - void MoveLeft(); - void MoveRight(); - virtual void SwitchToScreen(); virtual void SwitchToFrameBuffer(const std::string& frameName); void SwitchToCubemapBuffer(const std::string& frameName,cardinal cubeSide); diff --git a/include/SalmonEngineInterface.h b/include/SalmonEngineInterface.h index 218b111..b22315f 100644 --- a/include/SalmonEngineInterface.h +++ b/include/SalmonEngineInterface.h @@ -111,16 +111,19 @@ public: virtual void UpdateQuick() { } //To process input - this method is called more frequently than Update() + virtual void OuterOnTapDown(vec2 p); + + virtual void OuterOnTapUp(vec2 p); + virtual void OuterOnMove(vec2 shift); + + virtual void InnerOnTapDown(vec2 p) { } + + virtual void InnerOnTapUp(vec2 p) { } + virtual void InnerOnMove(vec2 shift) { } - //To do on mouse move (with or without pressed buttons) - virtual void OnMouseDown(TMouseState& mouseState) { } - //To do on mouse up (with or without pressed buttons) - - virtual void OnMouseUp(TMouseState& mouseState) { } - //To do on mouse down (with or without pressed buttons) - //Be careful - even when user "upped" button, in mouseState this button appears as pressed + virtual void OnMouseMove(TMouseState& mouseState) { } //Windows only virtual void OnMouseWheel(short int delta) { } //To do on mouse wheel move diff --git a/include/SalmonEngineWindows.h b/include/SalmonEngineWindows.h index a231836..5ac6523 100644 --- a/include/SalmonEngineWindows.h +++ b/include/SalmonEngineWindows.h @@ -51,15 +51,6 @@ public: virtual void UpdateQuick() { }; //To process input - this method is called more frequently than Update() - virtual void OnMouseMove(TMouseState& mouseState) { } - //To do on mouse move (with or without pressed buttons) - - virtual void OnMouseDown(TMouseState& mouseState) { } - //To do on mouse up (with or without pressed buttons) - - virtual void OnMouseUp(TMouseState& mouseState) { } - //To do on mouse down (with or without pressed buttons) - //Be careful - even when user "upped" button, in mouseState this button appears as pressed virtual void OnMouseWheel(short int delta) { } //To do on mouse wheel move diff --git a/include/SmartValueManager/SmartValueManager.h b/include/SmartValueManager/SmartValueManager.h index fc8baf8..feac70b 100644 --- a/include/SmartValueManager/SmartValueManager.h +++ b/include/SmartValueManager/SmartValueManager.h @@ -3,11 +3,10 @@ #include "include/Utils/Utils.h" -#pragma warning(disable: 4503) //ololo, DisctionariesMap expands into looong boolshit - namespace SE { + typedef boost::variant< std::shared_ptr>, std::shared_ptr>, diff --git a/include/Utils/DataTypes/DataTypes.h b/include/Utils/DataTypes/DataTypes.h index dbd3c55..294d697 100644 --- a/include/Utils/DataTypes/DataTypes.h +++ b/include/Utils/DataTypes/DataTypes.h @@ -74,6 +74,8 @@ 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 + int LineCrossTriangle(const vec3& a, const vec3& b, const TSmpTriangle& tr); int LineCrossTriangle(const vec3& a, const vec3& b, const TSmpTriangle& tr, vec3& CrossPoint); diff --git a/include/Utils/DataTypes/NewDataTypes.h b/include/Utils/DataTypes/NewDataTypes.h index 0e60046..c8b84e3 100644 --- a/include/Utils/DataTypes/NewDataTypes.h +++ b/include/Utils/DataTypes/NewDataTypes.h @@ -34,7 +34,7 @@ public: tvec2 operator+(const tvec2& a) const; tvec2& operator-=(const tvec2& vc); tvec2 operator-(const tvec2& a) const; - tvec2& operator-(); + tvec2 operator-(); tvec2& operator*=(TYPENAME c); }; @@ -70,7 +70,7 @@ public: tvec3& operator-=(const tvec3& vc); tvec3 operator+(const tvec3& a) const; tvec3 operator-(const tvec3& a) const; - tvec3& operator-(); + tvec3 operator-(); tvec3& operator*=(TYPENAME1 c); tvec3 operator*(const tmat3& mt) const; //MultRowMatrix() }; @@ -114,6 +114,7 @@ typedef tvec4 vec4; vec4 InverseQuat(const vec4& q); +vec4 NormalizeQuat(const vec4& q); template @@ -279,12 +280,14 @@ inline tvec2 tvec2::operator-(const tvec2& a) cons } template -inline tvec2& tvec2::operator-() +inline tvec2 tvec2::operator-() { - v[0] = -v[0]; - v[1] = -v[1]; + tvec2 r = *this; - return *this; + r.v[0] = -v[0]; + r.v[1] = -v[1]; + + return r; } template @@ -440,13 +443,15 @@ inline tvec3 tvec3::operator-(const tvec3& a) c } template -inline tvec3& tvec3::operator-() +inline tvec3 tvec3::operator-() { - v[0] = -v[0]; - v[1] = -v[1]; - v[2] = -v[2]; + tvec3 r = *this; - return *this; + r.v[0] = -v[0]; + r.v[1] = -v[1]; + r.v[2] = -v[2]; + + return r; } template @@ -732,14 +737,14 @@ inline vec4 InverseQuat(const vec4& q) { float n; vec4 r; - n = (q.v[0]*q.v[0]+q.v[1]*q.v[1]+q.v[2]*q.v[2]); + n = (q.v[0]*q.v[0]+q.v[1]*q.v[1]+q.v[2]*q.v[2]+q.v[3]*q.v[3]); if (n!=0.0f) { r.v[0] = -q.v[0] / n; r.v[1] = -q.v[1] / n; r.v[2] = -q.v[2] / n; - r.v[3] = q.v[3]; + r.v[3] = q.v[3] / n; } else { @@ -751,6 +756,26 @@ inline vec4 InverseQuat(const vec4& q) return r; +} + +inline vec4 NormalizeQuat(const vec4& q) +{ + float n; + + vec4 r; + + n = (q.v[0]*q.v[0]+q.v[1]*q.v[1]+q.v[2]*q.v[2]+q.v[3]*q.v[3]); + + if (n!=0.0f) + { + r.v[0] = q.v[0] / n; + r.v[1] = q.v[1] / n; + r.v[2] = q.v[2] / n; + r.v[3] = q.v[3] / n; + } + + return r; + } //========== mat2 =========== diff --git a/src/ModelManager/NewModelManager.cpp b/src/ModelManager/NewModelManager.cpp index b0be1e0..ed4a56a 100644 --- a/src/ModelManager/NewModelManager.cpp +++ b/src/ModelManager/NewModelManager.cpp @@ -109,6 +109,11 @@ void TFlexModel::Draw() Renderer->DrawTriangleList(RenderPair.second); } +TDataTriangleList& TFlexModel::GetDataTriangleList() +{ + + return RenderPair.second.Data; +} void TFlexModelManager::LoadModelFromXml(std::string xmlFileName) { diff --git a/src/Render/SalmonRender/SalmonRenderInterface.cpp b/src/Render/SalmonRender/SalmonRenderInterface.cpp index 5a069ed..4a3b81e 100644 --- a/src/Render/SalmonRender/SalmonRenderInterface.cpp +++ b/src/Render/SalmonRender/SalmonRenderInterface.cpp @@ -6,13 +6,226 @@ namespace SE { +TCameraInterface::TCameraInterface() + : CamShift(ZeroVec3) + , CamVec(ZeroVec3) +{ +} -TSalmonRendererInterface::TSalmonRendererInterface() +TPanoramicCamera::TPanoramicCamera() : CamAlpha(0.0f) , CamPhi(0.0f) , CamDist(0.0f) - , CamShift(ZeroVec3) - , GlobalShadowAreaHalfSize(CONST_DEFAULT_GLOBAL_SHADOW_AREA_HALFSIZE) +{ +} + + +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); +} + +//============================================ +//============================================ +//============================================ + +TSalmonRendererInterface::TSalmonRendererInterface() + : GlobalShadowAreaHalfSize(CONST_DEFAULT_GLOBAL_SHADOW_AREA_HALFSIZE) { ProjectionMatrixStack.push(IdentityMatrix4); @@ -100,17 +313,12 @@ void TSalmonRendererInterface::InitOpenGL(int screenWidth, int screenHeight, flo void TSalmonRendererInterface::CalcCamPosVec() { + + TCalcCamVecVisitor v; - float sina = sinf(CamAlpha); - float cosa = cosf(CamAlpha); - float sinp = sinf(CamPhi); - float cosp = cosf(CamPhi); + boost::apply_visitor(v, CameraMover); - CamVec.v[0] = CamDist * cosp * sina; - CamVec.v[1] = - CamDist * sinp; - CamVec.v[2] = - CamDist * cosp * cosa; - - CamPos = CamShift - CamVec; + CamPos = GetCamShift() - GetCamVec(); RenderUniform3fv(CONST_STRING_CAMPOS_UNIFORM,(float*)&CamPos); } @@ -175,26 +383,8 @@ void TSalmonRendererInterface::PushPerspectiveProjectionMatrix(float angle, floa void TSalmonRendererInterface::SetGLCamView() { - /* - glLoadIdentity(); - glTranslatef(0.0f, 0.0f, -CamDist); - glRotatef(CamPhi*180.0f/pi, 1.0f, 0.0f, 0.0f); - glRotatef(CamAlpha*180.0f/pi, 0.0f, 1.0f, 0.0f); - - //TODO - glTranslatef(-CamShift.v[0], -CamShift.v[1], -CamShift.v[2]); - - glGetFloatv(GL_MODELVIEW_MATRIX,CamModelViewMatrix.m); - - CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix); - - RenderUniform3fv(CONST_STRING_CAMPOS_UNIFORM,CamPos.v);*/ - - LoadIdentity(); - TranslateMatrix(vec3(0.0f, 0.0f, -CamDist)); - RotateMatrix(vec4(1.f * sin(CamPhi/2.f), 0.f, 0.f, 1.f * cos(CamPhi/2.f))); - RotateMatrix(vec4(0.f, 1.f * sin(CamAlpha/2.f), 0.f, 1.f * cos(CamAlpha/2.f))); - TranslateMatrix(-CamShift); + TSetCameraViewVisitor v; + boost::apply_visitor(v, CameraMover); CamModelViewMatrix = ModelviewMatrixStack.top(); CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix); @@ -238,7 +428,7 @@ void TSalmonRendererInterface::SetGlPosXView() RotateMatrix(vec4(0.f, 1.f * sin(pi / 4.f), 0.f, 1.f * cos(pi / 4.f))); RotateMatrix(vec4(1.f * sin(pi / 2.f), 0.f, 0.f, 1.f * cos(pi / 2.f))); - TranslateMatrix(-CamShift); + TranslateMatrix(-GetCamShift()); CamModelViewMatrix = ModelviewMatrixStack.top(); CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix); @@ -264,7 +454,7 @@ void TSalmonRendererInterface::SetGlNegXView() RotateMatrix(vec4(0.f, -1.f * sin(pi / 4.f), 0.f, 1.f * cos(pi / 4.f))); RotateMatrix(vec4(1.f * sin(pi / 2.f), 0.f, 0.f, 1.f * cos(pi / 2.f))); - TranslateMatrix(-CamShift); + TranslateMatrix(-GetCamShift()); CamModelViewMatrix = ModelviewMatrixStack.top(); CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix); @@ -286,7 +476,7 @@ void TSalmonRendererInterface::SetGlPosYView() LoadIdentity(); RotateMatrix(vec4(-1.f * sin(pi / 4.f), 0.f, 0.f, 1.f * cos(pi / 4.f))); - TranslateMatrix(-CamShift); + TranslateMatrix(-GetCamShift()); CamModelViewMatrix = ModelviewMatrixStack.top(); CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix); @@ -309,7 +499,7 @@ void TSalmonRendererInterface::SetGlNegYView() LoadIdentity(); RotateMatrix(vec4(1.f * sin(pi / 4.f), 0.f, 0.f, 1.f * cos(pi / 4.f))); - TranslateMatrix(-CamShift); + TranslateMatrix(-GetCamShift()); CamModelViewMatrix = ModelviewMatrixStack.top(); CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix); @@ -335,7 +525,7 @@ void TSalmonRendererInterface::SetGlPosZView() RotateMatrix(vec4(0.f, 1.f * sin(pi / 2.f), 0.f, 1.f * cos(pi / 2.f))); RotateMatrix(vec4(0.f, 0.f, 1.f * sin(pi / 2.f), 1.f * cos(pi / 2.f))); - TranslateMatrix(-CamShift); + TranslateMatrix(-GetCamShift()); CamModelViewMatrix = ModelviewMatrixStack.top(); CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix); @@ -358,7 +548,7 @@ void TSalmonRendererInterface::SetGlNegZView() RotateMatrix(vec4(0.f, 0.f, 1.f * sin(pi / 2.f), 1.f * cos(pi / 2.f))); - TranslateMatrix(-CamShift); + TranslateMatrix(-GetCamShift()); CamModelViewMatrix = ModelviewMatrixStack.top(); CamInversedModelViewMatrix = InverseModelViewMatrix(CamModelViewMatrix); @@ -374,368 +564,6 @@ vec3 TSalmonRendererInterface::GetCamPos() } -void TSalmonRendererInterface::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??? - CalcCamPosVec(); - /* - if (!IsCameraTransparentToLand && LandToCalcCollision->IsOnTheLand(CamPos)) - { - CamPhi -= CONST_CAMERA_PHI_ELEVATION_STEP; - - CalcCamPosVec(); - - float h = LandToCalcCollision->CalcVerticalCrossingFast(CamPos); - - if (h + CONST_CAMERA_VERTICAL_SHIFT > CamPos.v[1]) - { - CamPhi = CONST_MIN_CAM_PHI; - - CalcCamPosVec(); - - h = LandToCalcCollision->CalcVerticalCrossingFast(CamPos); - - while (h + CONST_CAMERA_VERTICAL_SHIFT > CamPos.v[1]) - { - CamPhi += CONST_CAMERA_PHI_ELEVATION_STEP; - CalcCamPosVec(); - } - } - else - { - CamPhi += CONST_CAMERA_PHI_ELEVATION_STEP; - CalcCamPosVec(); - } - } - */ -} - -void TSalmonRendererInterface::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??? - CalcCamPosVec(); - /* - if (!IsCameraTransparentToLand && LandToCalcCollision->IsOnTheLand(CamPos)) - { - CamPhi -= CONST_CAMERA_PHI_ELEVATION_STEP; - - CalcCamPosVec(); - - float h = LandToCalcCollision->CalcVerticalCrossingFast(CamPos); - - if (h + CONST_CAMERA_VERTICAL_SHIFT > CamPos.v[1]) - { - CamPhi = CONST_MIN_CAM_PHI; - - CalcCamPosVec(); - - h = LandToCalcCollision->CalcVerticalCrossingFast(CamPos); - - while (h + CONST_CAMERA_VERTICAL_SHIFT > CamPos.v[1]) - { - CamPhi += CONST_CAMERA_PHI_ELEVATION_STEP; - CalcCamPosVec(); - } - } - else - { - CamPhi += CONST_CAMERA_PHI_ELEVATION_STEP; - CalcCamPosVec(); - } - }*/ - -} - -void TSalmonRendererInterface::MoveDist(float dDist) -{ - CamDist += dDist; /* - if (CamDist>CONST_MAX_CAM_DIST) - { - CamDist = CONST_MAX_CAM_DIST; - }*/ - - if (CamDistIsOnTheLand(CamPos)) - { - CamPhi -= CONST_CAMERA_PHI_ELEVATION_STEP; - - CalcCamPosVec(); - - float h = LandToCalcCollision->CalcVerticalCrossingFast(CamPos); - - if (h + CONST_CAMERA_VERTICAL_SHIFT > CamPos.v[1]) - { - CamPhi = CONST_MIN_CAM_PHI; - - CalcCamPosVec(); - - h = LandToCalcCollision->CalcVerticalCrossingFast(CamPos); - - while (h + CONST_CAMERA_VERTICAL_SHIFT > CamPos.v[1]) - { - CamPhi += CONST_CAMERA_PHI_ELEVATION_STEP; - CalcCamPosVec(); - } - } - else - { - CamPhi += CONST_CAMERA_PHI_ELEVATION_STEP; - CalcCamPosVec(); - } - }*/ - -} - - -void TSalmonRendererInterface::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??? - CalcCamPosVec(); -} - -void TSalmonRendererInterface::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??? - CalcCamPosVec(); - /* - if (!IsCameraTransparentToLand && LandToCalcCollision->IsOnTheLand(CamPos)) - { - CamPhi -= CONST_CAMERA_PHI_ELEVATION_STEP; - - CalcCamPosVec(); - - float h = LandToCalcCollision->CalcVerticalCrossingFast(CamPos); - - if (h + CONST_CAMERA_VERTICAL_SHIFT > CamPos.v[1]) - { - CamPhi = CONST_MIN_CAM_PHI; - - CalcCamPosVec(); - - h = LandToCalcCollision->CalcVerticalCrossingFast(CamPos); - - while (h + CONST_CAMERA_VERTICAL_SHIFT > CamPos.v[1]) - { - CamPhi += CONST_CAMERA_PHI_ELEVATION_STEP; - CalcCamPosVec(); - } - } - else - { - CamPhi += CONST_CAMERA_PHI_ELEVATION_STEP; - CalcCamPosVec(); - } - }*/ - -} - -void TSalmonRendererInterface::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??? - CalcCamPosVec(); - /* - if (!IsCameraTransparentToLand && LandToCalcCollision->IsOnTheLand(CamPos)) - { - CamPhi -= CONST_CAMERA_PHI_ELEVATION_STEP; - - CalcCamPosVec(); - - float h = LandToCalcCollision->CalcVerticalCrossingFast(CamPos); - - if (h + CONST_CAMERA_VERTICAL_SHIFT > CamPos.v[1]) - { - CamPhi = CONST_MIN_CAM_PHI; - - CalcCamPosVec(); - - h = LandToCalcCollision->CalcVerticalCrossingFast(CamPos); - - while (h + CONST_CAMERA_VERTICAL_SHIFT > CamPos.v[1]) - { - CamPhi += CONST_CAMERA_PHI_ELEVATION_STEP; - CalcCamPosVec(); - } - } - else - { - CamPhi += CONST_CAMERA_PHI_ELEVATION_STEP; - CalcCamPosVec(); - } - }*/ - -} - -void TSalmonRendererInterface::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??? - CalcCamPosVec(); - /* - if (!IsCameraTransparentToLand && LandToCalcCollision->IsOnTheLand(CamPos)) - { - CamPhi -= CONST_CAMERA_PHI_ELEVATION_STEP; - - CalcCamPosVec(); - - float h = LandToCalcCollision->CalcVerticalCrossingFast(CamPos); - - if (h + CONST_CAMERA_VERTICAL_SHIFT > CamPos.v[1]) - { - CamPhi = CONST_MIN_CAM_PHI; - - CalcCamPosVec(); - - h = LandToCalcCollision->CalcVerticalCrossingFast(CamPos); - - while (h + CONST_CAMERA_VERTICAL_SHIFT > CamPos.v[1]) - { - CamPhi += CONST_CAMERA_PHI_ELEVATION_STEP; - CalcCamPosVec(); - } - } - else - { - CamPhi += CONST_CAMERA_PHI_ELEVATION_STEP; - CalcCamPosVec(); - } - } - */ -} - -void TSalmonRendererInterface::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??? - CalcCamPosVec(); - /* - if (!IsCameraTransparentToLand && LandToCalcCollision->IsOnTheLand(CamPos)) - { - CamPhi -= CONST_CAMERA_PHI_ELEVATION_STEP; - - CalcCamPosVec(); - - float h = LandToCalcCollision->CalcVerticalCrossingFast(CamPos); - - if (h + CONST_CAMERA_VERTICAL_SHIFT > CamPos.v[1]) - { - CamPhi = CONST_MIN_CAM_PHI; - - CalcCamPosVec(); - - h = LandToCalcCollision->CalcVerticalCrossingFast(CamPos); - - while (h + CONST_CAMERA_VERTICAL_SHIFT > CamPos.v[1]) - { - CamPhi += CONST_CAMERA_PHI_ELEVATION_STEP; - CalcCamPosVec(); - } - } - else - { - CamPhi += CONST_CAMERA_PHI_ELEVATION_STEP; - CalcCamPosVec(); - } - }*/ - -} - - - void TSalmonRendererInterface::SwitchToScreen() { glBindFramebuffer(GL_FRAMEBUFFER, 0); diff --git a/src/SalmonEngineInterface.cpp b/src/SalmonEngineInterface.cpp index c7a66e9..2b6ec6c 100644 --- a/src/SalmonEngineInterface.cpp +++ b/src/SalmonEngineInterface.cpp @@ -64,10 +64,23 @@ void TApplicationAncestor::OuterUpdate(cardinal timer) CheckGlError(); } + +void TApplicationAncestor::OuterOnTapDown(vec2 p) +{ + //ResourceManager->GUIManager.OnMouseDown(p); + InnerOnTapDown(p); +} + +void TApplicationAncestor::OuterOnTapUp(vec2 p) +{ + //ResourceManager->GUIManager.OnMouseUp(p); + InnerOnTapUp(p); +} + void TApplicationAncestor::OuterOnMove(vec2 shift) { + //ResourceManager->GUIManager.OnMove(shift); InnerOnMove(shift); } - } //namespace SE \ No newline at end of file diff --git a/src/SalmonEngineWindows.cpp b/src/SalmonEngineWindows.cpp index 35c6389..abae2f1 100644 --- a/src/SalmonEngineWindows.cpp +++ b/src/SalmonEngineWindows.cpp @@ -30,7 +30,10 @@ cardinal LastTickCount; //User application TApplication* App = NULL; - +vec2 MouseButtonPos; +vec2 MouseTotalShift; +bool MouseButtonPressed = false; +bool MouseMoved = false; void TApplication::OnKeyPress(cardinal key) { @@ -183,7 +186,7 @@ LONG WINAPI WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) }*/ break; - case WM_MOUSEMOVE: +case WM_MOUSEMOVE: mouseState.X = (lParam << 16) >> 16; mouseState.Y = lParam >> 16; mouseState.LeftButtonPressed = (wParam & MK_LBUTTON); @@ -191,6 +194,24 @@ LONG WINAPI WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) mouseState.RightButtonPressed = (wParam & MK_RBUTTON); App->OnMouseMove(mouseState); + + if (MouseButtonPressed) + { + vec2 currentMousePos(static_cast(mouseState.X), static_cast(App->Height - mouseState.Y)); + vec2 shift = (MouseButtonPos - currentMousePos); + //shift.v[1] = - shift.v[1]; + App->OuterOnMove(shift); + //App->OuterOnMove(currentMousePos - MouseButtonPos); + MouseButtonPos = currentMousePos; + + MouseTotalShift += shift; + + if (fabs(MouseTotalShift.v[0]) > 10.f || fabs(MouseTotalShift.v[1]) > 10.f) + { + MouseMoved = true; + } + } + break; case WM_LBUTTONDOWN: @@ -201,7 +222,22 @@ LONG WINAPI WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) mouseState.MiddleButtonPressed = (wParam & MK_MBUTTON); mouseState.RightButtonPressed = (wParam & MK_RBUTTON); - App->OnMouseDown(mouseState); + MouseButtonPos = vec2(static_cast(mouseState.X), static_cast(App->Height - mouseState.Y)); + + if (mouseState.LeftButtonPressed) + { + App->OuterOnTapDown(MouseButtonPos); + + } + + MouseButtonPressed = true; + + MouseMoved = false; + + MouseTotalShift = vec2(0,0); + + + break; case WM_LBUTTONUP: case WM_RBUTTONUP: @@ -211,7 +247,13 @@ LONG WINAPI WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) mouseState.MiddleButtonPressed = (wParam & MK_MBUTTON); mouseState.MiddleButtonPressed = (wParam & MK_RBUTTON); - App->OnMouseUp(mouseState); + if (!MouseMoved) + { + App->OuterOnTapUp(vec2(static_cast(mouseState.X), static_cast(App->Height - mouseState.Y))); + } + + MouseButtonPressed = false; + break; case WM_MOUSEWHEEL: diff --git a/src/Utils/DataTypes/DataTypes.cpp b/src/Utils/DataTypes/DataTypes.cpp index 7623072..9930c21 100644 --- a/src/Utils/DataTypes/DataTypes.cpp +++ b/src/Utils/DataTypes/DataTypes.cpp @@ -151,6 +151,29 @@ bool IsFloatEqual(float a, float b) return (fabs(b-a) <= CONST_EPSILON) ? true : false; } +bool LineCouldCrossTriangle(const vec3& a, const vec3& b, const TSmpTriangle& tr) +{ + for (int i=0; i<3; i++) + { + float min_tr = min(min(tr.p[0].v[i], tr.p[1].v[i]), tr.p[2].v[i]); + + if (max(a.v[i], b.v[i]) < min_tr) + { + return false; + } + + float max_tr = max(max(tr.p[0].v[i], tr.p[1].v[i]), tr.p[2].v[i]); + + if (min(a.v[i], b.v[i]) > max_tr) + { + return false; + } + } + + return true; + +} + int LineCrossTriangle(const vec3& a, const vec3& b, const TSmpTriangle& tr) {