Beispiel #1
0
void CollisionDetector::disablePair(dynamics::BodyNode* _node1,
                                    dynamics::BodyNode* _node2) {
  CollisionNode* collisionNode1 = getCollisionNode(_node1);
  CollisionNode* collisionNode2 = getCollisionNode(_node2);
  if (collisionNode1 && collisionNode2)
    getPairCollidable(collisionNode1, collisionNode2) = false;
}
Beispiel #2
0
bool CollisionDetector::detectCollision(dynamics::BodyNode* _node1,
                                        dynamics::BodyNode* _node2,
                                        bool _calculateContactPoints) {
  return detectCollision(getCollisionNode(_node1),
                         getCollisionNode(_node2),
                         _calculateContactPoints);
}
Beispiel #3
0
bool CollisionDetector::checkCollision(kinematics::BodyNode* _node1,
                                       kinematics::BodyNode* _node2,
                                       bool _calculateContactPoints)
{
    return checkCollision(getCollisionNode(_node1),
                          getCollisionNode(_node2),
                          _calculateContactPoints);
}
void GeometryCollisionParticleSystemAffector::affect(ParticleSystemRefPtr System, const Time& elps)
{
	UInt32 NumParticles(System->getNumParticles());
	
	Line ray;
    IntersectAction *iAct = IntersectAction::create();
	Pnt3f ParticlePos, ParticleSecPos;
    

	Real32 HitT(0.0f);
	for(UInt32 i(0) ; i<NumParticles ; ++i)
	{
		ParticlePos = System->getPosition(i);
		ParticleSecPos = System->getSecPosition(i);
		ray.setValue(ParticleSecPos, ParticlePos);
		iAct->setLine(ray);
		iAct->apply(getCollisionNode());
	    
		if (iAct->didHit())
		{
			HitT = iAct->getHitT();
			if(HitT > 0.0f && HitT*HitT<ParticlePos.dist2(ParticleSecPos))
			{
				produceParticleCollision(System, i, iAct);
                for(UInt32 j(0) ; j<getMFCollisionAffectors()->size(); ++j)
                {
                    getCollisionAffectors(i)->affect(System,i,elps);
                }
			}
		}
	}
}
Beispiel #5
0
void CollisionDetector::addCollisionSkeletonNode(dynamics::BodyNode* _bodyNode,
                                                 bool _isRecursive) {
  assert(_bodyNode != NULL && "Invalid body node.");

  // If this collision detector already has collision node for _bodyNode, then
  // we do nothing.
  if (getCollisionNode(_bodyNode) != NULL) {
    std::cout << "The collision detector already has a collision node for "
              << "body node [" << _bodyNode->getName() << "]." << std::endl;
    return;
  }

  // Create collision node and set index
  CollisionNode* collNode = createCollisionNode(_bodyNode);
  collNode->setIndex(mCollisionNodes.size());

  // Add the collision node to collision node list
  mCollisionNodes.push_back(collNode);

  // Add the collision node to map (BodyNode -> CollisionNode)
  mBodyCollisionMap[_bodyNode] = collNode;

  // Add collidable pairs for the collision node
  mCollidablePairs.push_back(
        std::vector<bool>(mCollisionNodes.size() - 1, true));

  if (_isRecursive) {
    for (int i = 0; i < _bodyNode->getNumChildBodyNodes(); i++)
      addCollisionSkeletonNode(_bodyNode->getChildBodyNode(i), true);
  }
}
Beispiel #6
0
void CollisionDetector::removeCollisionSkeletonNode(
    dynamics::BodyNode* _bodyNode, bool _isRecursive) {
  assert(_bodyNode != NULL && "Invalid body node.");

  // If a collision node is already created for _bodyNode, then we just return
  CollisionNode* collNode = getCollisionNode(_bodyNode);
  if (collNode == NULL) {
    std::cout << "The collision detector does not have any collision node "
              << "for body node [" << _bodyNode->getName() << "]."
              << std::endl;
    return;
  }

  // Update index of collision nodes.
  int iCollNode = collNode->getIndex();
  for (int i = iCollNode + 1; i < mCollisionNodes.size(); ++i)
    mCollisionNodes[i]->setIndex(mCollisionNodes[i]->getIndex() - 1);

  // Remove collNode from mCollisionNodes
  mCollisionNodes.erase(remove(mCollisionNodes.begin(), mCollisionNodes.end(),
                               collNode),
                        mCollisionNodes.end());

  // Remove collNode-_bodyNode pair from mBodyCollisionMap
  mBodyCollisionMap.erase(_bodyNode);

  // Delete collNode
  delete collNode;

  // Update mCollidablePairs
  for (int i = iCollNode + 1; i < mCollidablePairs.size(); ++i) {
    for (int j = 0; j < iCollNode; ++j)
      mCollidablePairs[i-1][j] = mCollidablePairs[i][j];
    for (int j = iCollNode + 1; j < mCollidablePairs[i].size(); ++j)
      mCollidablePairs[i-1][j-1] = mCollidablePairs[i][j];
  }
  mCollidablePairs.pop_back();

  if (_isRecursive) {
    for (int i = 0; i < _bodyNode->getNumChildBodyNodes(); i++)
      removeCollisionSkeletonNode(_bodyNode->getChildBodyNode(i), true);
  }
}
Beispiel #7
0
void CollisionDetector::enablePair(kinematics::BodyNode* _node1, kinematics::BodyNode* _node2) {
    CollisionNode* collisionNode1 = getCollisionNode(_node1);
    CollisionNode* collisionNode2 = getCollisionNode(_node2);
    if(collisionNode1 && collisionNode2)
        getPairCollidable(collisionNode1, collisionNode2) = true;
}