【发布时间】:2019-07-26 22:58:52
【问题描述】:
我有一张卡片的两半,我需要为卡片的开口设置动画。因此,我需要围绕该部分的最左边而不是中心旋转卡片的正面,获取“围绕一个点旋转”的代码会产生糟糕的结果:
//geometry for each half
var geometry1 = new THREE.PlaneGeometry( 10, 15 );
//rotation, offset by half width
...
else if (e.keyCode == '87'){
openAng+=0.1;
rotCusAxis(card, new THREE.Vector3( -5, 0, 0 ),new THREE.Vector3(0,1,0),openAng,false);
}
...
function rotCusAxis(obj, point, axis, theta, pointIsWorld){
pointIsWorld = (pointIsWorld === undefined)? false : pointIsWorld;
if(pointIsWorld){
obj.parent.localToWorld(obj.position); // compensate for world coordinate
}
obj.position.sub(point); // remove the offset
obj.position.applyAxisAngle(axis, theta); // rotate the POSITION
obj.position.add(point); // re-add the offset
if(pointIsWorld){
obj.parent.worldToLocal(obj.position); // undo world coordinates compensation
}
obj.rotateOnAxis(axis, theta); // rotate the OBJECT
}
我可以用什么替代方法来解决这个问题?
【问题讨论】:
-
不清楚你想如何展开卡片,但我假设它不是这样的examples,是吗?
-
不,这是两个 THREE.PlaneGeometry 类型的 THREE.Mesh。我正在尝试 var x = Math.cos(rot)*(width/2); var z = Math.cos(rot)*(width/2); card.applyMatrix(new THREE.Matrix4().makeTranslation(-x, 0, -z)); card.applyMatrix(new THREE.Matrix4().makeRotationY(openAng)); card.applyMatrix(new THREE.Matrix4().makeTranslation(x, 0, z));但它只是围绕一个圆圈旋转它,我知道它会但认为它看起来会正确(即两个卡片的一半看起来仍然相连)
标签: javascript three.js