HTML5技术

结合WebSocket编写WebGL综合场景示例 - ljzc002(4)

字号+ 作者:H5之家 来源:H5之家 2016-11-07 12:00 我要评论( )

{ 3 obj.ryt= obj.mesh.rotation.y; 4 obj.rychange=parseFloat(obj.ryt - obj.ry0); 5 obj.ry0= obj.ryt; v0t = {forward: 0, left: 0, up: 0 }; 8 v0t.forward = obj.v0.forward * parseFloat(Math.cos(obj.rycha

{ 3 obj.ryt=obj.mesh.rotation.y; 4 obj.rychange=parseFloat(obj.ryt - obj.ry0); 5 obj.ry0=obj.ryt; v0t = {forward: 0, left: 0, up: 0}; 8 v0t.forward = obj.v0.forward * parseFloat(Math.cos(obj.rychange)) + (-obj.v0.left * parseFloat(Math.sin(obj.rychange))); 9 v0t.left = (obj.v0.forward * parseFloat(Math.sin(obj.rychange))) + (obj.v0.left * parseFloat(Math.cos(obj.rychange))); 10 v0t.up = obj.v0.up; 11 obj.v0 = v0t;

  物体在这一小段时间内可能绕y轴转过了一定角度,所以要把物体在上一时刻的自身坐标系速度投影到经过变化之后的自身坐标系中。

2、计算水平加速度,与水平位移

(obj.flag_standonground==1) { (obj.v0.forward == 0) { 6 obj.witha.forward = 0; 7 } (obj.v0.forward > 0) { 9 obj.witha.forward = -0.5; 10 } 11 else { 12 obj.witha.forward = 0.5; 13 } 14 if (obj.v0.left == 0) { 15 obj.witha.left = 0; 16 } (obj.v0.left > 0) { 18 obj.witha.left = -0.5; 19 } 20 else { 21 obj.witha.left = 0.5; 22 } obj.witha2.forward = obj.witha.forward+obj.witha0.forward; 25 obj.witha2.left = obj.witha.left+obj.witha0.left; (obj.keys.w != 0) { 29 obj.witha2.forward += 5; 30 } (obj.keys.s != 0) { 32 obj.witha2.forward -= 2; 33 } (obj.keys.a != 0 && obj.keys.d != 0) { } (obj.keys.a != 0) { 39 obj.witha2.left += 2; 40 } (obj.keys.d != 0) { 42 obj.witha2.left -= 2; 43 } 44 } { 47 obj.witha2.forward=0; 48 obj.witha2.left=0; 49 } (obj.witha2.forward!=0) 52 { ((0 < obj.vt.forward && obj.vt.forward < obj.vm.forward) || (0 > obj.vt.forward && obj.vt.forward > -obj.vm.backwards)) obj.mchange.forward = obj.witha2.forward * schange * schange + obj.v0.forward * schange; } (obj.vm.forward <= obj.vt.forward) {//超出最大速度则按最大速度算 59 obj.vt.forward = obj.vm.forward; 60 obj.mchange.forward = obj.vt.forward * schange; 61 } (-obj.vm.backwards >= obj.vt.forward) { 63 obj.vt.forward = -obj.vm.backwards; 64 obj.mchange.forward = obj.vt.forward * schange; 65 } 66 } 67 else {//无加速度时匀速运动 68 obj.mchange.forward = obj.v0.forward * schange; 69 } 70 if(obj.witha2.left!=0) 71 { ((0 < obj.vt.left && obj.vt.left < obj.vm.left) || (0 > obj.vt.left && obj.vt.left > -obj.vm.right)) obj.mchange.left = obj.witha2.left * schange * schange + obj.v0.left * schange; } (obj.vm.left <= obj.vt.left) { 78 obj.vt.left = obj.vm.left; 79 obj.mchange.left = obj.vt.left * schange; 80 } (-obj.vm.right >= obj.vt.left) { 82 obj.vt.left = -obj.vm.right; 83 obj.mchange.left = obj.vt.left * schange; 84 } 85 } 86 else { 87 obj.mchange.left = obj.v0.left * schange; 88 }

 3、计算垂直加速度、垂直位移:

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • HTML5 WebSocket - Roberter

    HTML5 WebSocket - Roberter

    2016-10-25 16:00

  • websocket初探 - 2778085001

    websocket初探 - 2778085001

    2016-07-16 15:11

  • DIV+CSS:如何编写代码才能更有效率 - 2778085001

    DIV+CSS:如何编写代码才能更有效率 - 2778085001

    2016-06-29 15:00

  • 用node实现websocket协议 - 2778085001

    用node实现websocket协议 - 2778085001

    2016-06-25 14:00

网友点评