Chained Rotation/Translation 3d Objects

Hi to all !

I’m beginner in Opengl and i need help. I’ll try to explain my problem:
I’ve loaded 5 3d object models (.obj) and now I need to move them like a “chain”.
I’ll try to explain better: the first one has a position and an orientation. It can rotate along its Z axis.
The second one also has an own position and orientation but them depends from the position and the orientation of the first one.
All the next models have their own position and orientation depending from the previous one.
To obtain this I do this for each model: (short pseudocode)

  • load model (vertex)
  • translate it to (0,0,0)
  • rotate around its axis
  • translate it to original position
  • send to shader the resulting matrix
  • draw(1)

The next model:

  • load model
  • translate it to (0,0,0)
  • rotate around the axe of the previous model
  • rotate around its axis
  • translate it to its original position
  • send to shader the resulting matrix
  • draw(2)

…and so on.

The problem is that when accumulate rotations/translations the models don’t go where should go especially when accumulate different axis rotations.
I don’t know if I do a math mistake or an opengl error.
I hope be sufficently clear and I hope somebody can help me. Thanks in advance !

It’s hard to give advice when you don’t provide any details. But I’d suggest reading chapter 3 of the red book, specifically the section titled “Examples of Composing Several Transformations”.

If I understand what you are asking it’s actually pretty easy in OpenGL.
The picture below is of a small sim. I did in 2010. The tentacles are
made up of linked cylinders arranged end-to-end with small rotations
applied at each joint. The cylinder model is a very simple .obj file.
I suggest starting with a simple linked system - maybe of 3 or 4 links.
Don’t worry about moving it around at first. Just see if you can link
it together with small rotations at each joint. The code below is a
routine that calls itself recursively to generate a tentacle made up
of ‘segs’ links. All of the variables can be interactively set to bend and
twist the tentacle as shown in the picture.


void Inflatable_Tentacle::Shape (void)
{
      static int s = 0;

      glPushMatrix ();
         glScalef  (infl, rad, rad);
         Draw_Link ();
      glPopMatrix ();

      glTranslatef ( infl, 0, 0);
      glRotatef    (-bend, 0,1,0);
      glRotatef    ( oopl, 0,0,1);
      glRotatef    ( twst, 1,0,0);

      if (++s < segs)  Shape ();

      s = 0;
}

[ATTACH=CONFIG]2125[/ATTACH]