gaesup-world 0.0.1 → 0.0.2
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.
- package/index.html +1 -0
- package/package.json +3 -1
- package/src/gaesup/camera/control/normal.ts +3 -2
- package/src/gaesup/camera/index.tsx +1 -1
- package/src/gaesup/component/Airplane.tsx +23 -17
- package/src/gaesup/component/Character.tsx +16 -6
- package/src/gaesup/component/Vehicle.tsx +20 -17
- package/src/gaesup/component/gltf/CharacterGltf.tsx +73 -58
- package/src/gaesup/component/gltf/VehicleGltf.tsx +4 -4
- package/src/gaesup/component/ref/airplane.tsx +25 -11
- package/src/gaesup/component/ref/character.tsx +17 -12
- package/src/gaesup/component/ref/vehicle.tsx +23 -46
- package/src/gaesup/component/setInit.ts +14 -0
- package/src/gaesup/controller/index.tsx +21 -2
- package/src/gaesup/controller/type.ts +13 -0
- package/src/gaesup/initial/controller/index.ts +14 -1
- package/src/gaesup/initial/gaesupWorld/index.ts +3 -2
- package/src/gaesup/initial/gaesupWorld/type.ts +4 -0
- package/src/gaesup/physics/airplane/damping.ts +2 -4
- package/src/gaesup/physics/airplane/direction.ts +58 -47
- package/src/gaesup/physics/airplane/impulse.ts +11 -5
- package/src/gaesup/physics/character/direction.ts +1 -2
- package/src/gaesup/physics/check/moving.ts +2 -3
- package/src/gaesup/physics/index.ts +4 -5
- package/src/gaesup/physics/type.ts +0 -3
- package/src/gaesup/physics/vehicle/damping.ts +5 -1
- package/src/gaesup/physics/vehicle/direction.ts +35 -14
- package/src/gaesup/physics/vehicle/impulse.ts +20 -3
- package/src/gaesup/stores/airplane/index.ts +18 -2
- package/src/gaesup/stores/airplane/type.ts +22 -4
- package/src/gaesup/stores/context/controller/index.ts +19 -2
- package/src/gaesup/stores/context/controller/type.ts +5 -0
- package/src/gaesup/stores/context/gaesupworld/type.ts +9 -4
- package/src/gaesup/stores/gameboy/index.ts +3 -0
- package/src/gaesup/stores/gameboy/type.ts +8 -0
- package/src/gaesup/stores/joystick/index.ts +2 -0
- package/src/gaesup/stores/joystick/type.ts +11 -3
- package/src/gaesup/tools/gameboy/GameBoyButton.tsx +6 -0
- package/src/gaesup/tools/gameboy/index.tsx +9 -10
- package/src/gaesup/tools/gameboy/style.css.ts +18 -0
- package/src/gaesup/tools/gamepad/index.tsx +7 -21
- package/src/gaesup/tools/gamepad/style.css.ts +1 -1
- package/src/gaesup/tools/joystick/index.tsx +43 -19
- package/src/gaesup/tools/joystick/style.css.ts +8 -2
- package/src/gaesup/tools/jumpPoint/style.css.ts +3 -2
- package/src/gaesup/tools/minimap/index.tsx +24 -11
- package/src/gaesup/tools/minimap/style.css.ts +1 -1
- package/src/gaesup/camera/control/normal copy.ts +0 -19
- package/src/gaesup/physics/airplane copy/currentSetting.ts +0 -20
- package/src/gaesup/physics/airplane copy/direction.ts +0 -52
- package/src/gaesup/physics/airplane copy/gravity.ts +0 -6
- package/src/gaesup/physics/airplane copy/impulse.ts +0 -28
- package/src/gaesup/physics/airplane copy/index.tsx +0 -14
- package/src/gaesup/physics/airplane copy/turn.ts +0 -9
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { Collider, RevoluteImpulseJoint } from "@dimforge/rapier3d-compat";
|
|
4
4
|
import { RapierRigidBody } from "@react-three/rapier";
|
|
5
|
-
import
|
|
5
|
+
import { useContext, useMemo, useReducer, useRef } from "react";
|
|
6
6
|
import Camera from "../camera";
|
|
7
7
|
import { Airplane } from "../component/Airplane";
|
|
8
8
|
import { Character } from "../component/Character";
|
|
@@ -36,6 +36,19 @@ export default function GaesupController(props: controllerType) {
|
|
|
36
36
|
gaesupControllerDefault.orthographicCamera,
|
|
37
37
|
props.orthographicCamera || {}
|
|
38
38
|
),
|
|
39
|
+
airplane: Object.assign(
|
|
40
|
+
gaesupControllerDefault.airplane,
|
|
41
|
+
props.airplane || {}
|
|
42
|
+
),
|
|
43
|
+
vehicle: Object.assign(
|
|
44
|
+
gaesupControllerDefault.vehicle,
|
|
45
|
+
props.vehicle || {}
|
|
46
|
+
),
|
|
47
|
+
character: Object.assign(
|
|
48
|
+
gaesupControllerDefault.character,
|
|
49
|
+
props.character || {}
|
|
50
|
+
),
|
|
51
|
+
isRider: props.isRider !== null ? props.isRider : false,
|
|
39
52
|
});
|
|
40
53
|
|
|
41
54
|
const capsuleColliderRef = useRef<Collider>(null);
|
|
@@ -43,6 +56,7 @@ export default function GaesupController(props: controllerType) {
|
|
|
43
56
|
const outerGroupRef = useRef<THREE.Group>(null);
|
|
44
57
|
const innerGroupRef = useRef<THREE.Group>(null);
|
|
45
58
|
const slopeRayOriginRef = useRef<THREE.Mesh>(null);
|
|
59
|
+
const characterInnerRef = useRef<THREE.Group>(null);
|
|
46
60
|
const jointRefs = useRef<RevoluteImpulseJoint>(null);
|
|
47
61
|
|
|
48
62
|
const gaesupControl = useMemo(
|
|
@@ -55,7 +69,10 @@ export default function GaesupController(props: controllerType) {
|
|
|
55
69
|
controller.cameraOption,
|
|
56
70
|
controller.perspectiveCamera,
|
|
57
71
|
controller.orthographicCamera,
|
|
58
|
-
|
|
72
|
+
controller.airplane,
|
|
73
|
+
controller.vehicle,
|
|
74
|
+
controller.character,
|
|
75
|
+
controller.isRider,
|
|
59
76
|
]
|
|
60
77
|
);
|
|
61
78
|
|
|
@@ -65,6 +82,7 @@ export default function GaesupController(props: controllerType) {
|
|
|
65
82
|
outerGroupRef,
|
|
66
83
|
innerGroupRef,
|
|
67
84
|
slopeRayOriginRef,
|
|
85
|
+
characterInnerRef,
|
|
68
86
|
jointRefs,
|
|
69
87
|
};
|
|
70
88
|
|
|
@@ -81,6 +99,7 @@ export default function GaesupController(props: controllerType) {
|
|
|
81
99
|
},
|
|
82
100
|
children: props.children,
|
|
83
101
|
groupProps: props.groupProps,
|
|
102
|
+
isRider: props.isRider !== null ? props.isRider : false,
|
|
84
103
|
...refs,
|
|
85
104
|
};
|
|
86
105
|
|
|
@@ -11,6 +11,11 @@ import * as THREE from "three";
|
|
|
11
11
|
import { cameraRayType } from "../camera/type";
|
|
12
12
|
import { callbackType } from "../initial/callback/type";
|
|
13
13
|
|
|
14
|
+
import {
|
|
15
|
+
airplaneType,
|
|
16
|
+
characterType,
|
|
17
|
+
vehicleType,
|
|
18
|
+
} from "../stores/airplane/type";
|
|
14
19
|
import {
|
|
15
20
|
gaesupCameraOptionType,
|
|
16
21
|
gaesupCameraPropType,
|
|
@@ -82,6 +87,7 @@ export type groundRayType = Omit<rayType, "current" | "angle">;
|
|
|
82
87
|
export type propType = {
|
|
83
88
|
children?: ReactNode;
|
|
84
89
|
groupProps?: GroupProps;
|
|
90
|
+
rigidBodyProps?: RigidBodyProps;
|
|
85
91
|
slopeRay: slopeRayType;
|
|
86
92
|
groundRay: groundRayType;
|
|
87
93
|
cameraRay: cameraRayType;
|
|
@@ -98,6 +104,7 @@ export type propType = {
|
|
|
98
104
|
keyControl: keyControlType;
|
|
99
105
|
debug?: boolean;
|
|
100
106
|
callbacks?: callbackType;
|
|
107
|
+
isRider?: boolean;
|
|
101
108
|
};
|
|
102
109
|
|
|
103
110
|
export type animationTagType = {
|
|
@@ -121,6 +128,7 @@ export type refsType = {
|
|
|
121
128
|
outerGroupRef: RefObject<THREE.Group>;
|
|
122
129
|
innerGroupRef: RefObject<THREE.Group>;
|
|
123
130
|
slopeRayOriginRef: RefObject<THREE.Mesh>;
|
|
131
|
+
characterInnerRef: RefObject<THREE.Group>;
|
|
124
132
|
jointRefs: RefObject<RevoluteImpulseJoint>;
|
|
125
133
|
};
|
|
126
134
|
|
|
@@ -131,9 +139,14 @@ export interface controllerPropType extends RigidBodyProps {
|
|
|
131
139
|
props?: RigidBodyProps;
|
|
132
140
|
constant?: partialConstantType;
|
|
133
141
|
groupProps?: GroupProps;
|
|
142
|
+
rigidBodyProps?: RigidBodyProps;
|
|
134
143
|
cameraMode?: gaesupCameraPropType;
|
|
135
144
|
cameraOption?: gaesupCameraOptionType;
|
|
136
145
|
perspectiveCamera?: perspectiveCameraPropType;
|
|
137
146
|
orthographicCamera?: OrthographicCameraProps;
|
|
147
|
+
airplane?: airplaneType;
|
|
148
|
+
vehicle?: vehicleType;
|
|
149
|
+
character?: characterType;
|
|
150
|
+
isRider?: boolean;
|
|
138
151
|
}
|
|
139
152
|
export type controllerType = controllerPropType & {} & callbackType;
|
|
@@ -25,10 +25,23 @@ export default function initControllerProps({
|
|
|
25
25
|
}) {
|
|
26
26
|
const context = useContext(GaesupWorldContext);
|
|
27
27
|
const dispatch = useContext(GaesupWorldDispatchContext);
|
|
28
|
-
|
|
28
|
+
const { control, mode } = useContext(GaesupWorldContext);
|
|
29
29
|
const [_, getKeys] = useKeyboardControls();
|
|
30
30
|
const keyControl: keyControlType = getKeys();
|
|
31
31
|
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
if (keyControl && control) {
|
|
34
|
+
dispatch({
|
|
35
|
+
type: "update",
|
|
36
|
+
payload: {
|
|
37
|
+
control: {
|
|
38
|
+
...(mode.controller === "keyboard" ? keyControl : control),
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}, [mode.controller, keyControl, control]);
|
|
44
|
+
|
|
32
45
|
const groundRay: groundRayType = useMemo(() => {
|
|
33
46
|
return {
|
|
34
47
|
origin: vec3(),
|
|
@@ -9,11 +9,11 @@ import {
|
|
|
9
9
|
import { modeDefault } from "../../stores/context/gaesupworld";
|
|
10
10
|
import { gaesupReducer } from "../../stores/context/gaesupworld/reducer";
|
|
11
11
|
import { controlDefault } from "../../stores/control";
|
|
12
|
+
import { gameboyDefault } from "../../stores/gameboy";
|
|
12
13
|
import { joyStickDefault } from "../../stores/joystick";
|
|
13
14
|
import { minimapDefault } from "../../stores/minimap";
|
|
14
15
|
import { statesDefault } from "../../stores/states";
|
|
15
16
|
import { urlDefault } from "../../stores/url";
|
|
16
|
-
import minimap from "../../tools/minimap";
|
|
17
17
|
import { V3 } from "../../utils/vector";
|
|
18
18
|
import initColider from "./collider";
|
|
19
19
|
import { initGaesupWorldPropsType } from "./type";
|
|
@@ -44,8 +44,9 @@ export default function initGaesupWorld(props: initGaesupWorldPropsType) {
|
|
|
44
44
|
airplaneGltf: null,
|
|
45
45
|
states: statesDefault,
|
|
46
46
|
debug: false,
|
|
47
|
-
minimap: Object.assign(minimapDefault, minimap || {}),
|
|
47
|
+
minimap: Object.assign(minimapDefault, props.minimap || {}),
|
|
48
48
|
joystick: joyStickDefault,
|
|
49
|
+
gameboy: gameboyDefault,
|
|
49
50
|
control: controlDefault,
|
|
50
51
|
points: [],
|
|
51
52
|
refs: null,
|
|
@@ -10,6 +10,8 @@ import {
|
|
|
10
10
|
gaesupWorldPartialPropType,
|
|
11
11
|
gaesupWorldPropType,
|
|
12
12
|
} from "../../stores/context/gaesupworld/type";
|
|
13
|
+
import { gameboyType } from "../../stores/gameboy/type";
|
|
14
|
+
import { joyStickType } from "../../stores/joystick/type";
|
|
13
15
|
import { minimapType } from "../../stores/minimap/type";
|
|
14
16
|
import { urlType } from "../../stores/url/type";
|
|
15
17
|
import { getGltfResultType } from "./collider/gltf";
|
|
@@ -25,6 +27,8 @@ export type initGaesupWorldPropsType = {
|
|
|
25
27
|
mode?: gaesupControllerPropType;
|
|
26
28
|
debug?: boolean;
|
|
27
29
|
minimap?: Omit<minimapType, "props">;
|
|
30
|
+
joystick?: joyStickType;
|
|
31
|
+
gameboy?: gameboyType;
|
|
28
32
|
};
|
|
29
33
|
|
|
30
34
|
export type innerColliderPropType = {
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { calcPropType } from "../type";
|
|
2
2
|
|
|
3
3
|
export default function damping(prop: calcPropType) {
|
|
4
|
-
const { rigidBodyRef
|
|
5
|
-
|
|
6
|
-
const { brakeRate } = constant;
|
|
7
|
-
rigidBodyRef.current.setLinearDamping(space ? brakeRate : 0.5);
|
|
4
|
+
const { rigidBodyRef } = prop;
|
|
5
|
+
rigidBodyRef.current.setLinearDamping(0.1);
|
|
8
6
|
}
|
|
@@ -1,70 +1,81 @@
|
|
|
1
|
+
import { quat } from "@react-three/rapier";
|
|
1
2
|
import { V3 } from "../../utils/vector";
|
|
2
3
|
import { calcPropType } from "../type";
|
|
3
4
|
|
|
4
5
|
export default function direction(prop: calcPropType) {
|
|
5
6
|
const {
|
|
6
|
-
|
|
7
|
+
state,
|
|
7
8
|
innerGroupRef,
|
|
8
|
-
worldContext: { activeState },
|
|
9
|
+
worldContext: { joystick, activeState, control, mode },
|
|
10
|
+
controllerContext: { airplane },
|
|
9
11
|
} = prop;
|
|
10
|
-
const { forward, backward, leftward, rightward, shift } =
|
|
12
|
+
const { forward, backward, leftward, rightward, shift, space } = control;
|
|
13
|
+
const { angleChange, maxAngle, accelRatio } = airplane;
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
console.log(Number(joystick.joyStickOrigin.isUp));
|
|
16
|
+
|
|
17
|
+
let boost = 0;
|
|
18
|
+
if (mode.controller === "joystick") {
|
|
19
|
+
boost = space
|
|
20
|
+
? Number(joystick.joyStickOrigin.isOn)
|
|
21
|
+
: Number(joystick.joyStickOrigin.isOn) * accelRatio;
|
|
22
|
+
} else {
|
|
23
|
+
boost = space ? Number(shift) : Number(shift) * accelRatio;
|
|
24
|
+
}
|
|
25
|
+
const upDown =
|
|
26
|
+
mode.controller === "joystick"
|
|
27
|
+
? joystick.joyStickOrigin.isUp
|
|
28
|
+
? -1
|
|
29
|
+
: 1
|
|
30
|
+
: Number(backward) - Number(forward);
|
|
14
31
|
const leftRight = Number(rightward) - Number(leftward);
|
|
15
32
|
const front = V3().set(boost, boost, boost);
|
|
16
|
-
activeState.euler.y += (Number(leftward) - Number(rightward)) * 0.02;
|
|
17
33
|
|
|
18
|
-
const
|
|
19
|
-
const
|
|
34
|
+
const _euler = activeState.euler.clone();
|
|
35
|
+
const __euler = activeState.euler.clone();
|
|
36
|
+
if (mode.controller === "joystick") {
|
|
37
|
+
__euler.y =
|
|
38
|
+
-state.camera.rotation.y - joystick.joyStickOrigin.angle - Math.PI / 2;
|
|
39
|
+
} else {
|
|
40
|
+
activeState.euler.y += -leftRight * angleChange.y;
|
|
41
|
+
}
|
|
42
|
+
if (mode.controller === "joystick")
|
|
43
|
+
activeState.euler.setFromQuaternion(
|
|
44
|
+
quat()
|
|
45
|
+
.setFromEuler(_euler)
|
|
46
|
+
.slerp(
|
|
47
|
+
quat().setFromEuler(__euler),
|
|
48
|
+
joystick.joyStickOrigin.isIn ? 0.01 : 0.1
|
|
49
|
+
)
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const X = maxAngle.x * upDown;
|
|
53
|
+
const Z = maxAngle.z * leftRight;
|
|
20
54
|
|
|
21
55
|
const _x = innerGroupRef.current.rotation.x;
|
|
22
56
|
const _z = innerGroupRef.current.rotation.z;
|
|
23
57
|
|
|
24
|
-
const maxX =
|
|
25
|
-
const maxZ =
|
|
58
|
+
const maxX = maxAngle.x;
|
|
59
|
+
const maxZ = maxAngle.z;
|
|
60
|
+
|
|
61
|
+
const innerGrounRefRotation = innerGroupRef.current.clone();
|
|
26
62
|
|
|
27
|
-
if (_x < -maxX)
|
|
28
|
-
else if (_x > maxX)
|
|
29
|
-
else
|
|
63
|
+
if (_x < -maxX) innerGrounRefRotation.rotation.x = -maxX + X;
|
|
64
|
+
else if (_x > maxX) innerGrounRefRotation.rotation.x = maxX + X;
|
|
65
|
+
else innerGrounRefRotation.rotateX(X);
|
|
30
66
|
|
|
31
|
-
if (_z < -maxZ)
|
|
32
|
-
else if (_z > maxZ)
|
|
33
|
-
else
|
|
67
|
+
if (_z < -maxZ) innerGrounRefRotation.rotation.z = -maxZ + Z;
|
|
68
|
+
else if (_z > maxZ) innerGrounRefRotation.rotation.z = maxZ + Z;
|
|
69
|
+
else innerGrounRefRotation.rotateZ(Z);
|
|
70
|
+
|
|
71
|
+
innerGroupRef.current.setRotationFromQuaternion(
|
|
72
|
+
quat()
|
|
73
|
+
.setFromEuler(innerGroupRef.current.rotation.clone())
|
|
74
|
+
.slerp(quat().setFromEuler(innerGrounRefRotation.rotation), 0.1)
|
|
75
|
+
);
|
|
34
76
|
|
|
35
|
-
// current.dir = V3(
|
|
36
|
-
// Math.sin(current.euler.y),
|
|
37
|
-
// 0,
|
|
38
|
-
// Math.cos(current.euler.y)
|
|
39
|
-
// ).normalize();
|
|
40
|
-
// current.direction = front
|
|
41
|
-
// .multiply(current.dir)
|
|
42
|
-
// .multiplyScalar(shift ? accelRate : 1);
|
|
43
77
|
activeState.direction = front.multiply(
|
|
44
78
|
V3(Math.sin(activeState.euler.y), -upDown, Math.cos(activeState.euler.y))
|
|
45
79
|
);
|
|
46
80
|
activeState.dir = activeState.direction.normalize();
|
|
47
|
-
|
|
48
|
-
// const pitch = Number(forward) - Number(backward);
|
|
49
|
-
// // const front = vec3().set(start, start * 1, start);
|
|
50
|
-
// const yaw = Number(leftward) - Number(rightward);
|
|
51
|
-
//
|
|
52
|
-
// // activeState.euler.y += (side * Math.PI) / 64;
|
|
53
|
-
//
|
|
54
|
-
// // if (euler.x > Math.PI / 16) euler.x = Math.PI / 16 - 0.005;
|
|
55
|
-
// // else if (euler.x < -Math.PI / 16) euler.x = -Math.PI / 16 + 0.005;
|
|
56
|
-
// // if (euler.z > Math.PI / 16) euler.z = Math.PI / 16 - 0.005;
|
|
57
|
-
// // else if (euler.z < -Math.PI / 16) euler.z = -Math.PI / 16 + 0.005;
|
|
58
|
-
// // if (euler.y > Math.PI / 4) euler.y = Math.PI / 4 - 0.005;
|
|
59
|
-
// // else if (euler.y < -Math.PI / 4) euler.y = -Math.PI / 4 + 0.005;
|
|
60
|
-
//
|
|
61
|
-
// const delta = Math.PI * 0.005;
|
|
62
|
-
// euler.x += pitch * delta * Math.cos(euler.z) * Math.cos(euler.y);
|
|
63
|
-
// euler.z += -yaw * delta;
|
|
64
|
-
// euler.y += pitch * delta * Math.sin(euler.z) * Math.sin(euler.y);
|
|
65
|
-
//
|
|
66
|
-
// // activeState.direction = front.multiply(
|
|
67
|
-
// // V3(Math.sin(activeState.euler.y), 1, Math.cos(activeState.euler.y))
|
|
68
|
-
// // );
|
|
69
|
-
// // activeState.dir = activeState.direction.normalize();
|
|
70
81
|
}
|
|
@@ -4,12 +4,18 @@ import { calcPropType } from "../type";
|
|
|
4
4
|
export default function impulse(prop: calcPropType) {
|
|
5
5
|
const {
|
|
6
6
|
rigidBodyRef,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
worldContext: { activeState },
|
|
7
|
+
worldContext: { activeState, control },
|
|
8
|
+
controllerContext: { airplane },
|
|
10
9
|
} = prop;
|
|
11
|
-
const {
|
|
12
|
-
|
|
10
|
+
const { maxSpeed } = airplane;
|
|
11
|
+
|
|
12
|
+
const velocity = rigidBodyRef.current.linvel();
|
|
13
|
+
const currentSpeed = Math.sqrt(
|
|
14
|
+
velocity.x ** 2 + velocity.y ** 2 + velocity.z ** 2
|
|
15
|
+
);
|
|
16
|
+
if (currentSpeed > maxSpeed) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
13
19
|
|
|
14
20
|
rigidBodyRef.current.applyImpulse(
|
|
15
21
|
vec3({
|
|
@@ -91,9 +91,8 @@ export function normalDirection({
|
|
|
91
91
|
|
|
92
92
|
export default function direction(prop: calcPropType) {
|
|
93
93
|
const {
|
|
94
|
-
control,
|
|
95
94
|
state,
|
|
96
|
-
worldContext: { joystick, mode, activeState },
|
|
95
|
+
worldContext: { joystick, mode, activeState, control },
|
|
97
96
|
controllerContext: { cameraMode },
|
|
98
97
|
} = prop;
|
|
99
98
|
if (cameraMode.controlType === "normal") {
|
|
@@ -2,10 +2,9 @@ import { calcPropType } from "../type";
|
|
|
2
2
|
|
|
3
3
|
export default function moving(prop: calcPropType) {
|
|
4
4
|
const {
|
|
5
|
-
|
|
6
|
-
worldContext: { states, joystick, mode },
|
|
5
|
+
worldContext: { states, joystick, mode, control },
|
|
7
6
|
} = prop;
|
|
8
|
-
const { forward, backward, leftward, rightward, shift, space } =
|
|
7
|
+
const { forward, backward, leftward, rightward, shift, space } = control;
|
|
9
8
|
if (mode.controller === "gameboy" || mode.controller === "keyboard") {
|
|
10
9
|
states.isMoving = forward || backward || leftward || rightward;
|
|
11
10
|
states.isNotMoving = !states.isMoving;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { useFrame } from "@react-three/fiber";
|
|
2
2
|
|
|
3
|
-
import { useKeyboardControls } from "@react-three/drei";
|
|
4
3
|
import { useContext } from "react";
|
|
5
4
|
import { propType } from "../controller/type";
|
|
6
5
|
|
|
@@ -21,20 +20,20 @@ export default function calculation(prop: propType) {
|
|
|
21
20
|
const worldContext = useContext(GaesupWorldContext);
|
|
22
21
|
const controllerContext = useContext(GaesupControllerContext);
|
|
23
22
|
const dispatch = useContext(GaesupWorldDispatchContext);
|
|
24
|
-
const control = useKeyboardControls()[1]();
|
|
25
23
|
const { mode } = worldContext;
|
|
26
24
|
useFrame((state, delta) => {
|
|
27
|
-
const { rigidBodyRef, outerGroupRef } = prop;
|
|
25
|
+
const { rigidBodyRef, outerGroupRef, innerGroupRef } = prop;
|
|
28
26
|
if (
|
|
29
27
|
!rigidBodyRef ||
|
|
30
28
|
!rigidBodyRef.current ||
|
|
31
29
|
!outerGroupRef ||
|
|
32
|
-
!outerGroupRef.current
|
|
30
|
+
!outerGroupRef.current ||
|
|
31
|
+
!innerGroupRef ||
|
|
32
|
+
!innerGroupRef.current
|
|
33
33
|
)
|
|
34
34
|
return null;
|
|
35
35
|
const calcProp: calcPropType = {
|
|
36
36
|
...prop,
|
|
37
|
-
control,
|
|
38
37
|
state,
|
|
39
38
|
delta,
|
|
40
39
|
worldContext,
|
|
@@ -11,9 +11,6 @@ import {
|
|
|
11
11
|
export type SetAtom<Args extends unknown[], Result> = (...args: Args) => Result;
|
|
12
12
|
|
|
13
13
|
export type calcPropType = propType & {
|
|
14
|
-
control: {
|
|
15
|
-
[key: string]: boolean;
|
|
16
|
-
};
|
|
17
14
|
state?: RootState;
|
|
18
15
|
checkCollision?: (delta: number) => void;
|
|
19
16
|
worldContext?: gaesupWorldPropType;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { calcPropType } from "../type";
|
|
2
2
|
|
|
3
3
|
export default function damping(prop: calcPropType) {
|
|
4
|
-
const {
|
|
4
|
+
const {
|
|
5
|
+
rigidBodyRef,
|
|
6
|
+
constant,
|
|
7
|
+
worldContext: { control },
|
|
8
|
+
} = prop;
|
|
5
9
|
const { space } = control;
|
|
6
10
|
const { brakeRate } = constant;
|
|
7
11
|
rigidBodyRef.current.setLinearDamping(space ? brakeRate : 0.5);
|
|
@@ -1,25 +1,46 @@
|
|
|
1
|
-
import { vec3 } from "@react-three/rapier";
|
|
1
|
+
import { quat, vec3 } from "@react-three/rapier";
|
|
2
2
|
import { V3 } from "../../utils/vector";
|
|
3
3
|
import { calcPropType } from "../type";
|
|
4
4
|
|
|
5
5
|
export default function direction(prop: calcPropType) {
|
|
6
6
|
const {
|
|
7
|
-
|
|
7
|
+
state,
|
|
8
|
+
worldContext: { activeState, control, mode, joystick },
|
|
8
9
|
} = prop;
|
|
9
|
-
const { forward, backward, leftward, rightward } =
|
|
10
|
+
const { forward, backward, leftward, rightward } = control;
|
|
11
|
+
|
|
12
|
+
let start = Number(forward) - Number(backward);
|
|
13
|
+
if (mode.controller === "joystick") {
|
|
14
|
+
if (!joystick.joyStickOrigin.isCenter)
|
|
15
|
+
start = joystick.joyStickOrigin.isOn ? 1 : 0;
|
|
16
|
+
} else {
|
|
17
|
+
start = Number(forward) - Number(backward);
|
|
18
|
+
}
|
|
10
19
|
|
|
11
|
-
const start = Number(forward) - Number(backward);
|
|
12
20
|
const front = vec3().set(start, 0, start);
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
|
|
22
|
+
const _euler = activeState.euler.clone();
|
|
23
|
+
const __euler = activeState.euler.clone();
|
|
24
|
+
|
|
25
|
+
if (mode.controller === "joystick") {
|
|
26
|
+
if (!joystick.joyStickOrigin.isCenter)
|
|
27
|
+
__euler.y =
|
|
28
|
+
-state.camera.rotation.y - joystick.joyStickOrigin.angle - Math.PI / 2;
|
|
29
|
+
} else {
|
|
30
|
+
activeState.euler.y +=
|
|
31
|
+
((Number(leftward) - Number(rightward)) * Math.PI) / 64;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (mode.controller === "joystick")
|
|
35
|
+
activeState.euler.setFromQuaternion(
|
|
36
|
+
quat()
|
|
37
|
+
.setFromEuler(_euler)
|
|
38
|
+
.slerp(
|
|
39
|
+
quat().setFromEuler(__euler),
|
|
40
|
+
joystick.joyStickOrigin.isIn ? 0.01 : 0.1
|
|
41
|
+
)
|
|
42
|
+
);
|
|
43
|
+
|
|
23
44
|
activeState.direction = front.multiply(
|
|
24
45
|
V3(Math.sin(activeState.euler.y), 0, Math.cos(activeState.euler.y))
|
|
25
46
|
);
|
|
@@ -5,18 +5,35 @@ export default function impulse(prop: calcPropType) {
|
|
|
5
5
|
const {
|
|
6
6
|
rigidBodyRef,
|
|
7
7
|
constant,
|
|
8
|
-
control,
|
|
9
|
-
|
|
8
|
+
worldContext: { activeState, control, mode, joystick },
|
|
9
|
+
controllerContext: { vehicle },
|
|
10
10
|
} = prop;
|
|
11
11
|
const { shift } = control;
|
|
12
12
|
const { accelRate } = constant;
|
|
13
|
+
const { maxSpeed } = vehicle;
|
|
14
|
+
const velocity = rigidBodyRef.current.linvel();
|
|
15
|
+
const currentSpeed = Math.sqrt(
|
|
16
|
+
velocity.x ** 2 + velocity.y ** 2 + velocity.z ** 2
|
|
17
|
+
);
|
|
18
|
+
if (currentSpeed > maxSpeed) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let speed = 1;
|
|
23
|
+
if (mode.controller === "joystick") {
|
|
24
|
+
console.log(joystick.joyStickOrigin.isCenter);
|
|
25
|
+
if (!joystick.joyStickOrigin.isCenter)
|
|
26
|
+
speed = joystick.joyStickOrigin.isIn ? accelRate : 1;
|
|
27
|
+
} else {
|
|
28
|
+
speed = shift ? accelRate : 1;
|
|
29
|
+
}
|
|
13
30
|
|
|
14
31
|
rigidBodyRef.current.applyImpulse(
|
|
15
32
|
vec3({
|
|
16
33
|
x: activeState.direction.x,
|
|
17
34
|
y: 0,
|
|
18
35
|
z: activeState.direction.z,
|
|
19
|
-
}).multiplyScalar(
|
|
36
|
+
}).multiplyScalar(speed),
|
|
20
37
|
false
|
|
21
38
|
);
|
|
22
39
|
}
|
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
import { V3 } from "../../utils/vector";
|
|
2
2
|
|
|
3
3
|
export const airplaneDefault = {
|
|
4
|
-
angleChange: V3(0.
|
|
5
|
-
maxAngle: V3(0.
|
|
4
|
+
angleChange: V3(0.01, 0.005, 0.005),
|
|
5
|
+
maxAngle: V3(0.1, 0.1, 0.1),
|
|
6
|
+
maxSpeed: 60,
|
|
7
|
+
accelRatio: 2,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const vehicleDefault = {
|
|
11
|
+
angleChange: V3(0.01, 0.005, 0.005),
|
|
12
|
+
maxAngle: V3(0.1, 0.1, 0.1),
|
|
13
|
+
maxSpeed: 60,
|
|
14
|
+
accelRatio: 2,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const characterDefault = {
|
|
18
|
+
angleChange: V3(0.01, 0.005, 0.005),
|
|
19
|
+
maxAngle: V3(0.1, 0.1, 0.1),
|
|
20
|
+
maxSpeed: 60,
|
|
21
|
+
accelRatio: 2,
|
|
6
22
|
};
|
|
@@ -1,4 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { GroupProps } from "@react-three/fiber";
|
|
2
|
+
|
|
3
|
+
export interface airplaneType extends GroupProps {
|
|
4
|
+
angleChange?: THREE.Vector3;
|
|
5
|
+
maxAngle?: THREE.Vector3;
|
|
6
|
+
maxSpeed?: number;
|
|
7
|
+
accelRatio?: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface vehicleType extends GroupProps {
|
|
11
|
+
angleChange?: THREE.Vector3;
|
|
12
|
+
maxAngle?: THREE.Vector3;
|
|
13
|
+
maxSpeed?: number;
|
|
14
|
+
accelRatio?: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface characterType extends GroupProps {
|
|
18
|
+
angleChange?: THREE.Vector3;
|
|
19
|
+
maxAngle?: THREE.Vector3;
|
|
20
|
+
maxSpeed?: number;
|
|
21
|
+
accelRatio?: number;
|
|
22
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createContext } from "react";
|
|
2
2
|
import { V3 } from "../../../utils/vector";
|
|
3
|
-
import { airplaneDefault } from "../../airplane";
|
|
4
3
|
import { dispatchType } from "../gaesupworld/type";
|
|
5
4
|
import {
|
|
6
5
|
gaesupControllerType,
|
|
@@ -26,7 +25,25 @@ export const gaesupControllerDefault = {
|
|
|
26
25
|
near: 0.1,
|
|
27
26
|
far: 1000,
|
|
28
27
|
},
|
|
29
|
-
airplane: {
|
|
28
|
+
airplane: {
|
|
29
|
+
angleChange: V3(0.01, 0.005, 0.005),
|
|
30
|
+
maxAngle: V3(0.1, 0.1, 0.1),
|
|
31
|
+
maxSpeed: 60,
|
|
32
|
+
accelRatio: 2,
|
|
33
|
+
},
|
|
34
|
+
vehicle: {
|
|
35
|
+
angleChange: V3(0.01, 0.005, 0.005),
|
|
36
|
+
maxAngle: V3(0.1, 0.1, 0.1),
|
|
37
|
+
maxSpeed: 60,
|
|
38
|
+
accelRatio: 2,
|
|
39
|
+
},
|
|
40
|
+
character: {
|
|
41
|
+
angleChange: V3(0.01, 0.005, 0.005),
|
|
42
|
+
maxAngle: V3(0.1, 0.1, 0.1),
|
|
43
|
+
maxSpeed: 60,
|
|
44
|
+
accelRatio: 2,
|
|
45
|
+
},
|
|
46
|
+
isRider: false,
|
|
30
47
|
};
|
|
31
48
|
|
|
32
49
|
export const GaesupControllerContext = createContext<gaesupControllerType>({
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { OrthographicCameraProps } from "@react-three/fiber";
|
|
2
2
|
import { Dispatch } from "react";
|
|
3
|
+
import { airplaneType, characterType, vehicleType } from "../../airplane/type";
|
|
3
4
|
|
|
4
5
|
export type perspectiveCameraType = {
|
|
5
6
|
cameraType?: "perspective";
|
|
@@ -29,6 +30,10 @@ export type gaesupControllerType = {
|
|
|
29
30
|
cameraOption: gaesupCameraOptionType;
|
|
30
31
|
perspectiveCamera: perspectiveCameraPropType;
|
|
31
32
|
orthographicCamera: OrthographicCameraProps;
|
|
33
|
+
airplane: airplaneType;
|
|
34
|
+
vehicle: vehicleType;
|
|
35
|
+
character: characterType;
|
|
36
|
+
isRider: boolean;
|
|
32
37
|
};
|
|
33
38
|
|
|
34
39
|
export type gaesupControllerPartialType = Partial<gaesupControllerType>;
|