|
@@ -569,102 +569,148 @@ export class MoveService implements OnModuleInit {
|
|
|
const appId = user.appId;
|
|
|
|
|
|
const replys = [];
|
|
|
- const step = 0.1;
|
|
|
+ const step = 1;
|
|
|
const closestDis = 20; //小于这个距离就跳到邻居呼吸点
|
|
|
const distance = step * dir_action.speed_level;
|
|
|
let angle = null;
|
|
|
- console.log('joystick-1:' + JSON.stringify(user.player.position));
|
|
|
+
|
|
|
// debugger;
|
|
|
//TODO 临时增加断言
|
|
|
const playerPosition: Point = { x: 0, y: 0, z: 0 };
|
|
|
playerPosition.x =
|
|
|
- user.player.position.x + distance * Math.tan(dir_action.move_angle);
|
|
|
+ user.player.position.x +
|
|
|
+ distance * Math.cos((dir_action.move_angle / 360) * 2 * Math.PI);
|
|
|
playerPosition.y =
|
|
|
- user.player.position.y - distance * Math.atan(dir_action.move_angle);
|
|
|
+ user.player.position.y +
|
|
|
+ distance * Math.sin((dir_action.move_angle / 360) * 2 * Math.PI);
|
|
|
|
|
|
//找到邻居点,判断user.player.position与邻居点的距离,如果距离小于closestDis,就要更新camera的position
|
|
|
- const chooseBreakPointId = null;
|
|
|
+ let chooseBreakPointId = null;
|
|
|
const breakPoint = this.breakPointInfo[breakPointId];
|
|
|
const surroundPointIds = breakPoint.contact;
|
|
|
- const neighAngles = [];
|
|
|
- // //找到和角度最贴近的邻居点
|
|
|
- // 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));
|
|
|
+ //const neighAngles = [];
|
|
|
+ const traceIds = [];
|
|
|
+
|
|
|
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;
|
|
|
+ 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 =
|
|
|
+ dir_action.move_angle;
|
|
|
|
|
|
- this.reply['newUserStates'][0].playerState.player.position = JSON.parse(
|
|
|
- JSON.stringify(playerPosition),
|
|
|
+ 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;
|
|
|
+
|
|
|
+ //方向不对的话,人物不能走动,只是修改朝向
|
|
|
+ // 找到和角度最贴近的邻居点
|
|
|
+
|
|
|
+ let _angle = null;
|
|
|
+ if (surroundPointIds.length == 1) {
|
|
|
+ _angle = this.getAngle(
|
|
|
+ breakPoint.position,
|
|
|
+ {
|
|
|
+ x: this.breakPointInfo[surroundPointIds[0]].position.x,
|
|
|
+ y: this.breakPointInfo[surroundPointIds[0]].position.y,
|
|
|
+ },
|
|
|
+ playerPosition,
|
|
|
);
|
|
|
- this.reply['newUserStates'][0].playerState.player.angle.yaw =
|
|
|
- dir_action.move_angle;
|
|
|
+ if (_angle > -90 && _angle < 90) {
|
|
|
+ return this.reply;
|
|
|
+ } else {
|
|
|
+ //投影
|
|
|
+ return this.reply;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- 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),
|
|
|
+ //判断_angle与angle的差在45以内的个数,两个的话表示可以走
|
|
|
+ let count = 0;
|
|
|
+ let neighPoints = [];
|
|
|
+ _angle = this.getAngle(
|
|
|
+ breakPoint.position,
|
|
|
+ { x: breakPoint.position.x + 1, y: breakPoint.position.y },
|
|
|
+ playerPosition,
|
|
|
+ );
|
|
|
+ if (_angle < 0) {
|
|
|
+ _angle += 360;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (let i = 0; i < surroundPointIds.length; ++i) {
|
|
|
+ const neighPoint = this.breakPointInfo[surroundPointIds[i]];
|
|
|
+ neighPoint.breakPointId = surroundPointIds[i];
|
|
|
+ // const neighDistance = this.getDistance(
|
|
|
+ // playerPosition,
|
|
|
+ // neighPoint.position,
|
|
|
+ // );
|
|
|
+ // if (neighDistance < closestDis) {
|
|
|
+ // chooseBreakPointId = surroundPointIds[i];
|
|
|
+ // }
|
|
|
+ angle = this.getAngle(
|
|
|
+ breakPoint.position,
|
|
|
+ { x: breakPoint.position.x + 1, y: breakPoint.position.y },
|
|
|
+ neighPoint.position,
|
|
|
);
|
|
|
- this.reply['newUserStates'][0].playerState.cameraCenter = JSON.parse(
|
|
|
- JSON.stringify(breakPoint.position),
|
|
|
+ if (angle < 0) {
|
|
|
+ angle += 360;
|
|
|
+ }
|
|
|
+ //neighAngles.push(angle);
|
|
|
+ if(Math.abs(angle - _angle)<45){
|
|
|
+ neighPoints.push(neighPoint);
|
|
|
+ ++count;
|
|
|
+ }
|
|
|
+ else if(angle == 0 && _angle>315){
|
|
|
+ neighPoints.push(neighPoint);
|
|
|
+ ++count;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(count==2 || _angle%45 ==0){
|
|
|
+ //人物移动
|
|
|
+ user.player.position = JSON.parse(JSON.stringify(playerPosition));
|
|
|
+ this.reply['newUserStates'][0].playerState.player.position = JSON.parse(
|
|
|
+ JSON.stringify(playerPosition),
|
|
|
);
|
|
|
-
|
|
|
- this.reply['newUserStates'][0].renderInfo.isMoving = 1;
|
|
|
-
|
|
|
- this.reply['actionResponses'][0].traceId = traceId;
|
|
|
- this.reply.mediaSrc = null;
|
|
|
+ }
|
|
|
+ else{
|
|
|
return this.reply;
|
|
|
}
|
|
|
|
|
|
- angle = user.camera.angle.yaw % 45; //纠正需要
|
|
|
- //通过user.camera.angle矫正相机的angle
|
|
|
- const checkReplys = await this.modeifyCameraAngle(
|
|
|
- angle,
|
|
|
- userId,
|
|
|
- traceId,
|
|
|
- actionType,
|
|
|
- );
|
|
|
- replys.push(checkReplys);
|
|
|
+ //超出范围了
|
|
|
+ if(this.getDistance(playerPosition,breakPoint.position)>50){
|
|
|
+ //debugger;
|
|
|
+ if(this.getDistance(playerPosition,neighPoints[0].position)>this.getDistance(playerPosition,neighPoints[1].position)){
|
|
|
+ chooseBreakPointId = neighPoints[1].breakPointId;
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ chooseBreakPointId = neighPoints[0].breakPointId;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- console.log('joystick-2:' + JSON.stringify(user.player.position));
|
|
|
+ if (chooseBreakPointId == null) {
|
|
|
+ return this.reply;
|
|
|
+ }
|
|
|
//判断人物离该邻接点的距离是否在最小路径内,如果是,跳到这个邻接点里
|
|
|
- if (chooseBreakPointId != null) {
|
|
|
- //相机纠正
|
|
|
- const replys = [];
|
|
|
- const traceIds = [];
|
|
|
- traceIds.push(traceId);
|
|
|
+ //相机纠正加过渡
|
|
|
+ else {
|
|
|
+ angle = user.camera.angle.yaw % 45; //纠正需要
|
|
|
+ //通过user.camera.angle矫正相机的angle
|
|
|
+ const checkReplys = await this.modeifyCameraAngle(
|
|
|
+ angle,
|
|
|
+ userId,
|
|
|
+ traceId,
|
|
|
+ actionType,
|
|
|
+ );
|
|
|
+ replys.push(checkReplys);
|
|
|
|
|
|
//读redis里的数据,按照frame_index的大小排序
|
|
|
const key =
|
|
@@ -688,8 +734,6 @@ export class MoveService implements OnModuleInit {
|
|
|
);
|
|
|
replys.push(pathReplys);
|
|
|
return replys;
|
|
|
- } else {
|
|
|
- return replys;
|
|
|
}
|
|
|
} catch (error) {
|
|
|
console.log('MoveService', error);
|