spherecast

wip first person shooter engine
Download | Log | Files | Refs

physics.h (1128B)


      1 #pragma once
      2 
      3 #include "player.h"
      4 #include <raylib.h>
      5 #include <raymath.h>
      6 
      7 #define MAX_ITERS 3
      8 
      9 typedef enum { GROUND_AIRBORNE = 0, GROUND_GROUNDED } GroundState;
     10 
     11 typedef struct {
     12   bool hit;
     13   float distance;
     14   Vector3 normal;
     15 } HitInfo;
     16 
     17 typedef struct {
     18   Vector3 a, b, c;
     19   Vector3 normal;
     20   Vector3 min;
     21   Vector3 max;
     22 } Triangle;
     23 
     24 Vector3 ClosestPointOnTriangle(Vector3 p, Vector3 a, Vector3 b, Vector3 c);
     25 
     26 Vector3 ClosestPointOnSegment(Vector3 p, Vector3 a, Vector3 b);
     27 
     28 bool SphereCastTriangle(Vector3 pos, Vector3 dir, float radius, float dist,
     29                         const Triangle *tri, HitInfo *hit);
     30 
     31 bool SphereCast(Vector3 pos, Vector3 dir, float dist, float radius,
     32                 Triangle *tris, int triCount, HitInfo *outHit);
     33 
     34 void ResolveOverlaps(Vector3 *pos, Vector3 *vel, float radius, float height,
     35                      Triangle *tris, int triCount, GroundState *state);
     36 
     37 void ResolveCollisions(Player *p, Triangle *tris, int count);
     38 
     39 void SnapToGround(Vector3 *pos, float radius, Triangle *tris, int triCount,
     40                   GroundState *state);
     41 
     42 void ApplyGravity(Vector3 *velocity, float dt);