From 7ca709069cc280969b8d71bb19a09b8aeb13b859 Mon Sep 17 00:00:00 2001 From: quou Date: Fri, 24 Jan 2025 00:40:06 +1100 Subject: start on physics --- physics.hpp | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 physics.hpp (limited to 'physics.hpp') diff --git a/physics.hpp b/physics.hpp new file mode 100644 index 0000000..6e6b259 --- /dev/null +++ b/physics.hpp @@ -0,0 +1,78 @@ +#ifndef physics_hpp +#define physics_hpp + +#include "asset.hpp" +#include "maths.hpp" + +#include + +struct Arena; +struct Line_Renderer; +struct World; + +struct Manifold { + static constexpr int max_contacts = 16; + v3f contacts[max_contacts]; + int contact_count; + v3f normal; +}; + +struct Rigidbody; +struct Int_Collider { + Rigidbody* rb; + Int_Collider* next; + int vert_count; + int face_count; + v3f* verts; + v3f* faces; + + bool collide(const Int_Collider& other) const; +}; + +struct Collider : Asset { + struct Face { + v3f normal; + int vert_count; + uint16_t* verts; + }; + int face_count; + int vert_count; + Face* faces; + v3f* verts; + m3f moment; + + void debug_render( + Line_Renderer& lr, + const m4f& t, + const v3f& c + ); + Int_Collider* transform(const m4f& m, Arena* a) const; +}; + +struct Rigidbody { + v3f prev_pos, pos; + v3f vel, avel; + v3f force; + v3f torque; + v4f prev_rot, rot; + float inv_mass; + Collider* col; + int colliding; + + void init(Collider* c, const v3f& p, const v4f& r, float mass); + void set_pos(const v3f& p); + void set_rot(const v4f& r); + void set_mass(float m); + void add_force(const v3f& f); + void add_force(const v3f& f, const v3f& p); + void add_impulse(const v3f& f); + void add_impulse(const v3f& f, const v3f& p); + void add_torque(const v3f& t); +}; + +Collider* make_box(Arena* a, const v3f& size); + +void physics_update(World& w, Arena* a, float ts); +void physics_debug(World& w, Line_Renderer& lr); + +#endif -- cgit v1.2.3-54-g00ecf