I'm wondering how I can do a rotation on a global axis rather than the particle's local axis in a particle shader.
Here are my rotate y and x functions:
mat4 rotate_y(float theta) {
return mat4(vec4(cos(theta), 0, -sin(theta), 0), vec4(0, 1, 0, 0), vec4(sin(theta), 0, cos(theta), 0), vec4(0, 0, 0, 1));
}
mat4 rotate_x(float theta) {
return mat4(vec4(1, 0, 0, 0), vec4(0, cos(theta), sin(theta), 0), vec4(0, -sin(theta), cos(theta), 0), vec4(0, 0, 0, 1));
}
But these rotate along the local axis.
If I do this:
void start() {
TRANSFORM *= rotate_y(PI/2.0);
TRANSFORM *= rotate_x(PI/2.0);
}
I get something different than if I do the reverse:
void start() {
TRANSFORM *= rotate_x(PI/2.0);
TRANSFORM *= rotate_y(PI/2.0);
}
This is because the first rotation changes the local axis direction, and the second rotation then uses that new axis. How can instead do a rotation around the global x and y (and z) axis?
I'm very new to particle shaders and everything 3d. Let me know if there is an easier or better way to do anything. Thank you!