开发者

Rotate, then translate in three.js

I would like to rotate then a plane created with THREE.PlaneGeometry, but I have some problems.

  1. What's the axis in front of the camera with FirstPersonCamera ?

    My own tests have revealed a X-front/back, Y-top/bottom, Z-left/right, am I right ?

  2. In order to make a cube with these plane, I use the following code (cut for display only X-axis faces). For a reason I don't understand, there is a small space between the block and the orthogonal basis. It seems that rotation is applied after translation. How can I fix it ?
function lol() {
    var mesh = new THREE.Mesh(xFacesGeometry, material);
    mesh.matrix.setRotationFromEuler(new THREE.Vector3(0, ath.PI / 2),  'XYZ');
    mesh.matrix.setPosition(new THREE.Vector3(x * 20 + 10, y * 20 + 10, z * 20 + 10));
    mesh.matrixAutoUpdate = false;
}
lol(0, 0, 0);
lol(1, 0, 0);

Full code here (use ctrl+click to move b开发者_JAVA百科ackward) : http://jsfiddle.net/u8ZHC/


Just to answer this : the best way to specify the order in which translations / rotations have to be applied is to use multiple nodes.

var pitchNode = new THREE.Object3D( );
var yawNode = new THREE.Object3D( );
var rollNode = new THREE.Object3D( );
var positionNode = new THREE.Object3D( );

// here come the order
scene.add( pitchNode );
pitchNode.add( yawNode );
yawNode.add( rollNode );
rollNode.add( positionNode );


Try to update matrix before translate the position:

mesh.matrix.setRotationFromEuler(new THREE.Vector3(0, Math.PI / 2),  'XYZ');
mesh.updateMatrix();
mesh.translate(...);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