How to use matrices in 2D


I’m trying to wrap my head around matrices, and how to utilize them (using glm). From what I’ve seen, it seems like a neat solution to mutate sprites purely by matrix transformations, like affine transformations mentioned here:

In a 2d game, suppose I have a sprite at location glm::vec3(10.0f, 0.0f, 0.0f), so x=10 and y and z = 0.

But I also could store coordinates in a glm::map..to use glm::translate, I need a glm::map4 like:

1.0 0.0 0.0 0.0
0.0 1.0 0.0 0.0
0.0 0.0 1.0 0.0
0.0 0.0 0.0 1.0

Now I’m confused how to use all this, and where to store x and y coordinates. Should I store them in a vector, and multiple/translate by a matrix? Or the other way around?

glm::translate() returns a new matrix, so I think my sprite data should be in a matrix to start with?

I hope someone can provide/link me to a basic example..haven’t had much luck with tutorials so far.



Source link

Leave a Reply

Your email address will not be published.

Previous Article

Crystal Palace 0-2 Arsenal: Three Things We Learned - Soccer News

Next Article

how do I chage pixel color? (SDL2)

Related Posts