This commit is contained in:
enn0x 2012-01-16 23:00:04 +00:00
parent ec18c967dd
commit 2e3667e7d4
5 changed files with 72 additions and 20 deletions

View File

@ -28,6 +28,32 @@ INLINE BulletBodyNode::
}
}
////////////////////////////////////////////////////////////////////
// Function: BulletBodyNode::set_into_collide_mask
// Access: Published
// Description:
////////////////////////////////////////////////////////////////////
INLINE void BulletBodyNode::
set_into_collide_mask(CollideMask mask) {
PandaNode::set_into_collide_mask(mask);
/*
TODO: we would need a handle to the BulletWorld first
possible, but has to be set/cleared upon attach/remove to world
if (!_world) return;
btBroadphaseProxy* proxy = get_object()->getBroadphaseHandle();
if (proxy) {
btBroadphaseInterface *broadphase = _world->get_broadphase();
btDispatcher *dispatcher = _world->get_dispatcher();
broadphase->getOverlappingPairCache()->cleanProxyFromPairs(proxy, dispatcher);
}
*/
}
////////////////////////////////////////////////////////////////////
// Function: BulletBodyNode::notify_collisions
// Access: Published

View File

@ -58,6 +58,8 @@ PUBLISHED:
INLINE void set_kinematic(bool value);
// Contacts
INLINE void set_into_collide_mask(CollideMask mask);
INLINE void notify_collisions(bool value);
INLINE bool notifies_collisions() const;

View File

@ -52,9 +52,9 @@ BulletCharacterControllerNode(BulletShape *shape, PN_stdfloat step_height, const
_up = get_default_up_axis();
// Initialise movement
_linear_velocity_is_local = false;
_linear_velocity.set(0.0f, 0.0f, 0.0f);
_angular_velocity = 0.0f;
_linear_movement_is_local = false;
_linear_movement.set(0.0f, 0.0f, 0.0f);
_angular_movement = 0.0f;
// Character controller
_character = new btKinematicCharacterController(_ghost, convex, step_height, _up);
@ -172,28 +172,28 @@ safe_to_transform() const {
}
////////////////////////////////////////////////////////////////////
// Function: BulletCharacterControllerNode::set_linear_velocity
// Function: BulletCharacterControllerNode::set_linear_movement
// Access: Published
// Description:
////////////////////////////////////////////////////////////////////
void BulletCharacterControllerNode::
set_linear_velocity(const LVector3 &velocity, bool is_local) {
set_linear_movement(const LVector3 &movement, bool is_local) {
nassertv(!velocity.is_nan());
nassertv(!movement.is_nan());
_linear_velocity = velocity;
_linear_velocity_is_local = is_local;
_linear_movement = movement;
_linear_movement_is_local = is_local;
}
////////////////////////////////////////////////////////////////////
// Function: BulletCharacterControllerNode::set_angular_velocity
// Function: BulletCharacterControllerNode::set_angular_movement
// Access: Published
// Description:
////////////////////////////////////////////////////////////////////
void BulletCharacterControllerNode::
set_angular_velocity(PN_stdfloat omega) {
set_angular_movement(PN_stdfloat omega) {
_angular_velocity = omega;
_angular_movement = omega;
}
////////////////////////////////////////////////////////////////////
@ -208,7 +208,7 @@ sync_p2b(PN_stdfloat dt, int num_substeps) {
transform_changed();
// Angular rotation
btScalar angle = dt * deg_2_rad(_angular_velocity);
btScalar angle = dt * deg_2_rad(_angular_movement);
btMatrix3x3 m = _ghost->getWorldTransform().getBasis();
btVector3 up = m[_up];
@ -218,10 +218,10 @@ sync_p2b(PN_stdfloat dt, int num_substeps) {
_ghost->getWorldTransform().setBasis(m);
// Linear movement
LVector3 vp = _linear_velocity / (btScalar)num_substeps;
LVector3 vp = _linear_movement / (btScalar)num_substeps;
btVector3 v;
if (_linear_velocity_is_local) {
if (_linear_movement_is_local) {
btTransform xform = _ghost->getWorldTransform();
xform.setOrigin(btVector3(0.0f, 0.0f, 0.0f));
v = xform(LVecBase3_to_btVector3(vp));
@ -232,7 +232,7 @@ sync_p2b(PN_stdfloat dt, int num_substeps) {
//_character->setVelocityForTimeInterval(v, dt);
_character->setWalkDirection(v * dt);
_angular_velocity = 0.0f;
_angular_movement = 0.0f;
}
////////////////////////////////////////////////////////////////////

View File

@ -37,8 +37,8 @@ PUBLISHED:
BulletCharacterControllerNode(BulletShape *shape, PN_stdfloat step_height, const char *name="character");
INLINE ~BulletCharacterControllerNode();
void set_linear_velocity(const LVector3 &velocity, bool is_local);
void set_angular_velocity(PN_stdfloat omega);
void set_linear_movement(const LVector3 &velocity, bool is_local);
void set_angular_movement(PN_stdfloat omega);
BulletShape *get_shape() const;
@ -86,9 +86,9 @@ private:
PT(BulletShape) _shape;
LVector3 _linear_velocity;
bool _linear_velocity_is_local;
PN_stdfloat _angular_velocity;
LVector3 _linear_movement;
bool _linear_movement_is_local;
PN_stdfloat _angular_movement;
////////////////////////////////////////////////////////////////////
public:

View File

@ -725,6 +725,25 @@ get_collision_object(PandaNode *node) {
return NULL;
}
/*
////////////////////////////////////////////////////////////////////
// Function: BulletWorld::clean_manifolds_for_node
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
void BulletWorld::
clean_manifolds_for_node(PandaNode *node) {
btCollisionObject *object = get_collision_object(node);
if (object) {
btBroadphaseProxy* proxy = object->getBroadphaseHandle();
if (proxy) {
_world->getPairCache()->cleanProxyFromPairs(proxy, _dispatcher);
}
}
}
*/
////////////////////////////////////////////////////////////////////
// Function: BulletWorld::get_collision_object
// Access: Public
@ -775,6 +794,11 @@ needBroadphaseCollision(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1) co
CollideMask mask0 = node0->get_into_collide_mask();
CollideMask mask1 = node1->get_into_collide_mask();
// TODO
cout << node0->get_name() << " " << node1->get_name() << endl;
cout << mask0 << " " << mask1 << endl;
cout << ((mask0 & mask1) != 0) << endl;
return (mask0 & mask1) != 0;
}