samengine 1.7.2 → 1.7.4
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/dist/build/index.js
CHANGED
|
@@ -67,23 +67,25 @@ export function circleBoxCollision(circleObj, boxObj) {
|
|
|
67
67
|
}
|
|
68
68
|
export function resolveCollision(a, b, normal) {
|
|
69
69
|
const rv = subtract2d(b.body.velocity, a.body.velocity);
|
|
70
|
-
|
|
71
|
-
if (velAlongNormal > 0)
|
|
72
|
-
return;
|
|
73
|
-
const restitution = Math.min(a.body.restitution, b.body.restitution);
|
|
70
|
+
let velAlongNormal = dot2d(rv, normal);
|
|
74
71
|
const invMassA = a.body.isStatic ? 0 : 1 / a.body.mass;
|
|
75
72
|
const invMassB = b.body.isStatic ? 0 : 1 / b.body.mass;
|
|
73
|
+
// 👉 WICHTIG: wenn leicht rein → trotzdem pushen
|
|
74
|
+
if (velAlongNormal > -0.01) {
|
|
75
|
+
velAlongNormal = -0.01;
|
|
76
|
+
}
|
|
77
|
+
const restitution = Math.min(a.body.restitution, b.body.restitution);
|
|
76
78
|
const j = -(1 + restitution) * velAlongNormal /
|
|
77
79
|
(invMassA + invMassB);
|
|
78
80
|
const impulse = scale2d(normal, j);
|
|
79
81
|
if (!a.body.isStatic)
|
|
80
82
|
a.body.velocity = subtract2d(a.body.velocity, scale2d(impulse, invMassA));
|
|
81
83
|
if (!b.body.isStatic)
|
|
82
|
-
b.body.velocity =
|
|
84
|
+
b.body.velocity = add2d(b.body.velocity, scale2d(impulse, invMassB));
|
|
83
85
|
}
|
|
84
86
|
export function positionalCorrection(a, b, normal, penetration) {
|
|
85
|
-
const percent = 0
|
|
86
|
-
const slop = 0.01
|
|
87
|
+
const percent = 1.0; // vorher 0.8
|
|
88
|
+
const slop = 0.001; // vorher 0.01
|
|
87
89
|
const invMassA = a.body.isStatic ? 0 : 1 / a.body.mass;
|
|
88
90
|
const invMassB = b.body.isStatic ? 0 : 1 / b.body.mass;
|
|
89
91
|
const correction = scale2d(scale2d(normal, Math.max(penetration - slop, 0) / (invMassA + invMassB)), percent);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { makeVector2d, scale2d, add2d } from "../types/vector2d.js";
|
|
1
|
+
import { makeVector2d, scale2d, add2d, subtract2d, dot2d } from "../types/vector2d.js";
|
|
2
2
|
import { aabbCollision, circleBoxCollision, circleCollision, positionalCorrection, resolveCollision } from "./collision.js";
|
|
3
3
|
// Exapmle for a Use Case
|
|
4
4
|
// const world = new PhysicsWorld();
|
|
@@ -55,6 +55,19 @@ export class PhysicsWorld {
|
|
|
55
55
|
}
|
|
56
56
|
if (collision) {
|
|
57
57
|
resolveCollision(a, b, collision.normal);
|
|
58
|
+
// 👉 HIER REIN!
|
|
59
|
+
if (!a.body.isStatic && b.body.isStatic) {
|
|
60
|
+
const dot = dot2d(a.body.velocity, collision.normal);
|
|
61
|
+
if (dot < 0) {
|
|
62
|
+
a.body.velocity = subtract2d(a.body.velocity, scale2d(collision.normal, dot * 2));
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (!b.body.isStatic && a.body.isStatic) {
|
|
66
|
+
const dot = dot2d(b.body.velocity, scale2d(collision.normal, -1));
|
|
67
|
+
if (dot < 0) {
|
|
68
|
+
b.body.velocity = subtract2d(b.body.velocity, scale2d(scale2d(collision.normal, -1), dot * 2));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
58
71
|
positionalCorrection(a, b, collision.normal, collision.penetration);
|
|
59
72
|
}
|
|
60
73
|
}
|
package/dist/types/button.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Rect } from "./rectangle.js";
|
|
2
|
+
import { Mouse } from "../input.js";
|
|
2
3
|
export type Button = {
|
|
3
4
|
form: Rect;
|
|
4
5
|
text: string;
|
|
5
6
|
};
|
|
6
7
|
export declare function makeButton(form: Rect, text: string): Button;
|
|
7
|
-
export declare function clickedButton(btn: Button): boolean;
|
|
8
|
+
export declare function clickedButton(btn: Button, mouse: Mouse): boolean;
|
|
8
9
|
export declare function drawButton(btn: Button, ctx: CanvasRenderingContext2D, color?: string, textColor?: string, font?: string): void;
|
package/dist/types/button.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// Button
|
|
2
|
-
import { getMouse } from "../input.js";
|
|
3
2
|
import { isRectClicked } from "./rectangle.js";
|
|
4
3
|
import { drawRect } from "../renderer.js";
|
|
5
4
|
import { renderText } from "../renderer.js";
|
|
@@ -11,8 +10,7 @@ export function makeButton(form, text) {
|
|
|
11
10
|
};
|
|
12
11
|
}
|
|
13
12
|
// Prüft, ob der Button geklickt wurde
|
|
14
|
-
export function clickedButton(btn) {
|
|
15
|
-
const mouse = getMouse();
|
|
13
|
+
export function clickedButton(btn, mouse) {
|
|
16
14
|
return isRectClicked(mouse, btn.form);
|
|
17
15
|
}
|
|
18
16
|
// Zeichnet den Button (Rechteck + Text)
|