Try 3d still shitty

main
Cameron Murphy Reikes 2 years ago
parent 027789bcd8
commit 4542d44a7f

@ -152,17 +152,19 @@ handle_collision :: (m: Manifold, dt: float) {
//impulse_strength += m.depths[it] * 3.0; //impulse_strength += m.depths[it] * 3.0;
//impulse_strength += total_momentum / 2.0; //impulse_strength += total_momentum / 2.0;
restitution: float = 0.5; restitution: float = 0.5;
v_point_a := velocity_of_point(a, m.contact_points[it]); v_point_a := velocity_of_point(a, m.contact_points[it]);
v_point_b := velocity_of_point(b, m.contact_points[it]); v_point_b := velocity_of_point(b, m.contact_points[it]);
vr := v_point_b - v_point_a; vr := v_point_b - v_point_a;
r1 := m.contact_points[it] - a.pos; r1 := m.contact_points[it] - a.pos;
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});

Loading…
Cancel
Save