Collision Avoidance using ogre3 on visual 2010

我与ogre3d和visual 2010一起工作,我有两个机器人彼此相邻走路的实现避免碰撞的问题,我想:第一个机器人停下来,athor继续走,然后第一个机器人走。


The most simple way of doing it with Ogre is checking intersection between your Entities' axis aligned bounding boxes.

For example:

  Ogre::Entity *robot1(NULL), *robot2(NULL);
  Ogre::AnimationState* move_anim(NULL);
  Ogre::Real stop_t_s(0.0f);

  void app::init() {
    robot1 = scene_mgr_->createEntity("robot.mesh");
    robot2 = scene_mgr_->createEntity("robot.mesh");
    move_anim = robot1->getAnimationState("Walk");
    move_anim->setLoop(true);
    move_anim->setEnabled(true);
    root_->startRendering();
  }
  void app::frameRenderingQueued(const Ogre::FrameEvent& evt) {
    if (move_anim->getEnabled()) {
      move_anim->addTime(evt.timeSinceLastFrame);
    }
    else {
      stop_t_s += evt.timeSinceLastFrame;
      if (stop_t_s > 2.0f) {
        move_anim->setEnabled(true);
        stop_t_s = 0.0f;
      }
    }
    if (robot1->getBoundingBox().intersects(robot2->getBoundingBox())) {
      move_anim->setEnabled(false);
      /* more collide routine */
    }
    else {
      /* normal routine */
    }
  }

If you want to have more precise collision shapes you should consider using a physics engine to handle it


Update: I've added an example for stopping the "Walk" animation in robot.mesh upon collision and restart it after 2 seconds. For more details on animation control see Ogre Intermediate Tutorial 1

链接地址: http://www.djcxy.com/p/17118.html

上一篇: iPad Safari事件处理程序问题

下一篇: 在visual 2010上使用ogre3避免碰撞