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,157 @@
|
|
|
1
|
+
#include "rb_transform.hpp"
|
|
2
|
+
|
|
3
|
+
#include <stdexcept>
|
|
4
|
+
|
|
5
|
+
#include <LinearMath/btMatrix3x3.h>
|
|
6
|
+
#include <LinearMath/btQuaternion.h>
|
|
7
|
+
#include <LinearMath/btVector3.h>
|
|
8
|
+
#include <rice/rice.hpp>
|
|
9
|
+
|
|
10
|
+
#include "../util/type_conversions.hpp"
|
|
11
|
+
|
|
12
|
+
namespace bullet3 {
|
|
13
|
+
Transform::Transform()
|
|
14
|
+
{
|
|
15
|
+
transform_.setIdentity();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
Transform::Transform(VALUE rotation, VALUE origin)
|
|
19
|
+
{
|
|
20
|
+
transform_.setIdentity();
|
|
21
|
+
transform_.setRotation(coerce_quaternion(Rice::Object(rotation)));
|
|
22
|
+
transform_.setOrigin(coerce_vector(Rice::Object(origin)));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
Transform::Transform(const btTransform& transform)
|
|
26
|
+
: transform_(transform)
|
|
27
|
+
{
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const btTransform& Transform::value() const
|
|
31
|
+
{
|
|
32
|
+
return transform_;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
btTransform& Transform::value()
|
|
36
|
+
{
|
|
37
|
+
return transform_;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
btVector3 Transform::origin() const
|
|
41
|
+
{
|
|
42
|
+
return transform_.getOrigin();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
btVector3 Transform::set_origin(Rice::Object origin)
|
|
46
|
+
{
|
|
47
|
+
btVector3 vector = coerce_vector(origin);
|
|
48
|
+
transform_.setOrigin(vector);
|
|
49
|
+
return vector;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
btQuaternion Transform::rotation() const
|
|
53
|
+
{
|
|
54
|
+
return transform_.getRotation();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
btQuaternion Transform::set_rotation(Rice::Object rotation)
|
|
58
|
+
{
|
|
59
|
+
btQuaternion quaternion = coerce_quaternion(rotation);
|
|
60
|
+
transform_.setRotation(quaternion);
|
|
61
|
+
return quaternion;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
btMatrix3x3 Transform::basis() const
|
|
65
|
+
{
|
|
66
|
+
return transform_.getBasis();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
Rice::Object Transform::multiply(Rice::Object other) const
|
|
70
|
+
{
|
|
71
|
+
if (Rice::Data_Type<Transform>::is_bound() &&
|
|
72
|
+
rb_obj_is_kind_of(other.value(), Rice::Data_Type<Transform>::klass())) {
|
|
73
|
+
Transform* transform = Rice::detail::From_Ruby<Transform*>().convert(other);
|
|
74
|
+
return wrap_transform(transform_ * transform->value());
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
btVector3 vector = coerce_vector(other);
|
|
78
|
+
return Rice::Object(Rice::detail::To_Ruby<btVector3>().convert(transform_ * vector));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
Transform Transform::inverse() const
|
|
82
|
+
{
|
|
83
|
+
return Transform(transform_.inverse());
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
Transform Transform::inverse_times(Rice::Object other) const
|
|
87
|
+
{
|
|
88
|
+
return Transform(transform_.inverseTimes(coerce_transform(other)));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
Rice::Array Transform::to_array() const
|
|
92
|
+
{
|
|
93
|
+
Rice::Array array;
|
|
94
|
+
array.push(vector_to_array(transform_.getOrigin()));
|
|
95
|
+
array.push(quaternion_to_array(transform_.getRotation()));
|
|
96
|
+
return array;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
btTransform coerce_transform(Rice::Object object)
|
|
100
|
+
{
|
|
101
|
+
if (object.is_nil()) {
|
|
102
|
+
throw std::invalid_argument("expected Bullet3::Transform");
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (Rice::Data_Type<Transform>::is_bound() &&
|
|
106
|
+
rb_obj_is_kind_of(object.value(), Rice::Data_Type<Transform>::klass())) {
|
|
107
|
+
return Rice::detail::From_Ruby<Transform*>().convert(object)->value();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (object_responds_to(object, "origin") && object_responds_to(object, "rotation")) {
|
|
111
|
+
btTransform transform;
|
|
112
|
+
transform.setIdentity();
|
|
113
|
+
transform.setOrigin(coerce_vector(object.call("origin")));
|
|
114
|
+
transform.setRotation(coerce_quaternion(object.call("rotation")));
|
|
115
|
+
return transform;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (rb_obj_is_kind_of(object.value(), rb_cArray)) {
|
|
119
|
+
Rice::Array array(object);
|
|
120
|
+
if (array.size() != 2) {
|
|
121
|
+
throw std::invalid_argument("expected [origin, rotation] transform array");
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
btTransform transform;
|
|
125
|
+
transform.setIdentity();
|
|
126
|
+
transform.setOrigin(coerce_vector(Rice::Object(array[0].value())));
|
|
127
|
+
transform.setRotation(coerce_quaternion(Rice::Object(array[1].value())));
|
|
128
|
+
return transform;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
throw std::invalid_argument("expected Bullet3::Transform");
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
Rice::Object wrap_transform(const btTransform& transform)
|
|
135
|
+
{
|
|
136
|
+
return Rice::Object(Rice::detail::To_Ruby<Transform>().convert(Transform(transform)));
|
|
137
|
+
}
|
|
138
|
+
} // namespace bullet3
|
|
139
|
+
|
|
140
|
+
void Init_Transform(Rice::Module rb_mBullet)
|
|
141
|
+
{
|
|
142
|
+
Rice::define_class_under<bullet3::Transform>(rb_mBullet, "Transform")
|
|
143
|
+
.define_constructor(Rice::Constructor<bullet3::Transform>())
|
|
144
|
+
.define_constructor(Rice::Constructor<bullet3::Transform, VALUE, VALUE>(),
|
|
145
|
+
Rice::Arg("rotation").setValue(),
|
|
146
|
+
Rice::Arg("origin").setValue())
|
|
147
|
+
.define_singleton_method("identity", [](Rice::Object) { return bullet3::Transform(); })
|
|
148
|
+
.define_method("origin", &bullet3::Transform::origin)
|
|
149
|
+
.define_method("origin=", &bullet3::Transform::set_origin)
|
|
150
|
+
.define_method("rotation", &bullet3::Transform::rotation)
|
|
151
|
+
.define_method("rotation=", &bullet3::Transform::set_rotation)
|
|
152
|
+
.define_method("basis", &bullet3::Transform::basis)
|
|
153
|
+
.define_method("*", &bullet3::Transform::multiply)
|
|
154
|
+
.define_method("inverse", &bullet3::Transform::inverse)
|
|
155
|
+
.define_method("inverse_times", &bullet3::Transform::inverse_times)
|
|
156
|
+
.define_method("to_a", &bullet3::Transform::to_array);
|
|
157
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <LinearMath/btTransform.h>
|
|
4
|
+
#include <rice/rice.hpp>
|
|
5
|
+
|
|
6
|
+
namespace bullet3 {
|
|
7
|
+
class Transform {
|
|
8
|
+
public:
|
|
9
|
+
Transform();
|
|
10
|
+
Transform(VALUE rotation, VALUE origin);
|
|
11
|
+
explicit Transform(const btTransform& transform);
|
|
12
|
+
|
|
13
|
+
const btTransform& value() const;
|
|
14
|
+
btTransform& value();
|
|
15
|
+
|
|
16
|
+
btVector3 origin() const;
|
|
17
|
+
btVector3 set_origin(Rice::Object origin);
|
|
18
|
+
btQuaternion rotation() const;
|
|
19
|
+
btQuaternion set_rotation(Rice::Object rotation);
|
|
20
|
+
btMatrix3x3 basis() const;
|
|
21
|
+
Rice::Object multiply(Rice::Object other) const;
|
|
22
|
+
Transform inverse() const;
|
|
23
|
+
Transform inverse_times(Rice::Object other) const;
|
|
24
|
+
Rice::Array to_array() const;
|
|
25
|
+
|
|
26
|
+
private:
|
|
27
|
+
btTransform transform_;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
btTransform coerce_transform(Rice::Object object);
|
|
31
|
+
Rice::Object wrap_transform(const btTransform& transform);
|
|
32
|
+
} // namespace bullet3
|
|
33
|
+
|
|
34
|
+
void Init_Transform(Rice::Module rb_mBullet);
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
#include "rb_vector3.hpp"
|
|
2
|
+
|
|
3
|
+
#include <cmath>
|
|
4
|
+
#include <sstream>
|
|
5
|
+
#include <stdexcept>
|
|
6
|
+
|
|
7
|
+
#include <LinearMath/btVector3.h>
|
|
8
|
+
#include <rice/rice.hpp>
|
|
9
|
+
#include <rice/stl.hpp>
|
|
10
|
+
|
|
11
|
+
namespace {
|
|
12
|
+
constexpr btScalar kEpsilon = btScalar(1e-6);
|
|
13
|
+
|
|
14
|
+
btVector3 vector_from_array(Rice::Object object)
|
|
15
|
+
{
|
|
16
|
+
Rice::Array array(object);
|
|
17
|
+
if (array.size() != 3) {
|
|
18
|
+
throw std::invalid_argument("expected a 3-element Array");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return btVector3(
|
|
22
|
+
Rice::detail::From_Ruby<btScalar>().convert(array[0]),
|
|
23
|
+
Rice::detail::From_Ruby<btScalar>().convert(array[1]),
|
|
24
|
+
Rice::detail::From_Ruby<btScalar>().convert(array[2])
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
btVector3 coerce_vector(Rice::Object object)
|
|
29
|
+
{
|
|
30
|
+
if (rb_obj_is_kind_of(object.value(), rb_cArray)) {
|
|
31
|
+
return vector_from_array(object);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return *Rice::detail::From_Ruby<btVector3*>().convert(object);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
btScalar component_at(const btVector3& vector, int index)
|
|
38
|
+
{
|
|
39
|
+
if (index < 0 || index > 2) {
|
|
40
|
+
throw std::out_of_range("index outside vector");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return vector[index];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
void set_component_at(btVector3& vector, int index, btScalar value)
|
|
47
|
+
{
|
|
48
|
+
if (index < 0 || index > 2) {
|
|
49
|
+
throw std::out_of_range("index outside vector");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
vector[index] = value;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
Rice::Array to_array(const btVector3& vector)
|
|
56
|
+
{
|
|
57
|
+
Rice::Array array;
|
|
58
|
+
array.push(vector.getX());
|
|
59
|
+
array.push(vector.getY());
|
|
60
|
+
array.push(vector.getZ());
|
|
61
|
+
return array;
|
|
62
|
+
}
|
|
63
|
+
} // namespace
|
|
64
|
+
|
|
65
|
+
void Init_Vector3(Rice::Module rb_mBullet)
|
|
66
|
+
{
|
|
67
|
+
Rice::define_class_under<btVector3>(rb_mBullet, "Vector3")
|
|
68
|
+
.define_constructor(Rice::Constructor<btVector3, btScalar, btScalar, btScalar>(),
|
|
69
|
+
Rice::Arg("x") = 0.0,
|
|
70
|
+
Rice::Arg("y") = 0.0,
|
|
71
|
+
Rice::Arg("z") = 0.0)
|
|
72
|
+
.define_singleton_method("zero", [](Rice::Object) { return btVector3(0, 0, 0); })
|
|
73
|
+
.define_method("x", &btVector3::getX)
|
|
74
|
+
.define_method("y", &btVector3::getY)
|
|
75
|
+
.define_method("z", &btVector3::getZ)
|
|
76
|
+
.define_method("x=", &btVector3::setX)
|
|
77
|
+
.define_method("y=", &btVector3::setY)
|
|
78
|
+
.define_method("z=", &btVector3::setZ)
|
|
79
|
+
.define_method("[]", &component_at)
|
|
80
|
+
.define_method("[]=", &set_component_at)
|
|
81
|
+
.define_method("+", [](const btVector3& self, Rice::Object other) { return self + coerce_vector(other); })
|
|
82
|
+
.define_method("-", [](const btVector3& self, Rice::Object other) { return self - coerce_vector(other); })
|
|
83
|
+
.define_method("-@", [](const btVector3& self) { return -self; })
|
|
84
|
+
.define_method("*", [](const btVector3& self, btScalar scalar) { return self * scalar; })
|
|
85
|
+
.define_method("/", [](const btVector3& self, btScalar scalar) {
|
|
86
|
+
if (scalar == btScalar(0)) {
|
|
87
|
+
throw std::domain_error("divided by 0");
|
|
88
|
+
}
|
|
89
|
+
return self / scalar;
|
|
90
|
+
})
|
|
91
|
+
.define_method("==", [](const btVector3& self, Rice::Object other) {
|
|
92
|
+
return (self - coerce_vector(other)).length2() <= kEpsilon * kEpsilon;
|
|
93
|
+
})
|
|
94
|
+
.define_method("length", &btVector3::length)
|
|
95
|
+
.define_method("length2", &btVector3::length2)
|
|
96
|
+
.define_method("normalize", [](btVector3& self) -> btVector3& {
|
|
97
|
+
self.normalize();
|
|
98
|
+
return self;
|
|
99
|
+
})
|
|
100
|
+
.define_method("normalize!", [](btVector3& self) -> btVector3& {
|
|
101
|
+
self.normalize();
|
|
102
|
+
return self;
|
|
103
|
+
})
|
|
104
|
+
.define_method("normalized", &btVector3::normalized)
|
|
105
|
+
.define_method("dot", [](const btVector3& self, Rice::Object other) { return self.dot(coerce_vector(other)); })
|
|
106
|
+
.define_method("cross", [](const btVector3& self, Rice::Object other) { return self.cross(coerce_vector(other)); })
|
|
107
|
+
.define_method("distance", [](const btVector3& self, Rice::Object other) { return self.distance(coerce_vector(other)); })
|
|
108
|
+
.define_method("distance2", [](const btVector3& self, Rice::Object other) { return self.distance2(coerce_vector(other)); })
|
|
109
|
+
.define_method("lerp", [](const btVector3& self, Rice::Object other, btScalar t) { return self.lerp(coerce_vector(other), t); })
|
|
110
|
+
.define_method("angle", [](const btVector3& self, Rice::Object other) { return self.angle(coerce_vector(other)); })
|
|
111
|
+
.define_method("absolute", &btVector3::absolute)
|
|
112
|
+
.define_method("to_a", &to_array)
|
|
113
|
+
.define_method("to_s", [](const btVector3& self) {
|
|
114
|
+
std::ostringstream stream;
|
|
115
|
+
stream << "(" << self.getX() << ", " << self.getY() << ", " << self.getZ() << ")";
|
|
116
|
+
return stream.str();
|
|
117
|
+
})
|
|
118
|
+
.define_method("inspect", [](const btVector3& self) {
|
|
119
|
+
std::ostringstream stream;
|
|
120
|
+
stream << "#<Bullet3::Vector3 (" << self.getX() << ", " << self.getY() << ", " << self.getZ() << ")>";
|
|
121
|
+
return stream.str();
|
|
122
|
+
});
|
|
123
|
+
}
|