rotateWithPoint static method
dynamic
rotateWithPoint(
- dynamic obj,
- dynamic anchorPoint, {
- dynamic angleX = 0.0,
- dynamic angleY = 0.0,
- dynamic angleZ = 0.0,
Implementation
static rotateWithPoint(obj, anchorPoint, {angleX = 0.0, angleY = 0.0, angleZ = 0.0}) {
/// step 1: calculate move direction and move distance:
var moveDir =
Vector3(anchorPoint.x - obj.position.x, anchorPoint.y - obj.position.y, anchorPoint.z - obj.position.z);
moveDir.normalize();
var moveDist = obj.position.distanceTo(anchorPoint);
/// step 2: move camera to anchor point
obj.translateOnAxis(moveDir, moveDist);
/// step 3: rotate camera
// obj.rotateX(angleX);
// obj.rotateY(angleY);
// obj.rotateZ(angleZ);
obj.rotation.z = angleZ;
/// step4: move camera along the opposite direction
moveDir.multiplyScalar(-1);
obj.translateOnAxis(moveDir, moveDist);
}