diff options
author | Adrian Kummerlaender | 2019-02-24 12:25:08 +0100 |
---|---|---|
committer | Adrian Kummerlaender | 2019-02-24 12:25:08 +0100 |
commit | 1ab5f3db018a3169ad6074fc2b75d44c3a45dd16 (patch) | |
tree | d3229fb41d119db2a19810d4f625e0e7d3421e24 /src/shader | |
parent | 389da8159978571e8156ff7692bc595d957e846e (diff) | |
download | compustream-1ab5f3db018a3169ad6074fc2b75d44c3a45dd16.tar compustream-1ab5f3db018a3169ad6074fc2b75d44c3a45dd16.tar.gz compustream-1ab5f3db018a3169ad6074fc2b75d44c3a45dd16.tar.bz2 compustream-1ab5f3db018a3169ad6074fc2b75d44c3a45dd16.tar.lz compustream-1ab5f3db018a3169ad6074fc2b75d44c3a45dd16.tar.xz compustream-1ab5f3db018a3169ad6074fc2b75d44c3a45dd16.tar.zst compustream-1ab5f3db018a3169ad6074fc2b75d44c3a45dd16.zip |
Smoothen mouse interaction
Diffstat (limited to 'src/shader')
-rw-r--r-- | src/shader/code/collide.glsl | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/src/shader/code/collide.glsl b/src/shader/code/collide.glsl index 3f4e2c5..a73024e 100644 --- a/src/shader/code/collide.glsl +++ b/src/shader/code/collide.glsl @@ -9,8 +9,10 @@ layout (std430, binding=3) buffer bufferFluid { float fluidCells[]; }; /// external influence -uniform int mouseState; -uniform vec2 mousePos; +uniform int prevMouseState; +uniform vec2 prevMousePos; +uniform int currMouseState; +uniform vec2 currMousePos; /// LBM constants @@ -38,7 +40,23 @@ float sq(float x) { } float norm(vec2 v) { - return sqrt(sq(v.x)+sq(v.y)); + return sqrt(dot(v,v)); +} + +float distanceToLineSegment(vec2 a, vec2 b, vec2 p) { + const vec2 ab = b - a; + + const vec2 pa = a - p; + if ( dot(ab, pa) > 0.0 ) { + return norm(pa); + } + + const vec2 bp = p - b; + if ( dot(ab, bp) > 0.0 ) { + return norm(bp); + } + + return norm(pa - ab * (dot(ab, pa) / dot(ab, ab))); } /// Array indexing @@ -130,8 +148,16 @@ void disableWallInterior(uint x, uint y) { /// Determine external influence +bool isNearMouse(uint x, uint y, float eps) { + if ( prevMouseState == currMouseState ) { + return distanceToLineSegment(prevMousePos, currMousePos, vec2(x,y)) < eps; + } else { + return norm(vec2(x,y) - currMousePos) < eps; + } +} + float getExternalPressureInflux(uint x, uint y) { - if ( mouseState == 1 && norm(vec2(x,y) - mousePos) < 2 ) { + if ( currMouseState == 1 && isNearMouse(x, y, 3) ) { return 1.5; } else { return 0.0; @@ -139,7 +165,7 @@ float getExternalPressureInflux(uint x, uint y) { } bool isWallRequestedAt(uint x, uint y) { - if ( mouseState == 2 && norm(vec2(x,y) - mousePos) < 2 ) { + if ( currMouseState == 2 && isNearMouse(x, y, 3) ) { return true; } else { return false; |