Skip to content
Snippets Groups Projects
Verified Commit f6bb006a authored by Tobias Frisch's avatar Tobias Frisch
Browse files

Added position guards to stay in the grid

parent b88c10af
No related branches found
No related tags found
1 merge request!103Added project wobble_bobble and refactored some parts of the framework
......@@ -73,7 +73,6 @@ void main() {
gridValue.xyz += vec3(0.0f, -9.81f * dts * gridValue.w, 0.0f);
/*
bvec3 lowerID = lessThanEqual(gl_GlobalInvocationID, ivec3(0));
bvec3 negativeVelocity = lessThan(gridValue.xyz, vec3(0.0f));
......@@ -87,7 +86,6 @@ void main() {
);
gridValue.xyz = mix(gridValue.xyz, -gridValue.xyz, collision);
*/
barrier();
memoryBarrierShared();
......
......@@ -98,18 +98,38 @@ void main() {
position = position + velocity_pic * dts;
const float gridRange = (1.0f - 2.0f * size);
for (uint i = 0; i < 3; i++) {
if (position[i] - size < 0.0f) {
position[i] = -position[i] + 2.0f * size;
float a = (size - position[i]) / gridRange;
int b = int(floor(a));
a = (a - b) * gridRange;
if (b % 2 == 0) {
position[i] = size + a;
} else {
position[i] = 1.0f - size - a;
}
if (velocity_pic[i] < 0.0f) {
if ((velocity_pic[i] < 0.0f) == (b % 2 == 0)) {
velocity_pic[i] *= -1.0f;
}
} else
if (position[i] + size > 1.0f) {
position[i] = 2.0f * (1.0f - size) - position[i];
float a = (position[i] + size - 1.0f) / gridRange;
int b = int(floor(a));
a = (a - b) * gridRange;
if (b % 2 == 0) {
position[i] = 1.0f - size - a;
} else {
position[i] = size + a;
}
if (velocity_pic[i] > 0.0f) {
if ((velocity_pic[i] > 0.0f) == (b % 2 == 0)) {
velocity_pic[i] *= -1.0f;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment