PixelBullet  0.0.1
A C++ game engine
Loading...
Searching...
No Matches
rigid_body_component.h
1#pragma once
2
3#include "pixelbullet/physics/physics_serialization.h"
4#include "pixelbullet/physics/physics_types.h"
5#include "pixelbullet/serialization/node.h"
6
7namespace pixelbullet
8{
10{
11 bool enabled = true;
12 RigidBodyMotionType motion_type = RigidBodyMotionType::Dynamic;
13 float mass = 1.0f;
14 float linear_damping = 0.05f;
15 float angular_damping = 0.05f;
16 float gravity_scale = 1.0f;
17
18 [[nodiscard]] bool operator==(const RigidBodyComponent&) const noexcept = default;
19};
20
21inline Node& operator<<(Node& node, const RigidBodyComponent& component)
22{
23 node["enabled"] << component.enabled;
24 node["motionType"] << component.motion_type;
25 node["mass"] << component.mass;
26 node["linearDamping"] << component.linear_damping;
27 node["angularDamping"] << component.angular_damping;
28 node["gravityScale"] << component.gravity_scale;
29 return node;
30}
31
32inline const Node& operator>>(const Node& node, RigidBodyComponent& component)
33{
34 if (node.has_property("enabled"))
35 {
36 node["enabled"] >> component.enabled;
37 }
38 if (node.has_property("motionType"))
39 {
40 node["motionType"] >> component.motion_type;
41 }
42 if (node.has_property("mass"))
43 {
44 node["mass"] >> component.mass;
45 }
46 if (node.has_property("linearDamping"))
47 {
48 node["linearDamping"] >> component.linear_damping;
49 }
50 if (node.has_property("angularDamping"))
51 {
52 node["angularDamping"] >> component.angular_damping;
53 }
54 if (node.has_property("gravityScale"))
55 {
56 node["gravityScale"] >> component.gravity_scale;
57 }
58 return node;
59}
60} // namespace pixelbullet
Represents a hierarchical node capable of storing various data types and supporting YAML serializatio...
Definition node.h:49
Definition rigid_body_component.h:10