bullet3 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +21 -0
  3. data/README.md +194 -0
  4. data/data/cube.urdf +22 -0
  5. data/data/plane.urdf +19 -0
  6. data/ext/bullet3/CMakeLists.txt +224 -0
  7. data/ext/bullet3/bullet3.cpp +34 -0
  8. data/ext/bullet3/collision/rb_collision.cpp +428 -0
  9. data/ext/bullet3/collision/rb_collision.hpp +87 -0
  10. data/ext/bullet3/collision/shapes/rb_collision_shape.cpp +485 -0
  11. data/ext/bullet3/collision/shapes/rb_collision_shape.hpp +5 -0
  12. data/ext/bullet3/constraints/rb_constraints.cpp +1310 -0
  13. data/ext/bullet3/constraints/rb_constraints.hpp +226 -0
  14. data/ext/bullet3/dynamics/rb_dynamics.cpp +862 -0
  15. data/ext/bullet3/dynamics/rb_dynamics.hpp +180 -0
  16. data/ext/bullet3/extconf.rb +57 -0
  17. data/ext/bullet3/io/rb_io.cpp +108 -0
  18. data/ext/bullet3/io/rb_io.hpp +40 -0
  19. data/ext/bullet3/linear_math/rb_matrix3x3.cpp +93 -0
  20. data/ext/bullet3/linear_math/rb_matrix3x3.hpp +5 -0
  21. data/ext/bullet3/linear_math/rb_quaternion.cpp +134 -0
  22. data/ext/bullet3/linear_math/rb_quaternion.hpp +5 -0
  23. data/ext/bullet3/linear_math/rb_transform.cpp +157 -0
  24. data/ext/bullet3/linear_math/rb_transform.hpp +34 -0
  25. data/ext/bullet3/linear_math/rb_vector3.cpp +123 -0
  26. data/ext/bullet3/linear_math/rb_vector3.hpp +5 -0
  27. data/ext/bullet3/multi_body/rb_multi_body.cpp +1000 -0
  28. data/ext/bullet3/multi_body/rb_multi_body.hpp +190 -0
  29. data/ext/bullet3/soft_body/rb_soft_body.cpp +720 -0
  30. data/ext/bullet3/soft_body/rb_soft_body.hpp +122 -0
  31. data/ext/bullet3/util/rb_debug_draw.cpp +250 -0
  32. data/ext/bullet3/util/rb_debug_draw.hpp +47 -0
  33. data/ext/bullet3/util/ruby_cpp_compat.hpp +29 -0
  34. data/ext/bullet3/util/type_conversions.hpp +107 -0
  35. data/ext/bullet3/vehicle/rb_vehicle.cpp +467 -0
  36. data/ext/bullet3/vehicle/rb_vehicle.hpp +115 -0
  37. data/lib/bullet3/collision.rb +6 -0
  38. data/lib/bullet3/constraints.rb +6 -0
  39. data/lib/bullet3/data.rb +39 -0
  40. data/lib/bullet3/debug_draw.rb +73 -0
  41. data/lib/bullet3/dynamics.rb +4 -0
  42. data/lib/bullet3/io.rb +110 -0
  43. data/lib/bullet3/linear_math/matrix3x3.rb +69 -0
  44. data/lib/bullet3/linear_math/quaternion.rb +187 -0
  45. data/lib/bullet3/linear_math/transform.rb +48 -0
  46. data/lib/bullet3/linear_math/vector3.rb +199 -0
  47. data/lib/bullet3/linear_math.rb +6 -0
  48. data/lib/bullet3/multi_body.rb +6 -0
  49. data/lib/bullet3/simulation.rb +1170 -0
  50. data/lib/bullet3/soft_body.rb +6 -0
  51. data/lib/bullet3/vehicle.rb +4 -0
  52. data/lib/bullet3/version.rb +5 -0
  53. data/lib/bullet3.rb +49 -0
  54. metadata +124 -0
