Dav1dde / gl3n

OpenGL Maths for D (not glm for D).
http://dav1dde.github.com/gl3n/
Other
103 stars 49 forks source link

Transformation functions for 3x3/3x2 matrices (2d matrices) #57

Closed WebFreak001 closed 9 years ago

WebFreak001 commented 9 years ago

It would be nice to have rotate, translate and scale in 2d aswell

extrawurst commented 9 years ago

afaik they apply on mat3 awell:

static if((rows == cols) && (rows >= 3)) {
        static if(isFloatingPoint!mt) {
            /// Returns an identity matrix with an applied rotate_axis around an arbitrary axis (nxn matrices, n >= 3).
            static Matrix rotation(real alpha, Vector!(mt, 3) axis) {......

see: https://github.com/Dav1dde/gl3n/blob/master/gl3n/linalg.d#L1444

Dav1dde commented 9 years ago

A 2x2 rotation matrix is indeed missing, not sure how useful it would be (but I wouldnt be against adding it anyways), since you normally work with homogeneous coordinates anyways (correct me if I am wrong!). 3x3 rotation/translation/scale matrices are supported (as @Extrawurst stated), 3x2 aren't, if you give me a good resource why they are needed and what they do, I am all for adding them.

WebFreak001 commented 9 years ago

There is D2D1_MATRIX_3X2 in Direct2D for 2D transformation.

https://msdn.microsoft.com/en-us/library/windows/desktop/dd372275(v=vs.85).aspx

Dav1dde commented 9 years ago

Ok, but why is it important to have a 3x2 matrix, instead of a 3x3. How does it work? I was looking for something more mathematical, since I've never seen a use for a 3x2 matrix.

WebFreak001 commented 9 years ago

Not mathematical but it saves 12 bytes in ram for each matrix

Dav1dde commented 9 years ago

Which is irrelevant. You don't create millions of matrices and keep these in memory. Also you don't send them to the GPU with every vertex, but once via uniform.