diff --git a/TODO.md b/TODO.md
index 1c1bd97..a8c4c59 100644
--- a/TODO.md
+++ b/TODO.md
@@ -10,6 +10,14 @@ C++ has many major interesting non standard libs.
Google unit test framework:
+### Vision
+
+OpenCV.
+
+Originally by Intel:
+
+BSD.
+
### Linear algebra
#### eigen
diff --git a/bullet/README.md b/bullet/README.md
index 02e2558..4d8e82d 100644
--- a/bullet/README.md
+++ b/bullet/README.md
@@ -2,10 +2,12 @@
Tested on Bullet 2.83.
-1. [Introduction](introduction.md)
-1. [Concepts](concepts.md)
-1. [Build](build.md)
-1. [Users](users.md)
+1. Theory
+ 1. [Introduction](introduction.md)
+ 1. [Concepts](concepts.md)
+ 1. [Build](build.md)
+ 1. [Source code](source-code.md)
+ 1. [Users](users.md)
1. Examples
1. [Gravity](gravity.cpp)
1. [Ground ball](ground ball.cpp)
diff --git a/bullet/TODO.md b/bullet/TODO.md
index ec0efb4..c63f3dd 100644
--- a/bullet/TODO.md
+++ b/bullet/TODO.md
@@ -1,4 +1,13 @@
# TODO
+- detect when objects collide
+ - http://www.bulletphysics.org/mediawiki-1.5.8/index.php?title=Collision_Callbacks_and_Triggers
+ - http://stackoverflow.com/questions/9117932/detecting-collisions-with-bullet
+ - http://gamedev.stackexchange.com/questions/22442/how-get-collision-callback-of-two-specific-objects-using-bullet-physics
+ - http://www.bulletphysics.org/mediawiki-1.5.8/index.php?title=Collision_Callbacks_and_Triggers
+- get object rotation: 3 Euler angles. Attempt made at `gravity.cpp`
- Stairs physics: http://gamedev.stackexchange.com/questions/74794/make-the-player-run-onto-stairs-smoothly
- Voronoi: https://www.youtube.com/watch?v=FIPu9_OGFgc
+- what is the point of motion state?
+- substeps vs smaller time step on stepSimulation?
+- collision primitives: http://www.bulletphysics.org/mediawiki-1.5.8/index.php?title=Collision_Shapes
diff --git a/bullet/gravity.cpp b/bullet/gravity.cpp
index 822e59b..b2f39d6 100644
--- a/bullet/gravity.cpp
+++ b/bullet/gravity.cpp
@@ -9,6 +9,8 @@ A sphere falling infinitely to gravity.
#include
+#define PRINTF_FLOAT "%7.3f"
+
constexpr float gravity = -10.0f;
constexpr float initialY = 10.0f;
constexpr float timeStep = 1.0f / 60.0f;
@@ -58,12 +60,15 @@ int main() {
} else {
trans = obj->getWorldTransform();
}
- std::printf("%d %d %7.3f %7.3f %7.3f\n",
+ btVector3 origin = trans.getOrigin();
+ // TODO: how to get numbers out of this?
+ btQuaternion rotation = trans.getRotation();
+ std::printf("%d %d " PRINTF_FLOAT " " PRINTF_FLOAT " " PRINTF_FLOAT "\n",
i,
j,
- float(trans.getOrigin().getX()),
- float(trans.getOrigin().getY()),
- float(trans.getOrigin().getZ()));
+ float(origin.getX()),
+ float(origin.getY()),
+ float(origin.getZ()));
}
}
diff --git a/bullet/ground_ball.cpp b/bullet/ground_ball.cpp
index fe4aa50..8c3f30c 100644
--- a/bullet/ground_ball.cpp
+++ b/bullet/ground_ball.cpp
@@ -7,6 +7,8 @@ A sphere falling and hitting the ground.
#include
+#define PRINTF_FLOAT "%7.3f"
+
constexpr float gravity = -10.0f;
constexpr float initialY = 10.0f;
constexpr float timeStep = 1.0f / 60.0f;
@@ -16,17 +18,49 @@ constexpr float groundRestitution = 0.9f;
constexpr float sphereRestitution = 0.9f;
constexpr int maxNPoints = 500;
+static void myTickCallback(btDynamicsWorld *world, btScalar timeStep) {
+ bool hadCollision = false;
+ for (int i = 0; i < numManifolds; i++) {
+ btPersistentManifold* contactManifold = dynamicsWorld->getDispatcher()->getManifoldByIndexInternal(i);
+ const btCollisionObject* obA = static_cast(contactManifold->getBody0());
+ const btCollisionObject* obB = static_cast(contactManifold->getBody1());
+ int numContacts = contactManifold->getNumContacts();
+ for (int j = 0; j < numContacts; j++) {
+ if (!hadCollision)
+ std::printf("1 ");
+ hadCollision = true;
+ btManifoldPoint& pt = contactManifold->getContactPoint(j);
+ if (pt.getDistance() < 0.0f) {
+ const btVector3& ptA = pt.getPositionWorldOnA();
+ const btVector3& ptB = pt.getPositionWorldOnB();
+ const btVector3& normalOnB = pt.m_normalWorldOnB;
+ std::printf(
+ PRINTF_FLOAT " " PRINTF_FLOAT " " PRINTF_FLOAT " "
+ PRINTF_FLOAT " " PRINTF_FLOAT " " PRINTF_FLOAT " "
+ PRINTF_FLOAT " " PRINTF_FLOAT " " PRINTF_FLOAT " ",
+ ptA.getX(), ptA.getY(), ptA.getZ(),
+ ptB.getX(), ptB.getY(), ptB.getZ(),
+ normalOnB.getX(), normalOnB.getY(), normalOnB.getZ());
+ }
+ }
+ }
+ if (!hadCollision)
+ std::printf("0 ");
+ puts("");
+}
+
int main() {
int i, j;
- btDefaultCollisionConfiguration* collisionConfiguration
+ btDefaultCollisionConfiguration *collisionConfiguration
= new btDefaultCollisionConfiguration();
- btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
- btBroadphaseInterface* overlappingPairCache = new btDbvtBroadphase();
+ btCollisionDispatcher *dispatcher = new btCollisionDispatcher(collisionConfiguration);
+ btBroadphaseInterface *overlappingPairCache = new btDbvtBroadphase();
btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;
- btDiscreteDynamicsWorld* dynamicsWorld = new btDiscreteDynamicsWorld(
+ btDiscreteDynamicsWorld *dynamicsWorld = new btDiscreteDynamicsWorld(
dispatcher, overlappingPairCache, solver, collisionConfiguration);
dynamicsWorld->setGravity(btVector3(0, gravity, 0));
+ dynamicsWorld->setInternalTickCallback(myTickCallback);
btAlignedObjectArray collisionShapes;
// Ground.
@@ -77,7 +111,7 @@ int main() {
}
// Main loop.
- std::printf("step body x y z\n");
+ std::printf("step body x y z collision a b normal\n");
for (i = 0; i < maxNPoints; ++i) {
dynamicsWorld->stepSimulation(timeStep, 10);
for (j = dynamicsWorld->getNumCollisionObjects() - 1; j >= 0; --j) {
@@ -89,12 +123,14 @@ int main() {
} else {
trans = obj->getWorldTransform();
}
- std::printf("%d %d %7.3f %7.3f %7.3f\n",
+ btVector3 origin = trans.getOrigin();
+ std::printf("%d %d " PRINTF_FLOAT " " PRINTF_FLOAT " " PRINTF_FLOAT " ",
i,
j,
- float(trans.getOrigin().getX()),
- float(trans.getOrigin().getY()),
- float(trans.getOrigin().getZ()));
+ float(origin.getX()),
+ float(origin.getY()),
+ float(origin.getZ()));
+ int numManifolds = dynamicsWorld->getDispatcher()->getNumManifolds();
}
}
diff --git a/bullet/ground_ball.gnuplot b/bullet/ground_ball.gnuplot
index 189ef35..d121711 100644
--- a/bullet/ground_ball.gnuplot
+++ b/bullet/ground_ball.gnuplot
@@ -1,3 +1,4 @@
#!/usr/bin/env gnuplot
set key autotitle columnheader
-plot 'ground_ball.tmp' using 1:($2 == 1 ? $4 : 1/0)
+plot 'ground_ball.tmp' using 1:($2 == 1 ? $4 : 1/0), \
+ '' using 1:($2 == 1 ? $6 : 1/0)
diff --git a/bullet/introduction.md b/bullet/introduction.md
index 04c3faf..ac13060 100644
--- a/bullet/introduction.md
+++ b/bullet/introduction.md
@@ -1,5 +1,11 @@
# Introduction
+## Documentation
+
+Very little besides the Doxygen:
+
+Good luck.
+
## C API
Bullet is written in C++, and exposes only a C++ API.
diff --git a/bullet/source-code.md b/bullet/source-code.md
new file mode 100644
index 0000000..5df75e6
--- /dev/null
+++ b/bullet/source-code.md
@@ -0,0 +1,8 @@
+# Source code
+
+## Style
+
+Bullet is ugly :-)
+
+- bt hard-coded prefix instead of C++ namespace
+- tabs, including in the middle of lines