dacha 0.17.2 → 0.18.0-alpha.1

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.
Files changed (132) hide show
  1. package/build/contrib/components/collider/index.d.ts +17 -4
  2. package/build/contrib/components/collider/index.js +30 -2
  3. package/build/contrib/components/rigid-body/index.d.ts +29 -17
  4. package/build/contrib/components/rigid-body/index.js +64 -21
  5. package/build/contrib/components/shape/index.d.ts +17 -2
  6. package/build/contrib/components/shape/index.js +16 -0
  7. package/build/contrib/events/index.d.ts +10 -75
  8. package/build/contrib/events/index.js +0 -36
  9. package/build/contrib/systems/camera-system/{service.d.ts → api.d.ts} +4 -4
  10. package/build/contrib/systems/camera-system/{service.js → api.js} +2 -2
  11. package/build/contrib/systems/camera-system/index.d.ts +1 -1
  12. package/build/contrib/systems/camera-system/index.js +1 -1
  13. package/build/contrib/systems/camera-system/system.d.ts +1 -1
  14. package/build/contrib/systems/camera-system/system.js +5 -4
  15. package/build/contrib/systems/index.d.ts +3 -3
  16. package/build/contrib/systems/index.js +3 -3
  17. package/build/contrib/systems/mouse-input-system/subsystems/coordinates-projector/index.d.ts +0 -1
  18. package/build/contrib/systems/mouse-input-system/subsystems/coordinates-projector/index.js +4 -5
  19. package/build/contrib/systems/physics-system/api.d.ts +58 -0
  20. package/build/contrib/systems/physics-system/api.js +67 -0
  21. package/build/contrib/systems/physics-system/index.d.ts +2 -21
  22. package/build/contrib/systems/physics-system/index.js +2 -40
  23. package/build/contrib/systems/physics-system/physics-system.d.ts +24 -0
  24. package/build/contrib/systems/physics-system/physics-system.js +47 -0
  25. package/build/contrib/systems/physics-system/subsystems/collision-broadcast/collision.d.ts +5 -3
  26. package/build/contrib/systems/physics-system/subsystems/collision-broadcast/collision.js +7 -5
  27. package/build/contrib/systems/physics-system/subsystems/collision-broadcast/index.d.ts +4 -6
  28. package/build/contrib/systems/physics-system/subsystems/collision-broadcast/index.js +20 -17
  29. package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/build-circle-aabb.js +1 -2
  30. package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/build-point-aabb.d.ts +2 -0
  31. package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/build-point-aabb.js +7 -0
  32. package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/build-ray-aabb.d.ts +2 -0
  33. package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/build-ray-aabb.js +9 -0
  34. package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/build-segment-aabb.d.ts +2 -0
  35. package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/build-segment-aabb.js +14 -0
  36. package/build/contrib/systems/physics-system/subsystems/collision-detection/aabb-builders/index.js +6 -0
  37. package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-box-geometry.d.ts +3 -1
  38. package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-box-geometry.js +52 -16
  39. package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-circle-geometry.d.ts +3 -1
  40. package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-circle-geometry.js +32 -7
  41. package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-point-geometry.d.ts +3 -0
  42. package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-point-geometry.js +5 -0
  43. package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-ray-geometry.d.ts +3 -0
  44. package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-ray-geometry.js +7 -0
  45. package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-segment-geometry.d.ts +3 -0
  46. package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/build-segment-geometry.js +33 -0
  47. package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/index.d.ts +12 -1
  48. package/build/contrib/systems/physics-system/subsystems/collision-detection/geometry-builders/index.js +6 -0
  49. package/build/contrib/systems/physics-system/subsystems/collision-detection/index.d.ts +21 -9
  50. package/build/contrib/systems/physics-system/subsystems/collision-detection/index.js +177 -92
  51. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-box/check-boxes-intersection.d.ts +10 -0
  52. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-box/check-boxes-intersection.js +36 -0
  53. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-box/utils.d.ts +17 -0
  54. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-box/utils.js +126 -0
  55. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-circle/check-box-and-circle-intersection.d.ts +9 -0
  56. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-circle/check-box-and-circle-intersection.js +46 -0
  57. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-segment/check-box-and-segment-intersection.d.ts +10 -0
  58. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-segment/check-box-and-segment-intersection.js +28 -0
  59. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-segment/utils.d.ts +19 -0
  60. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/box-segment/utils.js +76 -0
  61. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/circle-circle/check-circles-intersection.d.ts +12 -0
  62. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/circle-circle/check-circles-intersection.js +47 -0
  63. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/circle-segment/check-circle-and-segment-intersection.d.ts +10 -0
  64. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/circle-segment/check-circle-and-segment-intersection.js +33 -0
  65. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/index.d.ts +2 -2
  66. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/index.js +27 -3
  67. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/point-box/check-point-and-box-intersection.d.ts +9 -0
  68. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/point-box/check-point-and-box-intersection.js +36 -0
  69. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/point-circle/check-point-and-circle-intersection.d.ts +9 -0
  70. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/point-circle/check-point-and-circle-intersection.js +33 -0
  71. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/point-segment/check-point-and-segment-intersection.d.ts +9 -0
  72. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/point-segment/check-point-and-segment-intersection.js +26 -0
  73. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/ray-box/check-ray-and-box-intersection.d.ts +11 -0
  74. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/ray-box/check-ray-and-box-intersection.js +69 -0
  75. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/ray-circle/check-ray-and-circle-intersection.d.ts +10 -0
  76. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/ray-circle/check-ray-and-circle-intersection.js +45 -0
  77. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/ray-segment/check-ray-and-segment-intersection.d.ts +16 -0
  78. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/ray-segment/check-ray-and-segment-intersection.js +51 -0
  79. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/ray-segment/utils.d.ts +2 -0
  80. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/ray-segment/utils.js +4 -0
  81. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/tests/helpers.d.ts +20 -0
  82. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/tests/helpers.js +69 -0
  83. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/utils.d.ts +9 -0
  84. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/utils.js +23 -0
  85. package/build/contrib/systems/physics-system/subsystems/collision-detection/query-utils.d.ts +10 -0
  86. package/build/contrib/systems/physics-system/subsystems/collision-detection/query-utils.js +63 -0
  87. package/build/contrib/systems/physics-system/subsystems/collision-detection/reorientation-checkers/check-collider.js +17 -8
  88. package/build/contrib/systems/physics-system/subsystems/collision-detection/types.d.ts +41 -11
  89. package/build/contrib/systems/physics-system/subsystems/collision-detection/types.js +0 -3
  90. package/build/contrib/systems/physics-system/subsystems/constraint-solver/index.d.ts +7 -10
  91. package/build/contrib/systems/physics-system/subsystems/constraint-solver/index.js +117 -79
  92. package/build/contrib/systems/physics-system/subsystems/index.d.ts +0 -1
  93. package/build/contrib/systems/physics-system/subsystems/index.js +0 -1
  94. package/build/contrib/systems/physics-system/subsystems/physics/index.d.ts +3 -9
  95. package/build/contrib/systems/physics-system/subsystems/physics/index.js +57 -93
  96. package/build/contrib/systems/physics-system/types.d.ts +37 -0
  97. package/build/contrib/systems/renderer/actor-render-tree.js +1 -2
  98. package/build/contrib/systems/renderer/{service → api}/index.d.ts +6 -6
  99. package/build/contrib/systems/renderer/{service → api}/index.js +14 -16
  100. package/build/contrib/systems/renderer/api/utils.d.ts +4 -0
  101. package/build/contrib/systems/renderer/{service → api}/utils.js +5 -0
  102. package/build/contrib/systems/renderer/builders/shape-builder/index.js +9 -1
  103. package/build/contrib/systems/renderer/builders/shape-builder/utils.js +16 -0
  104. package/build/contrib/systems/renderer/index.d.ts +1 -1
  105. package/build/contrib/systems/renderer/index.js +1 -1
  106. package/build/contrib/systems/renderer/renderer.d.ts +2 -1
  107. package/build/contrib/systems/renderer/renderer.js +9 -7
  108. package/build/engine/actor/actor-creator.js +6 -4
  109. package/build/engine/math-lib/math/ops.d.ts +1 -2
  110. package/build/engine/math-lib/math/ops.js +3 -3
  111. package/build/engine/math-lib/vector/ops.d.ts +18 -3
  112. package/build/engine/math-lib/vector/ops.js +28 -5
  113. package/build/engine/math-lib/vector/vector2.d.ts +22 -7
  114. package/build/engine/math-lib/vector/vector2.js +29 -5
  115. package/build/engine/template/template-collection.js +1 -1
  116. package/build/engine/world/index.d.ts +4 -24
  117. package/build/engine/world/index.js +5 -33
  118. package/build/engine/world/system-api-registry.d.ts +17 -0
  119. package/build/engine/world/system-api-registry.js +34 -0
  120. package/build/events/index.d.ts +2 -2
  121. package/build/events/index.js +1 -1
  122. package/build/types/global.d.ts +4 -0
  123. package/package.json +4 -1
  124. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/check-box-and-circle-intersection.d.ts +0 -16
  125. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/check-box-and-circle-intersection.js +0 -80
  126. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/check-boxes-intersection.d.ts +0 -6
  127. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/check-boxes-intersection.js +0 -72
  128. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/check-circles-intersection.d.ts +0 -11
  129. package/build/contrib/systems/physics-system/subsystems/collision-detection/intersection-checkers/check-circles-intersection.js +0 -39
  130. package/build/contrib/systems/physics-system/subsystems/collision-solver/index.d.ts +0 -10
  131. package/build/contrib/systems/physics-system/subsystems/collision-solver/index.js +0 -50
  132. package/build/contrib/systems/renderer/service/utils.d.ts +0 -3
