【发布时间】:2018-06-07 14:50:15
【问题描述】:
我无法找到对象在任意轴上的绝对旋转。
到目前为止,我已经能够获得对象的相对旋转。为了获得相对旋转,我在面向选定轴的对象后面放置了一个平面。通过在这个平面上进行光线投射,我可以使用atan2 检索 3D 坐标来计算角度。
获取对象相对旋转的代码:
let planeCrossObjectDir = planeNormal.clone().cross(this.objectUpDirection).normalize();
let projectedPoint = new THREE.Vector3();
rayPlane.projectPoint(intersection.point, projectedPoint);
let centerProjected = new THREE.Vector3();
rayPlane.projectPoint(this.raycastPlane.position, centerProjected);
let u1 = this.objectUpDirection.dot(projectedPoint);
let v1 = planeCrossObjectDir.dot(projectedPoint);
let u2 = this.objectUpDirection.dot(centerProjected);
let dotv2 = planeCrossObjectDir.dot(centerProjected);
let uvCoord = new THREE.Vector2(u1, v1).sub(new THREE.Vector2(u2, dotv2));
var theta = Math.atan2(uvCoord.y, uvCoord.x); // range [-PI, PI]
theta *= 180 / Math.PI; // range [-180, 180]
if (theta < 0) theta = 360 + theta; // range [0, 360]
let objectsRotation = Math.round(360 - theta); // invert rotation
我想通过更改planeCrossObjectDir 并使用平面的世界上矢量而不是this.objectUpDirection 来计算绝对旋转。
但问题是:我不知道如何计算..
【问题讨论】:
标签: javascript three.js calculus