美文网首页
2018-09-15

2018-09-15

作者: 浪巅 | 来源:发表于2018-09-15 15:25 被阅读0次

html

    this.shootHeight = 4

gui.add(c, 'shootHeight', 0, 10);

WebGLRenderer({precision: "mediump",

    hp = new OimoHelper(scene);

    world = new OIMO.World({gravity: [0,-20,0], random:false})

    levels = new canBallLevels(c, hp, ballControls)

    velocitySqLimit = (c.ballRad/world.timeStep); 

    oldTimeStep = world.timeStep

            // physics.update(dt, 5);

    }

    world.step();

    flyingCheck();

world.removeRigidBody(ground.body)

world.removeRigidBody(item.body)

wall = hp.addBox({ size:[c.roomWidth*2, 80,4*c.canRad],  pos:[0, 0 , -c.disdanceHalf-2*c.canHeight] , restitution:0.005});

ground = hp.addBox({ size:[c.roomWidth, 0.2,3*c.ballRad],  pos:[0,c.groundY -0.1 ,c.disdanceHalf], });

clearInterval(checkfun);  checkfun = setInterval(checkResult1, 3000)

--

var flyingBalls = []

var velocitySqLimit, oldTimeStep

var ballProcess = {

  zero : new THREE.Vector3(),

  selectBall : function (){

    controls.enabled = false;

  },

  throwBall : function (ball, to,delta){

    controls.enabled = true;

    // to.sub(ball.position).normalize()

    // to.divideScalar(delta).multiplyScalar (c.forceFactor)

    // ball.body.applyImpulse(this.zero, to);

var to = new THREE.Vector3();

to.set(0,c.shootHeight,-38)

to.normalize()

to.multiplyScalar(c.forceFactor)

ball.body.linearVelocity.copy(to)

var flyingBall = ball.body;

    if (Math.abs(flyingBall.linearVelocity.z) >= velocitySqLimit) {

        var dist2NearestZ = ball.body.position.z - levels.nearestZ ;

        var distOneSteps = world.timeStep*(-ball.body.linearVelocity.z);

        var distModLeft = dist2NearestZ % distOneSteps;

        flyingBall.changeStepAtPosZ = ball.body.position.z - (dist2NearestZ - distModLeft)

        flyingBall.newTimeStep = c.ballRad/(-ball.body.linearVelocity.z)

    }

    flyingBalls.push(flyingBall)

    var index = ballControls.arrBall.indexOf(flyingBall.mesh)

    ballControls.arrBall.splice(index, 1)

    ball.body.onCollide = function(bodyOther, pos){

        if (bodyOther !== ground.body){

            particle.createExplosion(pos)

        }

    }

  }

}

function flyingCheck(){

    var minTimeStep = oldTimeStep;

    flyingBalls.forEach(function(flyingBall, index) {

        if (flyingBall.position.y < 0){

            flyingBalls.splice(index,1)

            world.removeRigidBody(flyingBall)

            scene.remove(flyingBall.mesh)

            flyingBall.mesh = null;

            flyingBall = null;

            return;

        }

        if (Math.abs(flyingBall.linearVelocity.z) >= velocitySqLimit

            && flyingBall.position.z < flyingBall.changeStepAtPosZ)

        {

            if (flyingBall.newTimeStep < minTimeStep)

                minTimeStep = flyingBall.newTimeStep;

        }

    })

    world.timeStep = minTimeStep;

    ballControls.arrTarget.forEach(function(item, index) {

        if (item.position.y < 0){

            if (item.body){

                world.removeRigidBody(item.body)

                item.body = null;

            }

            scene.remove(item)

            ballControls.arrTarget.splice(index,1)

            levels.nTarget--;

        }

    });

}

function checkResult1(){

    if (levels.nTarget <= 0){

        console.log('succeed')

        clearInterval(checkfun);  checkfun = null;

        return;

    }

    if (ballControls.arrBall.length === 0){

        if (flyingBalls.length === 0){

            setTimeout(checkResult2, 3000)

        }else{

            setTimeout(checkResult2, 6000)           

        }

        clearInterval(checkfun);  checkfun = null;

    }

}

function checkResult2(){

    if (levels.nTarget <= 0){

        console.log('succeed')

    }

    else{

        console.log('failed')       

    }

}

相关文章

  • 面试:JavaScript进阶篇

    JavaScript前端2018-09-15 18:13:32 作者:yuxiaolian 链接:https://...

  • 学习强国|大国名医:张仲景

    张仲景 “学习强国”学习平台2018-09-15 张仲景(约公元150~154年——约公元215~219年),名机...

  • 2018-09-18

    去逛街 庞芸熙 修改一 2018-09-15 19:27 · 字数 356 · 阅读 20 · 日记本 星期天,...

  • 做精致女人&享性福人生

    时间:2018-09-15 女人,本该精致如花 女人,本该幸福快乐 女人,本该了解自己 女人,你应该爱你自己。 今...

  • 附录C:SQL 语言的分类

    时间:2018-09-15 作者:魏文应 一、分 类 SQL 语言,对数据进行增、删、改、查操作。这样,也就意味...

  • 应该改变的是企业家的”心“

    2018-09-15 (稻盛哲学学习会)打卡第117天 姓名:祝新华 部门:业务部 组别:待定 【知~学习】...

  • 电影记录

    碟中谍6:全面瓦解 2018-09-15 我不是妖神 208-07-17 超人总动员2 2018-06-23 头...

  • 逻辑思维(五)

    2018-09-15 D48【读书感悟】3173-安安 第3章:利用框架来节约时间和精力 1、框架(framewo...

  • 张苗的周检视

    2018-09-15 星期六 本周温馨时刻及点滴成果 一、健康:本周坚持了40公里的运动,感觉非常不错。下...

  • 喜欢的文章21

    中年如秋 春暖花开 2018-09-15 16:48:35 当秋叶落在时光雕刻的脉络里,季节里已满是秋的韵味了。 ...

网友评论

      本文标题:2018-09-15

      本文链接:https://www.haomeiwen.com/subject/owxtnftx.html