Writing a Physics Engine from scratch