ofxAssimpModelLoader set rotation

I am working with ofxAssimpModelLoader and have a question about the set rotation function below.

   void ofxAssimpModelLoader::setRotation(int which, float angle, float rot_x, float rot_y, float rot_z){
        if(which + 1 > (int)rotAngle.size()){
            int diff = 1 + (which - rotAngle.size());
            for(int i = 0; i < diff; i++){

        rotAngle[which]  = angle;
        rotAxis[which].x = rot_x;
        rotAxis[which].y = rot_y;
        rotAxis[which].z = rot_z;


I am not that adept at 3D rotation anyway, but I am trying to use this and I don’t understand what the ‘which’ parameter is and how it effects the rotation. After a few hours of putting parameters in (yes I am that slow) I can’t seem to find the pattern of what is going on. If anyone can point me in the right direction it would be great…

The last thing the function calls is updateModelMatrix(); if you go into that function you’ll see the line:

  for(int i = 0; i < (int)rotAngle.size(); i++){ // @julapy - not sure why rotAngle isn't a ofVec4f.
        modelMatrix.glRotate(rotAngle[i], rotAxis[i].x, rotAxis[i].y, rotAxis[i].z);

which may clarify it a little bit. For a 3d rotation, you need two things:

  • a rotation axis, defined by an (x,y,z) vector, and
  • an amount to rotate around this angle.

It looks like this object is meant to hold multiple rotations, indexed by i, and each rotation is applied one after another. You can also see how many rotations are already being applied with getNumRotations().

The safest way to do it would probably be to add another rotation on top of however many are already applied:

float angle = 90.0;
ofPoint axis = ofPoint(1.0, 0.0, 0.0);
int numRotation = model.getNumRotations();
model.setRotatation(numRotation, angle, axis.x, axis.y, axis.z);
1 Like

Cheers, I had understood a chunk of that, but this made it make more sense in the context of this function, to clarify one of the things that made this unclear was this line in the assimple example

model.setRotation(0, -90, 0, 0, 1);

Where which = 0, makes sense if it is the zero indexed number of rotations (make sense as in explains the line of code, but seems illogical in labelling to me). Is it my misunderstanding that makes it seem strange to call the number of rotations ‘which’ instead of ‘numRots’ or something similar, as well as having this remain zero indexed and when applying a single rotation entering 0 instead of 1 and having the function take care of the offset, or is this transparent.

Your explanation makes sense though, it is just the function is not so readable to me if this is correct.

Exactly. The line of code you posted sets the first rotation to be a -90 degree rotation around the z axis. The only reason I suggested something more complicated is that if there already exists a rotation in the rotation vector, this will override that rotation, whereas my code would add a rotation.

It depends on what you want!

That said, I agree that the way it is labelled is rather unintuitive and confusing.

Cheers, thanks for the tips, you method really is a good way to go forward for me. I think my problem was just the labelling.

Every time I loaded a obj model, the ofxAssimpModelLoader would automatically rotate the model 180 degree in z axis.

Don’t really know the reason. So I manually rotate it back(180 degree, z axis) to the normal orientation.