jPCT-AE - a 3d engine for Android > Support

Rotating multiple objects around a single object or center

(1/2) > >>

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:


--- Code: ---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();
}

--- End code ---

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:

--- Code: ---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]);

--- End code ---

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:
I'm not sure but I think you need to use radians for the rotate methods


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

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

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

Navigation

[0] Message Index

[#] Next page

Go to full version