mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-09-14 13:56:48 +08:00
Added g_PointerPositionLast
Improved delay calculation for parallax (should prevent backgrounds from flickering with big delays) Fixed g_TexelSize having the wrong value and g_TexelSizeHalf not being defined Signed-off-by: Alexis Maiquez <almamu@almamu.com>
This commit is contained in:
parent
e1fe215398
commit
4dc3a4bc01
5
main.cpp
5
main.cpp
@ -23,6 +23,7 @@
|
|||||||
#include "WallpaperEngine/Assets/CPackageLoadException.h"
|
#include "WallpaperEngine/Assets/CPackageLoadException.h"
|
||||||
|
|
||||||
float g_Time;
|
float g_Time;
|
||||||
|
float g_TimeLast;
|
||||||
bool g_KeepRunning = true;
|
bool g_KeepRunning = true;
|
||||||
int g_AudioVolume = 15;
|
int g_AudioVolume = 15;
|
||||||
|
|
||||||
@ -84,7 +85,7 @@ int validatePath(const char* path, std::string& final)
|
|||||||
char finalPath [PATH_MAX];
|
char finalPath [PATH_MAX];
|
||||||
char* pointer = realpath (path, finalPath);
|
char* pointer = realpath (path, finalPath);
|
||||||
|
|
||||||
if (finalPath == nullptr)
|
if (pointer == nullptr)
|
||||||
return errno;
|
return errno;
|
||||||
|
|
||||||
// ensure the path points to a folder
|
// ensure the path points to a folder
|
||||||
@ -631,6 +632,8 @@ int main (int argc, char* argv[])
|
|||||||
glfwGetFramebufferSize (window, &windowWidth, &windowHeight);
|
glfwGetFramebufferSize (window, &windowWidth, &windowHeight);
|
||||||
// set the default viewport
|
// set the default viewport
|
||||||
context->setDefaultViewport ({0, 0, windowWidth, windowHeight});
|
context->setDefaultViewport ({0, 0, windowWidth, windowHeight});
|
||||||
|
// keep track of the previous frame's time
|
||||||
|
g_TimeLast = g_Time;
|
||||||
// calculate the current time value
|
// calculate the current time value
|
||||||
g_Time = (float) glfwGetTime ();
|
g_Time = (float) glfwGetTime ();
|
||||||
// get the start time of the frame
|
// get the start time of the frame
|
||||||
|
@ -6,6 +6,9 @@
|
|||||||
|
|
||||||
#include "CScene.h"
|
#include "CScene.h"
|
||||||
|
|
||||||
|
extern float g_Time;
|
||||||
|
extern float g_TimeLast;
|
||||||
|
|
||||||
using namespace WallpaperEngine;
|
using namespace WallpaperEngine;
|
||||||
using namespace WallpaperEngine::Render;
|
using namespace WallpaperEngine::Render;
|
||||||
|
|
||||||
@ -239,10 +242,9 @@ void CScene::renderFrame (glm::ivec4 viewport)
|
|||||||
{
|
{
|
||||||
float influence = this->getScene ()->getCameraParallaxMouseInfluence ();
|
float influence = this->getScene ()->getCameraParallaxMouseInfluence ();
|
||||||
float amount = this->getScene ()->getCameraParallaxAmount ();
|
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 = glm::mix (this->m_parallaxDisplacement, (this->m_mousePosition * amount) * influence, delay);
|
||||||
this->m_parallaxDisplacement.y = glm::mix (this->m_parallaxDisplacement.y, (this->m_mousePosition.y * amount) * influence, delay);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// use the scene's framebuffer by default
|
// use the scene's framebuffer by default
|
||||||
@ -262,6 +264,10 @@ void CScene::updateMouse (glm::ivec4 viewport)
|
|||||||
CMouseInput* mouse = this->getContext ()->getMouse ();
|
CMouseInput* mouse = this->getContext ()->getMouse ();
|
||||||
// TODO: PROPERLY TRANSLATE THESE TO WHAT'S VISIBLE ON SCREEN (FOR BACKGROUNDS THAT DO NOT EXACTLY FIT ON SCREEN)
|
// 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.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);
|
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;
|
return &this->m_mousePosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glm::vec2* CScene::getMousePositionLast ()
|
||||||
|
{
|
||||||
|
return &this->m_mousePositionLast;
|
||||||
|
}
|
||||||
|
|
||||||
glm::vec2* CScene::getParallaxDisplacement ()
|
glm::vec2* CScene::getParallaxDisplacement ()
|
||||||
{
|
{
|
||||||
|
@ -22,6 +22,7 @@ namespace WallpaperEngine::Render
|
|||||||
Core::CScene* getScene ();
|
Core::CScene* getScene ();
|
||||||
|
|
||||||
glm::vec2* getMousePosition ();
|
glm::vec2* getMousePosition ();
|
||||||
|
glm::vec2* getMousePositionLast ();
|
||||||
glm::vec2* getParallaxDisplacement ();
|
glm::vec2* getParallaxDisplacement ();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -40,6 +41,7 @@ namespace WallpaperEngine::Render
|
|||||||
std::map<int, CObject*> m_objects;
|
std::map<int, CObject*> m_objects;
|
||||||
std::vector<CObject*> m_objectsByRenderOrder;
|
std::vector<CObject*> m_objectsByRenderOrder;
|
||||||
glm::vec2 m_mousePosition;
|
glm::vec2 m_mousePosition;
|
||||||
|
glm::vec2 m_mousePositionLast;
|
||||||
glm::vec2 m_parallaxDisplacement;
|
glm::vec2 m_parallaxDisplacement;
|
||||||
CFBO* _rt_4FrameBuffer;
|
CFBO* _rt_4FrameBuffer;
|
||||||
CFBO* _rt_8FrameBuffer;
|
CFBO* _rt_8FrameBuffer;
|
||||||
|
@ -628,10 +628,11 @@ void CPass::setupUniforms ()
|
|||||||
// add model-view-projection matrix
|
// add model-view-projection matrix
|
||||||
this->addUniform ("g_ModelViewProjectionMatrix", &this->m_modelViewProjectionMatrix);
|
this->addUniform ("g_ModelViewProjectionMatrix", &this->m_modelViewProjectionMatrix);
|
||||||
this->addUniform ("g_PointerPosition", this->m_material->getImage ()->getScene ()->getMousePosition ());
|
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_EffectTextureProjectionMatrix", glm::mat4(1.0));
|
||||||
this->addUniform ("g_EffectTextureProjectionMatrixInverse", 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 (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)
|
void CPass::addAttribute (const std::string& name, GLint type, GLint elements, const GLuint* value)
|
||||||
|
Loading…
Reference in New Issue
Block a user