|
@@ -48,8 +48,7 @@ export class MoveService implements OnModuleInit {
|
|
|
traceIds: [],
|
|
|
vehicle: null,
|
|
|
mediaSrc: null,
|
|
|
- //moveOver: false,
|
|
|
- moveStart: false,
|
|
|
+ joystickIDR: false,
|
|
|
newUserStates: [
|
|
|
{
|
|
|
userId: 'dcff36ae4fc1d',
|
|
@@ -214,6 +213,10 @@ export class MoveService implements OnModuleInit {
|
|
|
end_break_point_id,
|
|
|
angleIndex,
|
|
|
) {
|
|
|
+ console.log(
|
|
|
+ 'handlejoystick-angle->相机过渡angleIndex-------------------------:' +
|
|
|
+ angleIndex,
|
|
|
+ );
|
|
|
let moveFramesRes, moveFrames;
|
|
|
let key =
|
|
|
'moveframe:app_id:' +
|
|
@@ -521,7 +524,6 @@ export class MoveService implements OnModuleInit {
|
|
|
updateUser(userId, breakPointId, lastReply) {
|
|
|
const user = this.users[userId];
|
|
|
user.breakPointId = breakPointId;
|
|
|
- console.log('handlejoystick:updateUser');
|
|
|
if (lastReply.actionResponses[0].actionType != 15) {
|
|
|
user.player.position =
|
|
|
lastReply['newUserStates'][0].playerState.player.position;
|
|
@@ -880,12 +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,
|
|
|
+ );
|
|
|
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,
|
|
|
+ );
|
|
|
//TODO 临时增加断言
|
|
|
const playerPosition: Point = { x: 0, y: 0, z: 0 };
|
|
|
playerPosition.x =
|
|
@@ -895,6 +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;
|
|
|
+
|
|
|
//找到邻居点,判断user.player.position与邻居点的距离,如果距离小于closestDis,就要更新camera的position
|
|
|
let chooseBreakPointId = null;
|
|
|
const breakPoint = this.breakPointInfo[breakPointId];
|
|
@@ -924,12 +934,7 @@ export class MoveService implements OnModuleInit {
|
|
|
console.log('joystickjoystick:' + this.cameraInfos.length);
|
|
|
|
|
|
if (surroundPointIds.length == 1) {
|
|
|
- // console.log(
|
|
|
- // 'joystick校验--->' + breakPointId + '-' + surroundPointIds[0],
|
|
|
- // );
|
|
|
- console.log(
|
|
|
- 'handlejoysticktesttest:actionRequest-笔直' + new Date().getTime(),
|
|
|
- );
|
|
|
+ //console.log('handlejoysticktesttest:actionRequest-笔直'+new Date().getTime());
|
|
|
return await this.moveDirect(
|
|
|
playerPosition,
|
|
|
closestDis,
|
|
@@ -951,9 +956,26 @@ export class MoveService implements OnModuleInit {
|
|
|
playerPosition,
|
|
|
);
|
|
|
|
|
|
+ const offsetBreakPosition = {
|
|
|
+ x: breakPoint.position.x + offsetX,
|
|
|
+ y: breakPoint.position.y + offsetY,
|
|
|
+ };
|
|
|
+ let closestNeighorId = null;
|
|
|
+ let neighDis = null;
|
|
|
+
|
|
|
let singleInfo = null;
|
|
|
for (let i = 0; i < surroundPointIds.length; ++i) {
|
|
|
const neighPoint = this.breakPointInfo[surroundPointIds[i]];
|
|
|
+ if (closestNeighorId == null) {
|
|
|
+ neighDis = this.getDistance(offsetBreakPosition, neighPoint.position);
|
|
|
+ closestNeighorId = surroundPointIds[i];
|
|
|
+ } else if (
|
|
|
+ neighDis > this.getDistance(offsetBreakPosition, neighPoint.position)
|
|
|
+ ) {
|
|
|
+ neighDis = this.getDistance(offsetBreakPosition, neighPoint.position);
|
|
|
+ closestNeighorId = surroundPointIds[i];
|
|
|
+ }
|
|
|
+
|
|
|
neighPoint.breakPointId = surroundPointIds[i];
|
|
|
angle = this.getAngle(
|
|
|
breakPoint.position,
|
|
@@ -975,23 +997,7 @@ export class MoveService implements OnModuleInit {
|
|
|
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) {
|
|
@@ -1026,9 +1032,7 @@ export class MoveService implements OnModuleInit {
|
|
|
// 'joystick校验--->' + breakPointId + '-' + singleInfo.breakPointId,
|
|
|
// );
|
|
|
//console.log('handlejoysticktesttest校验0角度:'+_angle+','+move_angle) //这个没办法,得换方案
|
|
|
- console.log(
|
|
|
- 'handlejoysticktesttest:actionRequest-笔直' + new Date().getTime(),
|
|
|
- );
|
|
|
+ //console.log('handlejoysticktesttest:actionRequest-笔直'+new Date().getTime());
|
|
|
return await this.moveDirect(
|
|
|
playerPosition,
|
|
|
closestDis,
|
|
@@ -1040,12 +1044,7 @@ export class MoveService implements OnModuleInit {
|
|
|
actionType,
|
|
|
);
|
|
|
} else if (count == 1) {
|
|
|
- // console.log(
|
|
|
- // 'joystick校验--->' + breakPointId + '-' + neighPoints[0].breakPointId,
|
|
|
- // );
|
|
|
- console.log(
|
|
|
- 'handlejoysticktesttest:actionRequest-笔直' + new Date().getTime(),
|
|
|
- );
|
|
|
+ //console.log('handlejoysticktesttest:actionRequest-笔直'+new Date().getTime());
|
|
|
return await this.moveDirect(
|
|
|
playerPosition,
|
|
|
closestDis,
|
|
@@ -1060,9 +1059,7 @@ export class MoveService implements OnModuleInit {
|
|
|
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(),
|
|
|
- );
|
|
|
+ //console.log('handlejoysticktesttest:actionRequest-停止'+new Date().getTime());
|
|
|
return this.reply;
|
|
|
}
|
|
|
}
|
|
@@ -1070,25 +1067,25 @@ export class MoveService implements OnModuleInit {
|
|
|
//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 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));
|
|
|
- }
|
|
|
+ // 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;
|
|
|
+ // if (offsetAngle1 > offsetAngle2) {
|
|
|
+ // chooseBreakPointId = neighPoints[1].breakPointId;
|
|
|
+ // } else {
|
|
|
+ // chooseBreakPointId = neighPoints[0].breakPointId;
|
|
|
+ // }
|
|
|
+ if (closestNeighorId == null) {
|
|
|
+ debugger;
|
|
|
}
|
|
|
- // console.log(
|
|
|
- // 'joystick镜头过渡--->' + breakPointId + '-' + chooseBreakPointId,
|
|
|
- // );
|
|
|
- //this.reply.moveOver = true;
|
|
|
+ chooseBreakPointId = closestNeighorId;
|
|
|
return await this.moveCamera(
|
|
|
breakPointId,
|
|
|
chooseBreakPointId,
|
|
@@ -1113,28 +1110,23 @@ export class MoveService implements OnModuleInit {
|
|
|
|
|
|
if (cameraInfo.mediaSrc) {
|
|
|
this.reply.mediaSrc = cameraInfo.mediaSrc;
|
|
|
- if (this.cameraInfos.length == 0) {
|
|
|
- this.reply.moveStart = true;
|
|
|
- } else {
|
|
|
- this.reply.moveStart = false;
|
|
|
- }
|
|
|
+ this.reply.joystickIDR = cameraInfo.joystickIDR;
|
|
|
}
|
|
|
- // if (this.cameraInfos.length == 0) {
|
|
|
- // this.reply.moveOver = true;
|
|
|
- // }
|
|
|
|
|
|
user.camera.position = JSON.parse(
|
|
|
JSON.stringify(cameraInfo.camera_position),
|
|
|
);
|
|
|
+ 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(
|
|
|
- 'handlejoysticktesttest:actionRequest-自由' + new Date().getTime(),
|
|
|
- );
|
|
|
+ //console.log('handlejoysticktesttest:actionRequest-自由'+new Date().getTime());
|
|
|
return this.reply;
|
|
|
}
|
|
|
} catch (error) {
|
|
@@ -1195,19 +1187,16 @@ export class MoveService implements OnModuleInit {
|
|
|
|
|
|
if (cameraInfo.mediaSrc) {
|
|
|
this.reply.mediaSrc = cameraInfo.mediaSrc;
|
|
|
- if (this.cameraInfos.length == 0) {
|
|
|
- this.reply.moveStart = true;
|
|
|
- } else {
|
|
|
- this.reply.moveStart = false;
|
|
|
- }
|
|
|
+ this.reply.joystickIDR = cameraInfo.joystickIDR;
|
|
|
}
|
|
|
- // if (this.cameraInfos.length == 0) {
|
|
|
- // this.reply.moveOver = true;
|
|
|
- // }
|
|
|
|
|
|
user.camera.position = JSON.parse(
|
|
|
JSON.stringify(cameraInfo.camera_position),
|
|
|
);
|
|
|
+ console.log(
|
|
|
+ 'handlejoystick-angle->:moveDirect更新user.angle' +
|
|
|
+ cameraInfo.camera_angle.yaw,
|
|
|
+ );
|
|
|
user.camera.angle.yaw = cameraInfo.camera_angle.yaw;
|
|
|
|
|
|
this.sendingFrameForJoystick = true;
|
|
@@ -1252,11 +1241,15 @@ export class MoveService implements OnModuleInit {
|
|
|
);
|
|
|
|
|
|
for (let i = 0; i < checkReplys.length; ++i) {
|
|
|
- //checkReplys[i].actionResponses[0].actionType = actionType;
|
|
|
+ let joystickIDR = false;
|
|
|
+ if (i == 0 || i == checkReplys.length - 1) {
|
|
|
+ joystickIDR = true;
|
|
|
+ }
|
|
|
this.addCameraInfo(
|
|
|
checkReplys[i]['newUserStates'][0].playerState.camera.position,
|
|
|
checkReplys[i]['newUserStates'][0].playerState.camera.angle,
|
|
|
checkReplys[i].mediaSrc,
|
|
|
+ joystickIDR,
|
|
|
);
|
|
|
}
|
|
|
|
|
@@ -1296,17 +1289,19 @@ 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,
|
|
|
+ );
|
|
|
user.camera.angle.yaw = cameraInfo.camera_angle.yaw;
|
|
|
|
|
|
if (cameraInfo.mediaSrc) {
|
|
|
this.reply.mediaSrc = cameraInfo.mediaSrc;
|
|
|
- this.reply.moveStart = true;
|
|
|
+ this.reply.joystickIDR = cameraInfo.joystickIDR;
|
|
|
}
|
|
|
this.sendingFrameForJoystick = true;
|
|
|
}
|
|
|
- console.log(
|
|
|
- 'handlejoysticktesttest:actionRequest-镜头过渡' + new Date().getTime(),
|
|
|
- );
|
|
|
+ //console.log('handlejoysticktesttest:actionRequest-镜头过渡'+new Date().getTime());
|
|
|
return this.reply;
|
|
|
}
|
|
|
}
|
|
@@ -1345,15 +1340,23 @@ export class MoveService implements OnModuleInit {
|
|
|
'?m=' +
|
|
|
new Date().getTime();
|
|
|
}
|
|
|
+ if (i == 0) {
|
|
|
+ moveFrames[i].joystickIDR = true;
|
|
|
+ } else if (i == moveFrames.length - 1) {
|
|
|
+ moveFrames[i].joystickIDR = true;
|
|
|
+ } else {
|
|
|
+ moveFrames[i].joystickIDR = false;
|
|
|
+ }
|
|
|
this.cameraInfos.push(moveFrames[i]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- addCameraInfo(cameraPosition, cameraAngle, mediaSrc) {
|
|
|
+ addCameraInfo(cameraPosition, cameraAngle, mediaSrc, joystickIDR) {
|
|
|
this.cameraInfos.push({
|
|
|
camera_position: cameraPosition,
|
|
|
camera_angle: cameraAngle,
|
|
|
mediaSrc: mediaSrc,
|
|
|
+ joystickIDR: joystickIDR,
|
|
|
});
|
|
|
}
|
|
|
|
|
@@ -1368,12 +1371,7 @@ export class MoveService implements OnModuleInit {
|
|
|
|
|
|
complementFrame(userId) {
|
|
|
if (this.cameraInfos.length > 0) {
|
|
|
- console.log(
|
|
|
- 'handlejoysticktesttest:complementFrame-1 继续' +
|
|
|
- userId +
|
|
|
- ',' +
|
|
|
- new Date().getTime(),
|
|
|
- );
|
|
|
+ //console.log('handlejoysticktesttest:complementFrame-1 继续'+userId+','+new Date().getTime())
|
|
|
const user = this.users[userId];
|
|
|
const cameraInfo = this.cameraInfos.shift();
|
|
|
this.reply.traceIds = [];
|
|
@@ -1399,11 +1397,7 @@ export class MoveService implements OnModuleInit {
|
|
|
|
|
|
if (cameraInfo.mediaSrc) {
|
|
|
this.reply.mediaSrc = cameraInfo.mediaSrc;
|
|
|
- if (this.cameraInfos.length == 0) {
|
|
|
- this.reply.moveStart = true;
|
|
|
- } else {
|
|
|
- this.reply.moveStart = false;
|
|
|
- }
|
|
|
+ this.reply.joystickIDR = cameraInfo.joystickIDR;
|
|
|
}
|
|
|
|
|
|
user.camera.position = JSON.parse(
|
|
@@ -1416,23 +1410,17 @@ export class MoveService implements OnModuleInit {
|
|
|
return this.reply;
|
|
|
} else if (this.cameraInfos.length == 0) {
|
|
|
if (this.reply['newUserStates'][0].renderInfo.isMoving == 1) {
|
|
|
- console.log(
|
|
|
- 'handlejoysticktesttest:complementFrame-2 停止1' +
|
|
|
- new Date().getTime(),
|
|
|
- );
|
|
|
+ //console.log('handlejoysticktesttest:complementFrame-2 停止1'+new Date().getTime())
|
|
|
return this.stopJoystick(userId);
|
|
|
} else {
|
|
|
- console.log(
|
|
|
- 'handlejoysticktesttest:complementFrame-2 停止2' +
|
|
|
- new Date().getTime(),
|
|
|
- );
|
|
|
+ //console.log('handlejoysticktesttest:complementFrame-2 停止2'+new Date().getTime())
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
stopJoystick(userId) {
|
|
|
- console.log('handlejoysticktesttest:stopJoystick');
|
|
|
+ //console.log('handlejoysticktesttest:stopJoystick');
|
|
|
this.reply.traceIds = [];
|
|
|
const user = this.users[userId];
|
|
|
this.reply['newUserStates'][0].userId = userId;
|