|
@@ -70,12 +70,19 @@ const canvasRef = ref(null);
|
|
|
const props = defineProps({
|
|
|
type: {
|
|
|
type: String,
|
|
|
- default: false
|
|
|
+ default: ""
|
|
|
+ },
|
|
|
+ currentGameArea: {
|
|
|
+ type: String,
|
|
|
+ default: ""
|
|
|
+ },
|
|
|
+ areaStateList: {
|
|
|
+ type: Array,
|
|
|
+ default: () => []
|
|
|
},
|
|
|
});
|
|
|
|
|
|
const data = reactive<any>({
|
|
|
- bodyposeData: {},//姿态信息
|
|
|
clientObj: {},//浏览器对象
|
|
|
boxes: [],//四个点坐标
|
|
|
proportion: null,//人框和屏幕比例
|
|
@@ -84,7 +91,7 @@ const data = reactive<any>({
|
|
|
direction: null,//跑动
|
|
|
});
|
|
|
|
|
|
-const { bodyposeData, clientObj, boxes, proportion, myThrow, myTimer, direction } = toRefs(data);
|
|
|
+const { clientObj, boxes, proportion, myThrow, myTimer, direction } = toRefs(data);
|
|
|
|
|
|
// 游戏状态管理
|
|
|
const currentScene = ref('start');
|
|
@@ -1256,27 +1263,26 @@ const getInit = (e: any) => {
|
|
|
result.push(arr.slice(i, i + 2));
|
|
|
}
|
|
|
//console.log("result", result)
|
|
|
- bodyposeData.value = result;
|
|
|
- if (boxes.value.length == 0) {
|
|
|
- // speckText("识别成功");
|
|
|
- // proxy?.$modal.msgWarning(`识别成功`);
|
|
|
- let arr = e.data.result.boxes;
|
|
|
- boxes.value = [{ x: arr[0], y: arr[3] }, { x: arr[0], y: arr[1] }, { x: arr[2], y: arr[1] }, { x: arr[2], y: arr[3] }]
|
|
|
- proportion.value = (clientObj.value.height / (arr[3] - arr[1])).toFixed(2);
|
|
|
- }
|
|
|
- getCanvas();
|
|
|
+ // if (boxes.value.length == 0) {
|
|
|
+ // // speckText("识别成功");
|
|
|
+ // // proxy?.$modal.msgWarning(`识别成功`);
|
|
|
+ // let arr = e.data.result.boxes;
|
|
|
+ // boxes.value = [{ x: arr[0], y: arr[3] }, { x: arr[0], y: arr[1] }, { x: arr[2], y: arr[1] }, { x: arr[2], y: arr[3] }]
|
|
|
+ // proportion.value = (clientObj.value.height / (boxes.value[0].y - boxes.value[1].y)).toFixed(2);
|
|
|
+ // }
|
|
|
+ getCanvas(result);
|
|
|
};
|
|
|
|
|
|
|
|
|
-const getCanvas = () => {
|
|
|
+const getCanvas = (result: any) => {
|
|
|
|
|
|
- let leftA = { x: bodyposeData.value[12][0], y: bodyposeData.value[12][1] };//大腿
|
|
|
- let leftB = { x: bodyposeData.value[14][0], y: bodyposeData.value[14][1] };//膝盖
|
|
|
- let leftC = { x: bodyposeData.value[16][0], y: bodyposeData.value[16][1] };//脚
|
|
|
+ let leftA = { x: result[12][0], y: result[12][1] };//大腿
|
|
|
+ let leftB = { x: result[14][0], y: result[14][1] };//膝盖
|
|
|
+ let leftC = { x: result[16][0], y: result[16][1] };//脚
|
|
|
|
|
|
- let rightA = { x: bodyposeData.value[11][0], y: bodyposeData.value[11][1] };//大腿
|
|
|
- let rightB = { x: bodyposeData.value[13][0], y: bodyposeData.value[13][1] };//膝盖
|
|
|
- let rightC = { x: bodyposeData.value[15][0], y: bodyposeData.value[15][1] };//脚
|
|
|
+ let rightA = { x: result[11][0], y: result[11][1] };//大腿
|
|
|
+ let rightB = { x: result[13][0], y: result[13][1] };//膝盖
|
|
|
+ let rightC = { x: result[15][0], y: result[15][1] };//脚
|
|
|
|
|
|
let jiaodu1 = calculateAngleAtB(leftA, leftB, leftC)
|
|
|
let jiaodu2 = calculateAngleAtB(rightA, rightB, rightC)
|
|
@@ -1310,7 +1316,7 @@ const getCanvas = () => {
|
|
|
// console.log("人体中心", pointB);
|
|
|
// console.log("offset", offset)
|
|
|
// console.log("proportion.value",proportion.value)
|
|
|
- const originalPoints = bodyposeData.value;
|
|
|
+ const originalPoints = result;
|
|
|
// 计算缩放后坐标
|
|
|
const postData = originalPoints.map((point: any) => {
|
|
|
const newX = (point[0] - pointB.x) * proportion.value + pointB.x;
|
|
@@ -1437,15 +1443,21 @@ function calculateAngleAtB(pointA, pointB, pointC) {
|
|
|
}
|
|
|
|
|
|
onBeforeMount(() => {
|
|
|
+
|
|
|
});
|
|
|
|
|
|
// 组件挂载时初始化游戏
|
|
|
onMounted(() => {
|
|
|
- clientObj.value = {
|
|
|
- width: document.querySelector('.game-container').offsetWidth,
|
|
|
- height: document.querySelector('.game-container').offsetHeight,
|
|
|
- }
|
|
|
- initGame();
|
|
|
+ clientObj.value = {
|
|
|
+ width: document.querySelector('.game-container').offsetWidth,
|
|
|
+ height: document.querySelector('.game-container').offsetHeight,
|
|
|
+ }
|
|
|
+ let obj: any = props.areaStateList.find((item: any) => {
|
|
|
+ return item.area == props.currentGameArea
|
|
|
+ })
|
|
|
+ boxes.value = obj.boxes;
|
|
|
+ proportion.value = (clientObj.value.height / (boxes.value[0].y - boxes.value[1].y)).toFixed(2);
|
|
|
+ initGame();
|
|
|
});
|
|
|
|
|
|
|