|
@@ -7,6 +7,8 @@ import com.alibaba.fastjson.JSONObject;
|
|
import com.fdkk.fdkkmeta.config.MetaConfig;
|
|
import com.fdkk.fdkkmeta.config.MetaConfig;
|
|
import com.fdkk.fdkkmeta.domain.dto.RouteDto;
|
|
import com.fdkk.fdkkmeta.domain.dto.RouteDto;
|
|
import com.fdkk.fdkkmeta.domain.entity.mysql.BreakpointsEntity;
|
|
import com.fdkk.fdkkmeta.domain.entity.mysql.BreakpointsEntity;
|
|
|
|
+import com.fdkk.fdkkmeta.domain.entity.mysql.MoveFrameEntity;
|
|
|
|
+import com.fdkk.fdkkmeta.domain.entity.mysql.RotateFrameEntity;
|
|
import com.fdkk.fdkkmeta.domain.entity.mysql.UserEntity;
|
|
import com.fdkk.fdkkmeta.domain.entity.mysql.UserEntity;
|
|
import com.fdkk.fdkkmeta.domain.po.*;
|
|
import com.fdkk.fdkkmeta.domain.po.*;
|
|
import com.fdkk.fdkkmeta.grpc.*;
|
|
import com.fdkk.fdkkmeta.grpc.*;
|
|
@@ -203,6 +205,9 @@ public class sceneGrpcServer extends SceneGrpcServiceGrpc.SceneGrpcServiceImplBa
|
|
userService.save(userEntity);
|
|
userService.save(userEntity);
|
|
//todo 存入redis
|
|
//todo 存入redis
|
|
//redisCache.set("updateFrameMetadata:"+userEntity.getUserId(),a.toJSONString());
|
|
//redisCache.set("updateFrameMetadata:"+userEntity.getUserId(),a.toJSONString());
|
|
|
|
+ JSONObject myState = new JSONObject();
|
|
|
|
+ myState.put("isMoving",0);
|
|
|
|
+ redisCache.setCacheObject("UserState:"+userEntity.getUserId(),myState);
|
|
|
|
|
|
NormalReply.Builder builder = NormalReply.newBuilder();
|
|
NormalReply.Builder builder = NormalReply.newBuilder();
|
|
builder.setCode(1);
|
|
builder.setCode(1);
|
|
@@ -230,23 +235,40 @@ public class sceneGrpcServer extends SceneGrpcServiceGrpc.SceneGrpcServiceImplBa
|
|
"user_id":"0a3987974feb4"
|
|
"user_id":"0a3987974feb4"
|
|
}
|
|
}
|
|
*/
|
|
*/
|
|
- RotatePO rotateRequestPO = new RotatePO();
|
|
|
|
|
|
+ ActionPO rotateRequestPO = new ActionPO();
|
|
|
|
|
|
int action_type = request.getActionType();
|
|
int action_type = request.getActionType();
|
|
String trace_id = request.getTraceId();
|
|
String trace_id = request.getTraceId();
|
|
String user_id = request.getUserId();
|
|
String user_id = request.getUserId();
|
|
RotationAction rotationAction = request.getRotationAction();
|
|
RotationAction rotationAction = request.getRotationAction();
|
|
|
|
|
|
|
|
+ UserEntity user = userService.findUserId(user_id);
|
|
|
|
+ RotateFrameEntity rotateFrameEntity = rotateFrameService.findById(user.getFrameId());
|
|
|
|
+
|
|
JSONObject rotation_action = new JSONObject();
|
|
JSONObject rotation_action = new JSONObject();
|
|
- rotation_action.put("vertical_move",rotationAction.getVerticalMove());
|
|
|
|
- rotation_action.put("horizontal_move",rotationAction.getHorizontalMove());
|
|
|
|
|
|
+// rotation_action.put("vertical_move",rotationAction.getVerticalMove());
|
|
|
|
+// rotation_action.put("horizontal_move",rotationAction.getHorizontalMove());
|
|
|
|
|
|
rotateRequestPO.setAction_type(action_type);
|
|
rotateRequestPO.setAction_type(action_type);
|
|
- rotateRequestPO.setRotation_action(rotation_action);
|
|
|
|
|
|
+ //rotateRequestPO.setRotation_action(rotation_action);
|
|
rotateRequestPO.setTrace_id(trace_id);
|
|
rotateRequestPO.setTrace_id(trace_id);
|
|
rotateRequestPO.setUser_id(user_id);
|
|
rotateRequestPO.setUser_id(user_id);
|
|
- //redisCache.setCacheObject("setCacheRequest:"+user_id,rotateRequestPO);
|
|
|
|
- redisCache.setCacheList("setCacheRequest:rotate:"+user_id, Arrays.asList(rotateRequestPO));
|
|
|
|
|
|
+
|
|
|
|
+ double hAngle = rotationAction.getHorizontalMove() * 90;
|
|
|
|
+ int offFrameIndex = (int)Math.ceil(hAngle);
|
|
|
|
+ int currentFrame = rotateFrameEntity.getFrameIndex(); //从数据库里读取
|
|
|
|
+ currentFrame +=offFrameIndex;
|
|
|
|
+ if(currentFrame<0){
|
|
|
|
+ currentFrame+=360;
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ currentFrame = currentFrame % 359;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ rotateFrameEntity = rotateFrameService.findByAppIdAndBreakPointIdAndFrameIndex(user_id,user.getBreakPointId(),currentFrame);
|
|
|
|
+ rotateRequestPO.setFrameId(rotateFrameEntity.getId());
|
|
|
|
+ //每次存一帧
|
|
|
|
+ redisCache.setCacheList("setCacheRequest:"+user_id, Arrays.asList(rotateRequestPO));
|
|
/*
|
|
/*
|
|
//这三个变量从user表和rotateframe表里取
|
|
//这三个变量从user表和rotateframe表里取
|
|
UserEntity user = userService.findUserId(user_id);
|
|
UserEntity user = userService.findUserId(user_id);
|
|
@@ -428,18 +450,18 @@ public class sceneGrpcServer extends SceneGrpcServiceGrpc.SceneGrpcServiceImplBa
|
|
@Override
|
|
@Override
|
|
public void move(MoveRequest request, StreamObserver<NormalReply> responseObserver){
|
|
public void move(MoveRequest request, StreamObserver<NormalReply> responseObserver){
|
|
try{
|
|
try{
|
|
- int action_type= request.getActionType();
|
|
|
|
|
|
+ //int action_type= request.getActionType();
|
|
ClickingAction clicking_action = request.getClickingAction();
|
|
ClickingAction clicking_action = request.getClickingAction();
|
|
- State clicking_state = request.getClickingState();
|
|
|
|
|
|
+ //State clicking_state = request.getClickingState();
|
|
String trace_id = request.getTraceId();
|
|
String trace_id = request.getTraceId();
|
|
String user_id = request.getUserId();
|
|
String user_id = request.getUserId();
|
|
|
|
|
|
UserEntity user = userService.findUserId(user_id);
|
|
UserEntity user = userService.findUserId(user_id);
|
|
String appId = user.getAppId();
|
|
String appId = user.getAppId();
|
|
- //Long breakPointId = user.getBreakPointId();
|
|
|
|
|
|
+ Long breakPointId = user.getBreakPointId();
|
|
//BreakpointsEntity breakpointsEntity = breakpointsService.findByAppIdAndBreakPointId(appId,breakPointId);
|
|
//BreakpointsEntity breakpointsEntity = breakpointsService.findByAppIdAndBreakPointId(appId,breakPointId);
|
|
Point end = clicking_action.getClickingPoint();
|
|
Point end = clicking_action.getClickingPoint();
|
|
- //RotateFrameEntity rotateFrameEntity = rotateFrameService.findById(user.getFrameId());
|
|
|
|
|
|
+ RotateFrameEntity rotateFrameEntity = rotateFrameService.findById(user.getFrameId());
|
|
//计算路径
|
|
//计算路径
|
|
RouteDto po=new RouteDto();
|
|
RouteDto po=new RouteDto();
|
|
PointPO s= user.getPlayerPosition();
|
|
PointPO s= user.getPlayerPosition();
|
|
@@ -453,20 +475,50 @@ public class sceneGrpcServer extends SceneGrpcServiceGrpc.SceneGrpcServiceImplBa
|
|
JSONArray path = new JSONArray();
|
|
JSONArray path = new JSONArray();
|
|
|
|
|
|
JSONArray maps = GetRoute.getRoute(metaConfig.getFreespacePath()+ File.separator +appId+"_target_freespace.json", po);
|
|
JSONArray maps = GetRoute.getRoute(metaConfig.getFreespacePath()+ File.separator +appId+"_target_freespace.json", po);
|
|
|
|
+
|
|
|
|
+ ActionPO movePO = new ActionPO();
|
|
|
|
+
|
|
if (maps!=null&&maps.size()>=2){
|
|
if (maps!=null&&maps.size()>=2){
|
|
- Long nextbreakPointId = JSON.parseObject(JSONObject.toJSON(maps.get(1)).toString()).getLong("id");
|
|
|
|
- path.add(nextbreakPointId);
|
|
|
|
- }
|
|
|
|
|
|
+ for(int i=0;i< maps.size();++i){
|
|
|
|
+ Long _breakPointId = JSON.parseObject(JSONObject.toJSON(maps.get(i)).toString()).getLong("id");
|
|
|
|
+ path.add(_breakPointId);
|
|
|
|
+ //旋转矫正
|
|
|
|
+ if(i == 1){
|
|
|
|
+ AnglePO cameraAnglePO = rotateFrameEntity.getCameraAngle();
|
|
|
|
+// int angle = cameraAnglePO.getYaw();
|
|
|
|
+// int offAngle = 0;
|
|
|
|
+// offAngle = angle%45;
|
|
|
|
+
|
|
|
|
+// if(offAngle>45-offAngle) {
|
|
|
|
+// offAngle = 45-offAngle;
|
|
|
|
+// }
|
|
|
|
+// else {
|
|
|
|
+// offAngle = -1*offAngle;
|
|
|
|
+// }
|
|
|
|
+ //先简单来,就累加
|
|
|
|
+ //存储矫正的一组帧
|
|
|
|
+// for(int j=0;j<offAngle;++j){
|
|
|
|
+// ActionPO rotateRequestPO = new ActionPO();
|
|
|
|
+// rotateRequestPO.setAction_type(1014);
|
|
|
|
+// rotateRequestPO.setTrace_id(trace_id);
|
|
|
|
+// rotateRequestPO.setUser_id(user_id);
|
|
|
|
+// RotateFrameEntity _rotateFrameEntity = rotateFrameService.findByAppIdAndBreakPointIdAndFrameIndex(user.getAppId(),user.getBreakPointId(),angle+j);
|
|
|
|
+// rotateRequestPO.setFrameId(_rotateFrameEntity.getId());
|
|
|
|
+// redisCache.setCacheList("setCacheRequest:"+user_id, Arrays.asList(rotateRequestPO));
|
|
|
|
+// }
|
|
|
|
+ int angle = setRotateForMove( user, trace_id, cameraAnglePO.getYaw());
|
|
|
|
+ movePO.setPlayerAngle(angle);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
- MovePO movePO = new MovePO();
|
|
|
|
- movePO.setAction_type(action_type);
|
|
|
|
- movePO.setClicking_action(clicking_action);
|
|
|
|
- movePO.setClicking_state(clicking_state);
|
|
|
|
- movePO.setTrace_id(trace_id);
|
|
|
|
- movePO.setUser_id(user_id);
|
|
|
|
- movePO.setPath(path);
|
|
|
|
|
|
+ movePO.setAction_type(1);
|
|
|
|
+ movePO.setTrace_id(trace_id);
|
|
|
|
+ movePO.setUser_id(user_id);
|
|
|
|
+ movePO.setPath(path);
|
|
|
|
+ redisCache.setCacheList("setCacheRequest:"+user_id, Arrays.asList(movePO));
|
|
|
|
+ }
|
|
|
|
|
|
- redisCache.setCacheList("setCacheRequest:move:"+user_id, Arrays.asList(movePO));
|
|
|
|
NormalReply.Builder builder = NormalReply.newBuilder();
|
|
NormalReply.Builder builder = NormalReply.newBuilder();
|
|
builder.setCode(1);
|
|
builder.setCode(1);
|
|
responseObserver.onNext(builder.build());
|
|
responseObserver.onNext(builder.build());
|
|
@@ -477,6 +529,31 @@ public class sceneGrpcServer extends SceneGrpcServiceGrpc.SceneGrpcServiceImplBa
|
|
//builder.setCode(0);
|
|
//builder.setCode(0);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private int setRotateForMove(UserEntity user,String trace_id,int angle){
|
|
|
|
+ int offAngle = 0;
|
|
|
|
+ offAngle = angle%45;
|
|
|
|
+
|
|
|
|
+// if(offAngle>45-offAngle) {
|
|
|
|
+// offAngle = 45-offAngle;
|
|
|
|
+// }
|
|
|
|
+// else {
|
|
|
|
+// offAngle = -1*offAngle;
|
|
|
|
+// }
|
|
|
|
+ //先简单来,就累加
|
|
|
|
+ //存储矫正的一组帧
|
|
|
|
+ offAngle = Math.abs(45 - offAngle);
|
|
|
|
+ for(int j=0;j<offAngle;++j){
|
|
|
|
+ ActionPO rotateRequestPO = new ActionPO();
|
|
|
|
+ rotateRequestPO.setAction_type(1014);
|
|
|
|
+ rotateRequestPO.setTrace_id(trace_id);
|
|
|
|
+ rotateRequestPO.setUser_id(user.getUserId());
|
|
|
|
+ RotateFrameEntity _rotateFrameEntity = rotateFrameService.findByAppIdAndBreakPointIdAndFrameIndex(user.getAppId(),user.getBreakPointId(),angle+j);
|
|
|
|
+ rotateRequestPO.setFrameId(_rotateFrameEntity.getId());
|
|
|
|
+ redisCache.setCacheList("setCacheRequest:"+user.getUserId(), Arrays.asList(rotateRequestPO));
|
|
|
|
+ }
|
|
|
|
+ return (angle+offAngle)%360;
|
|
|
|
+ }
|
|
/*
|
|
/*
|
|
//返回的是角度矫正数据
|
|
//返回的是角度矫正数据
|
|
@Override
|
|
@Override
|
|
@@ -791,17 +868,61 @@ public class sceneGrpcServer extends SceneGrpcServiceGrpc.SceneGrpcServiceImplBa
|
|
String user_id = request.getUserId();
|
|
String user_id = request.getUserId();
|
|
String packet_id = request.getPacketId();
|
|
String packet_id = request.getPacketId();
|
|
|
|
|
|
- JoystickPO joystickPO = new JoystickPO();
|
|
|
|
|
|
+ //JoystickPO joystickPO = new JoystickPO();
|
|
|
|
+ ActionPO joystickPO = new ActionPO();
|
|
joystickPO.setAction_type(actionType);
|
|
joystickPO.setAction_type(actionType);
|
|
- JSONObject dir_action = new JSONObject();
|
|
|
|
- dir_action.put("move_angle",dirAction.getMoveAngle());
|
|
|
|
- dir_action.put("speed_level",dirAction.getSpeedLevel());
|
|
|
|
- joystickPO.setDir_action(dir_action);
|
|
|
|
|
|
+ //JSONObject dir_action = new JSONObject();
|
|
|
|
+ //dir_action.put("move_angle",dirAction.getMoveAngle());
|
|
|
|
+ //dir_action.put("speed_level",dirAction.getSpeedLevel());
|
|
|
|
+ //joystickPO.setDir_action(dir_action);
|
|
joystickPO.setTrace_id(trace_id);
|
|
joystickPO.setTrace_id(trace_id);
|
|
joystickPO.setUser_id(user_id);
|
|
joystickPO.setUser_id(user_id);
|
|
joystickPO.setPacket_id(packet_id);
|
|
joystickPO.setPacket_id(packet_id);
|
|
|
|
+ joystickPO.setPlayerAngle(dirAction.getMoveAngle());
|
|
|
|
+ redisCache.setCacheList("setCacheRequest:"+user_id, Arrays.asList(joystickPO));
|
|
|
|
+
|
|
|
|
+ if(dirAction.getSpeedLevel()<7){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ UserEntity user = userService.findUserId(user_id);
|
|
|
|
+ //邻居点里找角度最合适的点
|
|
|
|
+ BreakpointsEntity breakpointsEntity = breakpointsService.findByAppIdAndBreakPointId(user.getAppId(), user.getBreakPointId());
|
|
|
|
+ BreakpointsEntity targetBreakpointsEntity = null;
|
|
|
|
+ List<Integer> neighBreakPointIds = breakpointsEntity.getContact();
|
|
|
|
+ PointPO playerPosition = breakpointsEntity.getPosition();
|
|
|
|
+ PointPO temp = new PointPO();
|
|
|
|
+ temp.setX(playerPosition.getX()+1);
|
|
|
|
+ temp.setY(playerPosition.getY());
|
|
|
|
+ temp.setZ(playerPosition.getZ());
|
|
|
|
+ double offAngle = 1000;
|
|
|
|
+ double moveAngle = dirAction.getMoveAngle();
|
|
|
|
+
|
|
|
|
+ if(neighBreakPointIds.size()>0){
|
|
|
|
+ for(int j=0;j<neighBreakPointIds.size();++j){
|
|
|
|
+ BreakpointsEntity _breakpointsEntity = breakpointsService.findByAppIdAndBreakPointId(user.getAppId(), (long)neighBreakPointIds.get(j));
|
|
|
|
+ double angle = sceneGrpcService.calAngle(playerPosition, temp, _breakpointsEntity.getPosition());
|
|
|
|
+ if(Math.abs(angle - moveAngle)<offAngle){
|
|
|
|
+ offAngle = Math.abs(angle - moveAngle);
|
|
|
|
+ targetBreakpointsEntity = _breakpointsEntity;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ RotateFrameEntity rotateFrameEntity = rotateFrameService.findById(user.getFrameId());
|
|
|
|
+ AnglePO cameraAnglePO = rotateFrameEntity.getCameraAngle();
|
|
|
|
+ int angle = setRotateForMove( user, trace_id,cameraAnglePO.getYaw());
|
|
|
|
+
|
|
|
|
+ JSONArray path = new JSONArray();
|
|
|
|
+ path.add(user.getBreakPointId());
|
|
|
|
+ path.add(targetBreakpointsEntity.getBreakPointId());
|
|
|
|
+ ActionPO movePO = new ActionPO();
|
|
|
|
+ movePO.setAction_type(1);
|
|
|
|
+ movePO.setTrace_id(trace_id);
|
|
|
|
+ movePO.setUser_id(user_id);
|
|
|
|
+ movePO.setPath(path);
|
|
|
|
+ movePO.setMoveAngle(angle);
|
|
|
|
+ redisCache.setCacheList("setCacheRequest:"+user_id, Arrays.asList(movePO));
|
|
|
|
+ }
|
|
|
|
|
|
- redisCache.setCacheList("setCacheRequest:joystick:"+user_id, Arrays.asList(joystickPO));
|
|
|
|
//redisCache.setCacheObject("setCacheRequest:"+user_id,joystickPO);
|
|
//redisCache.setCacheObject("setCacheRequest:"+user_id,joystickPO);
|
|
//UserEntity user = userService.findUserId(user_id);
|
|
//UserEntity user = userService.findUserId(user_id);
|
|
//Long breakPointId = user.getBreakPointId();
|
|
//Long breakPointId = user.getBreakPointId();
|