|
@@ -35,7 +35,7 @@ export class MoveService implements OnModuleInit {
|
|
constructor(
|
|
constructor(
|
|
private cacheService: CacheService,
|
|
private cacheService: CacheService,
|
|
private rotateService: RotateService,
|
|
private rotateService: RotateService,
|
|
- ) { }
|
|
|
|
|
|
+ ) {}
|
|
private logger: Logger = new Logger('MoveService');
|
|
private logger: Logger = new Logger('MoveService');
|
|
private Actions = {
|
|
private Actions = {
|
|
Clicking: 1,
|
|
Clicking: 1,
|
|
@@ -247,8 +247,8 @@ export class MoveService implements OnModuleInit {
|
|
if (checkReplys.length > 0) {
|
|
if (checkReplys.length > 0) {
|
|
console.log(
|
|
console.log(
|
|
'move-1' +
|
|
'move-1' +
|
|
- checkReplys[checkReplys.length - 1].newUserStates[0].playerState
|
|
|
|
- .camera.angle.yaw,
|
|
|
|
|
|
+ checkReplys[checkReplys.length - 1].newUserStates[0].playerState
|
|
|
|
+ .camera.angle.yaw,
|
|
);
|
|
);
|
|
}
|
|
}
|
|
//过渡传到缓存里
|
|
//过渡传到缓存里
|
|
@@ -321,7 +321,6 @@ export class MoveService implements OnModuleInit {
|
|
let i;
|
|
let i;
|
|
for (i = 1; i < moveFrames.length; i += 3) {
|
|
for (i = 1; i < moveFrames.length; i += 3) {
|
|
const moveFrame = moveFrames[i];
|
|
const moveFrame = moveFrames[i];
|
|
-
|
|
|
|
const reply = JSON.parse(JSON.stringify(this.reply));
|
|
const reply = JSON.parse(JSON.stringify(this.reply));
|
|
reply.traceIds.push(traceId);
|
|
reply.traceIds.push(traceId);
|
|
reply['newUserStates'][0].userId = userId;
|
|
reply['newUserStates'][0].userId = userId;
|
|
@@ -355,7 +354,7 @@ export class MoveService implements OnModuleInit {
|
|
moveFrame.camera_angle;
|
|
moveFrame.camera_angle;
|
|
reply['newUserStates'][0].playerState.cameraCenter =
|
|
reply['newUserStates'][0].playerState.cameraCenter =
|
|
reply['newUserStates'][0].playerState.player.position;
|
|
reply['newUserStates'][0].playerState.player.position;
|
|
-
|
|
|
|
|
|
+ reply['newUserStates'][0].renderInfo.isMoving = 1;
|
|
reply['actionResponses'][0].traceId = traceId;
|
|
reply['actionResponses'][0].traceId = traceId;
|
|
|
|
|
|
reply.mediaSrc =
|
|
reply.mediaSrc =
|
|
@@ -570,52 +569,85 @@ export class MoveService implements OnModuleInit {
|
|
const appId = user.appId;
|
|
const appId = user.appId;
|
|
|
|
|
|
const replys = [];
|
|
const replys = [];
|
|
- const step = 1;
|
|
|
|
|
|
+ const step = 0.1;
|
|
const closestDis = 20; //小于这个距离就跳到邻居呼吸点
|
|
const closestDis = 20; //小于这个距离就跳到邻居呼吸点
|
|
const distance = step * dir_action.speed_level;
|
|
const distance = step * dir_action.speed_level;
|
|
let angle = null;
|
|
let angle = null;
|
|
|
|
+ console.log('joystick-1:' + JSON.stringify(user.player.position));
|
|
// debugger;
|
|
// debugger;
|
|
//TODO 临时增加断言
|
|
//TODO 临时增加断言
|
|
const playerPosition: Point = { x: 0, y: 0, z: 0 };
|
|
const playerPosition: Point = { x: 0, y: 0, z: 0 };
|
|
playerPosition.x =
|
|
playerPosition.x =
|
|
- user.player.position.x + distance * Math.atan(dir_action.move_angle);
|
|
|
|
|
|
+ user.player.position.x + distance * Math.tan(dir_action.move_angle);
|
|
playerPosition.y =
|
|
playerPosition.y =
|
|
- user.player.position.y + distance * Math.tan(dir_action.move_angle);
|
|
|
|
|
|
+ user.player.position.y - distance * Math.atan(dir_action.move_angle);
|
|
|
|
|
|
//找到邻居点,判断user.player.position与邻居点的距离,如果距离小于closestDis,就要更新camera的position
|
|
//找到邻居点,判断user.player.position与邻居点的距离,如果距离小于closestDis,就要更新camera的position
|
|
- let chooseBreakPointId = null;
|
|
|
|
|
|
+ const chooseBreakPointId = null;
|
|
const breakPoint = this.breakPointInfo[breakPointId];
|
|
const breakPoint = this.breakPointInfo[breakPointId];
|
|
const surroundPointIds = breakPoint.contact;
|
|
const surroundPointIds = breakPoint.contact;
|
|
const neighAngles = [];
|
|
const neighAngles = [];
|
|
- //找到和角度最贴近的邻居点
|
|
|
|
- for (let i = 0; i < surroundPointIds.length; ++i) {
|
|
|
|
- const neighPoint = this.breakPointInfo[surroundPointIds[i]];
|
|
|
|
- const neighDistance = this.getDistance(
|
|
|
|
- playerPosition,
|
|
|
|
- neighPoint.position,
|
|
|
|
|
|
+ // //找到和角度最贴近的邻居点
|
|
|
|
+ // for (let i = 0; i < surroundPointIds.length; ++i) {
|
|
|
|
+ // const neighPoint = this.breakPointInfo[surroundPointIds[i]];
|
|
|
|
+ // const neighDistance = this.getDistance(
|
|
|
|
+ // playerPosition,
|
|
|
|
+ // neighPoint.position,
|
|
|
|
+ // );
|
|
|
|
+ // if (neighDistance < closestDis) {
|
|
|
|
+ // chooseBreakPointId = surroundPointIds[i];
|
|
|
|
+ // }
|
|
|
|
+ // angle = -1*this.getAngle(
|
|
|
|
+ // user.player.position,
|
|
|
|
+ // { x: user.player.position.x + 1, y: user.player.position.y },
|
|
|
|
+ // neighPoint.position,
|
|
|
|
+ // );
|
|
|
|
+ // if(angle<0){
|
|
|
|
+ // angle += 360;
|
|
|
|
+ // }
|
|
|
|
+ // neighAngles.push(angle);
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+ // //方向不对的话,没有过渡内容
|
|
|
|
+ // if (
|
|
|
|
+ // dir_action.move_angle > Math.max(...neighAngles) ||
|
|
|
|
+ // dir_action.move_angle < Math.min(...neighAngles)
|
|
|
|
+ // ) {
|
|
|
|
+ // return replys;
|
|
|
|
+ // }
|
|
|
|
+ //人物移动
|
|
|
|
+ user.player.position = JSON.parse(JSON.stringify(playerPosition));
|
|
|
|
+ user.player.angle.yaw = dir_action.move_angle;
|
|
|
|
+ if (chooseBreakPointId == null) {
|
|
|
|
+ const traceIds = [];
|
|
|
|
+ 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.position = JSON.parse(
|
|
|
|
+ JSON.stringify(playerPosition),
|
|
);
|
|
);
|
|
- if (neighDistance < closestDis) {
|
|
|
|
- chooseBreakPointId = surroundPointIds[i];
|
|
|
|
- }
|
|
|
|
- angle = this.getAngle(
|
|
|
|
- user.player.position,
|
|
|
|
- { x: user.player.position.x + 1, y: user.player.position.y },
|
|
|
|
- neighPoint.position,
|
|
|
|
|
|
+ this.reply['newUserStates'][0].playerState.player.angle.yaw =
|
|
|
|
+ dir_action.move_angle;
|
|
|
|
+
|
|
|
|
+ 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),
|
|
);
|
|
);
|
|
- neighAngles.push(angle);
|
|
|
|
- }
|
|
|
|
|
|
|
|
- //方向不对的话,没有过渡内容
|
|
|
|
- if (
|
|
|
|
- dir_action.move_angle > Math.max(...neighAngles) ||
|
|
|
|
- dir_action.move_angle < Math.min(...neighAngles)
|
|
|
|
- ) {
|
|
|
|
- return replys;
|
|
|
|
|
|
+ this.reply['newUserStates'][0].renderInfo.isMoving = 1;
|
|
|
|
+
|
|
|
|
+ this.reply['actionResponses'][0].traceId = traceId;
|
|
|
|
+ this.reply.mediaSrc = null;
|
|
|
|
+ return this.reply;
|
|
}
|
|
}
|
|
|
|
|
|
- //人物移动
|
|
|
|
- user.player.position = JSON.parse(JSON.stringify(playerPosition));
|
|
|
|
- user.player.angle.yaw = dir_action.move_angle;
|
|
|
|
angle = user.camera.angle.yaw % 45; //纠正需要
|
|
angle = user.camera.angle.yaw % 45; //纠正需要
|
|
//通过user.camera.angle矫正相机的angle
|
|
//通过user.camera.angle矫正相机的angle
|
|
const checkReplys = await this.modeifyCameraAngle(
|
|
const checkReplys = await this.modeifyCameraAngle(
|
|
@@ -626,6 +658,7 @@ export class MoveService implements OnModuleInit {
|
|
);
|
|
);
|
|
replys.push(checkReplys);
|
|
replys.push(checkReplys);
|
|
|
|
|
|
|
|
+ console.log('joystick-2:' + JSON.stringify(user.player.position));
|
|
//判断人物离该邻接点的距离是否在最小路径内,如果是,跳到这个邻接点里
|
|
//判断人物离该邻接点的距离是否在最小路径内,如果是,跳到这个邻接点里
|
|
if (chooseBreakPointId != null) {
|
|
if (chooseBreakPointId != null) {
|
|
//相机纠正
|
|
//相机纠正
|
|
@@ -644,7 +677,7 @@ export class MoveService implements OnModuleInit {
|
|
':angle:' +
|
|
':angle:' +
|
|
Math.floor(user.camera.angle.yaw / 45);
|
|
Math.floor(user.camera.angle.yaw / 45);
|
|
const moveFramesRes = await this.cacheService.get(key);
|
|
const moveFramesRes = await this.cacheService.get(key);
|
|
- const moveFrames = JSON.parse(JSON.stringify(moveFramesRes));
|
|
|
|
|
|
+ const moveFrames = JSON.parse(moveFramesRes);
|
|
const pathReplys = this.createCacheReplys(
|
|
const pathReplys = this.createCacheReplys(
|
|
appId,
|
|
appId,
|
|
moveFrames,
|
|
moveFrames,
|
|
@@ -709,7 +742,7 @@ export class MoveService implements OnModuleInit {
|
|
getDistance(position1, position2) {
|
|
getDistance(position1, position2) {
|
|
return Math.sqrt(
|
|
return Math.sqrt(
|
|
(position1.x - position2.x) * (position1.x - position2.x) +
|
|
(position1.x - position2.x) * (position1.x - position2.x) +
|
|
- (position1.y - position2.y) * (position1.y - position2.y),
|
|
|
|
|
|
+ (position1.y - position2.y) * (position1.y - position2.y),
|
|
);
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|