fluid simulation jit.gl.multiple cubes directions X YZ
How can I find the angle of the direction of the particles on the axis X any Y in a fluid simulation applied to cubes with jit.gl.multiple. only the Z axis is right. thanks in advance.
hi MATTH, have you checked out the gl3 engine yet? this is a perfect project for extreme speed gains by converting to transform-feedback and gpu-instancing.
There is a shader in the package that demonstrates how to calculate a rotation matrix from a direction vector in GLSL, mat4 calculate_rotation_matrix(vec3 direction) {
vec3 forwards = normalize(direction);
vec3 outwards;
outwards = cross(forwards, vec3(1.0, 0.0, 0.0)) * forwards.x * forwards.x +
cross(forwards, vec3(0.0, 1.0, 0.0)) * forwards.y * forwards.y +
cross(forwards, vec3(0.0, 0.0, 1.0)) * forwards.z * forwards.z;
vec3 up = cross(forwards, outwards);
outwards = cross(forwards, up);
vec4 row3 = vec4(forwards, 0.0);
vec4 row2 = vec4(normalize(outwards), 0.0);
vec4 row1 = vec4(normalize(up), 0.0);
return mat4(row1, row2, row3, vec4(0.0));
}
And the internet has plenty of solutions for converting a rotation matrix to euler angles for use by jit.gl.multiple, like this one:Vec3f rotationMatrixToEulerAngles(Mat &R) {
float sy = sqrt(R.at(0,0) * R.at(0,0) + R.at(1,0) * R.at(1,0) );
bool singular = sy < 1e-6;
float x, y, z;
if (!singular) {
x = atan2(R.at(2,1) , R.at(2,2));
y = atan2(-R.at(2,0), sy);
z = atan2(R.at(1,0), R.at(0,0));
}
else {
x = atan2(-R.at(1,2), R.at(1,1));
y = atan2(-R.at(2,0), sy);
z = 0;
}
return Vec3f(x, y, z);
}
porting these solutions to a single Gen patcher should definitely be possible. But as mentioned I would do this in gl3 using GLSL shaders.
HI Rob thank you for this, of course i know the potential of gl3 engine , but the code lines are a bit esoteric ;-) for me, that's why I would like to have a solution with jit.gen and I could sell my mother for this solution ;-). I'm looking for a guy to do it.
yeah, this is definitely a tricky thing to get right.
a Gen version of direction to rotatexyz is something that I've been meaning to try out for a while now, so I went ahead and took a crack at it.
The patch below contains 2 Gen techniques that use quaternion math to turn a direction into a rotation. The second technique is more complicated in that it stores the previous quaternion and uses that in the calculation. The first technique is much simpler in that it simply uses the unit-z axis as the direction. Both seem to work as expected, so maybe the simpler one is preferred?
I'll probably get something like this into the distro for some future update, but for now this should get you going.
Wahoo thank you so much , it's exactly what i wanted. you are the best Rob.
++
Holy smokes: 14 fps on GL2, 60 on GL3 on my machine. That's great!
i been trying to told y'all
OMG
Nice!
a cleaner solution using the "rotor" gen operator posted by Rajan here: https://www.patreon.com/posts/how-to-orient-3d-30094920?fbclid=IwAR15lsbij9mimbE18W6XwGaO1pISart7LxnbszA0Ha1-VMZ3D2F1tCG0M9w