0

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);
    
  };
  
};
gman
  • 100,619
  • 31
  • 269
  • 393
vagus1975
  • 13
  • 5
  • By watching your fiddle it is quite clear that center of rotation isn't identical to center of cube. That's due to translating coordinates on cube. Rotation and translation are both applied to same reference: cube. I'd advise using a separate container object to do the translation or check toolkit for using other approaches for "moving" the cube. – Thomas Urban Mar 23 '16 at 11:20

1 Answers1

0

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.

Thomas Urban
  • 4,649
  • 26
  • 32
  • Thanks to you, i give up using xtk and switch to three.js.. using nrrd instead of DICOM. For my purpose i need on or two dynamical transformable (translation and rotation) object in relation to the dicom/nrrd volume. – vagus1975 Mar 23 '16 at 20:35