Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/outerra/bullet3
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrilgramblicka committed Feb 22, 2018
2 parents fc43f87 + 5ea1724 commit b466e34
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/BulletCollision/CollisionShapes/btCollisionShape.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ ATTRIBUTE_ALIGNED16(class) btCollisionShape

BT_DECLARE_ALIGNED_ALLOCATOR();

btCollisionShape() : m_shapeType (INVALID_SHAPE_PROXYTYPE), m_userPointer(0), m_userIndex(-1)
btCollisionShape() : m_shapeType (INVALID_SHAPE_PROXYTYPE), m_userPointer(0), m_userIndex(0)
{
}

Expand Down
24 changes: 18 additions & 6 deletions src/otbullet/discrete_dynamics_world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,10 @@ namespace ot {
uint tri_count = 0;

for (uints j = 0; j < _cow_internal.size(); j++) {

btCollisionObjectWrapper internal_obj_wrapper(_cow_internal[j]._parent,
if (_cow_internal[j]._shape->getUserIndex() & 1) { // do not collide with terrain
continue;
}
btCollisionObjectWrapper internal_obj_wrapper(_cow_internal[j]._parent,
_cow_internal[j]._shape,
obj,
_cow_internal[j]._worldTransform,
Expand Down Expand Up @@ -317,9 +319,13 @@ namespace ot {
//_relocation_offset = _tb_cache.get_array().ptr();

bool is_above_tm = false;
double3 under_terrain_contact;
float3 under_terrain_normal;

int col_result = _aabb_intersect(_context, _from, _basis, _lod_dim, _triangles, _tree_batches, _tb_cache, frame_count, is_above_tm, under_terrain_contact, under_terrain_normal);

if (!_aabb_intersect(_context, _from, _basis, _lod_dim, _triangles, _tree_batches, _tb_cache, frame_count,is_above_tm)) {
DASSERT(_tree_batches.size() == 0);
if (col_result == 0) {
//DASSERT(_tree_batches.size() == 0);
continue;
}
/*
Expand Down Expand Up @@ -357,7 +363,13 @@ namespace ot {
_stats.triangle_processing_time_ms += timer.time_ns() * 0.000001f;
#endif // _PROFILING_ENABLED

}
}
else if (col_result == -1) {
gContactAddedCallback = nullptr;
res.addContactPoint(btVector3(under_terrain_normal.x, under_terrain_normal.y, under_terrain_normal.z),
btVector3(_from.x, _from.y, _from.z),
-glm::length(_from - under_terrain_contact));
}

if (_tree_batches.size() > 0) {
prepare_tree_collision_pairs(obj, _tree_batches, frame_count);
Expand All @@ -369,7 +381,7 @@ namespace ot {

res.refreshContactPoints();

if (manifold->getNumContacts() == 0 || tri_count == 0) {
if (manifold->getNumContacts() == 0 /*|| (tri_count == 0)*/) {
getDispatcher()->releaseManifold(manifold);
_manifolds.get_item(rb->getTerrainManifoldHandle());
_manifolds.del(_manifolds.get_item(rb->getTerrainManifoldHandle()));
Expand Down
6 changes: 4 additions & 2 deletions src/otbullet/discrete_dynamics_world.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class discrete_dynamics_world : public btDiscreteDynamicsWorld
coid::slotalloc<bt::tree_batch>& tree_batches,
uint frame );

typedef bool(*fn_ext_collision_2)(
typedef int(*fn_ext_collision_2)(
const void* context,
const double3& center,
const float3x3& basis,
Expand All @@ -203,7 +203,9 @@ class discrete_dynamics_world : public btDiscreteDynamicsWorld
coid::dynarray<uint>& trees,
coid::slotalloc<bt::tree_batch>& tree_batches,
uint frame,
bool& is_above_tm);
bool& is_above_tm,
double3& under_contact,
float3& under_normal);

typedef float3(*fn_process_tree_collision)(btRigidBody * obj, bt::tree_collision_contex & ctx, float time_step, coid::slotalloc<bt::tree_batch>& tree_batches );

Expand Down
5 changes: 5 additions & 0 deletions src/otbullet/ot_terrain_contact_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ void ot_terrain_contact_common::collide_convex_triangle(const bt::triangle & tri


btCollisionObjectWrapper triObWrap(_manifold->getBody1Wrap(), &tm, _manifold->getBody1Wrap()->getCollisionObject(), _manifold->getBody1Wrap()->getWorldTransform(), 0, triangle.tri_idx);//correct transform?

const btCollisionObjectWrapper * curr_col_obj_wrapper = _manifold->getBody0Wrap();
_manifold->setBody0Wrap(_convex_object);

btCollisionAlgorithm* colAlgo = _collision_world->getDispatcher()->findAlgorithm(_manifold->getBody0Wrap(), &triObWrap, _manifold->getPersistentManifold());

const btCollisionObjectWrapper* tmpWrap = 0;
Expand All @@ -341,6 +345,7 @@ void ot_terrain_contact_common::collide_convex_triangle(const bt::triangle & tri

colAlgo->processCollision(_manifold->getBody0Wrap(), &triObWrap, _collision_world->getDispatchInfo(), _manifold);

_manifold->setBody1Wrap(curr_col_obj_wrapper);
_manifold->setBody1Wrap(tmpWrap);

colAlgo->~btCollisionAlgorithm();
Expand Down
6 changes: 4 additions & 2 deletions src/otbullet/otbullet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class physics : public policy_intrusive_base
coid::slotalloc<bt::tree_batch>& tree_batches,
uint frame );

ifc_event bool terrain_collisions_aabb(
ifc_event int terrain_collisions_aabb(
const void* context,
const double3& center,
float3x3 basis,
Expand All @@ -104,7 +104,9 @@ class physics : public policy_intrusive_base
coid::dynarray<uint>& trees,
coid::slotalloc<bt::tree_batch>& tree_batches,
uint frame,
bool& is_above_tm);
bool& is_above_tm,
double3& under_contact,
float3& under_normal);

ifc_event float3 tree_collisions(btRigidBody * obj,
bt::tree_collision_contex & ctx,
Expand Down
8 changes: 4 additions & 4 deletions src/otbullet/otbullet.intergen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,10 @@ class physics_dispatcher : public physics
on ? (void*)&_generic_interface_creator : nullptr);

interface_register::register_interface_creator(
"bt::physics.create@2719886067",
"bt::physics.create@2650151887",
on ? (void*)&create : nullptr);
interface_register::register_interface_creator(
"bt::physics.get@2719886067",
"bt::physics.get@2650151887",
on ? (void*)&get : nullptr);
}
};
Expand Down Expand Up @@ -240,12 +240,12 @@ bool physics::terrain_collisions( const void* context, const double3& center, fl
return _ifc_host->iface<bt::physics>()->terrain_collisions(context, center, radius, lod_dimension, data, trees, tree_batches, frame);
}

bool physics::terrain_collisions_aabb( const void* context, const double3& center, float3x3 basis, float lod_dimension, coid::dynarray<bt::triangle>& data, coid::dynarray<uint>& trees, coid::slotalloc<bt::tree_batch>& tree_batches, uint frame, bool& is_above_tm )
int physics::terrain_collisions_aabb( const void* context, const double3& center, float3x3 basis, float lod_dimension, coid::dynarray<bt::triangle>& data, coid::dynarray<uint>& trees, coid::slotalloc<bt::tree_batch>& tree_batches, uint frame, bool& is_above_tm, double3& under_contact, float3& under_normal )
{
if (!_ifc_host)
throw coid::exception() << "terrain_collisions_aabb" << " handler not implemented";
else
return _ifc_host->iface<bt::physics>()->terrain_collisions_aabb(context, center, basis, lod_dimension, data, trees, tree_batches, frame, is_above_tm);
return _ifc_host->iface<bt::physics>()->terrain_collisions_aabb(context, center, basis, lod_dimension, data, trees, tree_batches, frame, is_above_tm, under_contact, under_normal);
}

float3 physics::tree_collisions( btRigidBody* obj, bt::tree_collision_contex& ctx, float time_step, coid::slotalloc<bt::tree_batch>& tree_batches )
Expand Down
10 changes: 5 additions & 5 deletions src/otbullet/physics.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class physics

virtual bool terrain_collisions( const void* context, const double3& center, float radius, float lod_dimension, coid::dynarray<bt::triangle>& data, coid::dynarray<uint>& trees, coid::slotalloc<bt::tree_batch>& tree_batches, uint frame ){ throw coid::exception("handler not implemented"); }

virtual bool terrain_collisions_aabb( const void* context, const double3& center, float3x3 basis, float lod_dimension, coid::dynarray<bt::triangle>& data, coid::dynarray<uint>& trees, coid::slotalloc<bt::tree_batch>& tree_batches, uint frame, bool& is_above_tm ){ throw coid::exception("handler not implemented"); }
virtual int terrain_collisions_aabb( const void* context, const double3& center, float3x3 basis, float lod_dimension, coid::dynarray<bt::triangle>& data, coid::dynarray<uint>& trees, coid::slotalloc<bt::tree_batch>& tree_batches, uint frame, bool& is_above_tm, double3& under_contact, float3& under_normal ){ throw coid::exception("handler not implemented"); }

virtual float3 tree_collisions( btRigidBody* obj, bt::tree_collision_contex& ctx, float time_step, coid::slotalloc<bt::tree_batch>& tree_batches ){ throw coid::exception("handler not implemented"); }

Expand Down Expand Up @@ -170,7 +170,7 @@ class physics
if (_cleaner) _cleaner(this,0);
}

static const int HASHID = 2719886067;
static const int HASHID = 2650151887;

int intergen_hash_id() const override final { return HASHID; }

Expand All @@ -184,7 +184,7 @@ class physics
}

static const coid::token& intergen_default_creator_static( EBackend bck ) {
static const coid::token _dc("bt::physics.get@2719886067");
static const coid::token _dc("bt::physics.get@2650151887");
static const coid::token _djs("bt::physics@wrapper.js");
static const coid::token _dlua("bt::physics@wrapper.lua");
static const coid::token _dnone;
Expand Down Expand Up @@ -258,7 +258,7 @@ inline iref<T> physics::create( T* _subclass_, double r, void* context )
typedef iref<T> (*fn_creator)(physics*, double, void*);

static fn_creator create = 0;
static const coid::token ifckey = "bt::physics.create@2719886067";
static const coid::token ifckey = "bt::physics.create@2650151887";

if (!create)
create = reinterpret_cast<fn_creator>(
Expand All @@ -276,7 +276,7 @@ inline iref<T> physics::get( T* _subclass_ )
typedef iref<T> (*fn_creator)(physics*);

static fn_creator create = 0;
static const coid::token ifckey = "bt::physics.get@2719886067";
static const coid::token ifckey = "bt::physics.get@2650151887";

if (!create)
create = reinterpret_cast<fn_creator>(
Expand Down
14 changes: 9 additions & 5 deletions src/otbullet/wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ extern bool _ext_collider(const void* context,
coid::slotalloc<bt::tree_batch>& tree_batches,
uint frame );

extern bool _ext_collider_obb(
extern int _ext_collider_obb(
const void * context,
const double3& center,
const float3x3& basis,
Expand All @@ -49,7 +49,9 @@ extern bool _ext_collider_obb(
coid::dynarray<uint>& trees,
coid::slotalloc<bt::tree_batch>& tree_batches,
uint frame,
bool& is_above_tm);
bool& is_above_tm,
double3& under_contact,
float3& under_normal);

extern float _ext_terrain_ray_intersect(
const void* planet,
Expand Down Expand Up @@ -86,7 +88,7 @@ static bool _ext_collider(
return _physics->terrain_collisions(planet, center, radius, lod_dimension, data, trees, tree_batches, frame);
}

static bool _ext_collider_obb(
static int _ext_collider_obb(
const void * planet,
const double3& center,
const float3x3& basis,
Expand All @@ -95,9 +97,11 @@ static bool _ext_collider_obb(
coid::dynarray<uint>& trees,
coid::slotalloc<bt::tree_batch>& tree_batches,
uint frame,
bool& is_above_tm)
bool& is_above_tm,
double3& under_contact,
float3& under_normal)
{
return _physics->terrain_collisions_aabb(planet, center, basis, lod_dimension, data, trees, tree_batches, frame,is_above_tm);
return _physics->terrain_collisions_aabb(planet, center, basis, lod_dimension, data, trees, tree_batches, frame,is_above_tm, under_contact, under_normal);
}

static float _ext_terrain_ray_intersect(
Expand Down

0 comments on commit b466e34

Please sign in to comment.