2018-09-15

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')? ? ? ?

? ? }

}

?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi閱讀 7,424評論 0 10
  • The Inner Game of Tennis W Timothy Gallwey Jonathan Cape ...
    網事_79a3閱讀 12,230評論 3 20
  • 找到fullcalendar.js, 找到代碼為 isRTL:false,這句話 輸入以下幾句 monthName...
    迷你小小白閱讀 1,714評論 0 1
  • 負責公司的外聯工作。 負責公司的后勤工作。 負責公司的手法文件管理以及檔案資料的收集、管理、歸檔以及開發利用等工作...
    閉琥閱讀 105評論 0 0
  • 1.《黃帝內經》是我國戰國至秦漢時期,許多醫家論著己經修撰而成《神農本草經》是東漢時期神農所著《傷寒雜病論》東漢末...
    步云鵬閱讀 3,459評論 0 0