aboutsummaryrefslogtreecommitdiff
path: root/src/shader/code
diff options
context:
space:
mode:
authorAdrian Kummerlaender2019-02-24 14:07:16 +0100
committerAdrian Kummerlaender2019-02-24 14:07:16 +0100
commit1f2b1cb037a202cafe25167c071a2615341dafdb (patch)
tree783eaadf2e88235d4f0b4714cfb6e3965df4101f /src/shader/code
parentecaa33e25b42f945fa09dc21b6db53ef330f2cc2 (diff)
downloadcompustream-1f2b1cb037a202cafe25167c071a2615341dafdb.tar
compustream-1f2b1cb037a202cafe25167c071a2615341dafdb.tar.gz
compustream-1f2b1cb037a202cafe25167c071a2615341dafdb.tar.bz2
compustream-1f2b1cb037a202cafe25167c071a2615341dafdb.tar.lz
compustream-1f2b1cb037a202cafe25167c071a2615341dafdb.tar.xz
compustream-1f2b1cb037a202cafe25167c071a2615341dafdb.tar.zst
compustream-1f2b1cb037a202cafe25167c071a2615341dafdb.zip
Further abstract mouse handling
Diffstat (limited to 'src/shader/code')
-rw-r--r--src/shader/code/interact.glsl51
1 files changed, 22 insertions, 29 deletions
diff --git a/src/shader/code/interact.glsl b/src/shader/code/interact.glsl
index a65d96a..cb69333 100644
--- a/src/shader/code/interact.glsl
+++ b/src/shader/code/interact.glsl
@@ -10,10 +10,11 @@ uniform uint nY;
/// External influence
-uniform int prevMouseState;
-uniform vec2 prevMousePos;
-uniform int currMouseState;
-uniform vec2 currMousePos;
+uniform bool influxRequested;
+uniform bool wallRequested;
+
+uniform vec2 startOfLine;
+uniform vec2 endOfLine;
/// Vector utilities
@@ -37,6 +38,14 @@ float distanceToLineSegment(vec2 a, vec2 b, vec2 p) {
return norm(pa - ab * (dot(ab, pa) / dot(ab, ab)));
}
+bool isNearLine(uint x, uint y, float eps) {
+ if ( startOfLine == endOfLine ) {
+ return norm(vec2(x,y) - endOfLine) < eps;
+ } else {
+ return distanceToLineSegment(startOfLine, endOfLine, vec2(x,y)) < eps;
+ }
+}
+
/// Array indexing
uint indexOfFluidVertex(uint x, uint y) {
@@ -74,24 +83,6 @@ 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;
- }
-}
-
-bool isInfluxRequestedAt(uint x, uint y) {
- return currMouseState == 1 && isNearMouse(x, y, 3);
-}
-
-bool isWallRequestedAt(uint x, uint y) {
- return currMouseState == 2 && isNearMouse(x, y, 3);
-}
-
/// Actual interaction kernel
void main() {
@@ -105,13 +96,15 @@ void main() {
const int material = getMaterial(x,y);
if ( material == 1 ) {
- if ( isInfluxRequestedAt(x,y) ) {
- setMaterial(x,y,4);
- return;
- }
- if ( isWallRequestedAt(x,y) ) {
- setMaterial(x,y,3);
- return;
+ if ( isNearLine(x, y, 3) ) {
+ if ( influxRequested ) {
+ setMaterial(x,y,4);
+ return;
+ }
+ if ( wallRequested ) {
+ setMaterial(x,y,3);
+ return;
+ }
}
}