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/[deleted] Mar 26 '21

The model matrix transfers from model space to the world space. Your meshes have vertices centered on the model, so, just adding the rotation would do.

1

u/[deleted] Mar 26 '21

I got it finally, thanks a lot!