Unravel Engine C++ Reference
Loading...
Searching...
No Matches
gizmos.cpp
Go to the documentation of this file.
1#include "gizmos.h"
2
4#include <bx/math.h>
5namespace unravel
6{
7
8auto to_bx(const glm::vec3& data) -> bx::Vec3
9{
10 return {data.x, data.y, data.z};
11}
12
14{
15 bx::Sphere sphere;
16 sphere.center = to_bx(sh.center);
17 sphere.radius = sh.radius;
18 dde.draw(sphere);
19}
20
21// void draw(DebugDrawEncoder& dde, const physics_plane_shape& sh)
22// {
23// auto center = sh.normal * sh.constant;
24// dde.drawQuad(to_bx(-sh.normal), to_bx(center), 20);
25// }
26
28{
29 math::vec3 axis{0, 1, 0};
30 dde.drawCylinder(to_bx(sh.center + axis * -sh.length * 0.5f),
31 to_bx(sh.center + axis * sh.length * 0.5f),
32 sh.radius);
33}
34
36{
37 // auto axis = edyn::coordinate_axis_vector(sh.axis);
38 math::vec3 axis{0, 1, 0};
39 dde.drawCapsule(to_bx(sh.center + axis * -sh.length * 0.5f), to_bx(sh.center + axis * sh.length * 0.5f), sh.radius);
40}
41
43{
44 auto aabb = bx::Aabb{to_bx(sh.center - sh.extends * 0.5f), to_bx(sh.center + sh.extends * 0.5f)};
45 dde.draw(aabb);
46}
47
49{
50 // Draw a wireframe bounding box representation for mesh shapes
51 // In a full implementation, you could draw the actual mesh wireframe
52 if(sh.mesh_asset && sh.mesh_asset.is_ready())
53 {
54 const auto& mesh_ref = sh.mesh_asset.get();
55 auto bbox = mesh_ref->get_bounds();
56
57 // Offset by center
58 bbox.min += sh.center;
59 bbox.max += sh.center;
60
61 dde.setColor(sh.collision_type == mesh_collision_type::convex ? 0xff00ff00 : 0xff0000ff);
62 auto aabb = bx::Aabb{to_bx(bbox.min), to_bx(bbox.max)};
63 dde.draw(aabb);
64 //drawTriangleList
65 }
66}
67
69{
70 hpp::visit(
71 [&](auto&& s)
72 {
73 draw(dde, s);
74 },
75 sh.shape);
76}
77
78void draw(DebugDrawEncoder& dde, const std::vector<physics_compound_shape>& shapes)
79{
80 for(auto& shape : shapes)
81 {
82 draw(dde, shape);
83 }
84}
85
86
87} // namespace unravel
@ sphere
Sphere type reflection probe.
void draw(DebugDrawEncoder &dde, const physics_sphere_shape &sh)
Definition gizmos.cpp:13
@ convex
Convex mesh collision (can be dynamic, faster)
auto to_bx(const glm::vec3 &data) -> bx::Vec3
Definition gizmos.cpp:8
void draw(const bx::Aabb &_aabb)
void drawCylinder(const bx::Vec3 &_from, const bx::Vec3 &_to, float _radius)
void setColor(uint32_t _abgr)
void drawCapsule(const bx::Vec3 &_from, const bx::Vec3 &_to, float _radius)
Represents a box shape for physics calculations.
math::vec3 extends
Extents of the box.
math::vec3 center
Center of the box.
Represents a capsule shape for physics calculations.
float length
Length of the capsule.
math::vec3 center
Center of the capsule.
float radius
Radius of the capsule.
Represents a compound shape that can contain multiple types of shapes.
shape_t shape
The shape contained in the compound shape.
Represents a cylinder shape for physics calculations.
float length
Length of the cylinder.
math::vec3 center
Center of the cylinder.
float radius
Radius of the cylinder.
Represents a mesh shape for physics calculations.
math::vec3 center
Center offset of the mesh.
mesh_collision_type collision_type
Type of collision shape.
asset_handle< mesh > mesh_asset
Reference to the mesh asset.
Represents a sphere shape for physics calculations.
float radius
Radius of the sphere.
math::vec3 center
Center of the sphere.