gaesup-world 0.8.24 → 0.8.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -56,7 +56,7 @@ export function GaeSupProps(_a) {
56
56
  }
57
57
  }
58
58
  return (_jsx("group", { ref: groupRef, position: position, onPointerDown: function (e) {
59
- handleClick(e, moveClicker, clickerOption.throttle || 100);
59
+ moveClicker(e, false, type);
60
60
  }, onDoubleClick: function (e) {
61
61
  e.stopPropagation();
62
62
  }, children: children }));
@@ -1,24 +1,25 @@
1
- import { useContext, useEffect } from "react";
2
- import { V3 } from "../../utils";
1
+ import { useContext } from "react";
2
+ import { V3, calcNorm } from "../../utils";
3
3
  import { GaesupWorldContext, GaesupWorldDispatchContext, } from "../../world/context";
4
4
  export function useClicker() {
5
- var _a = useContext(GaesupWorldContext), activeState = _a.activeState, clicker = _a.clicker, mode = _a.mode;
5
+ var _a = useContext(GaesupWorldContext), activeState = _a.activeState, clicker = _a.clicker, mode = _a.mode, refs = _a.refs;
6
6
  var dispatch = useContext(GaesupWorldDispatchContext);
7
7
  var moveClicker = function (e, isRun, type) {
8
8
  if (mode.controller !== "clicker" || type !== "ground")
9
9
  return;
10
- var originPoint = activeState.position;
11
- var newPosition = e.point;
12
- var newAngle = Math.atan2(newPosition.z - originPoint.z, newPosition.x - originPoint.x);
13
- var norm = Math.sqrt(Math.pow(newPosition.z - originPoint.z, 2) +
14
- Math.pow(newPosition.x - originPoint.x, 2));
10
+ var u = activeState.position;
11
+ var v = V3(e.point.x, e.point.y, e.point.z);
12
+ var newAngle = Math.atan2(v.z - u.z, v.x - u.x);
13
+ var norm = calcNorm(u, v, false);
14
+ // console.log(e, v);
15
+ // refs.rigidBodyRef.current?.setLinvel(V3(10, 0, 10), true);
15
16
  if (norm < 2)
16
17
  return;
17
18
  dispatch({
18
19
  type: "update",
19
20
  payload: {
20
21
  clicker: {
21
- point: V3(e.point.x, e.point.y, e.point.z),
22
+ point: v,
22
23
  angle: newAngle,
23
24
  isOn: true,
24
25
  isRun: isRun,
@@ -26,24 +27,25 @@ export function useClicker() {
26
27
  },
27
28
  });
28
29
  };
29
- // 거리 계산
30
- useEffect(function () {
31
- if (mode.controller !== "clicker")
32
- return;
33
- var originPoint = activeState.position;
34
- var newPosition = clicker.point;
35
- var norm = Math.sqrt(Math.pow(newPosition.z - originPoint.z, 2) +
36
- Math.pow(newPosition.x - originPoint.x, 2));
37
- if (norm < 1) {
38
- clicker.isOn = false;
39
- dispatch({
40
- type: "update",
41
- payload: {
42
- clicker: clicker,
43
- },
44
- });
45
- }
46
- }, [activeState.position, clicker.point]);
30
+ // // 거리 계산
31
+ // useEffect(() => {
32
+ // if (mode.controller !== "clicker") return;
33
+ // const originPoint = activeState.position;
34
+ // const newPosition = clicker.point;
35
+ // const norm = Math.sqrt(
36
+ // Math.pow(newPosition.z - originPoint.z, 2) +
37
+ // Math.pow(newPosition.x - originPoint.x, 2)
38
+ // );
39
+ // if (norm < 1) {
40
+ // clicker.isOn = false;
41
+ // dispatch({
42
+ // type: "update",
43
+ // payload: {
44
+ // clicker: clicker,
45
+ // },
46
+ // });
47
+ // }
48
+ // }, [activeState.position, clicker.point]);
47
49
  return {
48
50
  moveClicker: moveClicker,
49
51
  };
@@ -1,8 +1,18 @@
1
+ import { vec3 } from "@react-three/rapier";
2
+ import { calcNorm } from "../../utils";
1
3
  export default function stop(prop) {
2
- var _a = prop.worldContext, control = _a.control, clicker = _a.clicker, mode = _a.mode;
4
+ var _a;
5
+ var rigidBodyRef = prop.rigidBodyRef, _b = prop.worldContext, control = _b.control, clicker = _b.clicker, mode = _b.mode;
3
6
  var keyS = control.keyS;
4
7
  if (keyS && mode.controller === "clicker") {
5
8
  clicker.isOn = false;
6
9
  clicker.isRun = false;
7
10
  }
11
+ // 목적지 도착
12
+ var u = vec3((_a = rigidBodyRef.current) === null || _a === void 0 ? void 0 : _a.translation());
13
+ var norm = calcNorm(u, clicker.point, false);
14
+ if (norm < 1 && mode.controller === "clicker") {
15
+ clicker.isOn = false;
16
+ clicker.isRun = false;
17
+ }
8
18
  }
@@ -1,5 +1,6 @@
1
1
  import * as THREE from "three";
2
2
  export declare function isVectorNonZero(v: THREE.Vector3): boolean;
3
+ export declare function calcNorm(u: THREE.Vector3, v: THREE.Vector3, calcZ: boolean): number;
3
4
  export declare function isValidOrZero(condision: boolean, vector: THREE.Vector3): THREE.Vector3;
4
5
  export declare function isValidOrOne(condision: boolean, vector: THREE.Vector3): THREE.Vector3;
5
6
  export declare function V3(x?: number, y?: number, z?: number): THREE.Vector3;
@@ -2,6 +2,11 @@ import * as THREE from "three";
2
2
  export function isVectorNonZero(v) {
3
3
  return v.toArray().every(function (value) { return value !== 0; });
4
4
  }
5
+ export function calcNorm(u, v, calcZ) {
6
+ return Math.sqrt(Math.pow(u.x - v.x, 2) +
7
+ (calcZ && Math.pow(u.y - v.y, 2)) +
8
+ Math.pow(u.z - v.z, 2));
9
+ }
5
10
  export function isValidOrZero(condision, vector) {
6
11
  return condision ? vector : new THREE.Vector3(0, 0, 0);
7
12
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gaesup-world",
3
- "version": "0.8.24",
3
+ "version": "0.8.25",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",