#ifndef RAPIER_H
#define RAPIER_H



typedef struct funnyphysics funnyphysics;

typedef struct px_collider_params {
  float friction;
} px_collider_params;

typedef struct px_vec3 {
  float m[3];
} px_vec3;

typedef struct px_cast_result {
  int8_t hit;
  float time;
  struct px_vec3 witness1;
  struct px_vec3 witness2;
  struct px_vec3 normal1;
  struct px_vec3 normal2;
} px_cast_result;

typedef struct px_matrix {
  float m[16];
} px_matrix;

typedef struct px_rigidbody_params {
  float velocity[3];
  float angular_velocity[3];
  float gravity_scale;
  float linear_damping;
  float angular_damping;
  uint8_t continous;
  uint8_t sleeping;
  uint8_t lockrotx;
  uint8_t lockroty;
  uint8_t lockrotz;
  uint8_t lockposx;
  uint8_t lockposy;
  uint8_t lockposz;
  int8_t dominance;
} px_rigidbody_params;

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

Collider *px_ball(float radius, struct px_collider_params params);

Collider *px_box(float x, float y, float z, struct px_collider_params params);

struct px_cast_result px_box_cast(struct funnyphysics *px_world,
                                  float x,
                                  float y,
                                  float z,
                                  struct px_vec3 pos,
                                  struct px_vec3 rot,
                                  struct px_vec3 vel,
                                  float time);

void px_fixedbody(struct funnyphysics *px_world, Collider *collider);

void px_frame(struct funnyphysics *px_world, float delta);

struct px_matrix px_getmatrix(struct funnyphysics *px_world, RigidBodyHandle *body);

struct px_vec3 px_getposition(struct funnyphysics *px_world, RigidBodyHandle *body);

struct px_vec3 px_getvelocity(struct funnyphysics *px_world, RigidBodyHandle *body);

struct funnyphysics *px_init(void);

RigidBodyHandle *px_kinematic_position_body(struct funnyphysics *px_world,
                                            Collider *collider,
                                            struct px_matrix m,
                                            struct px_rigidbody_params params);

RigidBodyHandle *px_rigidbody(struct funnyphysics *px_world,
                              Collider *collider,
                              struct px_matrix m,
                              struct px_rigidbody_params params);

void px_setposition(struct funnyphysics *px_world, RigidBodyHandle *body, struct px_vec3 vec);

void px_setvelocity(struct funnyphysics *px_world, RigidBodyHandle *body, struct px_vec3 vec);

RigidBodyHandle *px_staticbody(struct funnyphysics *px_world,
                               Collider *collider,
                               struct px_matrix m);

Collider *px_trimesh(const Point<float> *ptr_vert,
                     size_t len_vert,
                     const uint32_t (*ptr_ind)[3],
                     size_t len_ind,
                     struct px_collider_params params);

#ifdef __cplusplus
}  // extern "C"
#endif  // __cplusplus

#endif  /* RAPIER_H */
