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.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +194 -0
- data/data/cube.urdf +22 -0
- data/data/plane.urdf +19 -0
- data/ext/bullet3/CMakeLists.txt +224 -0
- data/ext/bullet3/bullet3.cpp +34 -0
- data/ext/bullet3/collision/rb_collision.cpp +428 -0
- data/ext/bullet3/collision/rb_collision.hpp +87 -0
- data/ext/bullet3/collision/shapes/rb_collision_shape.cpp +485 -0
- data/ext/bullet3/collision/shapes/rb_collision_shape.hpp +5 -0
- data/ext/bullet3/constraints/rb_constraints.cpp +1310 -0
- data/ext/bullet3/constraints/rb_constraints.hpp +226 -0
- data/ext/bullet3/dynamics/rb_dynamics.cpp +862 -0
- data/ext/bullet3/dynamics/rb_dynamics.hpp +180 -0
- data/ext/bullet3/extconf.rb +57 -0
- data/ext/bullet3/io/rb_io.cpp +108 -0
- data/ext/bullet3/io/rb_io.hpp +40 -0
- data/ext/bullet3/linear_math/rb_matrix3x3.cpp +93 -0
- data/ext/bullet3/linear_math/rb_matrix3x3.hpp +5 -0
- data/ext/bullet3/linear_math/rb_quaternion.cpp +134 -0
- data/ext/bullet3/linear_math/rb_quaternion.hpp +5 -0
- data/ext/bullet3/linear_math/rb_transform.cpp +157 -0
- data/ext/bullet3/linear_math/rb_transform.hpp +34 -0
- data/ext/bullet3/linear_math/rb_vector3.cpp +123 -0
- data/ext/bullet3/linear_math/rb_vector3.hpp +5 -0
- data/ext/bullet3/multi_body/rb_multi_body.cpp +1000 -0
- data/ext/bullet3/multi_body/rb_multi_body.hpp +190 -0
- data/ext/bullet3/soft_body/rb_soft_body.cpp +720 -0
- data/ext/bullet3/soft_body/rb_soft_body.hpp +122 -0
- data/ext/bullet3/util/rb_debug_draw.cpp +250 -0
- data/ext/bullet3/util/rb_debug_draw.hpp +47 -0
- data/ext/bullet3/util/ruby_cpp_compat.hpp +29 -0
- data/ext/bullet3/util/type_conversions.hpp +107 -0
- data/ext/bullet3/vehicle/rb_vehicle.cpp +467 -0
- data/ext/bullet3/vehicle/rb_vehicle.hpp +115 -0
- data/lib/bullet3/collision.rb +6 -0
- data/lib/bullet3/constraints.rb +6 -0
- data/lib/bullet3/data.rb +39 -0
- data/lib/bullet3/debug_draw.rb +73 -0
- data/lib/bullet3/dynamics.rb +4 -0
- data/lib/bullet3/io.rb +110 -0
- data/lib/bullet3/linear_math/matrix3x3.rb +69 -0
- data/lib/bullet3/linear_math/quaternion.rb +187 -0
- data/lib/bullet3/linear_math/transform.rb +48 -0
- data/lib/bullet3/linear_math/vector3.rb +199 -0
- data/lib/bullet3/linear_math.rb +6 -0
- data/lib/bullet3/multi_body.rb +6 -0
- data/lib/bullet3/simulation.rb +1170 -0
- data/lib/bullet3/soft_body.rb +6 -0
- data/lib/bullet3/vehicle.rb +4 -0
- data/lib/bullet3/version.rb +5 -0
- data/lib/bullet3.rb +49 -0
- metadata +124 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <memory>
|
|
4
|
+
#include <unordered_map>
|
|
5
|
+
#include <unordered_set>
|
|
6
|
+
|
|
7
|
+
#include <BulletSoftBody/btSoftBodyHelpers.h>
|
|
8
|
+
#include <BulletSoftBody/btSoftBodyRigidBodyCollisionConfiguration.h>
|
|
9
|
+
#include <BulletSoftBody/btSoftRigidDynamicsWorld.h>
|
|
10
|
+
#include <rice/rice.hpp>
|
|
11
|
+
|
|
12
|
+
#include "../dynamics/rb_dynamics.hpp"
|
|
13
|
+
|
|
14
|
+
namespace bullet3 {
|
|
15
|
+
class SoftBodyWorldInfo {
|
|
16
|
+
public:
|
|
17
|
+
SoftBodyWorldInfo();
|
|
18
|
+
explicit SoftBodyWorldInfo(btSoftBodyWorldInfo* world_info);
|
|
19
|
+
|
|
20
|
+
btSoftBodyWorldInfo& get();
|
|
21
|
+
const btSoftBodyWorldInfo& get() const;
|
|
22
|
+
btVector3 gravity() const;
|
|
23
|
+
btVector3 set_gravity(Rice::Object gravity);
|
|
24
|
+
btScalar air_density() const;
|
|
25
|
+
btScalar set_air_density(btScalar value);
|
|
26
|
+
btScalar water_density() const;
|
|
27
|
+
btScalar set_water_density(btScalar value);
|
|
28
|
+
btScalar water_offset() const;
|
|
29
|
+
btScalar set_water_offset(btScalar value);
|
|
30
|
+
btVector3 water_normal() const;
|
|
31
|
+
btVector3 set_water_normal(Rice::Object normal);
|
|
32
|
+
btScalar max_displacement() const;
|
|
33
|
+
btScalar set_max_displacement(btScalar value);
|
|
34
|
+
void reset_sparse_sdf();
|
|
35
|
+
|
|
36
|
+
private:
|
|
37
|
+
std::unique_ptr<btSoftBodyWorldInfo> owned_world_info_;
|
|
38
|
+
btSoftBodyWorldInfo* world_info_;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
class SoftBody {
|
|
42
|
+
public:
|
|
43
|
+
explicit SoftBody(btSoftBody* soft_body);
|
|
44
|
+
|
|
45
|
+
btSoftBody* get();
|
|
46
|
+
const btSoftBody* get() const;
|
|
47
|
+
int node_count() const;
|
|
48
|
+
int link_count() const;
|
|
49
|
+
int face_count() const;
|
|
50
|
+
int tetra_count() const;
|
|
51
|
+
int cluster_count() const;
|
|
52
|
+
btScalar total_mass() const;
|
|
53
|
+
void set_total_mass(btScalar mass, bool from_faces);
|
|
54
|
+
btScalar node_mass(int index) const;
|
|
55
|
+
btScalar set_node_mass(int index, btScalar mass);
|
|
56
|
+
btVector3 node_position(int index) const;
|
|
57
|
+
btVector3 node_velocity(int index) const;
|
|
58
|
+
btVector3 center_of_mass() const;
|
|
59
|
+
btVector3 linear_velocity();
|
|
60
|
+
void set_linear_velocity(Rice::Object velocity);
|
|
61
|
+
void set_velocity(Rice::Object velocity);
|
|
62
|
+
void set_angular_velocity(Rice::Object velocity);
|
|
63
|
+
void add_force(Rice::Object force);
|
|
64
|
+
void add_velocity(Rice::Object velocity);
|
|
65
|
+
void translate(Rice::Object translation);
|
|
66
|
+
void rotate(Rice::Object rotation);
|
|
67
|
+
void scale(Rice::Object scaling);
|
|
68
|
+
void transform(Rice::Object transform);
|
|
69
|
+
void set_pose(bool volume, bool frame);
|
|
70
|
+
int generate_bending_constraints(int distance);
|
|
71
|
+
int generate_clusters(int count);
|
|
72
|
+
void randomize_constraints();
|
|
73
|
+
btVector3 wind_velocity();
|
|
74
|
+
btVector3 set_wind_velocity(Rice::Object velocity);
|
|
75
|
+
void set_zero_velocity();
|
|
76
|
+
bool self_collision();
|
|
77
|
+
bool set_self_collision(bool enabled);
|
|
78
|
+
Rice::Array aabb() const;
|
|
79
|
+
Rice::Object ray_test(Rice::Object from, Rice::Object to);
|
|
80
|
+
void append_anchor(int node, RigidBody& rigid_body, bool disable_collision_between_linked_bodies, btScalar influence);
|
|
81
|
+
|
|
82
|
+
private:
|
|
83
|
+
int validate_node_index(int index) const;
|
|
84
|
+
|
|
85
|
+
std::unique_ptr<btSoftBody> soft_body_;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
class SoftRigidDynamicsWorld {
|
|
89
|
+
public:
|
|
90
|
+
SoftRigidDynamicsWorld();
|
|
91
|
+
~SoftRigidDynamicsWorld();
|
|
92
|
+
|
|
93
|
+
btSoftRigidDynamicsWorld* get();
|
|
94
|
+
btVector3 gravity() const;
|
|
95
|
+
btVector3 set_gravity(Rice::Object gravity);
|
|
96
|
+
SoftBodyWorldInfo* world_info();
|
|
97
|
+
void add_rigid_body_object(VALUE rigid_body);
|
|
98
|
+
void remove_rigid_body_object(VALUE rigid_body);
|
|
99
|
+
void add_soft_body_object(VALUE soft_body, int collision_filter_group, int collision_filter_mask);
|
|
100
|
+
void remove_soft_body_object(VALUE soft_body);
|
|
101
|
+
int step_simulation(btScalar time_step, int max_sub_steps, btScalar fixed_time_step);
|
|
102
|
+
int num_collision_objects() const;
|
|
103
|
+
int num_soft_bodies() const;
|
|
104
|
+
int draw_flags() const;
|
|
105
|
+
int set_draw_flags(int flags);
|
|
106
|
+
void clear_forces();
|
|
107
|
+
void mark() const;
|
|
108
|
+
|
|
109
|
+
private:
|
|
110
|
+
std::unique_ptr<btSoftBodyRigidBodyCollisionConfiguration> configuration_;
|
|
111
|
+
std::unique_ptr<btCollisionDispatcher> dispatcher_;
|
|
112
|
+
std::unique_ptr<btDbvtBroadphase> broadphase_;
|
|
113
|
+
std::unique_ptr<btSequentialImpulseConstraintSolver> solver_;
|
|
114
|
+
std::unique_ptr<btSoftRigidDynamicsWorld> world_;
|
|
115
|
+
std::unordered_set<btRigidBody*> rigid_bodies_;
|
|
116
|
+
std::unordered_set<btSoftBody*> soft_bodies_;
|
|
117
|
+
std::unordered_map<const btCollisionObject*, VALUE> collision_object_values_;
|
|
118
|
+
std::unordered_map<const btSoftBody*, VALUE> soft_body_values_;
|
|
119
|
+
};
|
|
120
|
+
} // namespace bullet3
|
|
121
|
+
|
|
122
|
+
void Init_SoftBody(Rice::Module rb_mBullet);
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
#include "rb_debug_draw.hpp"
|
|
2
|
+
|
|
3
|
+
#include <ruby.h>
|
|
4
|
+
|
|
5
|
+
#include "type_conversions.hpp"
|
|
6
|
+
|
|
7
|
+
namespace {
|
|
8
|
+
VALUE array_from_vector(const btVector3& vector)
|
|
9
|
+
{
|
|
10
|
+
return rb_ary_new_from_args(3,
|
|
11
|
+
DBL2NUM(vector.getX()),
|
|
12
|
+
DBL2NUM(vector.getY()),
|
|
13
|
+
DBL2NUM(vector.getZ()));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
VALUE line_hash(const btVector3& from, const btVector3& to, const btVector3& color)
|
|
17
|
+
{
|
|
18
|
+
VALUE hash = rb_hash_new();
|
|
19
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("from")), array_from_vector(from));
|
|
20
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("to")), array_from_vector(to));
|
|
21
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("color")), array_from_vector(color));
|
|
22
|
+
return hash;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
VALUE contact_hash(const btVector3& point,
|
|
26
|
+
const btVector3& normal,
|
|
27
|
+
btScalar distance,
|
|
28
|
+
int life_time,
|
|
29
|
+
const btVector3& color)
|
|
30
|
+
{
|
|
31
|
+
VALUE hash = rb_hash_new();
|
|
32
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("point")), array_from_vector(point));
|
|
33
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("normal")), array_from_vector(normal));
|
|
34
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("distance")), DBL2NUM(distance));
|
|
35
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("life_time")), INT2NUM(life_time));
|
|
36
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("color")), array_from_vector(color));
|
|
37
|
+
return hash;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
VALUE text_hash(const btVector3& location, const char* text)
|
|
41
|
+
{
|
|
42
|
+
VALUE hash = rb_hash_new();
|
|
43
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("location")), array_from_vector(location));
|
|
44
|
+
rb_hash_aset(hash, ID2SYM(rb_intern("text")), rb_str_new_cstr(text));
|
|
45
|
+
return hash;
|
|
46
|
+
}
|
|
47
|
+
} // namespace
|
|
48
|
+
|
|
49
|
+
namespace bullet3 {
|
|
50
|
+
DebugDraw::DebugDraw()
|
|
51
|
+
: DebugDraw(Qnil)
|
|
52
|
+
{
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
DebugDraw::DebugDraw(VALUE target)
|
|
56
|
+
: target_(target),
|
|
57
|
+
lines_(rb_ary_new()),
|
|
58
|
+
contact_points_(rb_ary_new()),
|
|
59
|
+
warnings_(rb_ary_new()),
|
|
60
|
+
texts_(rb_ary_new()),
|
|
61
|
+
debug_mode_(DBG_DrawWireframe | DBG_DrawAabb | DBG_DrawConstraints | DBG_DrawConstraintLimits)
|
|
62
|
+
{
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
btIDebugDraw* DebugDraw::get()
|
|
66
|
+
{
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
Rice::Array DebugDraw::lines() const
|
|
71
|
+
{
|
|
72
|
+
return Rice::Array(Rice::Object(lines_));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
Rice::Array DebugDraw::contact_points() const
|
|
76
|
+
{
|
|
77
|
+
return Rice::Array(Rice::Object(contact_points_));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
Rice::Array DebugDraw::warnings() const
|
|
81
|
+
{
|
|
82
|
+
return Rice::Array(Rice::Object(warnings_));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
Rice::Array DebugDraw::texts() const
|
|
86
|
+
{
|
|
87
|
+
return Rice::Array(Rice::Object(texts_));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
void DebugDraw::clear()
|
|
91
|
+
{
|
|
92
|
+
rb_ary_clear(lines_);
|
|
93
|
+
rb_ary_clear(contact_points_);
|
|
94
|
+
rb_ary_clear(warnings_);
|
|
95
|
+
rb_ary_clear(texts_);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
void DebugDraw::draw_line_object(VALUE from, VALUE to, VALUE color)
|
|
99
|
+
{
|
|
100
|
+
drawLine(
|
|
101
|
+
coerce_vector(Rice::Object(from)),
|
|
102
|
+
coerce_vector(Rice::Object(to)),
|
|
103
|
+
coerce_vector(Rice::Object(color)));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
void DebugDraw::draw_contact_point_object(VALUE point, VALUE normal, btScalar distance, int life_time, VALUE color)
|
|
107
|
+
{
|
|
108
|
+
drawContactPoint(
|
|
109
|
+
coerce_vector(Rice::Object(point)),
|
|
110
|
+
coerce_vector(Rice::Object(normal)),
|
|
111
|
+
distance,
|
|
112
|
+
life_time,
|
|
113
|
+
coerce_vector(Rice::Object(color)));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
void DebugDraw::report_error_warning_object(VALUE warning)
|
|
117
|
+
{
|
|
118
|
+
reportErrorWarning(StringValueCStr(warning));
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
void DebugDraw::draw_3d_text_object(VALUE location, VALUE text)
|
|
122
|
+
{
|
|
123
|
+
draw3dText(coerce_vector(Rice::Object(location)), StringValueCStr(text));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
void DebugDraw::drawLine(const btVector3& from, const btVector3& to, const btVector3& color)
|
|
127
|
+
{
|
|
128
|
+
VALUE entry = line_hash(from, to, color);
|
|
129
|
+
rb_ary_push(lines_, entry);
|
|
130
|
+
|
|
131
|
+
VALUE args[] = {
|
|
132
|
+
rb_hash_aref(entry, ID2SYM(rb_intern("from"))),
|
|
133
|
+
rb_hash_aref(entry, ID2SYM(rb_intern("to"))),
|
|
134
|
+
rb_hash_aref(entry, ID2SYM(rb_intern("color")))
|
|
135
|
+
};
|
|
136
|
+
call_target("draw_line", 3, args);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
void DebugDraw::drawContactPoint(const btVector3& point_on_b,
|
|
140
|
+
const btVector3& normal_on_b,
|
|
141
|
+
btScalar distance,
|
|
142
|
+
int life_time,
|
|
143
|
+
const btVector3& color)
|
|
144
|
+
{
|
|
145
|
+
VALUE entry = contact_hash(point_on_b, normal_on_b, distance, life_time, color);
|
|
146
|
+
rb_ary_push(contact_points_, entry);
|
|
147
|
+
VALUE args[] = { entry };
|
|
148
|
+
call_target("draw_contact_point", 1, args);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
void DebugDraw::reportErrorWarning(const char* warning_string)
|
|
152
|
+
{
|
|
153
|
+
VALUE warning = rb_str_new_cstr(warning_string);
|
|
154
|
+
rb_ary_push(warnings_, warning);
|
|
155
|
+
VALUE args[] = { warning };
|
|
156
|
+
call_target("report_error_warning", 1, args);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
void DebugDraw::draw3dText(const btVector3& location, const char* text_string)
|
|
160
|
+
{
|
|
161
|
+
VALUE entry = text_hash(location, text_string);
|
|
162
|
+
rb_ary_push(texts_, entry);
|
|
163
|
+
VALUE args[] = {
|
|
164
|
+
rb_hash_aref(entry, ID2SYM(rb_intern("location"))),
|
|
165
|
+
rb_hash_aref(entry, ID2SYM(rb_intern("text")))
|
|
166
|
+
};
|
|
167
|
+
call_target("draw_3d_text", 2, args);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
void DebugDraw::setDebugMode(int debug_mode)
|
|
171
|
+
{
|
|
172
|
+
debug_mode_ = debug_mode;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
int DebugDraw::getDebugMode() const
|
|
176
|
+
{
|
|
177
|
+
return debug_mode_;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
void DebugDraw::call_target(const char* method_name, int argc, const VALUE* argv) const
|
|
181
|
+
{
|
|
182
|
+
if (NIL_P(target_)) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
ID method_id = rb_intern(method_name);
|
|
187
|
+
if (!rb_respond_to(target_, method_id)) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
rb_funcallv(target_, method_id, argc, argv);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
void DebugDraw::mark() const
|
|
195
|
+
{
|
|
196
|
+
rb_gc_mark(target_);
|
|
197
|
+
rb_gc_mark(lines_);
|
|
198
|
+
rb_gc_mark(contact_points_);
|
|
199
|
+
rb_gc_mark(warnings_);
|
|
200
|
+
rb_gc_mark(texts_);
|
|
201
|
+
}
|
|
202
|
+
} // namespace bullet3
|
|
203
|
+
|
|
204
|
+
namespace Rice {
|
|
205
|
+
template <>
|
|
206
|
+
void ruby_mark<bullet3::DebugDraw>(bullet3::DebugDraw* debug_draw)
|
|
207
|
+
{
|
|
208
|
+
if (debug_draw != nullptr) {
|
|
209
|
+
debug_draw->mark();
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
} // namespace Rice
|
|
213
|
+
|
|
214
|
+
void Init_DebugDraw(Rice::Module rb_mBullet)
|
|
215
|
+
{
|
|
216
|
+
Rice::Class rb_cDebugDraw = Rice::define_class_under<bullet3::DebugDraw>(rb_mBullet, "DebugDraw")
|
|
217
|
+
.define_constructor(Rice::Constructor<bullet3::DebugDraw>())
|
|
218
|
+
.define_constructor(Rice::Constructor<bullet3::DebugDraw, VALUE>(),
|
|
219
|
+
Rice::Arg("target").setValue().keepAlive())
|
|
220
|
+
.define_method("lines", &bullet3::DebugDraw::lines)
|
|
221
|
+
.define_method("contact_points", &bullet3::DebugDraw::contact_points)
|
|
222
|
+
.define_method("warnings", &bullet3::DebugDraw::warnings)
|
|
223
|
+
.define_method("texts", &bullet3::DebugDraw::texts)
|
|
224
|
+
.define_method("clear", &bullet3::DebugDraw::clear)
|
|
225
|
+
.define_method("draw_line", &bullet3::DebugDraw::draw_line_object,
|
|
226
|
+
Rice::Arg("from").setValue(),
|
|
227
|
+
Rice::Arg("to").setValue(),
|
|
228
|
+
Rice::Arg("color").setValue())
|
|
229
|
+
.define_method("draw_contact_point", &bullet3::DebugDraw::draw_contact_point_object,
|
|
230
|
+
Rice::Arg("point").setValue(),
|
|
231
|
+
Rice::Arg("normal").setValue(),
|
|
232
|
+
Rice::Arg("distance"),
|
|
233
|
+
Rice::Arg("life_time"),
|
|
234
|
+
Rice::Arg("color").setValue())
|
|
235
|
+
.define_method("report_error_warning", &bullet3::DebugDraw::report_error_warning_object,
|
|
236
|
+
Rice::Arg("warning").setValue())
|
|
237
|
+
.define_method("draw_3d_text", &bullet3::DebugDraw::draw_3d_text_object,
|
|
238
|
+
Rice::Arg("location").setValue(),
|
|
239
|
+
Rice::Arg("text").setValue())
|
|
240
|
+
.define_method("debug_mode", &bullet3::DebugDraw::getDebugMode)
|
|
241
|
+
.define_method("debug_mode=", &bullet3::DebugDraw::setDebugMode);
|
|
242
|
+
|
|
243
|
+
rb_cDebugDraw.define_constant("NO_DEBUG", static_cast<int>(btIDebugDraw::DBG_NoDebug));
|
|
244
|
+
rb_cDebugDraw.define_constant("DRAW_WIREFRAME", static_cast<int>(btIDebugDraw::DBG_DrawWireframe));
|
|
245
|
+
rb_cDebugDraw.define_constant("DRAW_AABB", static_cast<int>(btIDebugDraw::DBG_DrawAabb));
|
|
246
|
+
rb_cDebugDraw.define_constant("DRAW_CONTACT_POINTS", static_cast<int>(btIDebugDraw::DBG_DrawContactPoints));
|
|
247
|
+
rb_cDebugDraw.define_constant("DRAW_CONSTRAINTS", static_cast<int>(btIDebugDraw::DBG_DrawConstraints));
|
|
248
|
+
rb_cDebugDraw.define_constant("DRAW_CONSTRAINT_LIMITS", static_cast<int>(btIDebugDraw::DBG_DrawConstraintLimits));
|
|
249
|
+
rb_cDebugDraw.define_constant("DRAW_FRAMES", static_cast<int>(btIDebugDraw::DBG_DrawFrames));
|
|
250
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <LinearMath/btIDebugDraw.h>
|
|
4
|
+
#include <rice/rice.hpp>
|
|
5
|
+
|
|
6
|
+
namespace bullet3 {
|
|
7
|
+
class DebugDraw : public btIDebugDraw {
|
|
8
|
+
public:
|
|
9
|
+
DebugDraw();
|
|
10
|
+
explicit DebugDraw(VALUE target);
|
|
11
|
+
|
|
12
|
+
btIDebugDraw* get();
|
|
13
|
+
Rice::Array lines() const;
|
|
14
|
+
Rice::Array contact_points() const;
|
|
15
|
+
Rice::Array warnings() const;
|
|
16
|
+
Rice::Array texts() const;
|
|
17
|
+
void clear();
|
|
18
|
+
void draw_line_object(VALUE from, VALUE to, VALUE color);
|
|
19
|
+
void draw_contact_point_object(VALUE point, VALUE normal, btScalar distance, int life_time, VALUE color);
|
|
20
|
+
void report_error_warning_object(VALUE warning);
|
|
21
|
+
void draw_3d_text_object(VALUE location, VALUE text);
|
|
22
|
+
void mark() const;
|
|
23
|
+
|
|
24
|
+
void drawLine(const btVector3& from, const btVector3& to, const btVector3& color) override;
|
|
25
|
+
void drawContactPoint(const btVector3& point_on_b,
|
|
26
|
+
const btVector3& normal_on_b,
|
|
27
|
+
btScalar distance,
|
|
28
|
+
int life_time,
|
|
29
|
+
const btVector3& color) override;
|
|
30
|
+
void reportErrorWarning(const char* warning_string) override;
|
|
31
|
+
void draw3dText(const btVector3& location, const char* text_string) override;
|
|
32
|
+
void setDebugMode(int debug_mode) override;
|
|
33
|
+
int getDebugMode() const override;
|
|
34
|
+
|
|
35
|
+
private:
|
|
36
|
+
void call_target(const char* method_name, int argc, const VALUE* argv) const;
|
|
37
|
+
|
|
38
|
+
VALUE target_;
|
|
39
|
+
VALUE lines_;
|
|
40
|
+
VALUE contact_points_;
|
|
41
|
+
VALUE warnings_;
|
|
42
|
+
VALUE texts_;
|
|
43
|
+
int debug_mode_;
|
|
44
|
+
};
|
|
45
|
+
} // namespace bullet3
|
|
46
|
+
|
|
47
|
+
void Init_DebugDraw(Rice::Module rb_mBullet);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
// Ruby 3.1 can define memcpy as a macro; include C++ headers before Ruby/Rice.
|
|
4
|
+
#include <algorithm>
|
|
5
|
+
#include <any>
|
|
6
|
+
#include <complex>
|
|
7
|
+
#include <cstdio>
|
|
8
|
+
#include <cstring>
|
|
9
|
+
#include <fstream>
|
|
10
|
+
#include <functional>
|
|
11
|
+
#include <iostream>
|
|
12
|
+
#include <locale>
|
|
13
|
+
#include <map>
|
|
14
|
+
#include <memory>
|
|
15
|
+
#include <optional>
|
|
16
|
+
#include <ostream>
|
|
17
|
+
#include <set>
|
|
18
|
+
#include <sstream>
|
|
19
|
+
#include <stdexcept>
|
|
20
|
+
#include <string>
|
|
21
|
+
#include <string_view>
|
|
22
|
+
#include <tuple>
|
|
23
|
+
#include <type_traits>
|
|
24
|
+
#include <typeindex>
|
|
25
|
+
#include <typeinfo>
|
|
26
|
+
#include <unordered_map>
|
|
27
|
+
#include <utility>
|
|
28
|
+
#include <variant>
|
|
29
|
+
#include <vector>
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <stdexcept>
|
|
4
|
+
|
|
5
|
+
#include <LinearMath/btQuaternion.h>
|
|
6
|
+
#include <LinearMath/btVector3.h>
|
|
7
|
+
#include <rice/rice.hpp>
|
|
8
|
+
|
|
9
|
+
namespace bullet3 {
|
|
10
|
+
template <typename Value_T>
|
|
11
|
+
inline btScalar scalar_from_object(Value_T object)
|
|
12
|
+
{
|
|
13
|
+
return Rice::detail::From_Ruby<btScalar>().convert(object);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
inline bool object_responds_to(Rice::Object object, const char* method_name)
|
|
17
|
+
{
|
|
18
|
+
return rb_respond_to(object.value(), rb_intern(method_name)) != 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
inline Rice::Array array_from_object(Rice::Object object)
|
|
22
|
+
{
|
|
23
|
+
if (rb_obj_is_kind_of(object.value(), rb_cArray)) {
|
|
24
|
+
return Rice::Array(object);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (object_responds_to(object, "to_a")) {
|
|
28
|
+
return Rice::Array(object.call("to_a"));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
throw std::invalid_argument("expected an Array-like object");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
inline btVector3 vector_from_array(Rice::Object object)
|
|
35
|
+
{
|
|
36
|
+
Rice::Array array = array_from_object(object);
|
|
37
|
+
if (array.size() != 3) {
|
|
38
|
+
throw std::invalid_argument("expected a 3-element Array");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return btVector3(
|
|
42
|
+
scalar_from_object(array[0]),
|
|
43
|
+
scalar_from_object(array[1]),
|
|
44
|
+
scalar_from_object(array[2])
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
inline btVector3 coerce_vector(Rice::Object object)
|
|
49
|
+
{
|
|
50
|
+
if (object.is_nil()) {
|
|
51
|
+
throw std::invalid_argument("expected Bullet3::Vector3 or a 3-element Array");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (rb_obj_is_kind_of(object.value(), rb_cArray) || object_responds_to(object, "to_a")) {
|
|
55
|
+
return vector_from_array(object);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return *Rice::detail::From_Ruby<btVector3*>().convert(object);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
inline btQuaternion quaternion_from_array(Rice::Object object)
|
|
62
|
+
{
|
|
63
|
+
Rice::Array array = array_from_object(object);
|
|
64
|
+
if (array.size() != 4) {
|
|
65
|
+
throw std::invalid_argument("expected a 4-element Array");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return btQuaternion(
|
|
69
|
+
scalar_from_object(array[0]),
|
|
70
|
+
scalar_from_object(array[1]),
|
|
71
|
+
scalar_from_object(array[2]),
|
|
72
|
+
scalar_from_object(array[3])
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
inline btQuaternion coerce_quaternion(Rice::Object object)
|
|
77
|
+
{
|
|
78
|
+
if (object.is_nil()) {
|
|
79
|
+
throw std::invalid_argument("expected Bullet3::Quaternion or a 4-element Array");
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (rb_obj_is_kind_of(object.value(), rb_cArray) || object_responds_to(object, "to_a")) {
|
|
83
|
+
return quaternion_from_array(object);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return *Rice::detail::From_Ruby<btQuaternion*>().convert(object);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
inline Rice::Array vector_to_array(const btVector3& vector)
|
|
90
|
+
{
|
|
91
|
+
Rice::Array array;
|
|
92
|
+
array.push(vector.getX());
|
|
93
|
+
array.push(vector.getY());
|
|
94
|
+
array.push(vector.getZ());
|
|
95
|
+
return array;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
inline Rice::Array quaternion_to_array(const btQuaternion& quaternion)
|
|
99
|
+
{
|
|
100
|
+
Rice::Array array;
|
|
101
|
+
array.push(quaternion.getX());
|
|
102
|
+
array.push(quaternion.getY());
|
|
103
|
+
array.push(quaternion.getZ());
|
|
104
|
+
array.push(quaternion.getW());
|
|
105
|
+
return array;
|
|
106
|
+
}
|
|
107
|
+
} // namespace bullet3
|