matrixrotationtransformxtk

Trouble with simple X.transform.rotate (rotation center offset)


I’m very confused right now: the basic X.transform.rotate() function gives unexpected result for me, even with very simple scenes!

The angles of the rotations are OK, as you can see here: http://jsfiddle.net/1sv25uLx/

The previous scene contains only objects for which Y = 0. The rotation of the yellow parallelepiped is good.

However, if I introduce more objects, a translation is added and I can’t understand why: http://jsfiddle.net/1bo7zdfs/1/

// create XYZ widgets with spheres
trysphere = new X.sphere();
trysphere.center = [0, 0, 0];
trysphere.color = [1, 1, 1];

trysphereX = new X.sphere();
trysphereX.center = [50, 0, 0];
trysphereX.color = [1, 0, 0];

trysphereY = new X.sphere();
trysphereY.center = [0, 50, 0];
trysphereY.color = [0, 1, 0];

trysphereZ = new X.sphere();
trysphereZ.center = [0, 0, 50];
trysphereZ.color = [0, 0, 1];

r.add(trysphere);
r.add(trysphereX);
r.add(trysphereY);
r.add(trysphereZ);

// create a parallelepiped
cube = new X.cube();
cube.center = [0, 0, 0];
cube.color = [1, 1, 0];
// orient it along X
cube.lengthY = cube.lengthZ = 5;
cube.lengthX = 40;
// add it
r.add(cube);
// rotate it (same result if done before or after .add)
cube.transform.rotateY(90);

I’ve tried using older versions of the plugin, entering the rotation matrix manually, changing the order of the .add, .transform and .render, ... but I can’t get rid of these annoying offsets.

Can anyone help me, please? @haehn: I’m working on Ricola3D’s interface, he couldn’t make this work either back in 2012.

Edit: I see you kinda talk about this issue in X/Wiki/Future. However, I don’t mind having to set the object’s position to [0,0,0], rotate it, then position it, but it doesn’t even work that way.


Solution

  • OK, I have found the origin of the problem: you have to call r.resetBoundingBox() before adding rotating your object.