PixelBullet  0.0.1
A C++ game engine
Loading...
Searching...
No Matches
collider_component.h
1#pragma once
2
3#include "pixelbullet/physics/physics_serialization.h"
4#include "pixelbullet/physics/physics_types.h"
5#include "pixelbullet/serialization/glm_node.h"
6#include "pixelbullet/serialization/node.h"
7
8namespace pixelbullet
9{
11{
12 bool enabled = true;
13 ColliderShapeType shape = ColliderShapeType::Box;
14 glm::vec3 box_half_extents = glm::vec3(0.5f);
15 float sphere_radius = 0.5f;
16 float capsule_radius = 0.5f;
17 float capsule_half_height = 0.5f;
18 glm::vec3 center = glm::vec3(0.0f);
19 float friction = 0.5f;
20 float restitution = 0.0f;
21 bool is_trigger = false;
22
23 [[nodiscard]] bool operator==(const ColliderComponent&) const noexcept = default;
24};
25
26inline Node& operator<<(Node& node, const ColliderComponent& component)
27{
28 node["enabled"] << component.enabled;
29 node["shape"] << component.shape;
30 node["boxHalfExtents"] << component.box_half_extents;
31 node["sphereRadius"] << component.sphere_radius;
32 node["capsuleRadius"] << component.capsule_radius;
33 node["capsuleHalfHeight"] << component.capsule_half_height;
34 node["center"] << component.center;
35 node["friction"] << component.friction;
36 node["restitution"] << component.restitution;
37 node["isTrigger"] << component.is_trigger;
38 return node;
39}
40
41inline const Node& operator>>(const Node& node, ColliderComponent& component)
42{
43 if (node.has_property("enabled"))
44 {
45 node["enabled"] >> component.enabled;
46 }
47 if (node.has_property("shape"))
48 {
49 node["shape"] >> component.shape;
50 }
51 if (node.has_property("boxHalfExtents"))
52 {
53 node["boxHalfExtents"] >> component.box_half_extents;
54 }
55 if (node.has_property("sphereRadius"))
56 {
57 node["sphereRadius"] >> component.sphere_radius;
58 }
59 if (node.has_property("capsuleRadius"))
60 {
61 node["capsuleRadius"] >> component.capsule_radius;
62 }
63 if (node.has_property("capsuleHalfHeight"))
64 {
65 node["capsuleHalfHeight"] >> component.capsule_half_height;
66 }
67 if (node.has_property("center"))
68 {
69 node["center"] >> component.center;
70 }
71 if (node.has_property("friction"))
72 {
73 node["friction"] >> component.friction;
74 }
75 if (node.has_property("restitution"))
76 {
77 node["restitution"] >> component.restitution;
78 }
79 if (node.has_property("isTrigger"))
80 {
81 node["isTrigger"] >> component.is_trigger;
82 }
83 else
84 {
85 component.is_trigger = false;
86 }
87 return node;
88}
89} // namespace pixelbullet
Represents a hierarchical node capable of storing various data types and supporting YAML serializatio...
Definition node.h:49
Definition collider_component.h:11