www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: behelit on March 14, 2018, 04:47:23 am

Title: Rotating multiple objects around a single object or center
Post by: behelit on March 14, 2018, 04:47:23 am
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: [Select]
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?
Title: Re: Rotating multiple objects around a single object or center
Post by: EgonOlsen on March 14, 2018, 09:08:59 am
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.
Title: Re: Rotating multiple objects around a single object or center
Post by: behelit on March 14, 2018, 11:18:30 pm
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:
(http://i68.tinypic.com/aokdj4.png)

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: [Select]
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:

(http://i68.tinypic.com/rbywlz.png)

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:

(http://i65.tinypic.com/254ydl1.png)
Title: Re: Rotating multiple objects around a single object or center
Post by: AeroShark333 on March 15, 2018, 12:56:54 am
I'm not sure but I think you need to use radians for the rotate methods

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

//new
clockBar[i].rotateZ(((float) i / 10) * ((float)Math.PI)*2f);
Title: Re: Rotating multiple objects around a single object or center
Post by: behelit on March 15, 2018, 03:26:19 am
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

(http://i67.tinypic.com/2j3r502.png)
Title: Re: Rotating multiple objects around a single object or center
Post by: EgonOlsen on March 15, 2018, 10:14:04 am
Make sure to call build() before setting the pivot. Otherwise, it will be resetted to a calculated one.
Title: Re: Rotating multiple objects around a single object or center
Post by: behelit on March 15, 2018, 11:10:39 pm
Yes, that was the problem.
Thanks for the help everyone.

(http://i66.tinypic.com/w01d9d.png)