RaycastCtrl = function (renderer,scene) {
    var _inst = this;
    this.awake = function () {
        this.initRay();
    }
    this.initRay = function () {
        var mouse = new BABYLON.Vector2(0, 0);
        var mouseDown = new BABYLON.Vector2();

        var onMouseDown = function (evt) {
            if (ToolMgr.isMobel()) {
                mouseDown.x = (evt.touches[0].clientX / window.innerWidth) * 2 - 1;
                mouseDown.y = -(evt.touches[0].clientY / window.innerHeight) * 2 + 1;
                mouse.x = (evt.touches[0].clientX / window.innerWidth) * 2 - 1;
                mouse.y = -(evt.touches[0].clientY / window.innerHeight) * 2 + 1;

                renderer.addEventListener("touchend", onPointerUp, false);
                renderer.addEventListener("touchmove", onTouchMove, false);
            }
            else {
                mouseDown.x = ((evt.clientX) / renderer.clientWidth) * 2 - 1;
                mouseDown.y = -((evt.clientY) / renderer.clientHeight) * 2 + 1;
                mouse.x = ((evt.clientX) / renderer.clientWidth) * 2 - 1;
                mouse.y = -((evt.clientY) / renderer.clientHeight) * 2 + 1;

                renderer.addEventListener("pointerup", onPointerUp, false);
                //renderer.addEventListener("pointermove", onPointerMove, false);
            }

        }
        var onPointerUp = function (evt) {
            if (ToolMgr.isMobel()) {
                renderer.removeEventListener("touchend", onPointerUp, false);
                renderer.removeEventListener("touchmove", onTouchMove, false);
            }
            else {
                mouse.x = (evt.clientX / window.innerWidth) * 2 - 1;
                mouse.y = -(evt.clientY / window.innerHeight) * 2 + 1;
                renderer.removeEventListener("pointerend", onPointerUp, false);
            }
            //renderer.removeEventListener("pointermove", onPointerMove, false);
            if (BABYLON.Vector2.Distance(mouse, mouseDown) > 0.005) { //处理鼠标旋转移动操作后，取消点击操作
                return;
            }
            // var pickInfo = scene.pick(scene.pointerX, scene.pointerY, function (mesh) {
            //     return mesh.name.match("PIC_");
            // });
            var pickInfo = scene.pick(scene.pointerX, scene.pointerY);
            if(pickInfo.hit && pickInfo.pickedMesh.name.startsWith("PIC_")){
                showPicInfo(pickInfo.pickedMesh.name.substring(4));
                return;
            }
            pickInfo = scene.pick(scene.pointerX, scene.pointerY, function (mesh) {
                return mesh.fRay == true;
            });
            if(pickInfo.hit){
                if(pickInfo.pickedMesh.name == ModelConfig.ground){
                    camCtrl.moveTarget(pickInfo.pickedPoint.x, pickInfo.pickedPoint.z);
                    objCircle.isVisible = true;
                    objCircle.position.x = pickInfo.pickedPoint.x;
                    objCircle.position.z = pickInfo.pickedPoint.z;
                    if (ModelConfig.type == 2) { // 古代
                        objCircle.position.y = 0.03;
                    } else if (ModelConfig.type == 1) { // 现代
                        objCircle.position.y = pickInfo.pickedPoint.y+0.01;
                    }
                }
            }
            else {
            }
        }
        var onPointerMove = function (evt) {
            mouse.x = ((evt.clientX) / renderer.clientWidth) * 2 - 1;
            mouse.y = -((evt.clientY) / renderer.clientHeight) * 2 + 1;
        }
        var onTouchMove = function (evt) {
            if (!ToolMgr.isMobel()) {
            }
            else {
                mouse.x = (evt.touches[0].clientX / window.innerWidth) * 2 - 1;
                mouse.y = -(evt.touches[0].clientY / window.innerHeight) * 2 + 1;
            }
        }
        if (ToolMgr.isMobel()) {
            renderer.addEventListener("touchstart", onMouseDown, false);
        }
        else {
            renderer.addEventListener("pointerdown", onMouseDown, false);
            renderer.addEventListener("pointermove", onPointerMove, false);
        }

    }
}
