您好,感谢您的宝贵时间。我正在尝试移动一个对象并同时旋转它。在执行这两个动作时,对象会不规律地移动。我已经读过旋转以某种方式改变了轴。真的吗?这是代码。我尝试使用世界轴和对象轴进行旋转,但遇到了同样的问题。
var rotObjectMatrix;
function rotateAroundObjectAxis(object, axis, radians) {
rotObjectMatrix = new THREE.Matrix4();
rotObjectMatrix.makeRotationAxis(axis.normalize(), radians);
object.matrix.multiply(rotObjectMatrix);
object.rotation.setFromRotationMatrix(object.matrix);
}
var rotWorldMatrix;
// Rotate an object around an arbitrary axis in world space
function rotateAroundWorldAxis(object, axis, radians) {
rotWorldMatrix = new THREE.Matrix4();
rotWorldMatrix.makeRotationAxis(axis.normalize(), radians);
rotWorldMatrix.multiply(object.matrix);
object.matrix = rotWorldMatrix;
object.rotation.setFromRotationMatrix(object.matrix);
}
function spriteAI2() {
//var ranTen = Math.floor((Math.random()*7)+2);
var xAxis = new THREE.Vector3(1,0,0);
var yAxis = new THREE.Vector3(0,1,0);
var zAxis = new THREE.Vector3(0,0,1);
rotateAroundObjectAxis(meshSprite, zAxis, Math.PI / 180);
if (meshSprite.position.x > 30 && meshSprite.position.x <= 450) {
meshSprite.translateX( -6 );
} else if (meshSprite.position.y > 30 && meshSprite.position.y <= 250) {
meshSprite.translateY( -6);
} else if (meshSprite.position.z > 30 && meshSprite.position.z <= 350) {
meshSprite.translateZ( -6 );
} else if (meshSprite.position.x < -30 && meshSprite.position.x >= -450) {
meshSprite.translateX( 6 );
} else if (meshSprite.position.y < -30 && meshSprite.position.y >= -250) {
meshSprite.translateY( 6 );
} else if (meshSprite.position.z < -30 && meshSprite.position.z >= -350) {
meshSprite.translateZ( 6 );
} else if (meshSprite.position.x < 31 && meshSprite.position.y < 31 && meshSprite.position.z < 31 && meshSprite.position.x > -31 && meshSprite.position.y > -31 && meshSprite.position.z > -31) {
var locX = Math.floor((Math.random()*450)+1);
locX *= Math.floor(Math.random()*2) == 1 ? 1 : -1;
var locY = Math.floor((Math.random()*250)+1);
locY *= Math.floor(Math.random()*2) == 1 ? 1 : -1;
var locZ = Math.floor((Math.random()*350)+1);
locZ *= Math.floor(Math.random()*2) == 1 ? 1 : -1;
scene.remove(meshSprite);
//texture.dispose();
c2ImgMaterial.dispose();
meshSprite.position.set( locX, locY, locZ );
scene.add( meshSprite );
//c2Sprite.clone;
}
}