### Author Topic: Rotation issue in JPCT-AE  (Read 1172 times)

#### mr.jack

• byte
• Posts: 5
##### Rotation issue in JPCT-AE
« on: October 30, 2013, 07:03:56 pm »
Hi everyone. So I was playing around with JPCT for Android, and discovered a small issue while playing with the default HelloWordAE example. Basically, I wanted to rotate the cube around on one of its edges. Everything went well, set a rotation pivot cube.setRotationPivot(value), then made the call cube.rotateX(value).

The strange thing I have discovered, is that when I set the rotation pivot, it must be set with with a difference from the original value. For example, if the Scale of the cube is 1, the rotation pivot values are
x=-1;
y=-1;
z=-2.4f;
so we add 0.4 to the value we need

if the scale is 10, then are the following values
x=-10;
y=-10;
z=-24f;
we add 4 to the original value

if I don't add the 0.4 or 4, the cube is not rotating on the edge, but is slightly displaced
Can anyone explain why this is happening? Wanted to create some things, but this is holding me for a while    Or maybe I am missing something?
« Last Edit: October 30, 2013, 07:06:26 pm by mr.jack »

#### EgonOlsen

• Posts: 11884
##### Re: Rotation issue in JPCT-AE
« Reply #1 on: October 30, 2013, 09:31:59 pm »
I don't get your values even with the additional 4. If the cube is axis aligned (which it isn't by default when created by the Primitives class), then the bounding box of the cube is [-1.0, 1.0, -1.0, 1.0, -1.0, 1.0]. If it's not, the edges are rotated 45° around in the y axis. I don't know how you come to this 2 (+x) in your pivot!?

#### mr.jack

• byte
• Posts: 5
##### Re: Rotation issue in JPCT-AE
« Reply #2 on: October 30, 2013, 10:52:03 pm »
I have read about the 45 degree thing, so I rotate the cube back by 45 (in radians) before the build process. I'll see tomorrow what is in my code, maybe I'm doing something wrong, still studying JPCT.
Here is the eclipse project with my experiments over the objects, maybe this can clear what magic I have done https://www.dropbox.com/s/z3mjq8eyqm25b24/cube.zip (I just edited the Helloworld plus added 2 new objects).

#### mr.jack

• byte
• Posts: 5
##### Re: Rotation issue in JPCT-AE
« Reply #3 on: October 31, 2013, 12:58:08 pm »
I'm trying to figure out this code. By the way, I scale the cube to 10, so this is why I'm using bigger values (10, 20..).

Ok, have drawn a polyline on the base of the cube, just to have a reference.
And made a rotation without setting a pivot (so it should be around it's center point, which should be 0,0,0 have made even a translate, and tried setOrigin()). Strangely when making .log calls and inspecting using cube.getRotationPivot() it shows these coordinates
(-7.947286E-8,0.0,0.0)
Not sure why x is -7.947286E-8 ...
« Last Edit: October 31, 2013, 02:45:38 pm by mr.jack »

#### EgonOlsen

• Posts: 11884
##### Re: Rotation issue in JPCT-AE
« Reply #4 on: October 31, 2013, 08:35:29 pm »
That's caused by inaccuracies when dealing with floats. You can ignore them. -7.947286E-8 is actually 0.

#### mr.jack

• byte
• Posts: 5
##### Re: Rotation issue in JPCT-AE
« Reply #5 on: November 02, 2013, 01:55:34 pm »
Some debugging, and still the is something not quite clear.
Tried rotate around a face (the middle of it, like 0,10,0), works nice. If I set already a X or Y, it goes where it shouldn't go, the feeling that the pivot doesn't work with the world coordinates, or it translates the object to some unknown coordinates.. (making it 0,0,10, also changes the X for pivot for some reason). Took into consideration the fact that the axes are rotated as explained http://www.jpct.net/wiki/index.php/Coordinate_system
Out of ideas.

#### EgonOlsen

• Posts: 11884
##### Re: Rotation issue in JPCT-AE
« Reply #6 on: November 03, 2013, 02:45:30 pm »
The pivot is given in object space...i'm not sure if you are aware of this after reading your post. Anyway, that might not matter in this case anyway. Setting a pivot doesn't cause a translation, at least not directly. It might of course look like one in the end, because the object will certainly move when rotating because of the pivot which isn't located in its center any longer, but that's not a real translation.
I haven't looked at the code but maybe your problem arises from the initial rotation to make the box axis aligned. If you are doing this by a simple rotation, the results of further rotations might be confusing, because they might not be what one expects (because the axes don't rotate with the object).
Try to make your initial 45° rotation permanent to the mesh by adding

Code: [Select]
`...box.rotateMesh();box.clearRotation();`

#### mr.jack

• byte
• Posts: 5
##### Re: Rotation issue in JPCT-AE
« Reply #7 on: November 04, 2013, 09:20:49 am »
"These are the Droids I was looking for"
Thank you! This is it, I should rotate the mesh.
Yep, I know that a rotation around a point is a combination of translation+rotation, just I didn't know about the mesh..
« Last Edit: November 04, 2013, 09:23:30 am by mr.jack »