Hello, thank you for your time. I'm trying to simultaneously move and rotate an object, but it seems to be behaving erratically. I've read that rotation can change the axis in some way. Is this true? Below is the code where I attempted to rotate using both a world axis and an object axis, but encountered the same issue.
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;
}
}