jPCT + Vuforia Issue: 3D Model's Rotation

Started by jiarongkoh, January 18, 2015, 11:13:00 AM

Previous topic - Next topic

jiarongkoh

Hi ppl, I'm experimenting on the the jPCT+Vuforia sample app and am facing some issues about the rotation of the 3D model. I changed out the cube and placed my own OBJ model.

I called translation to translate the 3D model at some translation vector, and when I rotate the image target, the 3D model rotates as well. However, the rotation of the 3D model is about its own center, not the image target's center. I tried using setRotationPivot about the origin in the world coordinate system (setRotationPivot(new SimpleVector(0,0,0)) but the rotation is still about the center of the 3D model.

Is anyone able to help me with this? The rotation/movement of the 3D model should be relative to the imagetarget, not the its own center.

EgonOlsen

The rotation pivot it given in object space, not in world space. I.e. 0,0,0 is the center of the object, not of the world. If you translate your object by 10,20,30, your rotation pivot to make it spin around the world's center would be the inverse translation, i.e. -10,-20,-30.

jiarongkoh

Hi Egon, thanks so much for replying. This rotation pivot is shifting my planes around. When I simply call getPlane, all my planes are drawn at the world origin correctly (see attached Capture2.jpg). However, when I do setRotationPivot, my planes somehow got shifted elsewhere.

float angle = (float) Math.PI/2;
xplane=Primitives.getPlane(10, 3);
yplane=Primitives.getPlane(10, 3);
zplane=Primitives.getPlane(10, 3);

xplane.rotateX(angle);
yplane.rotateY(angle);

xplane.build();
yplane.build();
zplane.build();

xplane.setRotationPivot(new SimpleVector(0,-50,0)); //This line moves my plane, see attached Capture1.jpg


I understand that setRotationPivot should be called after build() as I did above, but I do not understand why does setRotationPivot move my plane. I did not call any translation prior to setRotationPivot  :(

EgonOlsen

#3
That's the point of changing the pivot: You rotate around a different point in space and that will of course translate the object. It's like rotating a cup of coffee on your desktop: If you rotate it around it's center, it won't move. But if you rotate it around your mouse, it will change location.
I'm not sure what you actually want. You can't rotate an object around a point in space that's not the center and still don't change the location. That's just not possible. What should the actual result look like?

jiarongkoh

I uploaded a video on youtube and here's the link:
https://www.youtube.com/watch?v=--FMLcyKM1I&feature=youtu.be

In the video you will see two parts, the first part is what I want. You'll see 2 planes and a L-shaped gray model. When I rotate the model around to observe the model at different angle, you'll realise that the 2 planes rotate along with the model, as if the rotation is about the model's center.

In the second part of the video is what I have right now on my tablet. You'll see 3planes and as I rotate the model, you'll realise that the plane does not rotate as how the 2planes rotate in the first part of the video. They appear to rotate about its own center.

I hope I'm clearer now.

EgonOlsen

The easiest way should be to use a dummy object (http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Object3D.html#createDummyObj()) as parent of these planes (http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Object3D.html#addParent(com.threed.jpct.Object3D)). Place that dummy at the position of the rotation pivot/center (http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Object3D.html#getTransformedCenter()) of the L in world space, Translate the planes to their initial positions and apply your rotations to the L and the dummy and leave the planes alone.
You might as well use the L object directly as parent and skip the dummy, but it might be more flexible this way...

jiarongkoh

Hi Egon, thanks so much it works. I skipped the dummy object though, and simply setRotationPivot(Lshapedmodel.getTransformedCenter()) after calling plane.addParent(Lshapedmodel). It works just as well!  ;D