Forráskód Böngészése

add real simulation 1.0 by xyh

xyh 1 éve
szülő
commit
1bc3df9d48
1 módosított fájl, 90 hozzáadás és 11 törlés
  1. 90 11
      src/views/simulation/index.vue

+ 90 - 11
src/views/simulation/index.vue

@@ -67,6 +67,8 @@ export default {
       situation: [],
       nameIdList: [],
       satelliteRange: [],
+      missileList:{},
+      thaadList:{},
       websocket: null,
       leftwidth: 12,
       unit: [],
@@ -534,10 +536,19 @@ export default {
       if (type == 'red') {
         color = 'Red'
         modelUrl = missileModel
+        this.missileList[name] = {
+          disturb: 20,
+          id: this.id
+        }
       }
       else if (type == 'blue') {
         color = 'Blue'
         modelUrl = radarModel
+        this.thaadList[name] = {
+          range: 1000000.0,
+          health: 100.0,
+          id: this.id
+        }
       }
       else if (type == 'center') {
         color = 'Blue'
@@ -549,7 +560,7 @@ export default {
       }
       if (type == 'blue') {
         console.log(' radar!!!');
-        const range = 100000;
+        const range = 1000000;
         this.$data._viewer2D.entities.add({
           id: this.id,
           position: position,
@@ -578,14 +589,6 @@ export default {
         this.$data._viewer3D.entities.add({
           id: this.id,
           position: position,
-          //         cylinder: {
-          //   length: range * 2,
-          //   topRadius: 0,
-          //   bottomRadius: range,
-          //   material: this.Cesium.Color.RED.withAlpha(0.5), // 设置锥体的颜色和透明度
-          //   outline: true,
-          //   outlineColor: this.Cesium.Color.RED,
-          // },
           ellipsoid: {
             radii: new this.Cesium.Cartesian3(range, range, range),
             material: this.Cesium.Color.GREEN.withAlpha(0.5), // 设置球体的颜色和透明度
@@ -613,6 +616,7 @@ export default {
           name: name
         })
         this.id++;
+
       }
       else {
         this.$data._viewer2D.entities.add({
@@ -921,6 +925,22 @@ export default {
               this.modelEntityMoveByIDAndLocation(this.$data._viewer2D, this.nameIdList[i].id, data[this.nameIdList[i].name].x, data[this.nameIdList[i].name].y, data[this.nameIdList[i].name].z)
             }
           }
+          for(let i = 0; i < this.nameIdList.length; i++) {
+            if (this.thaadList[this.nameIdList[i].name] != null || this.thaadList[this.nameIdList[i].name] != undefined){
+              //查看在雷达原侦察范围内有几颗导弹
+              let missileNum = this.howManyMissile(this.$data._viewer2D,this.thaadList[this.nameIdList[i].name].id,this.nameIdList[i].name)
+              let health = 100.0
+              for(let j=0;j<missileNum;j++){
+                health = health*0.8
+              }
+              if(this.thaadList[this.nameIdList[i].name].health != health){
+                //修改健康值并修改范围
+                this.thaadList[this.nameIdList[i].name].health = health
+                this.changeRange(this.$data._viewer2D,this.thaadList[this.nameIdList[i].name].id,this.thaadList[this.nameIdList[i].name].range,this.thaadList[this.nameIdList[i].name].health)
+              }
+            }
+          }
+          this.judgeMissile(this.$data._viewer2D);
           //更新模型位置
           // this.modelEntityMoveByIDAndLocation(this.$data._viewer2D,"1654426964397658112",res.data[1].data.W1.x,res.data[1].data.W1.y,res.data[1].data.W1.z)
         })
@@ -944,10 +964,28 @@ export default {
               this.modelEntityMoveByIDAndLocation(this.$data._viewer3D, this.nameIdList[i].id, data[this.nameIdList[i].name].x, data[this.nameIdList[i].name].y, data[this.nameIdList[i].name].z)
             }
           }
+          for(let i = 0; i < this.nameIdList.length; i++) {
+            if (this.thaadList[this.nameIdList[i].name] != null || this.thaadList[this.nameIdList[i].name] != undefined){
+              //查看在雷达原侦察范围内有几颗导弹
+              let missileNum = this.howManyMissile(this.$data._viewer3D,this.thaadList[this.nameIdList[i].name].id,this.nameIdList[i].name)
+              let health = 100.0
+              //变化健康值
+              for(let j=0;j<missileNum;j++){
+                health = health*0.8
+              }
+              if(this.thaadList[this.nameIdList[i].name].health != health){
+                //修改健康值并修改范围
+                this.thaadList[this.nameIdList[i].name].health = health
+                this.changeRange(this.$data._viewer3D,this.thaadList[this.nameIdList[i].name].id,this.thaadList[this.nameIdList[i].name].range,this.thaadList[this.nameIdList[i].name].health)
+              }
+              
+            }
+          }
+          //判断是否有导弹被拦截
+          this.judgeMissile(this.$data._viewer3D);
           //更新模型位置
           //  this.modelEntityMoveByIDAndLocation(this.$data._viewer3D,viewer,"1654426964397658112",res.data[1].data.W1.x,res.data[1].data.W1.y,res.data[1].data.W1.z)  
         })
-
     },
     // 根据模型实体Id和终点位置进行移动
     modelEntityMoveByIDAndLocation(viewer, id, x, y, z) {
@@ -970,7 +1008,7 @@ export default {
           entity.position.setValue(position)
           //设置方向,根据实体的位置来配置方向
           rangeEntity.orientation = new this.Cesium.VelocityOrientationProperty(rangeEntity.position);
-          //设置实体位置
+          //设置实体位置getValue
           rangeEntity.position.setValue(cylinderposition)
           this.markSatelliteLine(oldPosition, position, 'Blue', viewer)
         }
@@ -983,7 +1021,48 @@ export default {
       //设置实体位置
       entity.position.setValue(position)
       this.markSatelliteLine(oldPosition, position, 'Blue', viewer)
+    },
+    //计算有多少个导弹进入了雷达的原始范围
+    howManyMissile(viewer,id,name){
+      let radar = viewer.entities.getById(id)
+      let radarPos = radar.position._value
+      let num = 0
+      for(let key in this.missileList){
+        let missilePos = viewer.entities.getById(this.missileList[key].id).position._value
+        if(this.Cesium.Cartesian3.distance(radarPos,missilePos)<=this.thaadList[name].range){//距离小于range
+          num++
+        }
+      }
+      return num;
+    },
+    //判断导弹是否被拦截
+    judgeMissile(viewer){
+      for(let key in this.missileList){
+        let missile = viewer.entities.getById(this.missileList[key].id)
+        let missilePos = viewer.entities.getById(this.missileList[key].id).position._value
+        for(let item in this.thaadList){
+          let radarPos = viewer.entities.getById(this.thaadList[item].id).position._value
+          console.log(key+'和'+item+'的距离:   ', this.Cesium.Cartesian3.distance(radarPos,missilePos));
+          console.log('this.thaadList[item].range*this.thaadList[item].health :>> ', this.thaadList[item].range*this.thaadList[item].health);
+          if(this.Cesium.Cartesian3.distance(radarPos,missilePos)<=this.thaadList[item].range*this.thaadList[item].health*0.01){
+            // 导弹进入了被干扰后的雷达探测范围,判断被拦截 移除实体,删除信息
+            console.log('导弹'+key+'被雷达'+item+'拦截!!!');
+            viewer.entities.remove(missile)
+            this.nameIdList = this.nameIdList.filter(item => item.id !== this.missileList[key].id);
+            delete this.missileList[key]
+            break
+          }
+        }
+      }
+    },
+    //修改雷达的显示范围
+    changeRange(viewer,id,range,health){
+      console.log('修改雷达'+id+'的范围!!!');
+      let radar = viewer.entities.getById(id)
+      let newRange = range*health*0.01
+      radar.ellipsoid.radii = new this.Cesium.Cartesian3(newRange, newRange, newRange);
     }
+
   }
 };
 </script>