@@ -1,80 +0,0 @@
1
- import { Collider } from '../../../../../components';
2
- import { MathOps, Vector2, VectorOps } from '../../../../../../engine/math-lib';
3
- const getMtvs = (axis, overlap, point1, point2) => {
4
- axis.multiplyNumber((1 / axis.magnitude) * overlap);
5
- const positiveX = Math.abs(axis.x);
6
- const negativeX = -Math.abs(axis.x);
7
- const positiveY = Math.abs(axis.y);
8
- const negativeY = -Math.abs(axis.y);
9
- return {
10
- mtv1: new Vector2(point1.x < point2.x ? negativeX : positiveX, point1.y < point2.y ? negativeY : positiveY),
11
- mtv2: new Vector2(point2.x > point1.x ? positiveX : negativeX, point2.y > point1.y ? positiveY : negativeY),
12
- };
13
- };
14
- /**
15
- * Checks box and circle colliders at the intersection.
16
- * The main target is to check two possible scenarios:
17
- * - circle lies inside box
18
- * - circle intersects one of the boxe's edges
19
- * Steps of the algorithm:
20
- * 1. Find the nearest edge to circle center and check wether it intersects with circle or not
21
- * For each edge three points should be considered: corners and circle center projection
22
- * 2. Determine is the circle center lies inside of the box or not.
23
- * This affects how we should compute mtv distance
24
- * 3. If circle doesn't have any intersection with boxe's edges
25
- * and circle center lies outside of the box – return false.
26
- * Otherwise compute mtv vectors considering relative position of circle and box centers
27
- */
28
- export const checkBoxAndCircleIntersection = (arg1, arg2) => {
29
- let box;
30
- let circle;
31
- if (arg1.actor.getComponent(Collider).type === 'box') {
32
- box = arg1.geometry;
33
- circle = arg2.geometry;
34
- }
35
- else {
36
- box = arg2.geometry;
37
- circle = arg1.geometry;
38
- }
39
- let isIntersection = false;
40
- let minDistance = Infinity;
41
- let minDistanceAxis;
42
- const { center: circleCenter } = circle;
43
- for (const edge of box.edges) {
44
- const projectedPoint = VectorOps.projectPointToEdge(circleCenter, edge);
45
- const minX = Math.min(edge.point1.x, edge.point2.x);
46
- const maxX = Math.max(edge.point1.x, edge.point2.x);
47
- const minY = Math.min(edge.point1.y, edge.point2.y);
48
- const maxY = Math.max(edge.point1.y, edge.point2.y);
49
- const isPointOnEdge = projectedPoint.x >= minX
50
- && projectedPoint.x <= maxX
51
- && projectedPoint.y >= minY
52
- && projectedPoint.y <= maxY;
53
- const distanceProjection = isPointOnEdge ? MathOps.getDistanceBetweenTwoPoints(circleCenter.x, projectedPoint.x, circleCenter.y, projectedPoint.y) : Infinity;
54
- const distance1 = MathOps.getDistanceBetweenTwoPoints(circleCenter.x, edge.point1.x, circleCenter.y, edge.point1.y);
55
- const distance2 = MathOps.getDistanceBetweenTwoPoints(circleCenter.x, edge.point2.x, circleCenter.y, edge.point2.y);
56
- const isInsideCircle = Math.min(distanceProjection, distance1, distance2) < circle.radius;
57
- isIntersection = isIntersection || isInsideCircle;
58
- if (isPointOnEdge && distanceProjection < minDistance) {
59
- minDistance = distanceProjection;
60
- minDistanceAxis = edge.normal.clone();
61
- }
62
- if (distance1 < minDistance) {
63
- minDistance = distance1;
64
- minDistanceAxis = minDistance !== 0
65
- ? new Vector2(edge.point1.x - circleCenter.x, edge.point1.y - circleCenter.y)
66
- : edge.normal.clone();
67
- }
68
- if (distance2 < minDistance) {
69
- minDistance = distance2;
70
- minDistanceAxis = minDistance !== 0
71
- ? new Vector2(edge.point2.x - circleCenter.x, edge.point2.y - circleCenter.y)
72
- : edge.normal.clone();
73
- }
74
- }
75
- const isInsidePolygon = VectorOps.isPointInPolygon(circleCenter, box.edges);
76
- if (!isIntersection && !isInsidePolygon) {
77
- return false;
78
- }
79
- return getMtvs(minDistanceAxis, isInsidePolygon ? circle.radius + minDistance : circle.radius - minDistance, arg1.geometry.center, arg2.geometry.center);
80
- };
@@ -1,6 +0,0 @@
1
- import type { CollisionEntry, Intersection } from '../types';
2
- /**
3
- * Checks boxes colliders at the intersection.
4
- * The SAT (separating axis theorem) is used to determine an intersection and mtvs.
5
- */
6
- export declare const checkBoxesIntersection: (arg1: CollisionEntry, arg2: CollisionEntry) => Intersection | false;
@@ -1,72 +0,0 @@
1
- import { Vector2, VectorOps } from '../../../../../../engine/math-lib';
2
- const projectPolygon = (polygon, axisVector) => {
3
- const initialProjectionValue = VectorOps.dotProduct(polygon.edges[0].point1, axisVector);
4
- const projection = {
5
- min: initialProjectionValue,
6
- max: initialProjectionValue,
7
- };
8
- for (let i = 1; i < polygon.edges.length; i += 1) {
9
- const projectionValue = VectorOps.dotProduct(polygon.edges[i].point1, axisVector);
10
- if (projectionValue < projection.min) {
11
- projection.min = projectionValue;
12
- }
13
- else if (projectionValue > projection.max) {
14
- projection.max = projectionValue;
15
- }
16
- }
17
- return projection;
18
- };
19
- /**
20
- * Checks boxes colliders at the intersection.
21
- * The SAT (separating axis theorem) is used to determine an intersection and mtvs.
22
- */
23
- export const checkBoxesIntersection = (arg1, arg2) => {
24
- let overlap = Infinity;
25
- let normal;
26
- const geometry1 = arg1.geometry;
27
- const geometry2 = arg2.geometry;
28
- // Consider arg1 box normals as axes
29
- for (const edge of geometry1.edges) {
30
- const axis = edge.normal;
31
- const aProjection = projectPolygon(geometry1, axis);
32
- const bProjection = projectPolygon(geometry2, axis);
33
- const aDistance = aProjection.min - bProjection.max;
34
- const bDistance = bProjection.min - aProjection.max;
35
- if (aDistance > 0 || bDistance > 0) {
36
- return false;
37
- }
38
- const axisOverlap = Math.min(Math.abs(aDistance), Math.abs(bDistance));
39
- if (axisOverlap < overlap) {
40
- overlap = axisOverlap;
41
- normal = axis;
42
- }
43
- }
44
- // Consider arg2 box normals as axes
45
- for (const edge of geometry2.edges) {
46
- const axis = edge.normal;
47
- const aProjection = projectPolygon(geometry1, axis);
48
- const bProjection = projectPolygon(geometry2, axis);
49
- const aDistance = aProjection.min - bProjection.max;
50
- const bDistance = bProjection.min - aProjection.max;
51
- if (aDistance > 0 || bDistance > 0) {
52
- return false;
53
- }
54
- const axisOverlap = Math.min(Math.abs(aDistance), Math.abs(bDistance));
55
- if (axisOverlap < overlap) {
56
- overlap = axisOverlap;
57
- normal = axis;
58
- }
59
- }
60
- const { x: xArg1, y: yArg1 } = geometry1.center;
61
- const { x: xArg2, y: yArg2 } = geometry2.center;
62
- const mtv = normal.clone();
63
- mtv.multiplyNumber(overlap);
64
- const positiveX = Math.abs(mtv.x);
65
- const negativeX = -Math.abs(mtv.x);
66
- const positiveY = Math.abs(mtv.y);
67
- const negativeY = -Math.abs(mtv.y);
68
- return {
69
- mtv1: new Vector2(xArg1 < xArg2 ? negativeX : positiveX, yArg1 < yArg2 ? negativeY : positiveY),
70
- mtv2: new Vector2(xArg2 > xArg1 ? positiveX : negativeX, yArg2 > yArg1 ? positiveY : negativeY),
71
- };
72
- };
@@ -1,11 +0,0 @@
1
- import type { CollisionEntry, Intersection } from '../types';
2
- /**
3
- * Checks circles at the intersection.
4
- * Steps of the alghorith:
5
- * 1. Calculate distance between circles centers.
6
- * 2. If distance greater or equal to summ of circles radiuses then is no intersection.
7
- * 3. If distance is zero then circles centers lie at the same point, so just X axis used for mtv.
8
- * 4. If distance less than summ of circles radiuses and it's non-zero
9
- * then circles centers used to get the axis.
10
- */
11
- export declare const checkCirclesIntersection: (arg1: CollisionEntry, arg2: CollisionEntry) => Intersection | false;
@@ -1,39 +0,0 @@
1
- import { Vector2 } from '../../../../../../engine/math-lib';
2
- /**
3
- * Checks circles at the intersection.
4
- * Steps of the alghorith:
5
- * 1. Calculate distance between circles centers.
6
- * 2. If distance greater or equal to summ of circles radiuses then is no intersection.
7
- * 3. If distance is zero then circles centers lie at the same point, so just X axis used for mtv.
8
- * 4. If distance less than summ of circles radiuses and it's non-zero
9
- * then circles centers used to get the axis.
10
- */
11
- export const checkCirclesIntersection = (arg1, arg2) => {
12
- const { radius: rArg1 } = arg1.geometry;
13
- const { radius: rArg2 } = arg2.geometry;
14
- const { x: xArg1, y: yArg1 } = arg1.geometry.center;
15
- const { x: xArg2, y: yArg2 } = arg2.geometry.center;
16
- const x = xArg1 - xArg2;
17
- const y = yArg1 - yArg2;
18
- const distance = Math.sqrt((x ** 2) + (y ** 2));
19
- if (distance >= rArg1 + rArg2) {
20
- return false;
21
- }
22
- if (distance === 0) {
23
- return {
24
- mtv1: new Vector2(rArg1 + rArg2, 0),
25
- mtv2: new Vector2(-(rArg1 + rArg2), 0),
26
- };
27
- }
28
- const mtv = new Vector2(x, y);
29
- const overlap = rArg1 + rArg2 - distance;
30
- mtv.multiplyNumber((1 / distance) * overlap);
31
- const positiveX = Math.abs(mtv.x);
32
- const negativeX = -Math.abs(mtv.x);
33
- const positiveY = Math.abs(mtv.y);
34
- const negativeY = -Math.abs(mtv.y);
35
- return {
36
- mtv1: new Vector2(xArg1 < xArg2 ? negativeX : positiveX, yArg1 < yArg2 ? negativeY : positiveY),
37
- mtv2: new Vector2(xArg2 < xArg1 ? negativeX : positiveX, yArg2 < yArg1 ? negativeY : positiveY),
38
- };
39
- };
@@ -1,10 +0,0 @@
1
- import type { SceneSystemOptions } from '../../../../../engine/system';
2
- export declare class CollisionSolver {
3
- private scene;
4
- private gravity;
5
- constructor(options: SceneSystemOptions);
6
- destroy(): void;
7
- private handleCollision;
8
- private validateCollision;
9
- private addReactionForce;
10
- }
@@ -1,50 +0,0 @@
1
- import { Vector2 } from '../../../../../engine/math-lib';
2
- import { RigidBody } from '../../../../components/rigid-body';
3
- import { Collision, AddForce, StopMovement } from '../../../../events';
4
- import { RIGID_BODY_TYPE } from '../../consts';
5
- const REACTION_FORCE_VECTOR_X = 0;
6
- const REACTION_FORCE_VECTOR_Y = -1;
7
- export class CollisionSolver {
8
- scene;
9
- gravity;
10
- constructor(options) {
11
- const { scene, gravity } = options;
12
- this.scene = scene;
13
- this.gravity = gravity;
14
- this.scene.addEventListener(Collision, this.handleCollision);
15
- }
16
- destroy() {
17
- this.scene.removeEventListener(Collision, this.handleCollision);
18
- }
19
- handleCollision = (event) => {
20
- const { actor1, actor2, mtv1 } = event;
21
- if (!this.validateCollision(actor1, actor2)) {
22
- return;
23
- }
24
- this.addReactionForce(actor1, mtv1);
25
- };
26
- validateCollision(actor1, actor2) {
27
- const rigidBody1 = actor1.getComponent(RigidBody);
28
- const rigidBody2 = actor2.getComponent(RigidBody);
29
- if (!rigidBody1 || !rigidBody2) {
30
- return false;
31
- }
32
- if (rigidBody2.type === RIGID_BODY_TYPE.STATIC) {
33
- return !rigidBody1.ghost && !rigidBody2.ghost;
34
- }
35
- return !rigidBody1.ghost && !rigidBody1.isPermeable
36
- && !rigidBody2.ghost && !rigidBody2.isPermeable;
37
- }
38
- addReactionForce(actor, mtv) {
39
- const rigidBody = actor.getComponent(RigidBody);
40
- const { useGravity, mass } = rigidBody;
41
- if (useGravity && mtv.y && Math.sign(mtv.y) === -1 && !mtv.x) {
42
- const reactionForce = new Vector2(REACTION_FORCE_VECTOR_X, REACTION_FORCE_VECTOR_Y);
43
- reactionForce.multiplyNumber(mass * this.gravity);
44
- actor.dispatchEventImmediately(AddForce, {
45
- value: reactionForce,
46
- });
47
- actor.dispatchEventImmediately(StopMovement);
48
- }
49
- }
50
- }
@@ -1,3 +0,0 @@
1
- import { type Container, type Matrix } from 'pixi.js';
2
- import { type Bounds } from '../types';
3
- export declare const convertBounds: (container: Container, matrix: Matrix) => Bounds;