[Solved] How to move/rotate a 3D obj mesh?

Hi,

I have been trying to apply simple transformations (rot/translate) to an obj file I loaded in. The model is loaded in using this code:

  ObjLoader loader( loadFile( "cube.obj" ) );
  myCubeRef = gl::Batch::create( loader, gl::getStockShader( gl::ShaderDef().texture() ) );

Is there a way to apply the cinder::geom::Translate or Rotate to a batch?

Thanks

BTW: I’ve had a look at Arcball, that seems to be specific to spheres and not random Obj meshes

I believe I might have found solution; calling gl::rotate() or gl::transform() before drawing the mesh seems to solve this. Not sure if this is a good way , Ideally I’d like to manipulate the mat4 by multiplication to achieve rotation/translate…

gl::multModelMatrix will let you do the mat4 manipulation what you’d like. (Cinder/wrapper.h at bb15730b3ff6865ee9f47874713d5ebf6ab6c3b0 · cinder/Cinder · GitHub)

Thanks for the reply. I have tried using gl::multModelMatrix with a mat4, however, I was getting errors when trying to apply rotation to the mat4, i.e.:

    mat4 my_matrix(1.0);
    my_matrix*=rotate(0.5,vec3(1.0,0.0,0.0));
    multModelMatrix(my_matrix);

gives me this error:

error: no match for ‘operator*=’ (operand types are ‘glm::mat4’ {aka ‘glm::mat<4, 4, float, glm::packed_highp>’} and ‘void’)
   64 |     my_matrix*=rotate(0.5,vec3(1.0,0.0,0.0));

Do you know how i can overcome this? Strangely enough, the Picking3DApp seems to use the same method . But it doesn’t compile when I try to use that in my project

You are probably using gl::rotate instead of glm::rotate. Specify the namespace.
https://glm.g-truc.net/0.9.4/api/a00206.html

ok i see, thanks for that, i used glm::rotate and it’s solved ! Thanks ver much

1 Like