2018-10-17

1.

var mov2 = new THREE.Vector2();

    var planeGeometry = new THREE.PlaneBufferGeometry(window.innerWidth*2 , window.innerHeight, 2, 2);

    var planeMaterial = new THREE.MeshBasicMaterial({ visible: true, side: THREE.DoubleSide, color: 0x808000, transparent :true, opacity :0.5 });

    var planeXY = new THREE.Mesh(planeGeometry, planeMaterial); scene.add(planeXY);

    scene.add(planeXY)


2.

var clickOffsetX = 0;

    var isMovUp = false;

    function onMouseDown(e){

        if ( scope.enabled === false ) return;     

        var pointer = e.changedTouches ? e.changedTouches[0] : e;

        startPointer.x = pointer.clientX;

        startPointer.y = pointer.clientY;

        var entity = intersectObjects(startPointer.x, startPointer.y, arrBall)

        if(entity){

            selectBall = entity.object

            gl.selectBall(selectBall)

            planeXY.position.copy(selectBall.position)

            clickOffsetX = entity.point.x - selectBall.position.x;

            isMovUp = false;

        } else

            selectBall = null;

    }

    function onMouseMove(e){

        if ( scope.enabled === false ) return;

        if (!selectBall) return;

        var pointer = e.changedTouches ? e.changedTouches[0] : e;

        mov2.x = pointer.clientX - startPointer.x;

        mov2.y = startPointer.y - pointer.clientY;


        var entity = intersectObjects(pointer.x, pointer.y, [planeXY])

        if(entity)

        {

            console.log(entity.point)

            // console.log

            if (entity.point.y < selectBall.position.y + selectBall.scale.y

                && Math.abs(mov2.x) > 0.2 && mov2.y*5 < Math.abs(mov2.x)){

                if (selectBall.body)

                    selectBall.body.setPosition( {x:entity.point.x - clickOffsetX, y:selectBall.body.position.y, z:selectBall.body.position.z});

                isMovUp = false;

            }else{

                if (!isMovUp){

                    isMovUp = true;

                    clock.getDelta();

                }

            }

        }

    }

    function onMouseUp(e) {

        if ( scope.enabled === false ) return;

        if (!selectBall) return;

        if (!isMovUp) {

            selectBall = null;

            return;

        }

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容