Rotating multiple objects around a single object or center

Started by behelit, March 14, 2018, 04:47:23 AM

Previous topic - Next topic

behelit

I'm struggling with a rotation concept.
I'm trying to rotate objects sequentially around a single point. Similar to each of the hours on a clock.
For example, I have 10 primitives and I want to loop these around a central point.
In opengl I could do something like:


for (int i = 0; i < 10; i++)
{
gl.glPushMatrix();

gl.glRotatef(((float) i / 10) * 361f, 0f, 0f, 1f);
gl.glTranslatef(0, 5f, 0);

clockBar.draw(gl, 0);
gl.glPopMatrix();
}


But I can't seem to achieve this through jpctae. From what I understand, all of the rotations/translations are performed at the end. So it isn't possible this way.

I've also tried attaching to a dummy object then rotating that but it's the same result because of the same fact.

Would using matrices solve this? Combinig the translation and rotations?

EgonOlsen

I'm not entirely sure, if I got the problem correctly. I would say that you could either just move the rotation pivot (which might be a little fiddly, because it's given in object space) or just use multiple dummy objects that are all located at that central point...and then rotate those.

behelit

Let me explain a little better.
I'm trying to rotate objects around a central point (0,0,0), in the same manner as clock hours, like this:


They don't need to move dynamically so it is all done before onDrawFrame.
The primitive in the image is a Cone.

When trying to rotate with setRotationPivot, I do the following in a loop:

clockBar[i].translate(new SimpleVector(0, 5, 0));
clockBar[i].setRotationPivot(new SimpleVector(0, -5, 0));
clockBar[i].rotateZ(((float) i / 10) * 361f); // To create the sequential positions around the clock

world.addObject(clockBar[i]);


but this produces the following, which appears to rotate around itself instead of 0,0,0:



am I misunderstanding how the pivot works?

Eventually it will be something like this, which I wrote in normal openGL and I'm converting to jpct:


AeroShark333

#3
I'm not sure but I think you need to use radians for the rotate methods


// old
clockBar[i].rotateZ(((float) i / 10) * 361f);

//new
clockBar[i].rotateZ(((float) i / 10) * ((float)Math.PI)*2f);

behelit

Thanks, you were right, now it rotates the correct amount but it is still only rotating on it's own axis and not the pivot


EgonOlsen

Make sure to call build() before setting the pivot. Otherwise, it will be resetted to a calculated one.

behelit

Yes, that was the problem.
Thanks for the help everyone.