0

I have a glm::mat3 constructed via the experimental glm::translate(mat3,vec2) function. However, using this matrix to modify a vec3 gives funky results. Here is a short program demonstrating:

#define GLM_ENABLE_EXPERIMENTAL

#include <glm/glm.hpp>
#include <glm/gtx/matrix_transform_2d.hpp>
#include <iostream>

std::ostream& operator<< (std::ostream& o, const glm::vec3& vec){
    return o << '(' << vec.x << ',' << vec.y << ',' << vec.z << ")\n";
}

int main(){
    glm::mat3 translate = glm::translate(glm::mat3(1.), glm::vec2(-1.,-1.));

    std::cout << glm::vec3(10.,10.,1.);                  //prints (10,10,1)
    std::cout << glm::vec3(10.,10.,1.) * translate;      //prints (10,10,-19)
}

What is wrong with my matrix that is causing it to modify the Z coordinate instead of translating it?

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
Fuzzyzilla
  • 356
  • 4
  • 15

1 Answers1

0

Your operations are in the wrong order; you want translate * glm::vec3(10, 10, 1).

kmdreko
  • 42,554
  • 6
  • 57
  • 106
  • I understood that multiplying matrices is order dependent, however I figured that matrix * vector could be done with commutativity in mind - You fixed it! I have no clue how the other way around resulted in something so blatantly wrong... Thank you so much for your help. – Fuzzyzilla Jun 25 '18 at 02:35