|
|
@ -159,10 +159,12 @@ handle_collision :: (m: Manifold, dt: float) {
|
|
|
|
r2 := m.contact_points[it] - b.pos;
|
|
|
|
r2 := m.contact_points[it] - b.pos;
|
|
|
|
I1 := moment_of_inertia(a);
|
|
|
|
I1 := moment_of_inertia(a);
|
|
|
|
I2 := moment_of_inertia(b);
|
|
|
|
I2 := moment_of_inertia(b);
|
|
|
|
impulse_strength += (-(1.0 + restitution) * dot(vr, m.normal)) / ( 1.0/a.mass + 1.0/b.mass + dot(cross(cross(r1, m.normal)/I1, r1) + cross(cross(r2, m.normal), r2)/I2, m.normal));
|
|
|
|
make3d :: (v2: Vector2) -> Vector3 { return .{v2.x, v2.y, 0.0}; }
|
|
|
|
|
|
|
|
make2d :: (v3: Vector3) -> Vector2 { return .{v3.x, v3.y}; }
|
|
|
|
|
|
|
|
cross_products: Vector2 = make2d(cross(cross(make3d(r1), make3d(m.normal))/I1, make3d(r1))) + make2d(cross(cross(make3d(r2), make3d(m.normal)), make3d(r2)))/I2;
|
|
|
|
|
|
|
|
divisor: float = 1.0/a.mass + 1.0/b.mass + dot(cross_products, m.normal);
|
|
|
|
|
|
|
|
|
|
|
|
// the momentum would be unused if put into static
|
|
|
|
impulse_strength += (-(1.0 + restitution) * dot(vr, m.normal)) / divisor;
|
|
|
|
if a.static || b.static impulse_strength *= 2.0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impulse := m.normal * impulse_strength;
|
|
|
|
impulse := m.normal * impulse_strength;
|
|
|
|
apply_impulse_at_point(b, impulse, m.contact_points[it]);
|
|
|
|
apply_impulse_at_point(b, impulse, m.contact_points[it]);
|
|
|
@ -535,8 +537,8 @@ main :: () {
|
|
|
|
Simp.set_render_target(window);
|
|
|
|
Simp.set_render_target(window);
|
|
|
|
|
|
|
|
|
|
|
|
rects: [..]Rect;
|
|
|
|
rects: [..]Rect;
|
|
|
|
array_add(*rects, .{pos = #run xy(0.0, 0.0), halfsize = #run xy(0.3)});
|
|
|
|
//array_add(*rects, .{pos = #run xy(0.0, 0.0), halfsize = #run xy(0.3)});
|
|
|
|
//array_add(*rects, .{pos = #run xy(2.5, 0.0), halfsize = #run xy(0.3)});
|
|
|
|
array_add(*rects, .{pos = #run xy(2.5, 0.0), halfsize = #run xy(0.3)});
|
|
|
|
//array_add(*rects, .{pos = #run xy(-2.5, 0.0), halfsize = #run xy(0.3)});
|
|
|
|
//array_add(*rects, .{pos = #run xy(-2.5, 0.0), halfsize = #run xy(0.3)});
|
|
|
|
array_add(*rects, .{pos = #run xy(0.0, -3.0), halfsize = #run xy(3.0, 0.2), static = true});
|
|
|
|
array_add(*rects, .{pos = #run xy(0.0, -3.0), halfsize = #run xy(3.0, 0.2), static = true});
|
|
|
|
|
|
|
|
|
|
|
|