diff --git a/main.cpp b/main.cpp index 764103f..ce8929e 100644 --- a/main.cpp +++ b/main.cpp @@ -23,6 +23,7 @@ #include "WallpaperEngine/Assets/CPackageLoadException.h" float g_Time; +float g_TimeLast; bool g_KeepRunning = true; int g_AudioVolume = 15; @@ -84,7 +85,7 @@ int validatePath(const char* path, std::string& final) char finalPath [PATH_MAX]; char* pointer = realpath (path, finalPath); - if (finalPath == nullptr) + if (pointer == nullptr) return errno; // ensure the path points to a folder @@ -631,6 +632,8 @@ int main (int argc, char* argv[]) glfwGetFramebufferSize (window, &windowWidth, &windowHeight); // set the default viewport context->setDefaultViewport ({0, 0, windowWidth, windowHeight}); + // keep track of the previous frame's time + g_TimeLast = g_Time; // calculate the current time value g_Time = (float) glfwGetTime (); // get the start time of the frame diff --git a/src/WallpaperEngine/Render/CScene.cpp b/src/WallpaperEngine/Render/CScene.cpp index 75306aa..7e9188c 100644 --- a/src/WallpaperEngine/Render/CScene.cpp +++ b/src/WallpaperEngine/Render/CScene.cpp @@ -6,6 +6,9 @@ #include "CScene.h" +extern float g_Time; +extern float g_TimeLast; + using namespace WallpaperEngine; using namespace WallpaperEngine::Render; @@ -239,10 +242,9 @@ void CScene::renderFrame (glm::ivec4 viewport) { float influence = this->getScene ()->getCameraParallaxMouseInfluence (); float amount = this->getScene ()->getCameraParallaxAmount (); - float delay = this->getScene ()->getCameraParallaxDelay (); + float delay = glm::min ((float) this->getScene ()->getCameraParallaxDelay (), g_Time - g_TimeLast); - this->m_parallaxDisplacement.x = glm::mix (this->m_parallaxDisplacement.x, (this->m_mousePosition.x * amount) * influence, delay); - this->m_parallaxDisplacement.y = glm::mix (this->m_parallaxDisplacement.y, (this->m_mousePosition.y * amount) * influence, delay); + this->m_parallaxDisplacement = glm::mix (this->m_parallaxDisplacement, (this->m_mousePosition * amount) * influence, delay); } // use the scene's framebuffer by default @@ -262,6 +264,10 @@ void CScene::updateMouse (glm::ivec4 viewport) CMouseInput* mouse = this->getContext ()->getMouse (); // TODO: PROPERLY TRANSLATE THESE TO WHAT'S VISIBLE ON SCREEN (FOR BACKGROUNDS THAT DO NOT EXACTLY FIT ON SCREEN) + // rollover the position to the last + this->m_mousePositionLast = this->m_mousePosition; + + // calculate the current position of the mouse this->m_mousePosition.x = glm::clamp ((mouse->position.x - viewport.x) / viewport.z, 0.0, 1.0); this->m_mousePosition.y = glm::clamp ((mouse->position.y - viewport.y) / viewport.w, 0.0, 1.0); @@ -278,6 +284,10 @@ glm::vec2* CScene::getMousePosition () return &this->m_mousePosition; } +glm::vec2* CScene::getMousePositionLast () +{ + return &this->m_mousePositionLast; +} glm::vec2* CScene::getParallaxDisplacement () { diff --git a/src/WallpaperEngine/Render/CScene.h b/src/WallpaperEngine/Render/CScene.h index f20539f..2b36dfa 100644 --- a/src/WallpaperEngine/Render/CScene.h +++ b/src/WallpaperEngine/Render/CScene.h @@ -22,6 +22,7 @@ namespace WallpaperEngine::Render Core::CScene* getScene (); glm::vec2* getMousePosition (); + glm::vec2* getMousePositionLast (); glm::vec2* getParallaxDisplacement (); protected: @@ -40,6 +41,7 @@ namespace WallpaperEngine::Render std::map m_objects; std::vector m_objectsByRenderOrder; glm::vec2 m_mousePosition; + glm::vec2 m_mousePositionLast; glm::vec2 m_parallaxDisplacement; CFBO* _rt_4FrameBuffer; CFBO* _rt_8FrameBuffer; diff --git a/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp b/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp index 1d09f4b..cde7cc9 100644 --- a/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp +++ b/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp @@ -628,10 +628,11 @@ void CPass::setupUniforms () // add model-view-projection matrix this->addUniform ("g_ModelViewProjectionMatrix", &this->m_modelViewProjectionMatrix); this->addUniform ("g_PointerPosition", this->m_material->getImage ()->getScene ()->getMousePosition ()); + this->addUniform ("g_PointerPositionLast", this->m_material->getImage ()->getScene ()->getMousePositionLast ()); this->addUniform ("g_EffectTextureProjectionMatrix", glm::mat4(1.0)); this->addUniform ("g_EffectTextureProjectionMatrixInverse", glm::mat4(1.0)); this->addUniform ("g_TexelSize", glm::vec2 (1.0 / projection->getWidth (), 1.0 / projection->getHeight ())); - this->addUniform ("g_TexelSize", glm::vec2 (0.5 / projection->getWidth (), 0.5 / projection->getHeight ())); + this->addUniform ("g_TexelSizeHalf", glm::vec2 (0.5 / projection->getWidth (), 0.5 / projection->getHeight ())); } void CPass::addAttribute (const std::string& name, GLint type, GLint elements, const GLuint* value)