Skip to content

Commit 6e8362f

Browse files
committed
tweak uppercut
1 parent 9f0e6a4 commit 6e8362f

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/components/ImageCanvas/drawHitbox.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { drawHurtboxLeftLeg } from '@/components/ImageCanvas/drawHurtboxLeftLeg'
1313
import { drawHurtboxRightArm } from '@/components/ImageCanvas/drawHurtboxRightArm';
1414
import { drawHurtboxRightLeg } from '@/components/ImageCanvas/drawHurtboxRightLeg';
1515
import { drawHurtboxUpperBody } from '@/components/ImageCanvas/drawHurtboxUpperBody';
16+
import { drawHitboxUpperBody } from './drawHitboxUpperBody';
1617
// import { drawTest } from './drawTest';
1718

1819
export const drawHitbox = async (
@@ -93,10 +94,12 @@ export const drawHitbox = async (
9394
// Anti-air
9495
case "LeftUppercut":
9596
drawHitboxLeftArm(cnv, ctx, landmark, side);
97+
drawHitboxUpperBody(cnv, ctx, landmark, side);
9698
drawHurtboxLowerBody(cnv, ctx, landmark);
9799
break;
98100
case "RightUppercut":
99101
drawHitboxRightArm(cnv, ctx, landmark, side);
102+
drawHitboxUpperBody(cnv, ctx, landmark, side);
100103
drawHurtboxLowerBody(cnv, ctx, landmark);
101104
break;
102105
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { NormalizedLandmark } from "@mediapipe/tasks-vision";
2+
import { Side } from "./checkSide";
3+
4+
export const drawHitboxUpperBody = (
5+
cnv: HTMLCanvasElement,
6+
ctx: CanvasRenderingContext2D,
7+
landmark: NormalizedLandmark[],
8+
side: Side,
9+
) => {
10+
const marginX = cnv.width * 0.1;
11+
const marginY = cnv.height * 0.1;
12+
const minWidth = cnv.width * 0.1;
13+
const minHeight = cnv.height * 0.1;
14+
15+
// upper body landmarks : 11, 12, 23, 24
16+
// https://ai.google.dev/edge/mediapipe/solutions/vision/pose_landmarker#pose_landmarker_model
17+
let maxX = -Infinity;
18+
let maxY = -Infinity;
19+
let minX = Infinity;
20+
let minY = Infinity;
21+
[11, 12, 23, 24].forEach((i) => {
22+
maxX = Math.max(maxX, landmark[i].x);
23+
maxY = Math.max(maxY, landmark[i].y);
24+
minX = Math.min(minX, landmark[i].x);
25+
minY = Math.min(minY, landmark[i].y);
26+
});
27+
const maxXPx = maxX * cnv.width;
28+
const maxYPx = maxY * cnv.height;
29+
const minXPx = minX * cnv.width;
30+
const minYPx = minY * cnv.height;
31+
32+
ctx.fillStyle = "rgb(255 0 0 / 50%)";
33+
if (side === "1P") {
34+
ctx.fillRect(
35+
minXPx,
36+
minYPx - marginY, // for uppercut
37+
Math.max((maxXPx - minXPx) + marginX, minWidth),
38+
Math.max((maxYPx - minYPx) + marginY, minHeight)
39+
);
40+
} else {
41+
ctx.fillRect(
42+
minXPx - marginX,
43+
minYPx - marginY, // for uppercut
44+
Math.max((maxXPx - minXPx) + marginX, minWidth),
45+
Math.max((maxYPx - minYPx) + marginY, minHeight)
46+
);
47+
}
48+
};

0 commit comments

Comments
 (0)