|
|
|
@ -9,6 +9,8 @@ TIMESTEP: float = 1.0 / 60.0;
|
|
|
|
|
window_width : s32 = 1280;
|
|
|
|
|
window_height : s32 = 720;
|
|
|
|
|
|
|
|
|
|
dbgprint :: print; // so can be
|
|
|
|
|
|
|
|
|
|
xy :: (x: int, y: int) -> Vector2 {
|
|
|
|
|
return xy(cast(float)x, cast(float)y);
|
|
|
|
|
}
|
|
|
|
@ -105,6 +107,12 @@ apply_force_at_point :: (r: *Rect, force: Vector2, point_world_space: Vector2) {
|
|
|
|
|
offset_from_center_of_mass := point_world_space - r.pos;
|
|
|
|
|
r.torque += offset_from_center_of_mass.x * force.y - offset_from_center_of_mass.y * force.x;
|
|
|
|
|
}
|
|
|
|
|
apply_impulse_at_point :: (using r: *Rect, impulse: Vector2, point_world_space: Vector2) {
|
|
|
|
|
//apply_force_at_point(r, impulse / TIMESTEP, point_world_space);
|
|
|
|
|
//return;
|
|
|
|
|
vel += impulse / r.mass;
|
|
|
|
|
angle_vel += length(impulse) * (cross(point_world_space - pos, normalize(impulse))/moment_of_inertia(r));
|
|
|
|
|
}
|
|
|
|
|
// everything needed to resolve the collision
|
|
|
|
|
Manifold :: struct {
|
|
|
|
|
a, b: *Rect;
|
|
|
|
@ -135,8 +143,8 @@ handle_collision :: (m: Manifold, dt: float) {
|
|
|
|
|
if a.static || b.static impulse_strength *= 2.0;
|
|
|
|
|
|
|
|
|
|
impulse := m.normal * impulse_strength;
|
|
|
|
|
apply_force_at_point(b, impulse / dt, m.contact_points[it]);
|
|
|
|
|
apply_force_at_point(a, -impulse / dt, m.contact_points[it]);
|
|
|
|
|
apply_impulse_at_point(b, impulse, m.contact_points[it]);
|
|
|
|
|
apply_impulse_at_point(a, -impulse, m.contact_points[it]);
|
|
|
|
|
}
|
|
|
|
|
/*k_scalar :: (a: Rectangle, b: Rectangle, r1: Vector2, r2: Vector2, n: Vector2) {
|
|
|
|
|
k_scalar_rect :: (a: Rectangle, r: Vector2, n: Vector2)
|
|
|
|
@ -586,6 +594,8 @@ main :: () {
|
|
|
|
|
// gravity
|
|
|
|
|
it.force.y += -9.81;
|
|
|
|
|
|
|
|
|
|
//if !it.static dbgprint("%\n", it.angle_vel);
|
|
|
|
|
|
|
|
|
|
if !it.static
|
|
|
|
|
{
|
|
|
|
|
it.vel += (it.force/it.mass) * TIMESTEP;
|
|
|
|
|