~vladh/peony

peony/src/physics.hpp -rw-r--r-- 1.5 KiB
7fc9922bVlad-Stefan Harbuz changes shaders namespace into class a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
  Peony Game Engine
  Copyright (C) 2020 Vlad-Stefan Harbuz <vlad@vladh.net>
  All rights reserved.
*/

#pragma once

#include "types.hpp"
#include "entities.hpp"
#include "spatial.hpp"

namespace physics {
  constexpr real32 PARALLEL_FACE_TOLERANCE = 1.0e-2;
  constexpr real32 RELATIVE_TOLERANCE = 1.00f;
  constexpr real32 ABSOLUTE_TOLERANCE = 0.10f;

  struct PhysicsComponent {
    EntityHandle entity_handle;
    Obb obb;
    Obb transformed_obb;
  };

  struct PhysicsComponentSet {
    Array<PhysicsComponent> components;
  };

  struct CollisionManifold {
    bool32 did_collide;
    PhysicsComponent *collidee;
    real32 sep_max;
    uint32 axis;
    v3 normal;
  };

  struct RaycastResult {
    bool32 did_intersect;
    real32 distance;
  };

  struct RayCollisionResult {
    bool32 did_intersect;
    real32 distance;
    PhysicsComponent *collidee;
  };

  RayCollisionResult find_ray_collision(
    Ray *ray,
    PhysicsComponent *physics_component_to_ignore_or_nullptr,
    PhysicsComponentSet *physics_component_set
  );
  CollisionManifold find_physics_component_collision(
    PhysicsComponent *self_physics,
    SpatialComponent *self_spatial,
    PhysicsComponentSet *physics_component_set,
    SpatialComponentSet *spatial_component_set
  );
  void update_physics_components(
    PhysicsComponentSet *physics_component_set,
    SpatialComponentSet *spatial_component_set
  );
}

using physics::RaycastResult, physics::RayCollisionResult, physics::CollisionManifold,
  physics::PhysicsComponent, physics::PhysicsComponentSet;