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