Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergej Reich <sergej.reich@googlemail.com>2013-04-21 23:53:40 +0400
committerSergej Reich <sergej.reich@googlemail.com>2013-04-21 23:53:40 +0400
commited191088913b6e36ad0749b7f487906ad7b80198 (patch)
tree94e1872b2da3b236795afe0b9c4b4856d3b96fcc /intern/rigidbody
parentedab8151374cbdbd877c2727170163a1ab33e8d8 (diff)
rigidbody: Add function to perform convex sweep test
This is a experimental collision detection function, so the API might change in the future. Note: The simulation needs to be stepped before this function can be used, otherwise the rigid body world might not be valid. Patch [#34989] Bullet Convex sweep test API by Vilem Novak (pildanovak), thanks!
Diffstat (limited to 'intern/rigidbody')
-rw-r--r--intern/rigidbody/RBI_api.h6
-rw-r--r--intern/rigidbody/rb_bullet_api.cpp50
2 files changed, 56 insertions, 0 deletions
diff --git a/intern/rigidbody/RBI_api.h b/intern/rigidbody/RBI_api.h
index e7c88d96873..7a04961f99d 100644
--- a/intern/rigidbody/RBI_api.h
+++ b/intern/rigidbody/RBI_api.h
@@ -110,6 +110,12 @@ extern void RB_dworld_add_body(rbDynamicsWorld *world, rbRigidBody *body, int co
/* Remove RigidBody from dynamics world */
extern void RB_dworld_remove_body(rbDynamicsWorld *world, rbRigidBody *body);
+/* Collision detection */
+
+void RB_world_convex_sweep_test(rbDynamicsWorld *world, rbRigidBody *object,
+ const float loc_start[3], const float loc_end[3],
+ float v_location[3], float v_hitpoint[3], float v_normal[3], int *r_hit);
+
/* ............ */
/* Create new RigidBody instance */
diff --git a/intern/rigidbody/rb_bullet_api.cpp b/intern/rigidbody/rb_bullet_api.cpp
index e9e5e2a5e32..7bc480b1583 100644
--- a/intern/rigidbody/rb_bullet_api.cpp
+++ b/intern/rigidbody/rb_bullet_api.cpp
@@ -242,6 +242,56 @@ void RB_dworld_remove_body(rbDynamicsWorld *world, rbRigidBody *object)
world->dynamicsWorld->removeRigidBody(body);
}
+/* Collision detection */
+
+void RB_world_convex_sweep_test(rbDynamicsWorld *world, rbRigidBody *object, const float loc_start[3], const float loc_end[3], float v_location[3], float v_hitpoint[3], float v_normal[3], int *r_hit)
+{
+ btRigidBody *body = object->body;
+ btCollisionShape *collisionShape = body->getCollisionShape();
+ /* only convex shapes are supported, but user can specify a non convex shape */
+ if (collisionShape->isConvex()) {
+ btCollisionWorld::ClosestConvexResultCallback result(btVector3(loc_start[0], loc_start[1], loc_start[2]), btVector3(loc_end[0], loc_end[1], loc_end[2]));
+
+ btQuaternion obRot = body->getWorldTransform().getRotation();
+
+ btTransform rayFromTrans;
+ rayFromTrans.setIdentity();
+ rayFromTrans.setRotation(obRot);
+ rayFromTrans.setOrigin(btVector3(loc_start[0], loc_start[1], loc_start[2]));
+
+ btTransform rayToTrans;
+ rayToTrans.setIdentity();
+ rayToTrans.setRotation(obRot);
+ rayToTrans.setOrigin(btVector3(loc_end[0], loc_end[1], loc_end[2]));
+
+ world->dynamicsWorld->convexSweepTest((btConvexShape*) collisionShape, rayFromTrans, rayToTrans, result, 0);
+
+ if (result.hasHit()) {
+ *r_hit = 1;
+
+ v_location[0] = result.m_convexFromWorld[0]+(result.m_convexToWorld[0]-result.m_convexFromWorld[0])*result.m_closestHitFraction;
+ v_location[1] = result.m_convexFromWorld[1]+(result.m_convexToWorld[1]-result.m_convexFromWorld[1])*result.m_closestHitFraction;
+ v_location[2] = result.m_convexFromWorld[2]+(result.m_convexToWorld[2]-result.m_convexFromWorld[2])*result.m_closestHitFraction;
+
+ v_hitpoint[0] = result.m_hitPointWorld[0];
+ v_hitpoint[1] = result.m_hitPointWorld[1];
+ v_hitpoint[2] = result.m_hitPointWorld[2];
+
+ v_normal[0] = result.m_hitNormalWorld[0];
+ v_normal[1] = result.m_hitNormalWorld[1];
+ v_normal[2] = result.m_hitNormalWorld[2];
+
+ }
+ else {
+ *r_hit = 0;
+ }
+ }
+ else{
+ /* we need to return a value if user passes non convex body, to report */
+ *r_hit = -2;
+ }
+}
+
/* ............ */
rbRigidBody *RB_body_new(rbCollisionShape *shape, const float loc[3], const float rot[4])