2

I know only one way which is glm::mat4 matrix

I tried even float matrix[9][3] which didn't work, I need it to multiply it with glm::vec3

How to create?

genpfault
  • 51,148
  • 11
  • 85
  • 139
MrRobot9
  • 2,402
  • 4
  • 31
  • 68
  • i'm afraid that would be beyond glm library capabilities since it is not some sort of generic math library – user7860670 Nov 15 '19 at 07:35
  • 2
    A matrix with 9 columns can't be multiplied to a vec3 since the inner dimensions of the multiplication doesn't match. At least not with the OpenGL Notation where vectors are column vectors. Are you sure you're not looking for a Matrix with 9 rows? But then the result would be a 9d-vector which wouldn't have any meaning in OpenGL. – BDL Nov 15 '19 at 07:51
  • 1
    You could `typedef glm::mat<9, 3, float, glm::defaultp> mat9x3`, but this really smells like an XY-problem. What would you do with the resulting `glm::mat<9,1,...>` ? – Botje Nov 15 '19 at 08:08
  • @Botje The 9d vector is storing x,y,z angles of 3 joints – MrRobot9 Nov 15 '19 at 13:03
  • @BDL Yeah, I'm sorry! I'm going to take transpose of it then multiply with vec3 – MrRobot9 Nov 15 '19 at 13:05

1 Answers1

3

You can compute that with 3x3 sub matrices and combine the outputs into final result. There are two options:

  1. 9 rows

    a a a       u'
    a a a       u'
    a a a       u'
    b b b   u   v'
    b b b * u = v'
    b b b   u   v'
    c c c       w'
    c c c       w'
    c c c       w'
    

    this is really simple:

    u' = a*u
    v' = b*u
    w' = c*u
    
  2. 9 columns

                        u
                        u
                        u
    a a a b b b c c c   v   u' 
    a a a b b b c c c * v = u'
    a a a b b b c c c   v   u'
                        w
                        w
                        w
    

    This is more complicated but not by much:

    u.x' = (a*u).x + (b*v).x + (c*w).x
    u.y' = (a*u).y + (b*v).y + (c*w).y
    u.z' = (a*u).z + (b*v).z + (c*w).z
    

This is common way for expanding dimensionality in GLSL for example for purposes like these:

Spektre
  • 49,595
  • 11
  • 110
  • 380