Browse Source

feat: update

test pc 3 years ago
parent
commit
d60c97000c
4 changed files with 82 additions and 91 deletions
  1. 31 32
      src/move/move.service.ts
  2. 44 55
      src/rotate/rotate.service.ts
  3. 3 2
      src/scene/scene.service.ts
  4. 4 2
      src/scene/stream/stream.d.ts

+ 31 - 32
src/move/move.service.ts

@@ -882,17 +882,17 @@ export class MoveService implements OnModuleInit {
       const closestDis = 80; //小于这个距离就跳到邻居呼吸点
       const distance = step * dir_action.speed_level;
       let angle = null;
-      console.log(
-        'handlejoystick-angle->:dir_action.move_angle' + dir_action.move_angle,
-      );
+      // console.log(
+      //   'handlejoystick-angle->:dir_action.move_angle' + dir_action.move_angle,
+      // );
       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;
-      console.log(
-        'handlejoystick-angle->:叠加后move_angle(也是user.angle)' + move_angle,
-      );
+      // console.log(
+      //   'handlejoystick-angle->:叠加后move_angle(也是user.angle)' + move_angle,
+      // );
       //TODO 临时增加断言
       const playerPosition: Point = { x: 0, y: 0, z: 0 };
       playerPosition.x =
@@ -902,9 +902,9 @@ export class MoveService implements OnModuleInit {
         user.player.position.y +
         distance * Math.sin((move_angle / 360) * 2 * Math.PI);
 
-      const offsetX = playerPosition.x - user.player.position.x;
-      const offsetY = playerPosition.y - user.player.position.y;
-
+      // const offsetX = playerPosition.x - user.player.position.x;
+      // const offsetY = playerPosition.y - user.player.position.y;
+      console.log('handlejoysticktesttest:actionRequest-playerPosition'+JSON.stringify(playerPosition));
       //找到邻居点,判断user.player.position与邻居点的距离,如果距离小于closestDis,就要更新camera的position
       let chooseBreakPointId = null;
       const breakPoint = this.breakPointInfo[breakPointId];
@@ -956,10 +956,10 @@ export class MoveService implements OnModuleInit {
         playerPosition,
       );
 
-      const offsetBreakPosition = {
-        x: breakPoint.position.x + offsetX,
-        y: breakPoint.position.y + offsetY,
-      };
+      // const offsetBreakPosition = {
+      //   x: breakPoint.position.x + offsetX,
+      //   y: breakPoint.position.y + offsetY,
+      // };
       let closestNeighorId = null;
       let neighDis = null;
 
@@ -967,12 +967,12 @@ export class MoveService implements OnModuleInit {
       for (let i = 0; i < surroundPointIds.length; ++i) {
         const neighPoint = this.breakPointInfo[surroundPointIds[i]];
         if (closestNeighorId == null) {
-          neighDis = this.getDistance(offsetBreakPosition, neighPoint.position);
+          neighDis = this.getDistance(playerPosition, neighPoint.position);
           closestNeighorId = surroundPointIds[i];
         } else if (
-          neighDis > this.getDistance(offsetBreakPosition, neighPoint.position)
+          neighDis > this.getDistance(playerPosition, neighPoint.position)
         ) {
-          neighDis = this.getDistance(offsetBreakPosition, neighPoint.position);
+          neighDis = this.getDistance(playerPosition, neighPoint.position);
           closestNeighorId = surroundPointIds[i];
         }
 
@@ -1066,6 +1066,7 @@ export class MoveService implements OnModuleInit {
 
       //count == 2
       //超出范围了
+      console.log('handlejoysticktesttest:距离:'+JSON.stringify(playerPosition)+'->'+JSON.stringify(breakPoint.position)+':'+this.getDistance(playerPosition, breakPoint.position));
       if (this.getDistance(playerPosition, breakPoint.position) > closestDis) {
         // let offsetAngle1 = Math.abs(_angle - neighPoints[0].angle);
         // if (neighPoints[0].angle == 0) {
@@ -1095,7 +1096,6 @@ export class MoveService implements OnModuleInit {
           actionType,
         );
       } else {
-        user.player.position = JSON.parse(JSON.stringify(playerPosition));
         this.reply['newUserStates'][0].playerState.player.position = JSON.parse(
           JSON.stringify(user.player.position),
         );
@@ -1116,17 +1116,18 @@ export class MoveService implements OnModuleInit {
           user.camera.position = JSON.parse(
             JSON.stringify(cameraInfo.camera_position),
           );
-          console.log(
-            'handlejoystick-angle->:自由并过渡更新user.angle' +
-              cameraInfo.camera_angle.yaw,
-          );
+          // console.log(
+          //   'handlejoystick-angle->:自由并过渡更新user.angle' +
+          //     cameraInfo.camera_angle.yaw,
+          // );
           user.camera.angle.yaw = cameraInfo.camera_angle.yaw;
 
           this.sendingFrameForJoystick = true;
         } else {
-          console.log('joystick自由--->不合并');
+          //console.log('joystick自由--->不合并');
         }
         //console.log('handlejoysticktesttest:actionRequest-自由'+new Date().getTime());
+        console.log('handlejoysticktesttest:自由:'+this.reply.mediaSrc+'->'+JSON.stringify(user.player.position));
         return this.reply;
       }
     } catch (error) {
@@ -1214,10 +1215,10 @@ export class MoveService implements OnModuleInit {
     actionType,
   ) {
     const user = this.users[userId];
+    this.reply['newUserStates'][0].playerState.player.position = JSON.parse(
+      JSON.stringify(user.player.position),
+    );
     if (chooseBreakPointId == null) {
-      this.reply['newUserStates'][0].playerState.player.position = JSON.parse(
-        JSON.stringify(user.player.position),
-      );
       this.reply.actionResponses[0].actionType = actionType;
       return this.reply;
     }
@@ -1225,9 +1226,6 @@ export class MoveService implements OnModuleInit {
     //相机纠正加过渡
     else {
       if (chooseBreakPointId == user.breakPointId) {
-        this.reply['newUserStates'][0].playerState.player.position = JSON.parse(
-          JSON.stringify(user.player.position),
-        );
         return this.reply;
       }
 
@@ -1289,10 +1287,10 @@ export class MoveService implements OnModuleInit {
         user.camera.position = JSON.parse(
           JSON.stringify(cameraInfo.camera_position),
         );
-        console.log(
-          'handlejoystick-angle->:刚刚过渡更新user.angle' +
-            cameraInfo.camera_angle.yaw,
-        );
+        // console.log(
+        //   'handlejoystick-angle->:刚刚过渡更新user.angle' +
+        //     cameraInfo.camera_angle.yaw,
+        // );
         user.camera.angle.yaw = cameraInfo.camera_angle.yaw;
 
         if (cameraInfo.mediaSrc) {
@@ -1302,6 +1300,7 @@ export class MoveService implements OnModuleInit {
         this.sendingFrameForJoystick = true;
       }
       //console.log('handlejoysticktesttest:actionRequest-镜头过渡'+new Date().getTime());
+      console.log('handlejoysticktesttest:actionRequest-镜头过渡:从'+breakPointId+'到'+chooseBreakPointId+','+JSON.stringify(user.player.position));
       return this.reply;
     }
   }

+ 44 - 55
src/rotate/rotate.service.ts

@@ -162,28 +162,28 @@ export class RotateService {
         },
       ],
       actionResponses: [
-        // {
-        //     "actionType": 15,
-        //     "pointType": 100,
-        //     "extra": "",
-        //     "traceId": "d0864cd0-378d-4d49-b7b0-3e8e1b9494c3",
-        //     "packetId": "d44bd2f5-f877-4dd7-868b-803c64f99082",
-        //     "nps": [],
-        //     "peopleNum": 0,
-        //     "zoneId": "",
-        //     "echoMsg": "",
-        //     "reserveDetail": null,
-        //     "userWithAvatarList": [],
-        //     "newUserStates": [],
-        //     "code": 0,
-        //     "msg": ""
-        // }
+        {
+            // "actionType": 15,
+            // "pointType": 100,
+            "extra": "",
+            // "traceId": "d0864cd0-378d-4d49-b7b0-3e8e1b9494c3",
+            // "packetId": "d44bd2f5-f877-4dd7-868b-803c64f99082",
+            "nps": [],
+            "peopleNum": 0,
+            "zoneId": "",
+            "echoMsg": "",
+            "reserveDetail": null,
+            "userWithAvatarList": [],
+            "newUserStates": [],
+            "code": 0,
+            "msg": ""
+        }
       ],
       getStateType: 0,
       code: 0,
       msg: 'OK',
     };
-
+    
     reply['newUserStates'][0].playerState.player.position = JSON.parse(
       JSON.stringify(this.firstPoint.player.position),
     );
@@ -194,45 +194,34 @@ export class RotateService {
     return reply;
   }
 
-  //首帧
-  getFirstStreamData(appId, userId) {
-    const user = this.users[userId];
-    const reply = this.replies[userId];
-    reply.traceIds = [];
-    reply['newUserStates'][0].userId = userId;
-    reply['newUserStates'][0].playerState.player.position = JSON.parse(
-      JSON.stringify(this.firstPoint.player.position),
-    );
-    reply['newUserStates'][0].playerState.player.angle = JSON.parse(
-      JSON.stringify(this.firstPoint.player.angle),
-    );
-    reply['newUserStates'][0].playerState.camera.position = JSON.parse(
-      JSON.stringify(this.firstPoint.camera.position),
-    );
-    reply['newUserStates'][0].playerState.camera.angle = JSON.parse(
-      JSON.stringify(this.firstPoint.camera.angle),
-    );
-    reply['newUserStates'][0].playerState.cameraCenter = JSON.parse(
-      JSON.stringify(this.firstPoint.player.position),
-    );
-    reply['actionResponses'][0].traceId = null;
+//首帧
+getFirstStreamData(appId,userId){
+  const user = this.users[userId];
+  let reply = this.replies[userId];
+  reply.traceIds = [];
+  reply['newUserStates'][0].userId = userId;
+  reply['newUserStates'][0].playerState.player.position = JSON.parse(JSON.stringify(this.firstPoint.player.position));
+  reply['newUserStates'][0].playerState.player.angle = JSON.parse(JSON.stringify(this.firstPoint.player.angle));
+  reply['newUserStates'][0].playerState.camera.position = JSON.parse(JSON.stringify(this.firstPoint.camera.position));
+  reply['newUserStates'][0].playerState.camera.angle = JSON.parse(JSON.stringify(this.firstPoint.camera.angle));
+  reply['newUserStates'][0].playerState.cameraCenter = JSON.parse(JSON.stringify(this.firstPoint.player.position));
+  reply['actionResponses'][0].traceId = null;
 
-    reply.mediaSrc =
-      '/' +
-      appId +
-      '/' +
-      user.breakPointId +
-      '/' +
-      user.breakPointId +
-      '/' +
-      user.breakPointId +
-      '.0000.h264' +
-      '?m=' +
-      new Date().getTime();
-    reply['newUserStates'][0].renderInfo.isMoving = 0;
-    this.replies[userId] = reply;
-    return reply;
-  }
+  reply.mediaSrc =
+    '/' +
+    appId +
+    '/' +
+    user.breakPointId +
+    '/' +
+    user.breakPointId +
+    '/' +
+    user.breakPointId+'.0000.h264' +
+    '?m=' +
+    new Date().getTime();
+  reply['newUserStates'][0].renderInfo.isMoving = 0;
+  this.replies[userId] = reply;
+  return reply;
+}
 
   /**
    * delete User object

+ 3 - 2
src/scene/scene.service.ts

@@ -744,7 +744,8 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
   async handlePushJoyStickSteam(joystickRes: StreamReplyType) {
     this.holdSteam();
 
-    console.log('joystickRes有mediaSrc', joystickRes.mediaSrc);
+    //console.log('joystickRes有mediaSrc', joystickRes.mediaSrc);
+    console.log('handlejoystick-angle->相机角度-------------------------:'+joystickRes['newUserStates'][0].playerState.camera.angle.yaw);
     let streamData: StreamFrameType | StreamMetaType;
 
     // if (this.joystickFrameCnt === -1) {
@@ -789,7 +790,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
       }
       this.moveService.sendingFrameForJoystick = false;
       const data = joystickRes as StreamReplyType;
-      console.log('handlejoystick-moveOver:' + data.moveOver);
+      console.log('handlejoystick-joystickIDR:' + data.joystickIDR);
       // if (data?.moveOver && data.moveOver) {
       //   // moveOver
       //   console.log('回传updateUser', data);

+ 4 - 2
src/scene/stream/stream.d.ts

@@ -7,8 +7,7 @@ interface StreamFrameType {
   mediaSrc?: string; // 临时
   mType?: string;
   newUserStates?: NewUserStatesType[];
-  moveStart?: boolean;
-  moveOver?: boolean;
+  joystickIDR?: boolean;
 }
 interface StreamMetaType {
   frame: number;
@@ -83,8 +82,11 @@ interface StreamReplyType {
   breakPointId?: number; //临时记录存在的点()
   mType?: string; //类型
   DIR: ?number;
+<<<<<<< HEAD
   moveStart?: boolean;
   moveOver?: boolean;
+=======
+>>>>>>> master
   joystickIDR?: boolean;
 }