javascript3dxtk

XTK - Toolkit.. the cube moves by should only rotating


Im a newbie in 3D computer graphics and seen an odd thing.

I used the XTK-Toolkit, witch is great with DICOM. I add a cube in the scene and translated it far from the center (http://jsfiddle.net/64L47wtd/2/).

when the cube rotate it looks like it is moving

Is this a bug in XTK, or an principle problem with 3D rendering?

window.onload = function() {

  // create and initialize a 3D renderer
  var r = new X.renderer3D();
  r.init();
  
  // create a cube
  cube = new X.cube();
  // skin it..
  cube.texture.file = 'http://x.babymri.org/?xtk.png';
  cube.transform.translateX(250);
  cube.transform.translateY(200);
  cube.transform.translateX(270);
  r.add(cube); // add the cube to the renderer
  r.render(); // ..and render it
  
  // add some animation
  r.onRender = function() {

    // rotation by 1 degree in X and Y directions
    cube.transform.rotateX(1);
    cube.transform.rotateY(1);
    
  };
  
};


Solution

  • You miss to consider the cube a compound object consisting of several vertices, edges and/or faces. As a compound object it's using local coordinate system consisting of axes X, Y, Z. The actual cube is described internally using coordinates for vertices related to that cube-local coordinate system.

    By "translating" you declare those relative coordinates of vertices being adjusted prior to applying inside that local coordinate system. Rotation is then still working on the axes of that local coordinate system.

    Thus, this isn't an error of X toolkit.

    You might need to put the cube into another (probably fully transparent) container object to translate/move it, but keep rotating the cube itself.

    I tried to extend your fiddle accordingly but didn't succeed at all. Taking obvious intentions of X Toolkit into account this might be an intended limitation of that toolkit for it doesn't obviously support programmatic construction of complex scenes consisting of multi-level object hierarchies by relying on its API only.