Exemple #1
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);
  }
}
Exemple #2
0
CollisionNode *SceneGraph::findCollisionNode(char *name) {
	if (!name || strlen(name) <= 0)
		return NULL;
	for (CollisionNode *node = findCollisionNode(); node; node = node->nextTraversal()) {
		const char *nodeName = node->getName();
		if (nodeName && strlen(nodeName)) {
			if (!strcmp(name, nodeName))
				return node;
		}
	}
	return NULL;
}
Exemple #3
0
void CollisionDetector::addCollisionSkeletonNode(kinematics::BodyNode* _bodyNode,
                                                 bool _recursive) {
    CollisionNode* collNode = createCollisionNode(_bodyNode);
    collNode->setIndex(mCollisionNodes.size());
    mCollisionNodes.push_back(collNode);
    mBodyCollisionMap[_bodyNode] = collNode;
    mCollidablePairs.push_back(vector<bool>(mCollisionNodes.size() - 1, true));

    if(_recursive) {
        for (int i = 0; i < _bodyNode->getNumChildJoints(); i++)
            addCollisionSkeletonNode(_bodyNode->getChildNode(i), true);
    }
}
void Character::initNodePath(Player *player,
							 CollisionTraverser *traverser,
							 CollisionTraverser *traverserQueue,
							 CollisionHandlerQueue *colliHandlerQueue,
							 Filename charDir,
							 Filename charWalkDir,
							 Filename charStandDir,
							 std::string lodNodename,
							 std::string colliNodeName) {
	LODNode *lod = new LODNode(lodNodename);
	NodePath lodNodePath(lod);
	lodNodePath.reparent_to(player->getWindow()->get_render());
	lod->add_switch(50, 0);

	// load character and place on the grounds
	NodePath character = player->getWindow()->load_model(player->getPanda()->get_models(), charDir);
	character.reparent_to(lodNodePath);
	character.set_scale(0.203, 0.203, 0.203);

	// add collision node to character
	CollisionNode *collNode = new CollisionNode(colliNodeName);
	collNode->add_solid(new CollisionSphere(0, 0, 0, 2.5));
	NodePath fromObj = character.attach_new_node(collNode);
	CollisionHandlerPusher *colliHandlerPusher = new CollisionHandlerPusher();
	colliHandlerPusher->add_collider(fromObj, character);

	traverser->add_collider(fromObj, colliHandlerPusher);
	traverserQueue->add_collider(fromObj, colliHandlerQueue);

	// Load the walk animation
	player->getWindow()->load_model(character, charStandDir);
	player->getWindow()->load_model(character, charWalkDir);

	// bind animation
	auto_bind(character.node(), animCollection);

	stopMoving();
	nodePath = character;
	
	standAnimName = animCollection.get_anim_name(0);
	walkAnimName = animCollection.get_anim_name(1);

	// get animation names
	//for(int i = 0; i < animCollection.get_num_anims(); i++)
	//	cout << animCollection.get_anim_name(i) << endl;
}
Exemple #5
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);
  }
}