Skip to content

Instantly share code, notes, and snippets.

@kylemcdonald
Created March 30, 2018 18:48
Show Gist options
  • Save kylemcdonald/411914969b25ce47786fd411f0ae6210 to your computer and use it in GitHub Desktop.
Save kylemcdonald/411914969b25ce47786fd411f0ae6210 to your computer and use it in GitHub Desktop.
ofMatrix4x4 compared to glm::mat4.
#include "ofMain.h"
int main() {
// both initialize to identity matrix
cout << glm::mat4() << endl;
cout << ofMatrix4x4() << endl;
// both row-major (translation stored in mat[3][0,1,2])
glm::mat4 glmMat;
glmMat = glm::translate(glmMat, glm::vec3(1,2,3));
ofMatrix4x4 ofMat;
ofMat.translate(1,2,3);
for(int i = 0; i < 4; i++) {
cout << glmMat[i] << endl;
cout << ofMat._mat[i] << endl;
}
// if working with multiple transformations, note that:
// glmMat *= glm::translate(glmMat, translation);
// is actually equivalent to:
// ofMat.preMultTranslate(translation);
// also,
glm::mat4 glmMat1, glmMat2;
glmMat1 *= glmMat2;
// is equivalent to:
ofMatrix4x4 ofMat1, ofMat2;
ofMat1.preMult(ofMat2);
// glm::eulerAngleX accepts radians
// ofMatrix4x4 uses float by default
// glm::mat4 can use float or double based on initialization
// so we explicitly initialize with a float
cout << glm::eulerAngleX(float(HALF_PI)) << endl;
// ofMatrix4x4::newRotationMatrix accepts degrees
cout << ofMatrix4x4::newRotationMatrix(90, 1, 0, 0) << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment