Skip to content

Commit

Permalink
Merge pull request #246 from hepengwei/feat_he
Browse files Browse the repository at this point in the history
优化代码,解决一些小BUG
  • Loading branch information
hepengwei authored Jan 18, 2024
2 parents 08ded36 + 50d0de8 commit 6382d83
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion docs/main.js

Large diffs are not rendered by default.

25 changes: 13 additions & 12 deletions src/pages/canvas/MatchLine/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ const MatchLine = () => {
const startPoint = useRef<Point>({ x: 0, y: 0 }); // 记录每一次连线开始点
const endPoint = useRef<Point>({ x: 0, y: 0 }); // 记录每一次连线结束点
const trigger = useRef<boolean>(false); // 标识是否触发连线
const backLines = useRef<any[]>([]); // 记录已经连接好的线·数据结构
const backLines = useRef<any[]>([]); // 记录已经连接好的线的数据结构
const anwsers = useRef<Partial<typeof standardAnwsers>>({}); // 记录答案
const question = useRef<string[]>(
Object.values(standardAnwsers).sort(() => Math.random() - 0.5)
); // 当前题目右边的顺序
const hasCheckout = useRef<boolean>(false); // 当前是否已校验

// 判断是否已有连接
Expand Down Expand Up @@ -451,17 +454,15 @@ const MatchLine = () => {
))}
</div>
<div className={styles.options} ref={rightOptionsRef}>
{Object.values(standardAnwsers)
.sort(() => Math.random() - 0.5)
.map((value: string) => (
<div
className={styles.option}
data-value={value}
data-ownership="R"
>
{value}
</div>
))}
{question.current.map((value: string) => (
<div
className={styles.option}
data-value={value}
data-ownership="R"
>
{value}
</div>
))}
</div>
{/* 实际连线 */}
<canvas ref={canvasRef}></canvas>
Expand Down
8 changes: 7 additions & 1 deletion src/pages/threejs/ThrowDice/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const g = 300; // 重力加速度
const restitution = 0.36; // 物理世界的反弹系数
const cameraInitPosition = { x: 0, y: 40, z: 120 }; // 相机位置
const floorY = -60; // 地板的y位置
const maxDistance = 1000; // 轨道控制器的最远距离

const ThrowDice = () => {
const intl = useIntl();
Expand Down Expand Up @@ -226,7 +227,11 @@ const ThrowDice = () => {
item.body.applyImpulse(new CANNON.Vec3(-16, force, -5));
} else {
// 隐藏其他不需要的骰子
item.body.position = new CANNON.Vec3(1000, floorY + diceSize / 2, 0);
item.body.position = new CANNON.Vec3(
0,
floorY + diceSize / 2,
maxDistance + diceSize * index
);
// @ts-ignore
item.mesh.position.copy(item.body.position);
item.mesh.rotation.set(0, 0, 0);
Expand Down Expand Up @@ -278,6 +283,7 @@ const ThrowDice = () => {

const controls = new OrbitControls(camera, renderer.domElement);
controls.enableRotate = false; // 禁止旋转,只能缩放
controls.maxDistance = maxDistance; // 最远距离
controlsRef.current = controls;

// 创建物理世界
Expand Down

0 comments on commit 6382d83

Please sign in to comment.