model move( 三 )


【model move】监听帧
view.clock.onTick.addEventListener((clock)=>{if(flag.moveUp){if(flag.moveLeft){hpRoll.heading -= radian;}if(flag.moveRight){hpRoll.heading += radian;}moveCar(true);}if(flag.moveDown){if(flag.moveLeft){hpRoll.heading -= radian;}if(flag.moveRight){hpRoll.heading += radian;}moveCar(false);}});// 移动小车function moveCar(isUP) {// 计算速度矩阵if(isUP>0){speedVector = Cesium.Cartesian3.multiplyByScalar(Cesium.Cartesian3.UNIT_X,speed,speedVector);}else{speedVector = Cesium.Cartesian3.multiplyByScalar(Cesium.Cartesian3.UNIT_X,-speed,speedVector);}// 根据速度计算出下一个位置的坐标position = Cesium.Matrix4.multiplyByPoint(carPrimitive.modelMatrix ,speedVector, position);// 小车移动Cesium.Transforms.headingPitchRollToFixedFrame(position, hpRoll, Cesium.Ellipsoid.WGS84, fixedFrameTransforms, carPrimitive.modelMatrix);}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39

完整代码