Unravel Engine C++ Reference
Loading...
Searching...
No Matches
physics_bindings.cpp
Go to the documentation of this file.
2#include "script_bindings.h"
3
4#include "../script_interop.h"
5
7
8namespace unravel
9{
10namespace
11{
12
13//-------------------------------------------------
14
15auto internal_m2n_physics_ray_cast(dotnetpp_backend::managed_interface::raycast_hit* hit,
16 const math::vec3& origin,
17 const math::vec3& direction,
18 float max_distance,
19 int layer_mask,
20 bool query_sensors) -> bool
21{
22 auto& ctx = engine::context();
23 auto& physics = ctx.get_cached<physics_system>();
24
25 auto ray_hit = physics.ray_cast(origin, direction, max_distance, layer_mask, query_sensors);
26
27 using converter = dotnet::managed_interface::converter;
28
29 if(ray_hit)
30 {
31 hit->entity = ray_hit->entity;
32 hit->point = converter::convert<math::vec3, dotnetpp_backend::managed_interface::vector3>(ray_hit->point);
33 hit->normal = converter::convert<math::vec3, dotnetpp_backend::managed_interface::vector3>(ray_hit->normal);
34 hit->distance = ray_hit->distance;
35 }
36
37 return ray_hit.has_value();
38}
39
40auto internal_m2n_physics_ray_cast_all(const math::vec3& origin,
41 const math::vec3& direction,
42 float max_distance,
43 int layer_mask,
44 bool query_sensors) -> hpp::small_vector<dotnetpp_backend::managed_interface::raycast_hit>
45{
46 auto& ctx = engine::context();
47 auto& physics = ctx.get_cached<physics_system>();
48
49 auto ray_hits = physics.ray_cast_all(origin, direction, max_distance, layer_mask, query_sensors);
50
51 hpp::small_vector<dotnetpp_backend::managed_interface::raycast_hit> hits;
52
53 using converter = dotnet::managed_interface::converter;
54 for(const auto& ray_hit : ray_hits)
55 {
56 auto& hit = hits.emplace_back();
57 hit.entity = ray_hit.entity;
58 hit.point = converter::convert<math::vec3, dotnetpp_backend::managed_interface::vector3>(ray_hit.point);
59 hit.normal = converter::convert<math::vec3, dotnetpp_backend::managed_interface::vector3>(ray_hit.normal);
60 hit.distance = ray_hit.distance;
61 }
62
63 return hits;
64}
65
66auto internal_m2n_physics_sphere_cast(dotnetpp_backend::managed_interface::raycast_hit* hit,
67 const math::vec3& origin,
68 const math::vec3& direction,
69 float radius,
70 float max_distance,
71 int layer_mask,
72 bool query_sensors) -> bool
73{
74 auto& ctx = engine::context();
75 auto& physics = ctx.get_cached<physics_system>();
76
77 auto ray_hit = physics.sphere_cast(origin, direction, radius, max_distance, layer_mask, query_sensors);
78
79 using converter = dotnet::managed_interface::converter;
80
81 if(ray_hit)
82 {
83 hit->entity = ray_hit->entity;
84 hit->point = converter::convert<math::vec3, dotnetpp_backend::managed_interface::vector3>(ray_hit->point);
85 hit->normal = converter::convert<math::vec3, dotnetpp_backend::managed_interface::vector3>(ray_hit->normal);
86 hit->distance = ray_hit->distance;
87 }
88
89 return ray_hit.has_value();
90}
91
92auto internal_m2n_physics_sphere_cast_all(const math::vec3& origin,
93 const math::vec3& direction,
94 float radius,
95 float max_distance,
96 int layer_mask,
97 bool query_sensors) -> hpp::small_vector<dotnetpp_backend::managed_interface::raycast_hit>
98{
99 auto& ctx = engine::context();
100 auto& physics = ctx.get_cached<physics_system>();
101
102 auto ray_hits = physics.sphere_cast_all(origin, direction, radius, max_distance, layer_mask, query_sensors);
103
104 hpp::small_vector<dotnetpp_backend::managed_interface::raycast_hit> hits;
105
106 using converter = dotnet::managed_interface::converter;
107 for(const auto& ray_hit : ray_hits)
108 {
109 auto& hit = hits.emplace_back();
110 hit.entity = ray_hit.entity;
111 hit.point = converter::convert<math::vec3, dotnetpp_backend::managed_interface::vector3>(ray_hit.point);
112 hit.normal = converter::convert<math::vec3, dotnetpp_backend::managed_interface::vector3>(ray_hit.normal);
113 hit.distance = ray_hit.distance;
114 }
115
116 return hits;
117}
118
119auto internal_m2n_physics_sphere_overlap(const math::vec3& origin, float radius, int layer_mask, bool query_sensors)
121{
122 auto& ctx = engine::context();
123 auto& physics = ctx.get_cached<physics_system>();
124
125 auto hits = physics.sphere_overlap(origin, radius, layer_mask, query_sensors);
126
127 return hits;
128}
129
130} // namespace
131
133{
134 APPLOG_TRACE("{}", __func__);
135 auto reg = dotnet::internal_call_registry("Unravel.Core.Physics");
136 reg.add_internal_call("internal_m2n_physics_ray_cast", dotnet_internal_call(internal_m2n_physics_ray_cast));
137 reg.add_internal_call("internal_m2n_physics_ray_cast_all", dotnet_internal_call(internal_m2n_physics_ray_cast_all));
138 reg.add_internal_call("internal_m2n_physics_sphere_cast", dotnet_internal_call(internal_m2n_physics_sphere_cast));
139 reg.add_internal_call("internal_m2n_physics_sphere_cast_all",
140 dotnet_internal_call(internal_m2n_physics_sphere_cast_all));
141 reg.add_internal_call("internal_m2n_physics_sphere_overlap",
142 dotnet_internal_call(internal_m2n_physics_sphere_overlap));
143}
144
145} // namespace unravel
int layer_mask
bool query_sensors
unravel::physics_vector< hit_info > hits
bool hit
Definition defaults.cpp:51
#define APPLOG_TRACE(...)
Definition logging.h:17
void register_physics_script_bindings()
hpp::small_vector< T, SmallSizeCapacity > physics_vector
static auto context() -> rtti::context &
Definition engine.cpp:111