test pc 3 years ago
parent
commit
2355daf061
2 changed files with 239 additions and 240 deletions
  1. 8 3
      src/get-router/get-router.service.ts
  2. 231 237
      src/move/move.service.ts

+ 8 - 3
src/get-router/get-router.service.ts

@@ -58,9 +58,9 @@ export class GetRouterService implements OnModuleInit {
       for (const key in this.breakPointInfo) {
         //const breakPointRes = await this.cacheService.get(keys[i]);
         //const breakPoint = JSON.parse(breakPointRes);
-        if (Number(key) == startPointId) {
-          continue;
-        }
+        // if (Number(key) == startPointId) {
+        //   continue;
+        // }
         //const position = breakPoint.position;
         const breakPoint = this.breakPointInfo[key];
         if (minDis == null) {
@@ -80,6 +80,11 @@ export class GetRouterService implements OnModuleInit {
         return null;
       }
 
+      if(startPointId == endPoint.breakPointId){
+        console.log('点击的点和当前点是同一个点')
+        return null;
+      }
+
       // const startPointRes = await this.cacheService.get(
       //   'breakpoints:app_id:' + appId + ':break_point_id:' + startPointId,
       // );

+ 231 - 237
src/move/move.service.ts

@@ -214,9 +214,6 @@ export class MoveService implements OnModuleInit {
     end_break_point_id,
     angleIndex,
   ) {
-    if (angleIndex < 0) {
-      debugger;
-    }
 
     let moveFramesRes, moveFrames;
     let key =
@@ -256,7 +253,6 @@ export class MoveService implements OnModuleInit {
       const traceId = actionRequest['trace_id'];
       const actionType = actionRequest['action_type'];
       const user = this.users[userId];
-
       const appId = user.appId;
       const path = pathArray || [100, 101, 102]; //需要计算路径
       const angle = user.camera.angle.yaw % 45; //纠正需要
@@ -868,274 +864,272 @@ export class MoveService implements OnModuleInit {
   // }
 
   async joystick(actionRequest) {
-    //try {
-
-    if (this.sendingFrameForJoystick) {
-      return null;
-    }
-    
-    const userId = actionRequest['user_id'];
-    const traceId = actionRequest['trace_id'];
-    const dir_action = actionRequest['dir_action'];
-    const actionType = actionRequest['action_type'];
-    const user = this.users[userId];
-    const breakPointId = user.breakPointId;
-    const appId = user.appId;
-    //const step = 0.3;
-    const step = 0.8;
-    const closestDis = 80; //小于这个距离就跳到邻居呼吸点
-    const distance = step * dir_action.speed_level;
-    let angle = null;
-    if(dir_action.move_angle<0 || user.camera.angle.yaw<0){
-      debugger;
-    }
-
-    let move_angle = dir_action.move_angle + user.camera.angle.yaw;
-    move_angle = move_angle % 360;
-
-    //TODO 临时增加断言
-    const playerPosition: Point = { x: 0, y: 0, z: 0 };
-    playerPosition.x =
-      user.player.position.x +
-      distance * Math.cos((move_angle / 360) * 2 * Math.PI);
-    playerPosition.y =
-      user.player.position.y +
-      distance * Math.sin((move_angle / 360) * 2 * Math.PI);
-
-    //找到邻居点,判断user.player.position与邻居点的距离,如果距离小于closestDis,就要更新camera的position
-    let chooseBreakPointId = null;
-    const breakPoint = this.breakPointInfo[breakPointId];
-    const surroundPointIds = breakPoint.contact;
-    const traceIds = [];
-
-    user.player.angle.yaw = move_angle;
-    traceIds.push(traceId);
-    this.reply.traceIds = traceIds;
-    this.reply['newUserStates'][0].userId = userId;
-    this.reply['actionResponses'][0].traceId = traceId;
-    this.reply['newUserStates'][0].playerState.player.angle.yaw = move_angle;
+    try {
 
-    this.reply['newUserStates'][0].playerState.camera.angle = JSON.parse(
-      JSON.stringify(user.camera.angle),
-    );
-    this.reply['newUserStates'][0].playerState.camera.position = JSON.parse(
-      JSON.stringify(user.camera.position),
-    );
-    this.reply['newUserStates'][0].playerState.cameraCenter = JSON.parse(
-      JSON.stringify(breakPoint.position),
-    );
-    this.reply['newUserStates'][0].renderInfo.isMoving = 1;
-    this.reply['actionResponses'][0].traceId = traceId;
-    this.reply.mediaSrc = null;
+      if (this.sendingFrameForJoystick) {
+        return null;
+      }
+      
+      const userId = actionRequest['user_id'];
+      const traceId = actionRequest['trace_id'];
+      const dir_action = actionRequest['dir_action'];
+      const actionType = actionRequest['action_type'];
+      const user = this.users[userId];
+      const breakPointId = user.breakPointId;
+      const appId = user.appId;
+      //const step = 0.3;
+      const step = 0.8;
+      const closestDis = 80; //小于这个距离就跳到邻居呼吸点
+      const distance = step * dir_action.speed_level;
+      let angle = null;
+      if(user.camera.angle.yaw<0){
+        user.camera.angle.yaw = 360 + user.camera.angle.yaw;
+      }
+      let move_angle = dir_action.move_angle + user.camera.angle.yaw;
+      move_angle = move_angle % 360;
+
+      //TODO 临时增加断言
+      const playerPosition: Point = { x: 0, y: 0, z: 0 };
+      playerPosition.x =
+        user.player.position.x +
+        distance * Math.cos((move_angle / 360) * 2 * Math.PI);
+      playerPosition.y =
+        user.player.position.y +
+        distance * Math.sin((move_angle / 360) * 2 * Math.PI);
+
+      //找到邻居点,判断user.player.position与邻居点的距离,如果距离小于closestDis,就要更新camera的position
+      let chooseBreakPointId = null;
+      const breakPoint = this.breakPointInfo[breakPointId];
+      const surroundPointIds = breakPoint.contact;
+      const traceIds = [];
 
-    console.log('joystickjoystick:' + this.cameraInfos.length);
+      user.player.angle.yaw = move_angle;
+      traceIds.push(traceId);
+      this.reply.traceIds = traceIds;
+      this.reply['newUserStates'][0].userId = userId;
+      this.reply['actionResponses'][0].traceId = traceId;
+      this.reply['newUserStates'][0].playerState.player.angle.yaw = move_angle;
 
-    if (surroundPointIds.length == 1) {
-      // console.log(
-      //   'joystick校验--->' + breakPointId + '-' + surroundPointIds[0],
-      // );
-      console.log('handlejoysticktesttest:actionRequest-笔直'+new Date().getTime());
-      return await this.moveDirect(
-        playerPosition,
-        closestDis,
-        breakPointId,
-        surroundPointIds[0],
-        appId,
-        userId,
-        traceId,
-        actionType,
+      this.reply['newUserStates'][0].playerState.camera.angle = JSON.parse(
+        JSON.stringify(user.camera.angle),
       );
-    }
-
-    let count = 0;
-    const neighPoints = [];
-    //人在哪个角度
-    const _angle = this.getAngle(
-      breakPoint.position,
-      { x: breakPoint.position.x + 1, y: breakPoint.position.y },
-      playerPosition,
-    );
-
-    let singleInfo = null;
-    for (let i = 0; i < surroundPointIds.length; ++i) {
-      const neighPoint = this.breakPointInfo[surroundPointIds[i]];
-      neighPoint.breakPointId = surroundPointIds[i];
-      angle = this.getAngle(
-        breakPoint.position,
-        { x: breakPoint.position.x + 1, y: breakPoint.position.y },
-        neighPoint.position,
+      this.reply['newUserStates'][0].playerState.camera.position = JSON.parse(
+        JSON.stringify(user.camera.position),
       );
+      this.reply['newUserStates'][0].playerState.cameraCenter = JSON.parse(
+        JSON.stringify(breakPoint.position),
+      );
+      this.reply['newUserStates'][0].renderInfo.isMoving = 1;
+      this.reply['actionResponses'][0].traceId = traceId;
+      this.reply.mediaSrc = null;
 
-      //if(angle<45&&angle!=0){
-      if (
-        // Math.abs(angle - move_angle) < 45 &&
-        // Math.abs(angle - move_angle) != 0
-        Math.abs(angle - _angle) < 45 &&
-        Math.abs(angle - _angle) != 0
-      ) {
-        neighPoint.angle = angle;
-        neighPoints.push(neighPoint);
-        ++count;
-      } else if (Math.abs(angle - move_angle) == 0) {
-        neighPoint.angle = angle;
-        neighPoints.push(neighPoint);
-        ++count;
-        //console.log('handlejoysticktesttest:45°的倍数');
-        //debugger;
-        break;
-
-        // console.log(
-        //   'joystick直走--->' + breakPointId + '-' + surroundPointIds[i],
-        // );
-        // return await this.moveDirect(
-        //   playerPosition,
-        //   closestDis,
-        //   breakPointId,
-        //   surroundPointIds[i],
-        //   appId,
-        //   userId,
-        //   traceId,
-        //   actionType,
-        // );
-      }
-
-      //if (angle == 0 && Math.abs(360 - move_angle) < 45) {
-      if (angle == 0 && Math.abs(360 - _angle) < 45) {
-        neighPoint.angle = angle;
-        neighPoints.push(neighPoint);
-        ++count;
-      }
-
-      if (
-        Math.abs(angle - move_angle) < 45 ||
-        Math.abs(angle + 360 - move_angle) < 45
-      ) {
-        if (singleInfo == null) {
-          singleInfo = {
-            angle: angle,
-            breakPointId: surroundPointIds[i],
-          };
-        }
-      }
-    }
+      console.log('joystickjoystick:' + this.cameraInfos.length);
 
-    if (count == 2) {
-      //人物移动
-      user.player.position = JSON.parse(JSON.stringify(playerPosition));
-      this.reply['newUserStates'][0].playerState.player.position = JSON.parse(
-        JSON.stringify(playerPosition),
-      );
-    } else {
-      if (singleInfo != null) {
+      if (surroundPointIds.length == 1) {
         // console.log(
-        //   'joystick校验--->' + breakPointId + '-' + singleInfo.breakPointId,
+        //   'joystick校验--->' + breakPointId + '-' + surroundPointIds[0],
         // );
-        //console.log('handlejoysticktesttest校验0角度:'+_angle+','+move_angle)       //这个没办法,得换方案
         console.log('handlejoysticktesttest:actionRequest-笔直'+new Date().getTime());
         return await this.moveDirect(
           playerPosition,
           closestDis,
           breakPointId,
-          singleInfo.breakPointId,
+          surroundPointIds[0],
           appId,
           userId,
           traceId,
           actionType,
         );
-      } else if (count == 1) {
+      }
+
+      let count = 0;
+      const neighPoints = [];
+      //人在哪个角度
+      const _angle = this.getAngle(
+        breakPoint.position,
+        { x: breakPoint.position.x + 1, y: breakPoint.position.y },
+        playerPosition,
+      );
+
+      let singleInfo = null;
+      for (let i = 0; i < surroundPointIds.length; ++i) {
+        const neighPoint = this.breakPointInfo[surroundPointIds[i]];
+        neighPoint.breakPointId = surroundPointIds[i];
+        angle = this.getAngle(
+          breakPoint.position,
+          { x: breakPoint.position.x + 1, y: breakPoint.position.y },
+          neighPoint.position,
+        );
+
+        //if(angle<45&&angle!=0){
+        if (
+          // Math.abs(angle - move_angle) < 45 &&
+          // Math.abs(angle - move_angle) != 0
+          Math.abs(angle - _angle) < 45 &&
+          Math.abs(angle - _angle) != 0
+        ) {
+          neighPoint.angle = angle;
+          neighPoints.push(neighPoint);
+          ++count;
+        } else if (Math.abs(angle - move_angle) == 0) {
+          neighPoint.angle = angle;
+          neighPoints.push(neighPoint);
+          ++count;
+          //console.log('handlejoysticktesttest:45°的倍数');
+          //debugger;
+          break;
+
+          // console.log(
+          //   'joystick直走--->' + breakPointId + '-' + surroundPointIds[i],
+          // );
+          // return await this.moveDirect(
+          //   playerPosition,
+          //   closestDis,
+          //   breakPointId,
+          //   surroundPointIds[i],
+          //   appId,
+          //   userId,
+          //   traceId,
+          //   actionType,
+          // );
+        }
+
+        //if (angle == 0 && Math.abs(360 - move_angle) < 45) {
+        if (angle == 0 && Math.abs(360 - _angle) < 45) {
+          neighPoint.angle = angle;
+          neighPoints.push(neighPoint);
+          ++count;
+        }
+
+        if (
+          Math.abs(angle - move_angle) < 45 ||
+          Math.abs(angle + 360 - move_angle) < 45
+        ) {
+          if (singleInfo == null) {
+            singleInfo = {
+              angle: angle,
+              breakPointId: surroundPointIds[i],
+            };
+          }
+        }
+      }
+
+      if (count == 2) {
+        //人物移动
+        user.player.position = JSON.parse(JSON.stringify(playerPosition));
+        this.reply['newUserStates'][0].playerState.player.position = JSON.parse(
+          JSON.stringify(playerPosition),
+        );
+      } else {
+        if (singleInfo != null) {
+          // console.log(
+          //   'joystick校验--->' + breakPointId + '-' + singleInfo.breakPointId,
+          // );
+          //console.log('handlejoysticktesttest校验0角度:'+_angle+','+move_angle)       //这个没办法,得换方案
+          console.log('handlejoysticktesttest:actionRequest-笔直'+new Date().getTime());
+          return await this.moveDirect(
+            playerPosition,
+            closestDis,
+            breakPointId,
+            singleInfo.breakPointId,
+            appId,
+            userId,
+            traceId,
+            actionType,
+          );
+        } else if (count == 1) {
+          // console.log(
+          //   'joystick校验--->' + breakPointId + '-' + neighPoints[0].breakPointId,
+          // );
+          console.log('handlejoysticktesttest:actionRequest-笔直'+new Date().getTime());
+          return await this.moveDirect(
+            playerPosition,
+            closestDis,
+            breakPointId,
+            neighPoints[0].breakPointId,
+            appId,
+            userId,
+            traceId,
+            actionType,
+          );
+        } else if (count == 0) {
+          this.reply['newUserStates'][0].playerState.player.position = JSON.parse(
+            JSON.stringify(user.player.position),
+          );
+          this.reply.actionResponses[0].actionType = actionType;
+          console.log('handlejoysticktesttest:actionRequest-停止'+new Date().getTime());
+          return this.reply;
+        }
+      }
+
+      //count == 2
+      //超出范围了
+      if (this.getDistance(playerPosition, breakPoint.position) > closestDis) {
+        let offsetAngle1 = Math.abs(_angle - neighPoints[0].angle);
+        if (neighPoints[0].angle == 0) {
+          offsetAngle1 = Math.min(offsetAngle1, Math.abs(_angle - 360));
+        }
+
+        let offsetAngle2 = Math.abs(_angle - neighPoints[1].angle);
+        if (neighPoints[1].angle == 0) {
+          offsetAngle2 = Math.min(offsetAngle2, Math.abs(_angle - 360));
+        }
+
+        if (offsetAngle1 > offsetAngle2) {
+          chooseBreakPointId = neighPoints[1].breakPointId;
+        } else {
+          chooseBreakPointId = neighPoints[0].breakPointId;
+        }
         // console.log(
-        //   'joystick校验--->' + breakPointId + '-' + neighPoints[0].breakPointId,
+        //   'joystick镜头过渡--->' + breakPointId + '-' + chooseBreakPointId,
         // );
-        console.log('handlejoysticktesttest:actionRequest-笔直'+new Date().getTime());
-        return await this.moveDirect(
-          playerPosition,
-          closestDis,
+        //this.reply.moveOver = true;
+        return await this.moveCamera(
           breakPointId,
-          neighPoints[0].breakPointId,
+          chooseBreakPointId,
           appId,
           userId,
           traceId,
           actionType,
         );
-      } else if (count == 0) {
+      } else {
+        user.player.position = JSON.parse(JSON.stringify(playerPosition));
         this.reply['newUserStates'][0].playerState.player.position = JSON.parse(
           JSON.stringify(user.player.position),
         );
         this.reply.actionResponses[0].actionType = actionType;
-        console.log('handlejoysticktesttest:actionRequest-停止'+new Date().getTime());
+        const cameraInfo = this.getCameraInfo();
+        if (cameraInfo != null) {
+          console.log('joystick自由--->合并');
+          this.reply['newUserStates'][0].playerState.camera.position =
+            cameraInfo.camera_position;
+          this.reply['newUserStates'][0].playerState.camera.angle =
+            cameraInfo.camera_angle;
+
+          if (cameraInfo.mediaSrc) {
+            this.reply.mediaSrc = cameraInfo.mediaSrc;
+          }
+          // if (this.cameraInfos.length == 0) {
+          //   this.reply.moveOver = true;
+          // }
+
+          user.camera.position = JSON.parse(
+            JSON.stringify(cameraInfo.camera_position),
+          );
+          user.camera.angle.yaw = cameraInfo.camera_angle.yaw;
+
+          this.sendingFrameForJoystick = true;
+        } else {
+          console.log('joystick自由--->不合并');
+        }
+        console.log('handlejoysticktesttest:actionRequest-自由'+new Date().getTime());
         return this.reply;
       }
     }
-
-    //count == 2
-    //超出范围了
-    if (this.getDistance(playerPosition, breakPoint.position) > closestDis) {
-      let offsetAngle1 = Math.abs(_angle - neighPoints[0].angle);
-      if (neighPoints[0].angle == 0) {
-        offsetAngle1 = Math.min(offsetAngle1, Math.abs(_angle - 360));
-      }
-
-      let offsetAngle2 = Math.abs(_angle - neighPoints[1].angle);
-      if (neighPoints[1].angle == 0) {
-        offsetAngle2 = Math.min(offsetAngle2, Math.abs(_angle - 360));
-      }
-
-      if (offsetAngle1 > offsetAngle2) {
-        chooseBreakPointId = neighPoints[1].breakPointId;
-      } else {
-        chooseBreakPointId = neighPoints[0].breakPointId;
-      }
-      // console.log(
-      //   'joystick镜头过渡--->' + breakPointId + '-' + chooseBreakPointId,
-      // );
-      //this.reply.moveOver = true;
-      return await this.moveCamera(
-        breakPointId,
-        chooseBreakPointId,
-        appId,
-        userId,
-        traceId,
-        actionType,
-      );
-    } else {
-      user.player.position = JSON.parse(JSON.stringify(playerPosition));
-      this.reply['newUserStates'][0].playerState.player.position = JSON.parse(
-        JSON.stringify(user.player.position),
-      );
-      this.reply.actionResponses[0].actionType = actionType;
-      const cameraInfo = this.getCameraInfo();
-      if (cameraInfo != null) {
-        console.log('joystick自由--->合并');
-        this.reply['newUserStates'][0].playerState.camera.position =
-          cameraInfo.camera_position;
-        this.reply['newUserStates'][0].playerState.camera.angle =
-          cameraInfo.camera_angle;
-
-        if (cameraInfo.mediaSrc) {
-          this.reply.mediaSrc = cameraInfo.mediaSrc;
-        }
-        // if (this.cameraInfos.length == 0) {
-        //   this.reply.moveOver = true;
-        // }
-
-        user.camera.position = JSON.parse(
-          JSON.stringify(cameraInfo.camera_position),
-        );
-        user.camera.angle.yaw = cameraInfo.camera_angle.yaw;
-
-        this.sendingFrameForJoystick = true;
-      } else {
-        console.log('joystick自由--->不合并');
-      }
-      console.log('handlejoysticktesttest:actionRequest-自由'+new Date().getTime());
-      return this.reply;
+    catch (error) {
+      console.log('MoveService', error);
+      return null;
     }
-    // }
-    // catch (error) {
-    //   console.log('MoveService', error);
-    //   debugger;
-    //   return null;
-    // }
   }
 
   //沿着最合适的neighBreakPointId走