@@ -0,0 +1,190 @@
1
+ #pragma once
2
+
3
+ #include <memory>
4
+ #include <unordered_map>
5
+ #include <unordered_set>
6
+
7
+ #include <BulletDynamics/Featherstone/btMultiBodyConstraintSolver.h>
8
+ #include <BulletDynamics/Featherstone/btMultiBodyDynamicsWorld.h>
9
+ #include <BulletDynamics/Featherstone/btMultiBodyJointLimitConstraint.h>
10
+ #include <BulletDynamics/Featherstone/btMultiBodyJointMotor.h>
11
+ #include <BulletDynamics/Featherstone/btMultiBodyLinkCollider.h>
12
+ #include <BulletDynamics/Featherstone/btMultiBodyPoint2Point.h>
13
+ #include <rice/rice.hpp>
14
+
15
+ #include "../dynamics/rb_dynamics.hpp"
16
+ #include "../linear_math/rb_transform.hpp"
17
+
18
+ namespace bullet3 {
19
+ class MultiBodyLinkCollider;
20
+
21
+ class MultiBody {
22
+ public:
23
+ MultiBody(int link_count, btScalar base_mass, Rice::Object base_inertia, bool fixed_base, bool can_sleep, bool deprecated_multi_dof);
24
+
25
+ btMultiBody* get();
26
+ const btMultiBody* get() const;
27
+ int num_links() const;
28
+ int num_dofs() const;
29
+ int num_pos_vars() const;
30
+ btScalar base_mass() const;
31
+ btScalar set_base_mass(btScalar mass);
32
+ btVector3 base_inertia() const;
33
+ btVector3 set_base_inertia(Rice::Object inertia);
34
+ btVector3 base_position() const;
35
+ btVector3 set_base_position(Rice::Object position);
36
+ btVector3 base_velocity() const;
37
+ btVector3 set_base_velocity(Rice::Object velocity);
38
+ btVector3 base_omega() const;
39
+ btVector3 set_base_omega(Rice::Object omega);
40
+ btQuaternion world_to_base_rotation() const;
41
+ btQuaternion set_world_to_base_rotation(Rice::Object rotation);
42
+ Transform base_world_transform() const;
43
+ Transform set_base_world_transform(Rice::Object transform);
44
+ bool fixed_base() const;
45
+ bool can_sleep() const;
46
+ bool set_can_sleep(bool can_sleep);
47
+ bool awake() const;
48
+ void wake_up();
49
+ void go_to_sleep();
50
+ btScalar linear_damping() const;
51
+ btScalar set_linear_damping(btScalar damping);
52
+ btScalar angular_damping() const;
53
+ btScalar set_angular_damping(btScalar damping);
54
+ bool self_collision() const;
55
+ bool set_self_collision(bool enabled);
56
+ btScalar joint_position(int link) const;
57
+ btScalar set_joint_position(int link, btScalar position);
58
+ btScalar joint_velocity(int link) const;
59
+ btScalar set_joint_velocity(int link, btScalar velocity);
60
+ void setup_fixed(int link, btScalar mass, Rice::Object inertia, int parent, Rice::Object parent_to_this_rotation, Rice::Object parent_pivot, Rice::Object child_pivot, bool disable_parent_collision);
61
+ void setup_revolute(int link, btScalar mass, Rice::Object inertia, int parent, Rice::Object parent_to_this_rotation, Rice::Object joint_axis, Rice::Object parent_pivot, Rice::Object child_pivot, bool disable_parent_collision);
62
+ void setup_prismatic(int link, btScalar mass, Rice::Object inertia, int parent, Rice::Object parent_to_this_rotation, Rice::Object joint_axis, Rice::Object parent_pivot, Rice::Object child_pivot, bool disable_parent_collision);
63
+ void finalize_multi_dof();
64
+ void clear_forces_and_torques();
65
+ void clear_velocities();
66
+ void add_base_force(Rice::Object force);
67
+ void add_base_torque(Rice::Object torque);
68
+ void add_link_force(int link, Rice::Object force);
69
+ void add_link_torque(int link, Rice::Object torque);
70
+ void add_joint_torque(int link, btScalar torque);
71
+ int parent(int link) const;
72
+ void set_base_collider(MultiBodyLinkCollider& collider);
73
+ void set_link_collider(int link, MultiBodyLinkCollider& collider);
74
+
75
+ private:
76
+ int validate_link_index(int link) const;
77
+
78
+ std::unique_ptr<btMultiBody> multi_body_;
79
+ };
80
+
81
+ class MultiBodyLinkCollider {
82
+ public:
83
+ MultiBodyLinkCollider(MultiBody& multi_body, int link);
84
+
85
+ btMultiBodyLinkCollider* get();
86
+ const btMultiBodyLinkCollider* get() const;
87
+ int link() const;
88
+ Transform world_transform() const;
89
+ Transform set_world_transform(Rice::Object transform);
90
+ void set_collision_shape(VALUE collision_shape);
91
+ btCollisionShape* collision_shape() const;
92
+ int collision_flags() const;
93
+ int set_collision_flags(int flags);
94
+ bool kinematic() const;
95
+ bool static_or_kinematic() const;
96
+
97
+ private:
98
+ std::unique_ptr<btMultiBodyLinkCollider> collider_;
99
+ };
100
+
101
+ class MultiBodyConstraint {
102
+ public:
103
+ virtual ~MultiBodyConstraint() = default;
104
+
105
+ btMultiBodyConstraint* get();
106
+ const btMultiBodyConstraint* get() const;
107
+ Rice::Symbol constraint_type() const;
108
+ int num_rows() const;
109
+ btScalar max_applied_impulse() const;
110
+ btScalar set_max_applied_impulse(btScalar impulse);
111
+ btScalar applied_impulse(int row);
112
+ btScalar position(int row) const;
113
+
114
+ protected:
115
+ explicit MultiBodyConstraint(std::unique_ptr<btMultiBodyConstraint> constraint);
116
+
117
+ private:
118
+ std::unique_ptr<btMultiBodyConstraint> constraint_;
119
+ };
120
+
121
+ class MultiBodyJointMotor : public MultiBodyConstraint {
122
+ public:
123
+ MultiBodyJointMotor(VALUE multi_body, int link, btScalar desired_velocity, btScalar max_motor_impulse);
124
+ MultiBodyJointMotor(VALUE multi_body, int link, int link_dof, btScalar desired_velocity, btScalar max_motor_impulse);
125
+
126
+ void set_velocity_target(btScalar velocity, btScalar kd);
127
+ void set_position_target(btScalar position, btScalar kp);
128
+ btScalar erp() const;
129
+ btScalar set_erp(btScalar erp);
130
+ void set_rhs_clamp(btScalar clamp);
131
+ };
132
+
133
+ class MultiBodyJointLimitConstraint : public MultiBodyConstraint {
134
+ public:
135
+ MultiBodyJointLimitConstraint(VALUE multi_body, int link, btScalar lower, btScalar upper);
136
+
137
+ btScalar lower_bound() const;
138
+ btScalar set_lower_bound(btScalar lower);
139
+ btScalar upper_bound() const;
140
+ btScalar set_upper_bound(btScalar upper);
141
+ };
142
+
143
+ class MultiBodyPoint2Point : public MultiBodyConstraint {
144
+ public:
145
+ MultiBodyPoint2Point(VALUE multi_body, int link, VALUE rigid_body, VALUE pivot_in_a, VALUE pivot_in_b);
146
+ MultiBodyPoint2Point(VALUE multi_body_a, int link_a, VALUE multi_body_b, int link_b, VALUE pivot_in_a, VALUE pivot_in_b);
147
+
148
+ btVector3 pivot_in_b() const;
149
+ btVector3 set_pivot_in_b(Rice::Object pivot);
150
+ };
151
+
152
+ class MultiBodyDynamicsWorld {
153
+ public:
154
+ MultiBodyDynamicsWorld();
155
+ ~MultiBodyDynamicsWorld();
156
+
157
+ btMultiBodyDynamicsWorld* get();
158
+ btVector3 gravity() const;
159
+ btVector3 set_gravity(Rice::Object gravity);
160
+ void add_multi_body_object(VALUE multi_body, int group, int mask);
161
+ void remove_multi_body_object(VALUE multi_body);
162
+ void add_constraint_object(VALUE constraint);
163
+ void remove_constraint_object(VALUE constraint);
164
+ void add_link_collider_object(VALUE collider, int group, int mask);
165
+ void remove_link_collider_object(VALUE collider);
166
+ int step_simulation(btScalar time_step, int max_sub_steps, btScalar fixed_time_step);
167
+ int num_multi_bodies() const;
168
+ int num_multi_body_constraints() const;
169
+ int num_collision_objects() const;
170
+ void forward_kinematics();
171
+ void clear_forces();
172
+ void clear_multi_body_forces();
173
+ void mark() const;
174
+
175
+ private:
176
+ std::unique_ptr<btDefaultCollisionConfiguration> configuration_;
177
+ std::unique_ptr<btCollisionDispatcher> dispatcher_;
178
+ std::unique_ptr<btDbvtBroadphase> broadphase_;
179
+ std::unique_ptr<btMultiBodyConstraintSolver> solver_;
180
+ std::unique_ptr<btMultiBodyDynamicsWorld> world_;
181
+ std::unordered_set<btMultiBody*> multi_bodies_;
182
+ std::unordered_set<btMultiBodyConstraint*> constraints_;
183
+ std::unordered_set<btMultiBodyLinkCollider*> colliders_;
184
+ std::unordered_map<const btMultiBody*, VALUE> multi_body_values_;
185
+ std::unordered_map<const btMultiBodyConstraint*, VALUE> constraint_values_;
186
+ std::unordered_map<const btCollisionObject*, VALUE> collider_values_;
187
+ };
188
+ } // namespace bullet3
189
+
190
+ void Init_MultiBody(Rice::Module rb_mBullet);