@@ -33,7 +33,7 @@ protected void update(float dt) {
33
33
34
34
float [][] densityAddBuffer = new float [X_SIZE ][Y_SIZE ];
35
35
float [][] densityRemoveBuffer = new float [X_SIZE ][Y_SIZE ];
36
- advection (densityAddBuffer , densityRemoveBuffer );
36
+ advection (densityAddBuffer );
37
37
}
38
38
39
39
@ Override
@@ -48,37 +48,57 @@ public void dispose() {
48
48
background .dispose ();
49
49
}
50
50
51
- private void advection (float [][] densityAddBuffer , float [][] densityRemoveBuffer ) {
51
+ private void advection (float [][] densityAddBuffer ) {
52
52
53
53
54
54
for (int x = 0 ; x < X_SIZE ; x ++) {
55
55
for (int y = 0 ; y < X_SIZE ; y ++) {
56
- pushDensity (x , y , densityAddBuffer , densityRemoveBuffer );
56
+ pushDensity (x , y , densityAddBuffer );
57
57
}
58
58
}
59
59
}
60
60
61
- private void pushDensity (int x , int y , float [][] densityAddBuffer , float [][] densityRemoveBuffer ) {
61
+ private Buffer pushDensity (int x , int y , Buffer buffer ) {
62
62
float newX = x + velX [x ][y ];
63
63
float newY = y + velY [x ][y ];
64
64
65
65
float right = (newX % 1 );
66
66
float up = newY % 1 ;
67
67
68
- float value = (1 -right )*(1 -up )*density [x ][y ];
69
- densityAddBuffer [(int )Math .floor (newX )][(int )Math .floor (newY )] += value ;
70
- densityRemoveBuffer [x ][y ] -= value ;
71
-
68
+ //TODO: loop this shit
69
+ int destX , destY ;
70
+ float value ;
71
+
72
+ //down left
73
+ destX = (int )Math .floor (newX );
74
+ destY = (int )Math .floor (newY );
75
+ value = (1 -right )*(1 -up )*density [x ][y ];
76
+ buffer .density [destX ][destY ] += value ;
77
+ buffer .velXxDens [destX ][destY ] += value *velX [x ][y ];
78
+ buffer .velYxDens [destX ][destY ] += value *velY [x ][y ];
79
+
80
+ //down right
81
+ destX = (int )Math .floor (newX +1 );
82
+ destY = (int )Math .floor (newY );
72
83
value = (right )*(1 -up )*density [x ][y ];
73
- densityAddBuffer [(int )Math .floor (newX +1 )][(int )Math .floor (newY )] += value ;
74
- densityRemoveBuffer [x ][y ] -= value ;
84
+ buffer .density [destX ][destY ] += value ;
85
+ buffer .velXxDens [destX ][destY ] += value *velX [x ][y ];
86
+ buffer .velYxDens [destX ][destY ] += value *velY [x ][y ];
75
87
88
+ //up left
89
+ destX = (int )Math .floor (newX );
90
+ destY = (int )Math .floor (newY +1 );
76
91
value = (1 -right )*(up )*density [x ][y ];
77
- densityAddBuffer [(int )Math .floor (newX )][(int )Math .floor (newY +1 )] += value ;
78
- densityRemoveBuffer [x ][y ] -= value ;
92
+ buffer .density [destX ][destY ] += value ;
93
+ buffer .velXxDens [destX ][destY ] += value *velX [x ][y ];
94
+ buffer .velYxDens [destX ][destY ] += value *velY [x ][y ];
79
95
96
+ //up right
97
+ destX = (int )Math .floor (newX +1 );
98
+ destY = (int )Math .floor (newY +1 );
80
99
value = (right )*(up )*density [x ][y ];
81
- densityAddBuffer [(int )Math .floor (newX +1 )][(int )Math .floor (newY +1 )] += value ;
82
- densityRemoveBuffer [x ][y ] -= value ;
100
+ buffer .density [destX ][destY ] += value ;
101
+ buffer .velXxDens [destX ][destY ] += value *velX [x ][y ];
102
+ buffer .velYxDens [destX ][destY ] += value *velY [x ][y ];
83
103
}
84
104
}
0 commit comments