|
|
|
@ -43,6 +43,67 @@ 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;
|
|
|
|
|
}
|
|
|
|
|
Manifold :: struct {
|
|
|
|
|
count: int;
|
|
|
|
|
depths: [2] float;
|
|
|
|
|
contact_points: [2] Vector2;
|
|
|
|
|
normal: Vector2;
|
|
|
|
|
};
|
|
|
|
|
MAX_POLYGON_VERTS :: 8;
|
|
|
|
|
Polygon :: struct {
|
|
|
|
|
count: int;
|
|
|
|
|
verts: [MAX_POLYGON_VERTS] Vector2;
|
|
|
|
|
norms: [MAX_POLYGON_VERTS] Vector2;
|
|
|
|
|
};
|
|
|
|
|
// a halfspace (aka plane, aka line)
|
|
|
|
|
Halfspace :: struct {
|
|
|
|
|
n: Vector2;
|
|
|
|
|
d: float;
|
|
|
|
|
}
|
|
|
|
|
poly_from :: (using r: Rect) -> Polygon {
|
|
|
|
|
to_return: Polygon;
|
|
|
|
|
|
|
|
|
|
facing_to_right := rotate(xy(halfsize.x,0.0), angle);
|
|
|
|
|
facing_to_up := rotate(xy(0.0,halfsize.y), angle);
|
|
|
|
|
|
|
|
|
|
to_return.count = 4;
|
|
|
|
|
to_return.verts[0] = -facing_to_right + facing_up; // upper left
|
|
|
|
|
to_return.norms[0] = #run normalize(xy(-1.0, 1.0));
|
|
|
|
|
|
|
|
|
|
to_return.verts[1] = facing_to_right + facing_up; // upper right
|
|
|
|
|
to_return.norms[1] = #run normalize(xy(1.0, 1.0));
|
|
|
|
|
|
|
|
|
|
to_return.verts[2] = facing_to_right + -facing_up; // lower right
|
|
|
|
|
to_return.norms[2] = #run normalize(xy(1.0, -1.0));
|
|
|
|
|
|
|
|
|
|
to_return.verts[3] = -facing_to_right + -facing_up; // lower left
|
|
|
|
|
to_return.norms[3] = #run normalize(xy(-1.0, -1.0));
|
|
|
|
|
|
|
|
|
|
return to_return;
|
|
|
|
|
}
|
|
|
|
|
rect_to_rect :: (a: Rect, b: Rect) -> Manifold {
|
|
|
|
|
to_return : Manifold;
|
|
|
|
|
|
|
|
|
|
check_faces :: (a: Polygon, b: Polygon) -> float {
|
|
|
|
|
|
|
|
|
|
plane_at :: (p : Polygon, i: int) -> Halfspace {
|
|
|
|
|
return .{n = p.norms[i], d = dot(p.norms[i], p.verts[i]};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
support :: (verts: [] Vector2, d: Vector2 {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sep : float = FLT_MAX;
|
|
|
|
|
index: int = ~0;
|
|
|
|
|
|
|
|
|
|
for 0..a.count-1 {
|
|
|
|
|
h := plane_at(a, i);
|
|
|
|
|
idx :=
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
draw_rect :: (using r: Rect) {
|
|
|
|
|
facing_to_right := rotate(xy(halfsize.x,0.0), angle);
|
|
|
|
|