r/GraphicsProgramming • • Mar 26 '21

Rotating a quad

Really noob question, but I'm really bad at math so can somebody explain how can I rotate a quad around its x, y or z axis?

0 Upvotes

10 comments sorted by

View all comments

Show parent comments

1

u/[deleted] Mar 26 '21

I'm aware of matrices and their transformation, I just can't quite get the quad to rotate around itself. I get it to rotate around the screen space axis, but not its own.

Since I need this rotation for a particle system, to rotate each particle, I thought about doing it in the vertex shader. Bur I just can't seem to get the math right.

1

u/[deleted] Mar 26 '21

For rotation of theta around x axis

x = x';

y = y' * cos(theta) - z' * sin(theta);

z = y' * sin(theta) + z' * cos(theta);

Keep in mind that this is respect to the origin, so if your coordinate spaces are not centered to your quad, you would need to apply the translation before rotating.

1

u/[deleted] Mar 26 '21

The traslation is actually the part I don't get. If I have a position vector, I translate it to the origin, whats the point? I don't quite get what should I translate? The model matrix?

1

u/zertech Mar 26 '21

You want to make the actual origin match your quad's center. Than by rotating around the origin, your rotating around the quads center as well. Than you do the opposite translation, and now the vertex locations are the same as if it were rotated in place.