import { __awaiter, __generator } from "tslib";
import Instance from '../core/Instance';
import { TIMESPAN_SOON } from '../core/Constant';
import { Cartesian3, Matrix4 } from '@msign/angularis';
var CameraControl = /** @class */ (function () {
    function CameraControl(viewer) {
        this._viewer = viewer;
        this._camera = viewer.camera;
    }
    /** ************************************
     *  飞行到指定目标点
     ***************************************/
    CameraControl.prototype.flyto = function (target, direction, up, timespan) {
        if (timespan === void 0) { timespan = TIMESPAN_SOON; }
        return __awaiter(this, void 0, void 0, function () {
            var cam, _position, _direction, _up, cAn;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        cam = this._camera;
                        _position = cam.position;
                        _direction = cam.direction;
                        _up = cam.up;
                        return [4 /*yield*/, Instance.getInstanceAnimaControl()];
                    case 1:
                        cAn = _a.sent();
                        return [4 /*yield*/, Promise.all([
                                cAn.trans(_position, target, timespan),
                                direction && cAn.trans(_direction, direction, timespan),
                                up && cAn.trans(_up, up, timespan)
                            ])];
                    case 2:
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    CameraControl.prototype.transPositionWithMatrix = function (matrixArray, point) {
        var matrix = Matrix4.fromArray(matrixArray);
        return Matrix4.multiplyByPoint(matrix, point, new Cartesian3());
    };
    CameraControl.prototype.shaking = function () {
        return __awaiter(this, void 0, void 0, function () {
            var cam, position, p0, ps, cAn, i, p;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        cam = this._camera;
                        position = cam.position;
                        p0 = position.clone();
                        ps = [];
                        return [4 /*yield*/, Instance.getInstanceAnimaControl()];
                    case 1:
                        cAn = _a.sent();
                        i = 0;
                        _a.label = 2;
                    case 2:
                        if (!(i < 5)) return [3 /*break*/, 5];
                        p = p0.clone();
                        p.x += Math.random() > 0.5 ? 0.2 : -0.2;
                        p.y += Math.random() > 0.5 ? 0.2 : -0.2;
                        p.z += Math.random() > 0.5 ? 0.2 : -0.2;
                        return [4 /*yield*/, cAn.trans(position, p, 100)];
                    case 3:
                        _a.sent();
                        _a.label = 4;
                    case 4:
                        i++;
                        return [3 /*break*/, 2];
                    case 5: return [4 /*yield*/, cAn.trans(position, p0, 100)];
                    case 6:
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    return CameraControl;
}());
export default CameraControl;
